00001 // $Header: /cvs/lcd/slic/include/LcioManager.hh,v 1.56 2007/04/27 01:54:32 jeremy Exp $ 00002 00003 #ifndef SLIC_LCIOMANAGER_HH 00004 #define SLIC_LCIOMANAGER_HH 1 00005 00006 // lcdd 00007 #include "G4SensitiveDetector.hh" 00008 #include "G4CalorimeterHit.hh" 00009 #include "G4TrackerHit.hh" 00010 00011 // slic 00012 #include "LcioPrimaryGenerator.hh" 00013 #include "LcioMcpManager.hh" 00014 #include "LcioHitsCollectionBuilder.hh" 00015 #include "LcioFileNamer.hh" 00016 #include "Trajectory.hh" 00017 #include "Singleton.hh" 00018 00019 // lcio 00020 #include "IO/LCWriter.h" 00021 #include "EVENT/MCParticle.h" 00022 #include "IMPL/SimCalorimeterHitImpl.h" 00023 #include "IMPL/SimTrackerHitImpl.h" 00024 #include "IMPL/LCCollectionVec.h" 00025 #include "IMPL/LCEventImpl.h" 00026 #include "IMPL/LCRunHeaderImpl.h" 00027 #include "IMPL/MCParticleImpl.h" 00028 00029 // geant4 00030 #include "G4Event.hh" 00031 #include "G4PrimaryParticle.hh" 00032 00033 // std 00034 #include <string> 00035 #include <map> 00036 00037 class G4Run; 00038 class G4VHitsCollection; 00039 class G4TrajectoryContainer; 00040 00041 namespace slic 00042 { 00043 00044 class LcioMessenger; 00045 00052 class LcioManager : public Module, public Singleton<LcioManager> 00053 { 00054 00055 public: 00056 00057 enum EFileExistsAction { 00058 eInvalid = -1, 00059 eFail = 0, 00060 eDelete = 1, 00061 eAppend = 2 00062 }; 00063 00064 typedef unsigned int RunNumberType; 00065 00066 public: 00067 virtual ~LcioManager(); 00068 00069 //static LcioManager* instance(); 00070 00071 LcioManager(); 00072 00073 public: 00074 00075 // open file from mvar vals 00076 void openLcioFile(); 00077 00078 // path and filename 00079 void setPath(const std::string& path); 00080 void setFilename(const std::string& filename); 00081 void setAutonameFields(const std::vector<std::string>& fields); 00082 00083 const std::string& getPath() const; 00084 const std::string& getFilename() const; 00085 00086 // get path + filename; arg == true to include ".slcio" extension 00087 std::string getFullOutputPath(bool withExtension = false); 00088 00089 // convert to file exists setting from a string 00090 static EFileExistsAction getFileExistsActionFromString( const std::string& fea); 00091 00092 void setRunNumber(RunNumberType rnt); 00093 const int getRunNumber(); 00094 00095 // run actions 00096 void beginRun( const G4Run* ); 00097 void endRun( const G4Run* ); 00098 00099 // create the LCEvent 00100 IMPL::LCEventImpl* createLCEvent(const G4Event* anEvent); 00101 IMPL::LCEventImpl* createLCEvent(); 00102 00103 // create Mcp coll 00104 void createFinalMcpCollection(); 00105 00106 void addCollection( EVENT::LCEvent*, EVENT::LCCollection*, const std::string& ); 00107 00108 void addCollection( EVENT::LCCollection*, const std::string& ); 00109 00110 void addInitialMCParticleCollection(); 00111 00112 // formerly writeEvent() 00113 void endEvent(const G4Event* anEvent); 00114 00115 // set the current LCEvent 00116 void setCurrentLCEvent(IMPL::LCEventImpl* anLCEvent) { m_currentLCEvent = anLCEvent; } 00117 IMPL::LCEventImpl* getCurrentLCEvent() { return m_currentLCEvent; } 00118 00119 void setStoreMomentum(bool s = true) 00120 { 00121 m_HCBuilder->setStoreMomentum(s); 00122 } 00123 00124 void setFileExistsAction(EFileExistsAction fea) 00125 { 00126 if ( fea == eInvalid ) { 00127 #ifdef SLIC_LOG 00128 log() << LOG::error << "Invalid setting for FileExistsAction." << LOG::done; 00129 #endif 00130 return; 00131 } 00132 00133 m_fileExistsAction = fea; 00134 } 00135 00136 EFileExistsAction getFileExistsAction() 00137 { 00138 return m_fileExistsAction; 00139 } 00140 00141 inline LcioPrimaryGenerator* getGenerator() 00142 { 00143 return m_eventGenerator; 00144 } 00145 00146 inline LcioMcpManager* getMcpManager() 00147 { 00148 return m_mcpManager; 00149 } 00150 00151 inline LcioHitsCollectionBuilder* getHCBuilder() 00152 { 00153 return m_HCBuilder; 00154 } 00155 00156 inline LcioFileNamer* getFileNamer() 00157 { 00158 return m_namer; 00159 } 00160 00161 void enableDumpEvent(bool p = true) 00162 { 00163 m_enableDumpEvent = p; 00164 } 00165 00166 private: 00167 00168 void makeAutoname(); 00169 00170 // add HCs using builder and current ptrs 00171 void createHitsCollections(); 00172 00173 // LCWriter 00174 void createWriter(); 00175 void deleteWriter(); 00176 00177 // run header 00178 void createRunHeader(const G4Run*); 00179 void deleteRunHeader(); 00180 00181 // set detector tag in LCIO output header 00182 void setDetectorName(); 00183 00184 // set timestamp 00185 void setEventTimeStamp(); 00186 00187 // add actives detectors from LCDD parser into the LCIO header 00188 void addActiveSubdetectors(); 00189 00190 // reset cached instance vars 00191 void reset(); 00192 00193 private: 00194 00195 // final Mcp collection with all info from McpInitial, Trajectories, Primaries 00196 IMPL::LCCollectionVec* m_McpFinalColl; 00197 00198 // writer 00199 IO::LCWriter* m_writer; 00200 00201 // run header 00202 IMPL::LCRunHeaderImpl* m_runHdr; 00203 00204 // file info 00205 std::string m_filename; 00206 std::string m_path; 00207 00208 // Mcp manager 00209 LcioMcpManager* m_mcpManager; 00210 00211 // event generator from MCP Coll 00212 LcioPrimaryGenerator* m_eventGenerator; 00213 00214 // creation of HCs 00215 LcioHitsCollectionBuilder* m_HCBuilder; 00216 00217 // current LCEvent 00218 IMPL::LCEventImpl* m_currentLCEvent; 00219 00220 // messenger 00221 LcioMessenger* m_messenger; 00222 00223 // action when file exists 00224 EFileExistsAction m_fileExistsAction; 00225 00226 // starting run number 00227 RunNumberType m_runNumber; 00228 00229 LcioFileNamer* m_namer; 00230 00231 static std::string m_defaultFileName; 00232 std::vector<std::string> m_currentAutonameFields; 00233 00234 bool m_enableDumpEvent; 00235 bool m_writerIsOpen; 00236 bool m_usingAutoname; 00237 bool m_abortCurrentRun; 00238 }; 00239 } 00240 00241 #endif
1.5.4