Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

ParsersVct.cpp

Go to the documentation of this file.
00001 // $Id:$
00002 // ============================================================================
00003 // Include files
00004 // ============================================================================
00005 #include "GaudiKernel/VectorsAsProperty.h"
00006 // ============================================================================
00007 #include "GaudiKernel/ParsersFactory.h"
00008 #include "GaudiKernel/ToStream.h"
00009 // ============================================================================
00010 namespace
00011 {
00012   // ==========================================================================
00013   typedef std::map<std::string,double> MAP   ;
00014 
00015   template <unsigned int N>
00016   inline MAP::const_iterator find
00017   ( const MAP&           m         ,
00018     const std::string  (&keys)[N]  )
00019   {
00020     for ( unsigned int i =  0 ; i < N ; ++ i )
00021     {
00022       MAP::const_iterator found = m.find ( keys[i] ) ;
00023       if ( m.end() != found ) { return found ; }
00024     }
00025     return m.end() ;
00026   }
00027   // ==========================================================================
00028   const std::string s_X[] = { "x" , "X" , "px" , "pX" , "Px" , "PX" } ;
00029   const std::string s_Y[] = { "y" , "Y" , "py" , "pY" , "Py" , "PY" } ;
00030   const std::string s_Z[] = { "z" , "Z" , "pz" , "pZ" , "Pz" , "PZ" } ;
00031   const std::string s_E[] = { "t" , "T" ,  "e" ,  "E"               } ;
00032   // ==========================================================================
00033 }
00034 // ============================================================================
00035 namespace Gaudi { namespace Parsers {
00036   template<typename T1, typename T2>
00037   inline StatusCode
00038   parse_(ROOT::Math::PositionVector3D<T1,T2>& result, const std::string& input){
00039     Skipper skipper;
00040     typename Grammar_<IteratorT, ROOT::Math::PositionVector3D<T1,T2>, Skipper >::Grammar g;
00041     IteratorT iter = input.begin(), end = input.end();
00042     if (qi::phrase_parse( iter, end, g, skipper, result)){
00043       return StatusCode::SUCCESS;
00044     }
00045     //@attention always
00046     return true;
00047   }
00048   // ==========================================================================
00049 
00050   StatusCode parse(Gaudi::XYZPoint& result,
00051                    const std::string& input  ) {
00052     return parse_(result, input);
00053   }
00054 
00055   // ==========================================================================
00056   /*  parse 3D-vector
00057    *  @param result (output) the parsed vector
00058    *  @param input  (input)  the input string
00059    *  @return status code
00060    *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00061    *  @date 2009-09-05
00062    */
00063   StatusCode parse
00064   ( Gaudi::XYZVector&  result  ,
00065     const std::string& input   )
00066   {
00067 
00068     Gaudi::XYZPoint point ;
00069     StatusCode sc = parse ( point , input ) ;
00070     if ( sc.isFailure() ){ return sc ; }                               // RETURN
00071     result = point ;
00072     return StatusCode::SUCCESS ;                                       // RETURN
00073   }
00074 
00075   StatusCode parse(Gaudi::LorentzVector& result, const std::string& input) {
00076     return parse_(result, input);
00077   }
00078 
00079   // ==========================================================================
00080   /*  parse the vector of points
00081    *  @param resut (OUTPUT) the parser vector
00082    *  @param input (INPIUT) the string to be parsed
00083    *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00084    *  @date 2009-09-05
00085    */
00086   // ==========================================================================
00087   StatusCode parse
00088   ( std::vector<Gaudi::XYZPoint>&  result  ,
00089     const std::string&             input   )
00090   {
00091     result.clear() ;
00092     return parse_(result, input);
00093   }
00094   // ==========================================================================
00095   /*  parse the vector of vectors
00096    *  @param resut (OUTPUT) the parser vector
00097    *  @param input (INPIUT) the string to be parsed
00098    *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00099    *  @date 2009-09-05
00100    */
00101   // ==========================================================================
00102   StatusCode parse
00103   ( std::vector<Gaudi::XYZVector>&  result  ,
00104     const std::string&              input   )
00105   {
00106     result.clear() ;
00107     return parse_(result, input);
00108   }
00109 
00110 #ifndef _WIN32
00111   // ==========================================================================
00112   /*  parse the vector of vectors
00113    *  @param resut (OUTPUT) the parser vector
00114    *  @param input (INPIUT) the string to be parsed
00115    *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00116    *  @date 2009-09-05
00117    */
00118   // ==========================================================================
00119   StatusCode parse
00120   ( std::vector<Gaudi::LorentzVector>&  result  ,
00121     const std::string&              input   )
00122   {
00123     return parse_(result, input);
00124   }
00125 #endif
00126 } } // namespace Gaudi::Parsers
00127 // ============================================================================
00128 // print XYZ-point
00129 // ============================================================================
00130 std::ostream& Gaudi::Utils::toStream
00131 ( const Gaudi::XYZPoint&  obj, std::ostream& s )
00132 {
00133   s << "( "  ;
00134   toStream ( obj.X () , s ) ;
00135   s << " , " ;
00136   toStream ( obj.Y () , s ) ;
00137   s << " , " ;
00138   toStream ( obj.Z () , s ) ;
00139   s << " )"  ;
00140   return s ;
00141 }
00142 // ============================================================================
00143 // print XYZ-vector
00144 // ============================================================================
00145 std::ostream& Gaudi::Utils::toStream
00146 ( const Gaudi::XYZVector&  obj, std::ostream& s )
00147 {
00148   s << "( "  ;
00149   toStream ( obj.X () , s ) ;
00150   s << " , " ;
00151   toStream ( obj.Y () , s ) ;
00152   s << " , " ;
00153   toStream ( obj.Z () , s ) ;
00154   s << " )"  ;
00155 
00156   return s ;
00157 }
00158 // ============================================================================
00159 // print LorentzVector
00160 // ============================================================================
00161 std::ostream& Gaudi::Utils::toStream
00162 ( const Gaudi::LorentzVector&  obj, std::ostream& s )
00163 {
00164 
00165   s << "( " ;
00166   toStream ( obj.Px () , s , 12 ) ;
00167   s << " , " ;
00168   toStream ( obj.Py () , s , 12 ) ;
00169   s << " , " ;
00170   toStream ( obj.Pz () , s , 13 ) ;
00171   s << " , "  ;
00172   toStream ( obj.E  () , s , 14 ) ;
00173   s << " )"  ;
00174 
00175   return s ;
00176 }
00177 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:34 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004