LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Operators.h
Go to the documentation of this file.
1 #ifndef LCIO_OPERATORS_H
2 #define LCIO_OPERATORS_H 1
3 
5 // Define operators for convenient printing of LCIO objects.
6 //
7 //
8 // @author J Engels, H. Hoelbe
9 // @version $Id: Operators.h,v 1.8.2.1 2011-03-04 14:09:07 engels Exp $
11 
12 
15 #include "EVENT/MCParticle.h"
16 #include "EVENT/SimTrackerHit.h"
17 #include "EVENT/TrackerHit.h"
18 #include "EVENT/TrackerHitPlane.h"
20 #include "EVENT/Track.h"
21 #include "EVENT/TrackState.h"
22 #include "EVENT/Cluster.h"
23 #include "EVENT/CalorimeterHit.h"
24 #include "EVENT/LCFlag.h"
25 #include "EVENT/LCIntVec.h"
26 #include "EVENT/LCRunHeader.h"
28 //#include "EVENT/TPCHit.h"
29 #include "EVENT/TrackerPulse.h"
30 #include "EVENT/LCFloatVec.h"
31 #include "EVENT/LCObject.h"
32 #include "EVENT/TrackerRawData.h"
33 #include "EVENT/LCCollection.h"
34 #include "EVENT/LCGenericObject.h"
35 #include "EVENT/LCParameters.h"
36 #include "EVENT/TrackerData.h"
37 #include "EVENT/LCEvent.h"
38 #include "EVENT/LCIO.h"
39 #include "EVENT/LCRelation.h"
40 #include "EVENT/ParticleID.h"
41 #include "EVENT/Vertex.h"
42 //#include "EVENT/LCStrVec.h"
43 
44 
45 #include <iostream>
46 #include <iomanip>
47 #include <string>
48 #include <sstream>
49 
50 
51 namespace UTIL{
52 
53  //template to enable the use of the operator << for a "one-line" output of an object.
54  //since there are two ostream& << operators for sending an object to the output stream this
55  //template works like a "wrapper class" so that the correct operator can be triggered for the
56  //respective detailed/short output
57 /*
58  template <class T> struct lcio_short{
59  const T* obj;
60  lcio_short(const T* t) : obj(p) {}
61  };
62 */
63  template <class T>
64  class lcio_short{
65  public:
66  const T* obj;
68  lcio_short(const T* t, const EVENT::LCCollection* b=NULL) : obj(t), col(b) {}
69  //lcio_short(const T* t) : obj(t) {col = NULL;}
70  };
71 
72 
73  //template to enable a "one-line" output
74  template <class T> lcio_short<T> lcshort( const T* t, const EVENT::LCCollection* b=NULL){ return lcio_short<T>(t,b); }
75 
80  const std::string& header(const EVENT::Vertex *);
81  const std::string& tail(const EVENT::Vertex *);
82  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::Vertex>& sV);
83 
84 
85 
86 //hauke 2010 (start)
87  const std::string& header( const EVENT::MCParticle *);
88  const std::string& tail( const EVENT::MCParticle *);
89  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::MCParticle>& sV);
90 
91 
92 
93  const std::string& header( const EVENT::TrackerHit *);
94  const std::string& tail( const EVENT::TrackerHit *);
95  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::TrackerHit>& sV);
96 
97 
98  const std::string& header( const EVENT::TrackerHitPlane *);
99  const std::string& tail( const EVENT::TrackerHitPlane *);
100  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::TrackerHitPlane>& sV);
101 
102 
105  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::TrackerHitZCylinder>& sV);
106 
107 
108  const std::string& header( const EVENT::SimTrackerHit *);
109  const std::string& tail( const EVENT::SimTrackerHit *);
110  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::SimTrackerHit>& sV);
111 
112 
113  const std::string& header( const EVENT::CalorimeterHit *);
114  const std::string& tail( const EVENT::CalorimeterHit *);
115  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::CalorimeterHit>& sV);
116 
117 
119  const std::string& tail( const EVENT::SimCalorimeterHit *);
120  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::SimCalorimeterHit>& sV);
121 
122 
125  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::ReconstructedParticle> & );
126 
127 
128  const std::string& header( const EVENT::Track *);
129  const std::string& tail( const EVENT::Track *);
130  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::Track> &);
131 
132 
133  const std::string& header( const EVENT::TrackState *);
134  const std::string& tail( const EVENT::TrackState *);
135  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::TrackState> &);
136 
137 
138  const std::string& header( const EVENT::Cluster *);
139  const std::string& tail( const EVENT::Cluster *);
140  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::Cluster> &);
141 
142 
143  const std::string& header( const EVENT::LCRelation *);
144  const std::string& tail( const EVENT::LCRelation *);
145  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCRelation> &);
146 
147 
148  const std::string& header( const EVENT::LCFloatVec *);
149  const std::string& tail( const EVENT::LCFloatVec *);
150  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCFloatVec> &);
151 
152 
153  template <class T>
154  const std::string & header(){return header((T*)(0)); }
155  template <class T>
156  const std::string & tail(){return tail((T)(0)); }
157 
158 
159  template <class T>
160  class LCIO_LONG{
161  public:
162  LCIO_LONG() = default ;
163  LCIO_LONG(const LCIO_LONG& ) = default ;
164  LCIO_LONG& operator=(const LCIO_LONG& ) = default ;
165  LCIO_LONG(const T& o, const EVENT::LCCollection* c){ obj=&o; col=c;};
166  const T *object(void) const {return(obj);};
167  const EVENT::LCCollection *collection(void) const {return(col);};
168  private:
169  const T *obj{NULL};
170  const EVENT::LCCollection *col{NULL};
171  };
172 
173  //test:
174  template <class T>
175  LCIO_LONG<T> lcio_long(const T& o, const EVENT::LCCollection* c){return(LCIO_LONG<T>(o,c));}
176 
177 
178  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::CalorimeterHit> l);
179  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::Cluster> l);
180  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::Track> l);
181  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::TrackState> l);
182  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::ReconstructedParticle> ll);
183  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::SimCalorimeterHit> ll);
184  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::TrackerHit> ll);
185  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::TrackerHitPlane> ll);
186  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::TrackerHitZCylinder> ll);
187  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::SimTrackerHit> ll);
188  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::MCParticle> ll);
189  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::Vertex> ll);
190  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::LCRelation> ll);
191  std::ostream& operator<<( std::ostream& out, const LCIO_LONG<EVENT::LCFloatVec> ll);
192 
193 
194  const std::string& header( const EVENT::LCCollection *);
195  const std::string& tail( const EVENT::LCCollection *);
196  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCCollection> &);
197 
198 
199  const std::string& header( const EVENT::LCEvent *);
200  const std::string& tail( const EVENT::LCEvent *);
201  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCEvent> &);
202 
203 
204  const std::string& header( const EVENT::LCFlag *);
205  const std::string& tail( const EVENT::LCFlag *);
206  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCFlag> &);
207 
208 
209  const std::string& header( const EVENT::LCGenericObject *, const EVENT::LCCollection *v = NULL);
210  const std::string& tail( const EVENT::LCGenericObject *);
211  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCGenericObject> &);
212 
213 
214  const std::string& header( const EVENT::LCIntVec *);
215  const std::string& tail( const EVENT::LCIntVec *);
216  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCIntVec> &);
217 
218 
219  const std::string& header( const EVENT::LCObject *);
220  const std::string& tail( const EVENT::LCObject *);
221  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCObject> &);
222 
223 
224  const std::string& header( const EVENT::LCParameters *);
225  const std::string& tail( const EVENT::LCParameters *);
226  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCParameters> &);
227 
228 
229  const std::string& header( const EVENT::LCRunHeader *);
230  const std::string& tail( const EVENT::LCRunHeader *);
231  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCRunHeader> &);
232 
233 
234 /*
235  const std::string& header( const EVENT::LCStrVec &);
236  const std::string& tail( const EVENT::LCStrVec &);
237  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCStrVec> &);
238  std::ostream& operator<<( std::ostream& out, const EVENT::LCStrVec &);
239 */
240 
241  const std::string& header( const EVENT::ParticleID *);
242  const std::string& tail( const EVENT::ParticleID *);
243  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::ParticleID> &);
244 
245 
247  const std::string& tail( const EVENT::RawCalorimeterHit *);
248  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::RawCalorimeterHit> &);
249 
250 
251 // const std::string& header( const EVENT::TPCHit &);
252 // const std::string& tail( const EVENT::TPCHit &);
253 // std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::TPCHit> &);
254 // std::ostream& operator<<( std::ostream& out, const EVENT::TPCHit &);
255 
256  const std::string& header( const EVENT::TrackerData *);
257  const std::string& tail( const EVENT::TrackerData *);
258  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::TrackerData> &);
259 
260 
261  const std::string& header( const EVENT::TrackerPulse *);
262  const std::string& tail( const EVENT::TrackerPulse *);
263  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::TrackerPulse> &);
264 
265 
266  const std::string& header( const EVENT::TrackerRawData *);
267  const std::string& tail( const EVENT::TrackerRawData *);
268  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::TrackerRawData> &);
269 
270 
271  const std::string& header( const EVENT::LCIO *);
272  const std::string& tail( const EVENT::LCIO *);
273  std::ostream& operator<<( std::ostream& out, const UTIL::lcio_short<EVENT::LCIO> &);
274 
275 
276 
277 
278 /*
279  template <class T>
280  std::ostream& operator<<( std::ostream& out, const T obj) {
281  out << lcio_long<T>( obj , NULL ) ;
282  return out;
283  }
284 */
285 
286 
287  template <class T>
288  std::string toString(const T* obj) {
289  std::stringstream ss ;
290  ss << *obj ;
291  return ss.str() ;
292  }
293 
294 }//namespace
295 
296 // rete, 2019: Move stream operator overloads of EVENT
297 // objects in namespace EVENT, where they should be ...
298 // see: https://stackoverflow.com/questions/3623631/where-should-non-member-operator-overloads-be-placed
299 namespace EVENT {
300 
328  std::ostream& operator<<( std::ostream& out, const EVENT::LCIO &);
329 }
330 
331 #endif /* ifndef LCIO_OPERATORS_H */
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
lcio_short(const T *t, const EVENT::LCCollection *b=NULL)
Definition: Operators.h:68
const std::string & header(const EVENT::Vertex *)
operator for detailed output of a vertex object (e.g.
Definition: Operators.cc:2756
A generic tracker hit to be used by pattern recognition.
Definition: TrackerHit.h:26
LCIO_LONG(const T &o, const EVENT::LCCollection *c)
Definition: Operators.h:165
The generic simulated calorimeter hit.
The Vertex class for LCIO.
Definition: Vertex.h:34
std::string toString(const T *obj)
Definition: Operators.h:288
Interface for the run header.
Definition: LCRunHeader.h:23
lcio_short< T > lcshort(const T *t, const EVENT::LCCollection *b=NULL)
Definition: Operators.h:74
const EVENT::LCCollection * col
Definition: Operators.h:67
LCIO_LONG & operator=(const LCIO_LONG &)=default
A tracker hit on a planar surface - the hit is stored as: x,y,z, u(theta, phi), v(theta,phi), du, dv where (x,y,z) is the position in global cartesian coordinates, u,v are the the meassurement directions (unit vectors, spanning the plane) and du,dv are the measurement errors along these directions.
A generic simulated tracker hit.
Definition: SimTrackerHit.h:23
The LCIO TrackState class.
Definition: TrackState.h:26
const T * obj
Definition: Operators.h:169
TrackerData contains the corrected (calibrated) raw tracker data.
Definition: TrackerData.h:23
STL class.
const EVENT::LCCollection * collection(void) const
Definition: Operators.h:167
Tracker pulses as computed from TrackerData objects or as directly measured by a specific subdetector...
Definition: TrackerPulse.h:26
std::ostream & operator<<(std::ostream &out, const EVENT::Vertex &v)
Definition: Operators.cc:2980
Simple interface to store generic named parameters of type int, float and string. ...
Definition: LCParameters.h:28
const T * object(void) const
Definition: Operators.h:166
The LCIO cluster.
Definition: Cluster.h:30
The LCIO track class.
Definition: Track.h:33
T str(T...args)
Int vector used for user extensions.
Definition: LCIntVec.h:24
Float vector used for user extensions.
Definition: LCFloatVec.h:25
Simple interface to store generic user data.
LCIO_LONG()=default
const EVENT::LCCollection * col
Definition: Operators.h:170
The LCIO reconstructedParticle.
The LCIO Monte Carlo particle.
Definition: MCParticle.h:27
Persistent interface for LCIO ParticleIDs.
Definition: ParticleID.h:28
A single weighted relationship between two LCObjects.
Definition: LCRelation.h:29
const std::string & tail(const EVENT::Vertex *)
Definition: Operators.cc:2761
The generic calorimeter hit for real data (or simulation thereof).
LCIO_LONG< T > lcio_long(const T &o, const EVENT::LCCollection *c)
Definition: Operators.h:175
The main event interface.
Definition: LCEvent.h:31
Generic class for raw tracker data.
The generic collection used in LCIO.
Definition: LCCollection.h:29
A tracker hit on a cylindrical surface that runs parallel to the z-axis - the hit is stored as: x...
const T * obj
Definition: Operators.h:66
Helper class to create and interpret the 32-bit flag word in LCCollections.
Definition: LCFlag.h:19
The generic calorimeter hit - created from SimCalorimeterHit or RawCalorimeterHit.
STL class.