8 #include "PackageInfo.hh"
15 #include "lcdd/core/LCDDProcessor.hh"
16 #include "lcdd/hits/CalorimeterHit.hh"
17 #include "lcdd/hits/TrackerHit.hh"
18 #include "lcdd/util/StringUtil.hh"
21 #include "EVENT/LCIO.h"
22 #include "IMPL/LCCollectionVec.h"
23 #include "IO/LCWriter.h"
24 #include "IOIMPL/LCFactory.h"
25 #include "UTIL/LCTOOLS.h"
26 #include "UTIL/lStdHep.hh"
29 #include "G4EventManager.hh"
31 #include "G4RunManager.hh"
32 #include "G4SDManager.hh"
33 #include "G4TrajectoryContainer.hh"
34 #include "G4VHitsCollection.hh"
40 using EVENT::MCParticle;
41 using IMPL::LCCollectionVec;
42 using IMPL::LCEventImpl;
43 using IMPL::LCRunHeaderImpl;
54 Module(
"LcioManager"), m_writer(NULL), m_runHdr(NULL), m_fileExistsAction(
LcioManager::eFail), m_runNumber(0), m_enableDumpEvent(false), m_writerIsOpen(false), m_usingAutoname(false) {
87 int writeMode = LCIO::WRITE_NEW;
103 log().
okay(
"Deleted old LCIO file: " + fullFilename);
108 log().
okay(
"Appending to existing LCIO file: " + fullFilename);
109 writeMode = LCIO::WRITE_APPEND;
114 log().
okay(
"Creating new LCIO file: " + fullFilename);
131 string s = StringUtil::toLower(feaStr);
135 }
else if (s ==
"overwrite" || s ==
"delete") {
137 }
else if (s ==
"append") {
146 log().
verbose(
"Set starting run number <" + StringUtil::toString((
int)runNumber) +
">");
150 m_writer = IOIMPL::LCFactory::getInstance()->createLCWriter();
170 if (
m_path.length() > 0) {
183 fullPath +=
".slcio";
192 #if ( G4VERSION_NUMBER >= 1000 )
193 G4RunManager::GetRunManager()->GetNonConstCurrentRun()->SetRunID(
m_runNumber);
196 const_cast<G4Run *
>(G4RunManager::GetRunManager()->GetCurrentRun())->SetRunID(
m_runNumber);
245 m_runHdr->parameters().setValue(
"SLIC_VERSION", PackageInfo::getVersion());
258 string det_tag = LCDDProcessor::instance()->getDetectorName();
260 log().
okay(
"Detector name set to <" + det_tag +
"> in run header.");
271 LCDDProcessor::SensitiveDetectors::const_iterator iter;
272 LCDDProcessor* lcddProc = LCDDProcessor::instance();
274 for (iter = lcddProc->getSensitiveDetectorsBegin(); iter != lcddProc->getSensitiveDetectorsEnd(); iter++) {
275 m_runHdr->addActiveSubdetector((iter->second)->GetName());
280 log().
okay(
"Set output directory to <" + path +
">.");
290 size_t hasExt = filename.find(
".slcio");
291 if (hasExt != string::npos) {
292 m_filename.replace(filename.size() - 6, 6,
"");
301 for (std::vector<std::string>::const_iterator it = fields.begin(); it != fields.end(); it++) {
308 if (autoname.size() == 0 || autoname ==
"") {
313 log().
okay(
"Autoname set file name to <" + autoname +
">.");
320 LCEventImpl* lcevt =
new LCEventImpl();
321 lcevt->setEventNumber(anEvent->GetEventID());
322 lcevt->setRunNumber(
m_runHdr->getRunNumber());
323 lcevt->setDetectorName(
m_runHdr->getDetectorName());
331 float eventWeight = mcpColl->getParameters().getFloatVal(
"_weight");
332 if (eventWeight != 0.0) {
333 lcevt->setWeight(eventWeight);
337 int idrup = mcpColl->getParameters().getIntVal(
"_idrup");
340 lcevt->parameters().setValue(
"_idrup", idrup);
345 lcevt->parameters().setValue(
"SLIC_VERSION", PackageInfo::getVersion());
354 return createLCEvent(G4EventManager::GetEventManager()->GetNonconstCurrentEvent());
390 event->addCollection(collection, collectionName);
static SlicApplication * instance()
static int removeFile(const char *filename)
static bool fileExists(const char *filename)
Automatically name LCIO output files according to input settings.
std::string makeFileName(std::vector< std::string > fields)
Builds Lcio hits collections from G4/SLIC event data.
EVENT::LCEvent * createHitCollectionsFromEvent(const G4Event *event, EVENT::LCEvent *lcioEvent)
Singleton manager class of LCIO configuration and output file operations.
std::vector< std::string > m_currentAutonameFields
void endRun(const G4Run *run)
void setCurrentLCEvent(IMPL::LCEventImpl *anLCEvent)
LcioHitsCollectionBuilder * m_HCBuilder
std::string getFullOutputPath(bool withExtension=false)
void setRunNumber(int runNumber)
void createHitsCollections()
static EFileExistsAction getFileExistsActionFromString(const std::string &fileExists)
void setFilename(const std::string &filename)
LcioMessenger * m_messenger
void addActiveSubdetectors()
void setAutonameFields(const std::vector< std::string > &fields)
IMPL::LCEventImpl * getCurrentLCEvent()
void setPath(const std::string &path)
void endEvent(const G4Event *anEvent)
void beginRun(const G4Run *run)
static std::string m_defaultFileName
IMPL::LCEventImpl * m_currentLCEvent
void addCollection(EVENT::LCEvent *lcevent, EVENT::LCCollection *collection, const std::string &name)
EFileExistsAction m_fileExistsAction
IMPL::LCEventImpl * createLCEvent()
void createRunHeader(const G4Run *run)
IMPL::LCRunHeaderImpl * m_runHdr
G4UIcommand class for LCIO commands.
Base class for slic code modules that provides common functionality, such as logging to an output str...
static RunManager * instance()
@ FAILED_DELETE_LCIO_FILE
static long64 getTimeNS()