All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ParsersVct.cpp
Go to the documentation of this file.
1 // $Id:$
2 // ============================================================================
3 // Include files
4 // ============================================================================
6 // ============================================================================
8 #include "GaudiKernel/ToStream.h"
9 // ============================================================================
10 namespace
11 {
12  // ==========================================================================
13  typedef std::map<std::string,double> MAP ;
14 
15  template <unsigned int N>
16  inline MAP::const_iterator find
17  ( const MAP& m ,
18  const std::string (&keys)[N] )
19  {
20  for ( unsigned int i = 0 ; i < N ; ++ i )
21  {
22  MAP::const_iterator found = m.find ( keys[i] ) ;
23  if ( m.end() != found ) { return found ; }
24  }
25  return m.end() ;
26  }
27  // ==========================================================================
28  const std::string s_X[] = { "x" , "X" , "px" , "pX" , "Px" , "PX" } ;
29  const std::string s_Y[] = { "y" , "Y" , "py" , "pY" , "Py" , "PY" } ;
30  const std::string s_Z[] = { "z" , "Z" , "pz" , "pZ" , "Pz" , "PZ" } ;
31  const std::string s_E[] = { "t" , "T" , "e" , "E" } ;
32  // ==========================================================================
33 }
34 // ============================================================================
35 namespace Gaudi { namespace Parsers {
36  template<typename T1, typename T2>
37  inline StatusCode
38  parse_(ROOT::Math::PositionVector3D<T1,T2>& result, const std::string& input){
39  Skipper skipper;
41  IteratorT iter = input.begin(), end = input.end();
42  if (qi::phrase_parse( iter, end, g, skipper, result)){
43  return StatusCode::SUCCESS;
44  }
45  //@attention always
46  return true;
47  }
48  // ==========================================================================
49 
51  const std::string& input ) {
52  return parse_(result, input);
53  }
54 
55  // ==========================================================================
56  /* parse 3D-vector
57  * @param result (output) the parsed vector
58  * @param input (input) the input string
59  * @return status code
60  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
61  * @date 2009-09-05
62  */
64  ( Gaudi::XYZVector& result ,
65  const std::string& input )
66  {
67 
68  Gaudi::XYZPoint point ;
69  StatusCode sc = parse ( point , input ) ;
70  if ( sc.isFailure() ){ return sc ; } // RETURN
71  result = point ;
72  return StatusCode::SUCCESS ; // RETURN
73  }
74 
75  StatusCode parse(Gaudi::LorentzVector& result, const std::string& input) {
76  return parse_(result, input);
77  }
78 
79  // ==========================================================================
80  /* parse the vector of points
81  * @param resut (OUTPUT) the parser vector
82  * @param input (INPIUT) the string to be parsed
83  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
84  * @date 2009-09-05
85  */
86  // ==========================================================================
88  ( std::vector<Gaudi::XYZPoint>& result ,
89  const std::string& input )
90  {
91  result.clear() ;
92  return parse_(result, input);
93  }
94  // ==========================================================================
95  /* parse the vector of vectors
96  * @param resut (OUTPUT) the parser vector
97  * @param input (INPIUT) the string to be parsed
98  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
99  * @date 2009-09-05
100  */
101  // ==========================================================================
103  ( std::vector<Gaudi::XYZVector>& result ,
104  const std::string& input )
105  {
106  result.clear() ;
107  return parse_(result, input);
108  }
109 
110 #ifndef _WIN32
111  // ==========================================================================
112  /* parse the vector of vectors
113  * @param resut (OUTPUT) the parser vector
114  * @param input (INPIUT) the string to be parsed
115  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
116  * @date 2009-09-05
117  */
118  // ==========================================================================
120  ( std::vector<Gaudi::LorentzVector>& result ,
121  const std::string& input )
122  {
123  return parse_(result, input);
124  }
125 #endif
126 } } // namespace Gaudi::Parsers
127 // ============================================================================
128 // print XYZ-point
129 // ============================================================================
130 std::ostream& Gaudi::Utils::toStream
131 ( const Gaudi::XYZPoint& obj, std::ostream& s )
132 {
133  s << "( " ;
134  toStream ( obj.X () , s ) ;
135  s << " , " ;
136  toStream ( obj.Y () , s ) ;
137  s << " , " ;
138  toStream ( obj.Z () , s ) ;
139  s << " )" ;
140  return s ;
141 }
142 // ============================================================================
143 // print XYZ-vector
144 // ============================================================================
145 std::ostream& Gaudi::Utils::toStream
146 ( const Gaudi::XYZVector& obj, std::ostream& s )
147 {
148  s << "( " ;
149  toStream ( obj.X () , s ) ;
150  s << " , " ;
151  toStream ( obj.Y () , s ) ;
152  s << " , " ;
153  toStream ( obj.Z () , s ) ;
154  s << " )" ;
155 
156  return s ;
157 }
158 // ============================================================================
159 // print LorentzVector
160 // ============================================================================
161 std::ostream& Gaudi::Utils::toStream
162 ( const Gaudi::LorentzVector& obj, std::ostream& s )
163 {
164 
165  s << "( " ;
166  toStream ( obj.Px () , s , 12 ) ;
167  s << " , " ;
168  toStream ( obj.Py () , s , 12 ) ;
169  s << " , " ;
170  toStream ( obj.Pz () , s , 13 ) ;
171  s << " , " ;
172  toStream ( obj.E () , s , 14 ) ;
173  s << " )" ;
174 
175  return s ;
176 }
177 // ============================================================================
StatusCode parse_(ResultT &result, const std::string &input)
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
int N
Definition: IOTest.py:90
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition: ToStream.h:341
boost::spirit::position_iterator< string::const_iterator > IteratorT
the actual type of position iterator
Definition: Parsers.icpp:64
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Skipping spaces and comments.
Definition: Grammar.h:45
tuple end
Definition: IOTest.py:101
string s
Definition: gaudirun.py:210
dictionary g
Definition: gaudirun.py:364
ROOT::Math::PxPyPzEVector LorentzVector
Cartesian 4 Vector.
Definition: Vector4DTypes.h:34
implemenattiono fvarioud functions for streaming.
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:14
list i
Definition: ana.py:128
Declaration of parsing functions for various ROOT::Math objects to allow their usage as properties fo...