00001
00002
00003
00004
00005
00006
00007 #include <map>
00008
00009
00010
00011 #include "GaudiKernel/VectorsAsProperty.h"
00012 #include "GaudiKernel/Parsers.h"
00013 #include "GaudiKernel/ToStream.h"
00014
00015
00016
00017 #include "GaudiKernel/Parsers.icpp"
00018 #include "GaudiKernel/Grammars.h"
00019 #include "GaudiKernel/GrammarsForVectors.h"
00020
00026
00027 namespace
00028 {
00029
00030 typedef std::map<std::string,double> MAP ;
00031
00032 template <unsigned int N>
00033 inline MAP::const_iterator find
00034 ( const MAP& m ,
00035 const std::string (&keys)[N] )
00036 {
00037 for ( unsigned int i = 0 ; i < N ; ++ i )
00038 {
00039 MAP::const_iterator found = m.find ( keys[i] ) ;
00040 if ( m.end() != found ) { return found ; }
00041 }
00042 return m.end() ;
00043 }
00044
00045 const std::string s_X[] = { "x" , "X" , "px" , "pX" , "Px" , "PX" } ;
00046 const std::string s_Y[] = { "y" , "Y" , "py" , "pY" , "Py" , "PY" } ;
00047 const std::string s_Z[] = { "z" , "Z" , "pz" , "pZ" , "Pz" , "PZ" } ;
00048 const std::string s_E[] = { "t" , "T" , "e" , "E" } ;
00049
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 StatusCode Gaudi::Parsers::parse
00061 ( Gaudi::XYZPoint& result ,
00062 const std::string& input )
00063 {
00064
00065 Pnt3DGrammar<RealGrammar<double>,Gaudi::XYZPoint> g ;
00066
00067 if ( parse ( input.begin () ,
00068 input.end () ,
00069 g[var(result)=arg1],SkipperGrammar()).full )
00070 { return StatusCode::SUCCESS ; }
00071
00072
00073 MAP m ;
00074 StatusCode sc = parse ( m , input ) ;
00075
00076 if ( sc.isFailure () ) { return sc ; }
00077 if ( 3 != m.size () ) { return StatusCode::FAILURE ; }
00078
00079 MAP::const_iterator x = find ( m , s_X ) ;
00080 MAP::const_iterator y = find ( m , s_Y ) ;
00081 MAP::const_iterator z = find ( m , s_Z ) ;
00082
00083 if ( m.end() == x ||
00084 m.end() == y ||
00085 m.end() == z ) { return StatusCode::FAILURE ; }
00086
00087 result.SetXYZ ( x->second ,
00088 y->second ,
00089 z->second ) ;
00090
00091 return StatusCode::SUCCESS ;
00092
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 StatusCode Gaudi::Parsers::parse
00104 ( Gaudi::XYZVector& result ,
00105 const std::string& input )
00106 {
00107
00108 Gaudi::XYZPoint point ;
00109
00110 StatusCode sc = parse ( point , input ) ;
00111 if ( sc.isFailure() ){ return sc ; }
00112
00113 result = point ;
00114 return StatusCode::SUCCESS ;
00115 }
00116 #ifndef _WIN32
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 StatusCode Gaudi::Parsers::parse
00127 ( Gaudi::LorentzVector& result ,
00128 const std::string& input )
00129 {
00130
00131 Pnt4DGrammar<RealGrammar<double>,Gaudi::LorentzVector> g ;
00132
00133
00134 if ( parse ( input.begin () ,
00135 input.end () ,
00136 g[var(result)=arg1],SkipperGrammar()).full )
00137 { return StatusCode::SUCCESS ; }
00138
00139
00140 MAP m ;
00141 StatusCode sc = parse ( m , input ) ;
00142
00143 if ( sc.isFailure () ) { return sc ; }
00144 if ( 4 != m.size () ) { return StatusCode::FAILURE ; }
00145
00146 MAP::const_iterator x = find ( m , s_X ) ;
00147 MAP::const_iterator y = find ( m , s_Y ) ;
00148 MAP::const_iterator z = find ( m , s_Z ) ;
00149 MAP::const_iterator e = find ( m , s_E ) ;
00150
00151 if ( m.end() == x ||
00152 m.end() == y ||
00153 m.end() == z ||
00154 m.end() == e ) { return StatusCode::FAILURE ; }
00155
00156 result.SetXYZT ( x->second ,
00157 y->second ,
00158 z->second ,
00159 e->second ) ;
00160
00161 return StatusCode::SUCCESS ;
00162
00163 }
00164 #endif
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 StatusCode Gaudi::Parsers::parse
00175 ( std::vector<Gaudi::XYZPoint>& result ,
00176 const std::string& input )
00177 {
00178 result.clear() ;
00179
00180
00181 VectorGrammar < Pnt3DGrammar<RealGrammar<double>,Gaudi::XYZPoint> > g ;
00182
00183 if ( parse ( input.begin () ,
00184 input.end () ,
00185 g[var(result)=arg1],SkipperGrammar()).full )
00186 { return StatusCode::SUCCESS ; }
00187
00188 return StatusCode::FAILURE ;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198 StatusCode Gaudi::Parsers::parse
00199 ( std::vector<Gaudi::XYZVector>& result ,
00200 const std::string& input )
00201 {
00202 result.clear() ;
00203
00204
00205 VectorGrammar < Pnt3DGrammar<RealGrammar<double>,Gaudi::XYZVector> > g ;
00206
00207 if ( parse ( input.begin () ,
00208 input.end () ,
00209 g[var(result)=arg1],SkipperGrammar()).full )
00210 { return StatusCode::SUCCESS ; }
00211
00212 return StatusCode::FAILURE ;
00213 }
00214 #ifndef _WIN32
00215
00216
00217
00218
00219
00220
00221
00222
00223 StatusCode Gaudi::Parsers::parse
00224 ( std::vector<Gaudi::LorentzVector>& result ,
00225 const std::string& input )
00226 {
00227 result.clear() ;
00228
00229
00230 VectorGrammar < Pnt4DGrammar<RealGrammar<double>,Gaudi::LorentzVector> > g ;
00231
00232 if ( parse ( input.begin () ,
00233 input.end () ,
00234 g[var(result)=arg1],SkipperGrammar()).full )
00235 { return StatusCode::SUCCESS ; }
00236
00237 return StatusCode::FAILURE ;
00238 }
00239 #endif
00240
00241
00242
00243 std::ostream& Gaudi::Utils::toStream
00244 ( const Gaudi::XYZPoint& obj, std::ostream& s )
00245 {
00246 s << "( " ;
00247 toStream ( obj.X () , s ) ;
00248 s << " , " ;
00249 toStream ( obj.Y () , s ) ;
00250 s << " , " ;
00251 toStream ( obj.Z () , s ) ;
00252 s << " )" ;
00253 return s ;
00254 }
00255
00256
00257
00258 std::ostream& Gaudi::Utils::toStream
00259 ( const Gaudi::XYZVector& obj, std::ostream& s )
00260 {
00261 s << "( " ;
00262 toStream ( obj.X () , s ) ;
00263 s << " , " ;
00264 toStream ( obj.Y () , s ) ;
00265 s << " , " ;
00266 toStream ( obj.Z () , s ) ;
00267 s << " )" ;
00268
00269 return s ;
00270 }
00271
00272
00273
00274 std::ostream& Gaudi::Utils::toStream
00275 ( const Gaudi::LorentzVector& obj, std::ostream& s )
00276 {
00277
00278 s << "( " ;
00279 toStream ( obj.Px () , s , 12 ) ;
00280 s << " , " ;
00281 toStream ( obj.Py () , s , 12 ) ;
00282 s << " , " ;
00283 toStream ( obj.Pz () , s , 13 ) ;
00284 s << " , " ;
00285 toStream ( obj.E () , s , 14 ) ;
00286 s << " )" ;
00287
00288 return s ;
00289 }
00290
00291
00292