/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/include/UTIL/lStdHep.hh

Go to the documentation of this file.
00001 //// lStdHep.hh
00002 //
00003 // Header file for a light-weight StdHep class.
00004 // This class is based on the light-weight XDR class lXDR,
00005 // and parses/writes StdHep files. It was mainly written,
00006 // to provide a faster alternative to the more cumdersome
00007 // methods using mcfio in CLHEP.
00008 //
00009 // W.G.J. Langeveld, 24 May 2002
00010 //
00011 // Release notes:
00012 // - Version 1.0 (23-Oct-2003, WGL):
00013 //   o Implements "read" but not "write" functions
00014 //   o Standalone (previous versions depended on sgarray,
00015 //     which comes with the "vec" package in the Lelaps
00016 //     distribution). It now uses one std::vector.
00017 // - Version 1.1 (18-Mar-2004, WGL):
00018 //   o Fixed a file positioning bug which made it fail to
00019 //     read some files.
00020 // - Version 1.2 (18-Mar-2004, WGL):
00021 //   o Fixed a bug where it would skip one event at the
00022 //     boundaries between event blocks.
00023 // - Version 1.3 (19-Mar-2004, WGL):
00024 //   o Improved handling of end-of-file. Now, when there
00025 //     are no more events, readEvent() returns an error.
00026 //     The error code is LSH_ENDOFFILE.
00027 // - Version 1.4 (30-Mar-2004, WGL):
00028 //   o Fixed memory leak
00029 // - Version 1.5 (10-Aug-2004, WGL):
00030 //   o Added numEvents() method by request.
00031 //
00032 ////
00033 #ifndef LSTDHEP__HH
00034 #define LSTDHEP__HH
00035 
00036 #include "UTIL/lXDR.hh"
00037 #include <vector>
00038 
00039 
00040 namespace UTIL{
00041 
00042 //
00043 // MCFIO block codes
00044 //
00045 #define LSH_GENERIC           0
00046 #define LSH_FILEHEADER        1    // supported 5/28/2002
00047 #define LSH_EVENTTABLE        2    // supported 5/28/2002
00048 #define LSH_SEQUENTIALHEADER  3
00049 #define LSH_EVENTHEADER       4    // supported 5/28/2002
00050 #define LSH_NOTHING           5
00051 //
00052 // lStdHepError codes
00053 //
00054 #define LSH_SUCCESS           0
00055 #define LSH_BLOCKERROR      101
00056 #define LSH_NOEVENTTABLE    102
00057 #define LSH_NOEVENT         103
00058 #define LSH_NOTSUPPORTED    104
00059 #define LSH_EVTABLECORRUPT  105
00060 #define LSH_ENDOFFILE       106
00061 //
00062 // StdHep block codes
00063 //
00064 #define LSH_STDHEP          101    // supported 5/28/2002
00065 #define LSH_OFFTRACKARRAYS  102
00066 #define LSH_OFFTRACKSTRUCT  103
00067 #define LSH_TRACEARRAYS     104
00068 #define LSH_STDHEPM         105
00069 #define LSH_STDHEPBEG       106    // supported 5/28/2002
00070 #define LSH_STDHEPEND       107    // supported 5/28/2002
00071 #define LSH_STDHEPCXX       108
00072 #define LSH_STDHEPEV4       201    // supported 1/23/2006
00073 
00074 ////
00075 //
00076 // The basic lStdHep track. Note that access controls are
00077 // unneeded here since this is an old standard unlikely to
00078 // change.
00079 //
00080 ////
00081 struct lStdTrack {
00082    double         X;
00083    double         Y;
00084    double         Z;
00085    double         T;
00086    double         Px;
00087    double         Py;
00088    double         Pz;
00089    double         E;
00090    double         M;
00091    long           pid;
00092    long           status;
00093    long           mother1;
00094    long           mother2;
00095    long           daughter1;
00096    long           daughter2;
00097 };
00098 
00099 
00100 ////
00101 //
00102 // The basic lStdHep event
00103 //
00104 ////
00105 struct lStdEvent : public std::vector<lStdTrack>  {
00106    long evtNum;
00107    long nTracks(void) { return(size()); };
00108 };
00109 
00110 ////
00111 //
00112 // The lStdHep class is the "handle" for the StdHep file, and
00113 // provides the access mechanism to the events.
00114 //
00115 ////
00116 class lStdHep : public lXDR {
00117 private:
00118 //
00119 // The current version/revision is:
00120 //
00121    enum { MAJOR = 2, MINOR = 0, DAY = 23, MONTH = 1, YEAR = 2006 };
00122 //       ========================================================
00123 public:
00124    static int         getMajor(void) { return(MAJOR); };
00125    static int         getMinor(void) { return(MINOR); };
00126    static const char *getText(void)  {
00127       static char buff[80];
00128       sprintf(buff, "lStdHep version %d.%d (%02d.%02d.%d) by W.G.J. Langeveld, SLAC",
00129               MAJOR, MINOR, DAY, MONTH, YEAR);
00130       return(buff);
00131    };
00132 
00133 
00134 //
00135 // Constructors, destructor
00136 // ------------------------
00137 // Constructor opens file, destructor closes file. Once opened for
00138 // reading, the file cannot be written to, and v.v.
00139 //
00140    lStdHep(const char *filename = 0, bool open_for_write = false);
00141 //
00142 // Prevent copying:
00143 //
00144 private:
00145    lStdHep(const lStdHep &);
00146 public:
00147    virtual ~lStdHep();
00148 //
00149 // Prevent assignment:
00150 //
00151 private:
00152    lStdHep       &operator=(const lStdHep &);
00153 public:
00154 //
00155 // See if there are more events
00156 //
00157    bool           more(void);
00158 //
00159 // Event reading functions. They return the last error encountered,
00160 // or LSH_SUCCESS.
00161 // - Read the next event into the event buffer:
00162 //
00163    long           readEvent(void);
00164 //
00165 // - Fill the provided lStdEvent with the current event:
00166 //
00167    long           getEvent(lStdEvent &lse) const;
00168 //
00169 // - Combine readEvent() with getEvent():
00170 //
00171    long           readEvent(lStdEvent &lse);
00172 //
00173 // Get the number of events in the input file
00174 //
00175    long           numEvents()      const { return(numevts);                  };
00176 //
00177 // Direct access to the event buffer. Note that using readEvent(void)
00178 // in combination with the functions below is faster than using
00179 // readEvent(lStdEvent &), especially when only a few quantities are
00180 // needed.
00181 //
00182    long           blockId()         const { return(event.blockid);            };
00183    long           nTracks(void)     const { return(event.nhep);               };
00184    long           evtNum(void)      const { return(event.nevhep);             };
00185    long           runNum(void)      const { return(event.runnum);             };
00186 
00187    double         X(int i)          const { return(event.vhep[i * 4 + 0]);    };
00188    double         Y(int i)          const { return(event.vhep[i * 4 + 1]);    };
00189    double         Z(int i)          const { return(event.vhep[i * 4 + 2]);    };
00190    double         T(int i)          const { return(event.vhep[i * 4 + 3]);    };
00191    double         Px(int i)         const { return(event.phep[i * 5 + 0]);    };
00192    double         Py(int i)         const { return(event.phep[i * 5 + 1]);    };
00193    double         Pz(int i)         const { return(event.phep[i * 5 + 2]);    };
00194    double         E(int i)          const { return(event.phep[i * 5 + 3]);    };
00195    double         M(int i)          const { return(event.phep[i * 5 + 4]);    };
00196    long           pid(int i)        const { return(event.idhep[i]);           };
00197    long           status(int i)     const { return(event.isthep[i]);          };
00198    long           mother1(int i)    const { return(event.jmohep[i + i + 0]);  };
00199    long           mother2(int i)    const { return(event.jmohep[i + i + 1]);  };
00200    long           daughter1(int i)  const { return(event.jdahep[i + i + 0]);  };
00201    long           daughter2(int i)  const { return(event.jdahep[i + i + 1]);  };
00202    double         eventweight(void) const { return(event.eventweight);        };
00203    double         alphaQED(void)    const { return(event.alphaqed);           };
00204    double         alphaQCD(void)    const { return(event.alphaqcd);           };
00205    double         scale(int i, int j) const { return(event.scale[i * 10 + j] ); };
00206    double         spinX(int i)      const { return(event.spin[i * 3 + 0] );   };
00207    double         spinY(int i)      const { return(event.spin[i * 3 + 1] );   };
00208    double         spinZ(int i)      const { return(event.spin[i * 3 + 2] );   };
00209    long           colorflow(int i, int j)  const { return(event.colorflow[i * 2 + j] ); };
00210    long           idrup(void)       const { return(event.idrup);              };
00211 //
00212 // Call this to make sure you can call things like scale, spin and colorflow:
00213 //
00214    bool           isStdHepEv4(void) const { return(event.scale != 0);         };
00215 //
00216 // Event writing functions. They return the last error encountered,
00217 // or LSH_SUCCESS.
00218 // - Write the current event buffer to thefile:
00219 //
00220    long           writeEvent(void);
00221 //
00222 // - Fill the event buffer with the data from the provided lStdEvent:
00223 //
00224    long           setEvent(const lStdEvent &lse);
00225 //
00226 // - Combine setEvent() with writeEvent():
00227 //
00228    long           writeEvent(lStdEvent &lse);
00229 //
00230 // Direct access to the event buffer.
00231 //
00232    void           setNTracks(long n)          { event.nhep = n; return;               };
00233    void           setEvtNum(long n)           { event.nevhep = n; return;             };
00234 
00235    void           setX(int i, double x)       { event.vhep[i * 4 + 0] = x; return;    };
00236    void           setY(int i, double y)       { event.vhep[i * 4 + 1] = y; return;    };
00237    void           setZ(int i, double z)       { event.vhep[i * 4 + 2] = z; return;    };
00238    void           setT(int i, double t)       { event.vhep[i * 4 + 3] = t; return;    };
00239    void           setPx(int i, double px)     { event.phep[i * 5 + 0] = px; return;   };
00240    void           setPy(int i, double py)     { event.phep[i * 5 + 1] = py; return;   };
00241    void           setPz(int i, double pz)     { event.phep[i * 5 + 2] = pz; return;   };
00242    void           setE(int i, double e)       { event.phep[i * 5 + 3] = e; return;    };
00243    void           setM(int i, double m)       { event.phep[i * 5 + 4] = m; return;    };
00244    void           setPid(int i, long pid)     { event.idhep[i] = pid; return;         };
00245    void           setStatus(int i, long s)    { event.isthep[i] = s; return;          };
00246    void           setMother1(int i, long n)   { event.jmohep[i + i + 0] = n; return;  };
00247    void           setMother2(int i, long n)   { event.jmohep[i + i + 1] = n; return;  };
00248    void           setDaughter1(int i, long n) { event.jdahep[i + i + 0] = n; return;  };
00249    void           setDaughter2(int i, long n) { event.jdahep[i + i + 1] = n; return;  };
00250 //
00251 // Informational printout
00252 //
00253    void           printFileHeader(FILE *fp = 0);
00254    void           printBeginRunRecord(FILE *fp = 0);
00255    void           printEndRunRecord(FILE *fp = 0);
00256    void           printEventTable(FILE *fp = 0);
00257    void           printEventHeader(FILE *fp = 0);
00258    void           printEvent(FILE *fp = 0);
00259    void           printTrack(int i, FILE *fp = 0);
00260 
00261 private:
00262    long           readFileHeader(void);
00263 //
00264 // File Header
00265 //
00266    long           ntot;
00267    const char    *version;
00268    const char    *title;
00269    const char    *comment;
00270    const char    *date;
00271    const char    *closingDate;
00272 
00273    long           numevts_expect;
00274    long           numevts;
00275    long           firstTable;
00276    long           dimTable;
00277    long           nNTuples;
00278    long           nBlocks;
00279    long          *blockIds;
00280    const char   **blockNames;
00281 //
00282 // Event table
00283 //
00284    class EventTable {
00285    public:
00286       EventTable();
00287       ~EventTable();
00288       void cleanup(void);
00289       long read(lStdHep &ls);
00290       long print(FILE *fp);
00291 //
00292 // ...Empty flag
00293 //
00294       long  isEmpty;
00295 //
00296 // Index into the event table
00297 //
00298       long  ievt;
00299 //
00300 // ...MCFIO header
00301 //
00302       long  blockid;
00303       long  ntot;
00304       const char *version;
00305 //
00306 // ...Location of next table
00307 //
00308       long  nextlocator;
00309 //
00310 // ...The event table itself
00311 //
00312       long  numEvts;
00313       long *evtnums;
00314       long *storenums;
00315       long *runnums;
00316       long *trigMasks;
00317       long *ptrEvents;
00318    };
00319    EventTable     eventTable;
00320 //
00321 // The event
00322 //
00323    class Event {
00324    public:
00325       Event();
00326       ~Event();
00327       void cleanup(void);
00328       long read(lStdHep &ls);
00329       long printHeader(FILE *fp);
00330       long print(FILE *fp);
00331 //
00332 // ...Empty flag
00333 //
00334       long isEmpty;
00335 //
00336 // ...MCFIO header
00337 //
00338       long blockid;
00339       long ntot;
00340       const char *version;
00341 //
00342 // ...Event header:
00343 //
00344       long    evtnum;
00345       long    storenum;
00346       long    runnum;
00347       long    trigMask;
00348       long    nBlocks;
00349       long    dimBlocks;
00350       long    nNTuples;
00351       long    dimNTuples;
00352       long   *blockIds;
00353       long   *ptrBlocks;
00354 //
00355 // ...Event:
00356 //
00357       long    nevhep;
00358       long    nhep;
00359       long   *isthep;
00360       long   *idhep;
00361       long   *jmohep;
00362       long   *jdahep;
00363       double *phep;
00364       double *vhep;
00365 //
00366 // ...New for STDHEPEV4:
00367 //
00368       double  eventweight;
00369       double  alphaqed;
00370       double  alphaqcd;
00371       double *scale;
00372       double *spin;
00373       long   *colorflow;
00374       long    idrup;
00375 //
00376 // ...Begin run record:
00377 //
00378       long    bnevtreq;
00379       long    bnevtgen;
00380       long    bnevtwrt;
00381       double  bstdecom;
00382       double  bstdxsec;
00383       double  bstdseed1;
00384       double  bstdseed2;
00385 //
00386 // ...End run record:
00387 //
00388       long    enevtreq;
00389       long    enevtgen;
00390       long    enevtwrt;
00391       double  estdecom;
00392       double  estdxsec;
00393       double  estdseed1;
00394       double  estdseed2;
00395    };
00396    Event          event;
00397 };
00398 
00399 } // end namespace
00400 
00401 #endif

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7