Gaudi Framework, version v22r2

Home   Generated: Tue May 10 2011

ParseVct.cpp

Go to the documentation of this file.
00001 // $Id: $
00002 // ============================================================================
00003 // Include files 
00004 // ============================================================================
00005 // STD & STL 
00006 // ============================================================================
00007 #include <map>
00008 // ============================================================================
00009 // GaudiKernel
00010 // ============================================================================
00011 #include "GaudiKernel/VectorsAsProperty.h"
00012 #include "GaudiKernel/Parsers.h"
00013 #include "GaudiKernel/ToStream.h"
00014 // ============================================================================
00015 // Local
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 /*  parse 3D-point 
00053  *  @param result (output) the parsed point 
00054  *  @param input  (input)  the input string 
00055  *  @return status code 
00056  *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00057  *  @date 2009-09-05
00058  */
00059 // ============================================================================
00060 StatusCode Gaudi::Parsers::parse 
00061 ( Gaudi::XYZPoint&   result  , 
00062   const std::string& input   ) 
00063 {
00064   // the grammar 
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 ; } // RETURN 
00071   
00072   // try map:
00073   MAP m ;
00074   StatusCode sc = parse ( m , input ) ;
00075   
00076   if ( sc.isFailure () ) { return sc                  ; } // RETURN 
00077   if ( 3 != m.size  () ) { return StatusCode::FAILURE ; } // REUTRN
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 ; } // RETURN 
00086   
00087   result.SetXYZ ( x->second , 
00088                   y->second ,
00089                   z->second ) ;
00090   
00091   return StatusCode::SUCCESS ;
00092   
00093 }
00094 // ============================================================================
00095 /*  parse 3D-vector 
00096  *  @param result (output) the parsed vector
00097  *  @param input  (input)  the input string 
00098  *  @return status code 
00099  *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00100  *  @date 2009-09-05
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 ; }                               // RETURN 
00112   
00113   result = point ;
00114   return StatusCode::SUCCESS ;                                       // RETURN  
00115 }
00116 #ifndef _WIN32
00117 // ============================================================================
00118 /*  parse LorentzVector
00119  *  @param result (output) the parsed lorentz vector  
00120  *  @param input  (input)  the input string 
00121  *  @return status code 
00122  *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00123  *  @date 2009-09-05
00124  */
00125 // ============================================================================
00126 StatusCode Gaudi::Parsers::parse 
00127 ( Gaudi::LorentzVector&  result  , 
00128   const std::string&     input   ) 
00129 {
00130   // the grammar 
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 ; } // RETURN 
00138   
00139   // try map:
00140   MAP m ;
00141   StatusCode sc = parse ( m , input ) ;
00142   
00143   if ( sc.isFailure () ) { return sc                  ; } // RETURN 
00144   if ( 4 != m.size  () ) { return StatusCode::FAILURE ; } // REUTRN
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 ; } // RETURN 
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 /*  parse the vector of points 
00168  *  @param resut (OUTPUT) the parser vector 
00169  *  @param input (INPIUT) the string to be parsed 
00170  *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00171  *  @date 2009-09-05
00172  */
00173 // ============================================================================
00174 StatusCode Gaudi::Parsers::parse 
00175 ( std::vector<Gaudi::XYZPoint>&  result  , 
00176   const std::string&             input   ) 
00177 {
00178   result.clear() ;
00179   
00180   // the grammar 
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 ; }                                  // RETURN 
00187   //
00188   return StatusCode::FAILURE ;
00189 }
00190 // ============================================================================
00191 /*  parse the vector of vectors 
00192  *  @param resut (OUTPUT) the parser vector 
00193  *  @param input (INPIUT) the string to be parsed 
00194  *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00195  *  @date 2009-09-05
00196  */
00197 // ============================================================================
00198 StatusCode Gaudi::Parsers::parse 
00199 ( std::vector<Gaudi::XYZVector>&  result  , 
00200   const std::string&              input   ) 
00201 {
00202   result.clear() ;
00203   
00204   // the grammar 
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 ; }                                  // RETURN 
00211   //
00212   return StatusCode::FAILURE ;
00213 }
00214 #ifndef _WIN32
00215 // ============================================================================
00216 /*  parse the vector of vectors 
00217  *  @param resut (OUTPUT) the parser vector 
00218  *  @param input (INPIUT) the string to be parsed 
00219  *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00220  *  @date 2009-09-05
00221  */
00222 // ============================================================================
00223 StatusCode Gaudi::Parsers::parse 
00224 ( std::vector<Gaudi::LorentzVector>&  result  , 
00225   const std::string&              input   ) 
00226 {
00227   result.clear() ;
00228   
00229   // the grammar 
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 ; }                                  // RETURN 
00236   //
00237   return StatusCode::FAILURE ;
00238 }
00239 #endif
00240 // ============================================================================
00241 // print XYZ-point 
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 // print XYZ-vector 
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 // print LorentzVector 
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 // The END 
00292 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Tue May 10 2011 18:53:45 for Gaudi Framework, version v22r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004