Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:01

0001 #ifndef Input_HepMCFileReader_h
0002 #define Input_HepMCFileReader_h
0003 
0004 /** \class HepMCFileReader
0005 * 
0006 *  This class is used by the implementation of DaqEventFactory present 
0007 *  in this package to read in the full event raw data from a flat 
0008 *  binary file. 
0009 *  WARNING: If you want to use this class for other purposes you must 
0010 *  always invoke the method initialize before starting using the interface
0011 *  it exposes.
0012 *
0013 *  \author G. Bruno - CERN, EP Division
0014 */
0015 
0016 #include <vector>
0017 #include <map>
0018 
0019 #include "FWCore/Utilities/interface/get_underlying_safe.h"
0020 
0021 namespace HepMC {
0022   class IO_BaseClass;
0023   class GenEvent;
0024   class GenParticle;
0025 }  // namespace HepMC
0026 
0027 class HepMCFileReader {
0028 protected:
0029   HepMCFileReader();
0030 
0031 public:
0032   virtual ~HepMCFileReader();
0033   virtual void initialize(const std::string &filename);
0034   inline bool isInitialized() const;
0035 
0036   virtual bool setEvent(int event);
0037   virtual bool readCurrentEvent();
0038   virtual bool printHepMcEvent() const;
0039   HepMC::GenEvent *fillCurrentEventData();
0040   //  virtual bool fillEventData(HepMC::GenEvent *event);
0041   // this method prints the event information as
0042   // obtained by the input file in HepEvt style
0043   void printEvent() const;
0044   // get all the 'integer' properties of a particle
0045   // like mother, daughter, pid and status
0046   // 'j' is the number of the particle in the HepMc
0047   virtual void getStatsFromTuple(int &mo1, int &mo2, int &da1, int &da2, int &status, int &pid, int j) const;
0048   virtual void ReadStats();
0049 
0050   static HepMCFileReader *instance();
0051 
0052 private:
0053   HepMC::IO_BaseClass const *input() const { return get_underlying_safe(input_); }
0054   HepMC::IO_BaseClass *&input() { return get_underlying_safe(input_); }
0055 
0056   // current  HepMC evt
0057   edm::propagate_const<HepMC::GenEvent *> evt_;
0058   edm::propagate_const<HepMC::IO_BaseClass *> input_;
0059 
0060   static HepMCFileReader *instance_;
0061 
0062   int rdstate() const;
0063   //maps to convert HepMC::GenParticle to particles # and vice versa
0064   // -> needed for HepEvt like output
0065   std::vector<HepMC::GenParticle *> index_to_particle;
0066   std::map<HepMC::GenParticle *, int> particle_to_index;
0067   // find index to HepMC::GenParticle* p in map m
0068   int find_in_map(const std::map<HepMC::GenParticle *, int> &m, HepMC::GenParticle *p) const;
0069 };
0070 
0071 bool HepMCFileReader::isInitialized() const { return input_ != nullptr; }
0072 
0073 #endif