LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lStdHep.hh
Go to the documentation of this file.
1 //
3 // Header file for a light-weight StdHep class.
4 // This class is based on the light-weight XDR class lXDR,
5 // and parses/writes StdHep files. It was mainly written,
6 // to provide a faster alternative to the more cumdersome
7 // methods using mcfio in CLHEP.
8 //
9 // W.G.J. Langeveld, 24 May 2002
10 //
11 // Release notes:
12 // - Version 1.0 (23-Oct-2003, WGL):
13 // o Implements "read" but not "write" functions
14 // o Standalone (previous versions depended on sgarray,
15 // which comes with the "vec" package in the Lelaps
16 // distribution). It now uses one std::vector.
17 // - Version 1.1 (18-Mar-2004, WGL):
18 // o Fixed a file positioning bug which made it fail to
19 // read some files.
20 // - Version 1.2 (18-Mar-2004, WGL):
21 // o Fixed a bug where it would skip one event at the
22 // boundaries between event blocks.
23 // - Version 1.3 (19-Mar-2004, WGL):
24 // o Improved handling of end-of-file. Now, when there
25 // are no more events, readEvent() returns an error.
26 // The error code is LSH_ENDOFFILE.
27 // - Version 1.4 (30-Mar-2004, WGL):
28 // o Fixed memory leak
29 // - Version 1.5 (10-Aug-2004, WGL):
30 // o Added numEvents() method by request.
31 //
33 #ifndef LSTDHEP__HH
34 #define LSTDHEP__HH
35 
36 #include "UTIL/lXDR.hh"
37 #include <vector>
38 
39 
40 namespace UTIL{
41 
42 //
43 // MCFIO block codes
44 //
45 #define LSH_GENERIC 0
46 #define LSH_FILEHEADER 1 // supported 5/28/2002
47 #define LSH_EVENTTABLE 2 // supported 5/28/2002
48 #define LSH_SEQUENTIALHEADER 3
49 #define LSH_EVENTHEADER 4 // supported 5/28/2002
50 #define LSH_NOTHING 5
51 //
52 // lStdHepError codes
53 //
54 #define LSH_SUCCESS 0
55 #define LSH_BLOCKERROR 101
56 #define LSH_NOEVENTTABLE 102
57 #define LSH_NOEVENT 103
58 #define LSH_NOTSUPPORTED 104
59 #define LSH_EVTABLECORRUPT 105
60 #define LSH_ENDOFFILE 106
61 //
62 // StdHep block codes
63 //
64 #define LSH_STDHEP 101 // supported 5/28/2002
65 #define LSH_OFFTRACKARRAYS 102
66 #define LSH_OFFTRACKSTRUCT 103
67 #define LSH_TRACEARRAYS 104
68 #define LSH_STDHEPM 105
69 #define LSH_STDHEPBEG 106 // supported 5/28/2002
70 #define LSH_STDHEPEND 107 // supported 5/28/2002
71 #define LSH_STDHEPCXX 108
72 #define LSH_STDHEPEV4 201 // supported 1/23/2006
73 
75 //
76 // The basic lStdHep track. Note that access controls are
77 // unneeded here since this is an old standard unlikely to
78 // change.
79 //
81 struct lStdTrack {
82  double X;
83  double Y;
84  double Z;
85  double T;
86  double Px;
87  double Py;
88  double Pz;
89  double E;
90  double M;
91  long pid;
92  long status;
93  long mother1;
94  long mother2;
95  long daughter1;
96  long daughter2;
97 };
98 
99 
101 //
102 // The basic lStdHep event
103 //
105 struct lStdEvent : public std::vector<lStdTrack> {
106  long evtNum;
107  long nTracks(void) { return(size()); };
108 };
109 
111 //
112 // The lStdHep class is the "handle" for the StdHep file, and
113 // provides the access mechanism to the events.
114 //
116 class lStdHep : public lXDR {
117 private:
118 //
119 // The current version/revision is:
120 //
121  enum { MAJOR = 2, MINOR = 0, DAY = 23, MONTH = 1, YEAR = 2006 };
122 // ========================================================
123 public:
124  static int getMajor(void) { return(MAJOR); };
125  static int getMinor(void) { return(MINOR); };
126  static const char *getText(void) {
127  static char buff[80];
128  sprintf(buff, "lStdHep version %d.%d (%02d.%02d.%d) by W.G.J. Langeveld, SLAC",
129  MAJOR, MINOR, DAY, MONTH, YEAR);
130  return(buff);
131  };
132 
133 
134 //
135 // Constructors, destructor
136 // ------------------------
137 // Constructor opens file, destructor closes file. Once opened for
138 // reading, the file cannot be written to, and v.v.
139 //
140  lStdHep(const char *filename = 0, bool open_for_write = false);
141 //
142 // Prevent copying:
143 //
144 private:
145  lStdHep(const lStdHep &);
146 public:
147  virtual ~lStdHep();
148 //
149 // Prevent assignment:
150 //
151 private:
152  lStdHep &operator=(const lStdHep &);
153 public:
154 //
155 // See if there are more events
156 //
157  bool more(void);
158 //
159 // Event reading functions. They return the last error encountered,
160 // or LSH_SUCCESS.
161 // - Read the next event into the event buffer:
162 //
163  long readEvent(void);
164 //
165 // - Fill the provided lStdEvent with the current event:
166 //
167  long getEvent(lStdEvent &lse) const;
168 //
169 // - Combine readEvent() with getEvent():
170 //
171  long readEvent(lStdEvent &lse);
172 //
173 // Get the number of events in the input file
174 //
175  long numEvents() const { return(numevts); };
176  long numEventsExpected() const { return(numevts_expect); };
177 
178 //
179 // Direct access to the event buffer. Note that using readEvent(void)
180 // in combination with the functions below is faster than using
181 // readEvent(lStdEvent &), especially when only a few quantities are
182 // needed.
183 //
184  long blockId() const { return(event.blockid); };
185  long nTracks(void) const { return(event.nhep); };
186  long evtNum(void) const { return(event.nevhep); };
187  long runNum(void) const { return(event.runnum); };
188 
189  double X(int i) const { return(event.vhep[i * 4 + 0]); };
190  double Y(int i) const { return(event.vhep[i * 4 + 1]); };
191  double Z(int i) const { return(event.vhep[i * 4 + 2]); };
192  double T(int i) const { return(event.vhep[i * 4 + 3]); };
193  double Px(int i) const { return(event.phep[i * 5 + 0]); };
194  double Py(int i) const { return(event.phep[i * 5 + 1]); };
195  double Pz(int i) const { return(event.phep[i * 5 + 2]); };
196  double E(int i) const { return(event.phep[i * 5 + 3]); };
197  double M(int i) const { return(event.phep[i * 5 + 4]); };
198  long pid(int i) const { return(event.idhep[i]); };
199  long status(int i) const { return(event.isthep[i]); };
200  long mother1(int i) const { return(event.jmohep[i + i + 0]); };
201  long mother2(int i) const { return(event.jmohep[i + i + 1]); };
202  long daughter1(int i) const { return(event.jdahep[i + i + 0]); };
203  long daughter2(int i) const { return(event.jdahep[i + i + 1]); };
204  double eventweight(void) const { return(event.eventweight); };
205  double alphaQED(void) const { return(event.alphaqed); };
206  double alphaQCD(void) const { return(event.alphaqcd); };
207  double scale(int i, int j) const { return(event.scale[i * 10 + j] ); };
208  double spinX(int i) const { return(event.spin[i * 3 + 0] ); };
209  double spinY(int i) const { return(event.spin[i * 3 + 1] ); };
210  double spinZ(int i) const { return(event.spin[i * 3 + 2] ); };
211  long colorflow(int i, int j) const { return(event.colorflow[i * 2 + j] ); };
212  long idrup(void) const { return(event.idrup); };
213 //
214 // Call this to make sure you can call things like scale, spin and colorflow:
215 //
216  bool isStdHepEv4(void) const { return(event.scale != 0); };
217 //
218 // Event writing functions. They return the last error encountered,
219 // or LSH_SUCCESS.
220 // - Write the current event buffer to thefile:
221 //
222  long writeEvent(void);
223 //
224 // - Fill the event buffer with the data from the provided lStdEvent:
225 //
226  long setEvent(const lStdEvent &lse);
227 //
228 // - Combine setEvent() with writeEvent():
229 //
230  long writeEvent(lStdEvent &lse);
231 //
232 // Direct access to the event buffer.
233 //
234  void setNTracks(long n) { event.nhep = n; return; };
235  void setEvtNum(long n) { event.nevhep = n; return; };
236 
237  void setX(int i, double x) { event.vhep[i * 4 + 0] = x; return; };
238  void setY(int i, double y) { event.vhep[i * 4 + 1] = y; return; };
239  void setZ(int i, double z) { event.vhep[i * 4 + 2] = z; return; };
240  void setT(int i, double t) { event.vhep[i * 4 + 3] = t; return; };
241  void setPx(int i, double px) { event.phep[i * 5 + 0] = px; return; };
242  void setPy(int i, double py) { event.phep[i * 5 + 1] = py; return; };
243  void setPz(int i, double pz) { event.phep[i * 5 + 2] = pz; return; };
244  void setE(int i, double e) { event.phep[i * 5 + 3] = e; return; };
245  void setM(int i, double m) { event.phep[i * 5 + 4] = m; return; };
246  void setPid(int i, long aPid) { event.idhep[i] = aPid; return; };
247  void setStatus(int i, long s) { event.isthep[i] = s; return; };
248  void setMother1(int i, long n) { event.jmohep[i + i + 0] = n; return; };
249  void setMother2(int i, long n) { event.jmohep[i + i + 1] = n; return; };
250  void setDaughter1(int i, long n) { event.jdahep[i + i + 0] = n; return; };
251  void setDaughter2(int i, long n) { event.jdahep[i + i + 1] = n; return; };
252 //
253 // Informational printout
254 //
255  void printFileHeader(FILE *fp = 0);
256  void printBeginRunRecord(FILE *fp = 0);
257  void printEndRunRecord(FILE *fp = 0);
258  void printEventTable(FILE *fp = 0);
259  void printEventHeader(FILE *fp = 0);
260  void printEvent(FILE *fp = 0);
261  void printTrack(int i, FILE *fp = 0);
262 
263 private:
264  long readFileHeader(void);
265 //
266 // File Header
267 //
268  long ntot;
269  const char *version;
270  const char *title;
271  const char *comment;
272  const char *date;
273  const char *closingDate;
274 
276  long numevts;
278  long dimTable;
279  long nNTuples;
280  long nBlocks;
281  long *blockIds;
282  const char **blockNames;
283 //
284 // Event table
285 //
286  class EventTable {
287  public:
288  EventTable();
290  EventTable(const EventTable&) = delete ;
292  EventTable& operator=(const EventTable&) = delete ;
293  ~EventTable();
294  void cleanup(void);
295  long read(lStdHep &ls);
296  long print(FILE *fp);
297 //
298 // ...Empty flag
299 //
300  long isEmpty;
301 //
302 // Index into the event table
303 //
304  long ievt;
305 //
306 // ...MCFIO header
307 //
308  long blockid;
309  long ntot;
310  const char *version;
311 //
312 // ...Location of next table
313 //
315 //
316 // ...The event table itself
317 //
318  long numEvts;
319  long *evtnums;
320  long *storenums;
321  long *runnums;
322  long *trigMasks;
323  long *ptrEvents;
324  };
326 //
327 // The event
328 //
329  class Event {
330  public:
331  Event();
333  Event(const Event&) = delete ;
335  Event& operator=(const Event&) = delete ;
336  ~Event();
337  void cleanup(void);
338  long read(lStdHep &ls);
339  long printHeader(FILE *fp);
340  long print(FILE *fp);
341 //
342 // ...Empty flag
343 //
344  long isEmpty;
345 //
346 // ...MCFIO header
347 //
348  long blockid;
349  long ntot;
350  const char *version;
351 //
352 // ...Event header:
353 //
354  long evtnum;
355  long storenum;
356  long runnum;
357  long trigMask;
358  long nBlocks;
359  long dimBlocks;
360  long nNTuples;
362  long *blockIds;
363  long *ptrBlocks;
364 //
365 // ...Event:
366 //
367  long nevhep;
368  long nhep;
369  long *isthep;
370  long *idhep;
371  long *jmohep;
372  long *jdahep;
373  double *phep;
374  double *vhep;
375 //
376 // ...New for STDHEPEV4:
377 //
378  double eventweight;
379  double alphaqed;
380  double alphaqcd;
381  double *scale;
382  double *spin;
383  long *colorflow;
384  long idrup;
385 //
386 // ...Begin run record:
387 //
388  long bnevtreq;
389  long bnevtgen;
390  long bnevtwrt;
391  double bstdecom;
392  double bstdxsec;
393  double bstdseed1;
394  double bstdseed2;
395 //
396 // ...End run record:
397 //
398  long enevtreq;
399  long enevtgen;
400  long enevtwrt;
401  double estdecom;
402  double estdxsec;
403  double estdseed1;
404  double estdseed2;
405  };
406  Event event{};
407 };
408 
409 } // end namespace
410 
411 #endif
double Y(int i) const
Definition: lStdHep.hh:190
long mother2(int i) const
Definition: lStdHep.hh:201
void setDaughter1(int i, long n)
Definition: lStdHep.hh:250
double alphaQCD(void) const
Definition: lStdHep.hh:206
bool more(void)
Definition: lStdHep.cc:130
long daughter1
Definition: lStdHep.hh:95
long getEvent(lStdEvent &lse) const
Definition: lStdHep.cc:176
long daughter1(int i) const
Definition: lStdHep.hh:202
double X(int i) const
Definition: lStdHep.hh:189
void printBeginRunRecord(FILE *fp=0)
Definition: lStdHep.cc:118
void printFileHeader(FILE *fp=0)
Definition: lStdHep.cc:60
void setPid(int i, long aPid)
Definition: lStdHep.hh:246
long mother1(int i) const
Definition: lStdHep.hh:200
double scale(int i, int j) const
Definition: lStdHep.hh:207
Event event
Definition: lStdHep.hh:406
long numEventsExpected() const
Definition: lStdHep.hh:176
void cleanup(void)
Definition: lStdHep.cc:380
void printTrack(int i, FILE *fp=0)
Definition: lStdHep.cc:106
long daughter2(int i) const
Definition: lStdHep.hh:203
double alphaQED(void) const
Definition: lStdHep.hh:205
long status(int i) const
Definition: lStdHep.hh:199
long runNum(void) const
Definition: lStdHep.hh:187
void printEventTable(FILE *fp=0)
Definition: lStdHep.cc:85
long readEvent(void)
Definition: lStdHep.cc:135
void printEvent(FILE *fp=0)
Definition: lStdHep.cc:99
long idrup(void) const
Definition: lStdHep.hh:212
Event & operator=(const Event &)=delete
no assignment operator
void setPx(int i, double px)
Definition: lStdHep.hh:241
double Z(int i) const
Definition: lStdHep.hh:191
void setT(int i, double t)
Definition: lStdHep.hh:240
double spinX(int i) const
Definition: lStdHep.hh:208
long print(FILE *fp)
Definition: lStdHep.cc:546
long daughter2
Definition: lStdHep.hh:96
long nNTuples
Definition: lStdHep.hh:279
long pid(int i) const
Definition: lStdHep.hh:198
void setDaughter2(int i, long n)
Definition: lStdHep.hh:251
void setNTracks(long n)
Definition: lStdHep.hh:234
void printEndRunRecord(FILE *fp=0)
Definition: lStdHep.cc:124
long printHeader(FILE *fp)
Definition: lStdHep.cc:526
void setY(int i, double y)
Definition: lStdHep.hh:238
lStdHep(const char *filename=0, bool open_for_write=false)
Definition: lStdHep.cc:29
long nTracks(void)
Definition: lStdHep.hh:107
void setX(int i, double x)
Definition: lStdHep.hh:237
static int getMinor(void)
Definition: lStdHep.hh:125
const char ** blockNames
Definition: lStdHep.hh:282
const char * date
Definition: lStdHep.hh:272
double spinY(int i) const
Definition: lStdHep.hh:209
void setM(int i, double m)
Definition: lStdHep.hh:245
lStdHep & operator=(const lStdHep &)
void setE(int i, double e)
Definition: lStdHep.hh:244
const char * version
Definition: lStdHep.hh:269
long read(lStdHep &ls)
Definition: lStdHep.cc:399
EventTable & operator=(const EventTable &)=delete
no assignment operator
double Px(int i) const
Definition: lStdHep.hh:193
void setPz(int i, double pz)
Definition: lStdHep.hh:243
long readFileHeader(void)
Definition: lStdHep.cc:212
void setPy(int i, double py)
Definition: lStdHep.hh:242
double E(int i) const
Definition: lStdHep.hh:196
virtual ~lStdHep()
Definition: lStdHep.cc:43
long read(lStdHep &ls)
Definition: lStdHep.cc:323
long print(FILE *fp)
Definition: lStdHep.cc:348
void setZ(int i, double z)
Definition: lStdHep.hh:239
double Py(int i) const
Definition: lStdHep.hh:194
void setEvtNum(long n)
Definition: lStdHep.hh:235
const char * closingDate
Definition: lStdHep.hh:273
lStdTrack size(lStdTrack...args)
double spinZ(int i) const
Definition: lStdHep.hh:210
long firstTable
Definition: lStdHep.hh:277
EventTable eventTable
Definition: lStdHep.hh:325
void setStatus(int i, long s)
Definition: lStdHep.hh:247
long nBlocks
Definition: lStdHep.hh:280
long nTracks(void) const
Definition: lStdHep.hh:185
long setEvent(const lStdEvent &lse)
Definition: lStdHep.cc:263
long * blockIds
Definition: lStdHep.hh:281
long numEvents() const
Definition: lStdHep.hh:175
void setMother1(int i, long n)
Definition: lStdHep.hh:248
double M(int i) const
Definition: lStdHep.hh:197
double Pz(int i) const
Definition: lStdHep.hh:195
long blockId() const
Definition: lStdHep.hh:184
long dimTable
Definition: lStdHep.hh:278
long numevts_expect
Definition: lStdHep.hh:275
long numevts
Definition: lStdHep.hh:276
double T(int i) const
Definition: lStdHep.hh:192
const char * title
Definition: lStdHep.hh:270
const char * version
Definition: lStdHep.hh:350
const char * comment
Definition: lStdHep.hh:271
long colorflow(int i, int j) const
Definition: lStdHep.hh:211
long evtNum(void) const
Definition: lStdHep.hh:186
void printEventHeader(FILE *fp=0)
Definition: lStdHep.cc:92
double eventweight(void) const
Definition: lStdHep.hh:204
long writeEvent(void)
Definition: lStdHep.cc:258
void setMother2(int i, long n)
Definition: lStdHep.hh:249
static int getMajor(void)
Definition: lStdHep.hh:124
const char * version
Definition: lStdHep.hh:310
static const char * getText(void)
Definition: lStdHep.hh:126
bool isStdHepEv4(void) const
Definition: lStdHep.hh:216