Commit in slic on MAIN | |||
include/LcioManager.hh | +2 | -2 | 1.57 -> 1.58 |
/RunManager.hh | +13 | -2 | 1.13 -> 1.14 |
src/LcioManager.cc | +69 | -90 | 1.88 -> 1.89 |
/PrimaryGeneratorAction.cc | +7 | -1 | 1.34 -> 1.35 |
/RunManager.cc | +20 | -19 | 1.18 -> 1.19 |
+111 | -114 |
fix ignoring of run abort when LCIO file already exists; move abort run flag to RunManager instead of LcioManager; some code reformatting
diff -u -r1.57 -r1.58 --- LcioManager.hh 26 Jul 2010 20:41:18 -0000 1.57 +++ LcioManager.hh 2 Aug 2012 23:05:38 -0000 1.58 @@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/include/LcioManager.hh,v 1.57 2010/07/26 20:41:18 jeremy Exp $
+// $Header: /cvs/lcd/slic/include/LcioManager.hh,v 1.58 2012/08/02 23:05:38 jeremy Exp $
#ifndef SLIC_LCIOMANAGER_HH #define SLIC_LCIOMANAGER_HH 1
@@ -233,7 +233,7 @@
bool m_enableDumpEvent; bool m_writerIsOpen; bool m_usingAutoname;
- bool m_abortCurrentRun;
+ //bool m_abortCurrentRun;
}; }
diff -u -r1.13 -r1.14 --- RunManager.hh 8 Jan 2010 23:18:56 -0000 1.13 +++ RunManager.hh 2 Aug 2012 23:05:38 -0000 1.14 @@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/include/RunManager.hh,v 1.13 2010/01/08 23:18:56 jeremy Exp $
+// $Header: /cvs/lcd/slic/include/RunManager.hh,v 1.14 2012/08/02 23:05:38 jeremy Exp $
#ifndef SLIC_RUNMANAGER_HH #define SLIC_RUNMANAGER_HH 1
@@ -23,8 +23,19 @@
public:
+ static RunManager* instance() + { + return dynamic_cast<RunManager*>(G4RunManager::GetRunManager()); + } + + void abortRun() { + //std::cout << "RunManager.abortRun - run will be aborted!!!" << std::endl; + m_abortRun = true; + } +
void Initialize(); int getNumberOfEventsToRun();
+ bool isRunAborted();
protected:
@@ -39,7 +50,7 @@
bool m_userActionsInitialized; int m_numberOfEventsToRun;
-
+ bool m_abortRun;
}; }
diff -u -r1.88 -r1.89 --- LcioManager.cc 4 Jul 2012 01:01:48 -0000 1.88 +++ LcioManager.cc 2 Aug 2012 23:05:38 -0000 1.89 @@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/LcioManager.cc,v 1.88 2012/07/04 01:01:48 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/LcioManager.cc,v 1.89 2012/08/02 23:05:38 jeremy Exp $
#include "LcioManager.hh" // slic
@@ -12,6 +12,7 @@
#include "LcioFileNamer.hh" #include "TrajectoryManager.hh" #include "SlicApplication.hh"
+#include "RunManager.hh"
// lcdd #include "G4CalorimeterHit.hh"
@@ -62,8 +63,7 @@
m_runNumber(0), m_enableDumpEvent(false), m_writerIsOpen(false),
- m_usingAutoname(false) - {
+ m_usingAutoname(false) {
// Initialize the Geant4 UI messenger for the LCIO. m_messenger = new LcioMessenger(this);
@@ -86,38 +86,40 @@
m_filename = m_defaultFileName; }
- LcioManager::~LcioManager() - {
+ LcioManager::~LcioManager() {
deleteWriter();
- if ( m_messenger != 0 ) {
+ if (m_messenger != 0) {
delete m_messenger; } }
- void LcioManager::openLcioFile() - {
+ void LcioManager::openLcioFile() { +
// Get full output path with extension to check its existence.
- string fullFilename = getFullOutputPath( true );
+ string fullFilename = getFullOutputPath(true);
// Default to writing a new file. int writeMode = LCIO::WRITE_NEW; // File exists?
- if ( FileUtil::fileExists( fullFilename ) ) {
+ if (FileUtil::fileExists(fullFilename)) {
// Failure mode is on, so kill the current run.
- if ( m_fileExistsAction == eFail ) { - log().error("LCIO file <" + fullFilename + "> already exists and FileExistsAction is fail."); - m_abortCurrentRun = true;
+ if (m_fileExistsAction == eFail) { + log().fatal("LCIO file <" + fullFilename + "> already exists and will not be deleted."); + //G4Exception("LcioManager::openLcioFile()", "", RunMustBeAborted, "LCIO output file already exists."); + RunManager::instance()->abortRun(); + //m_abortCurrentRun = true;
} // Deletion mode is on, so try to remove the current file.
- else if ( m_fileExistsAction == eDelete ) { - if ( FileUtil::removeFile( fullFilename ) != 0 ) {
+ else if (m_fileExistsAction == eDelete) { + if (FileUtil::removeFile( fullFilename) != 0) {
// Fatal error. File could not be removed.
- //log().fatal("Unable to delete old LCIO file <" + fullFilename + ">"); - G4Exception("", "", FatalException, "Unable to delete old LCIO file.");
+ log().fatal("Unable to delete old LCIO file <" + fullFilename + ">"); + //G4Exception("", "", FatalException, "Unable to delete old LCIO file."); + RunManager::instance()->abortRun();
} else { log().okay("Deleted old LCIO file <" + fullFilename + ">");
@@ -135,17 +137,18 @@
} // Open the file using the writer with the full path.
- if( m_writer ) { - m_writer->open( getFullOutputPath( false ), writeMode ); - m_writerIsOpen = true;
+ if(m_writer) { + if (!RunManager::instance()->isRunAborted()) { + m_writer->open(getFullOutputPath(false), writeMode); + m_writerIsOpen = true; + }
} else { G4Exception("", "", FatalException, "LCWriter is null."); } }
- LcioManager::EFileExistsAction LcioManager::getFileExistsActionFromString( const string& feaStr) - {
+ LcioManager::EFileExistsAction LcioManager::getFileExistsActionFromString( const string& feaStr) {
string s = StringUtil::toLower( feaStr ); EFileExistsAction fea = eInvalid; if ( s == "fail" ) {
@@ -161,20 +164,17 @@
return fea; }
- void LcioManager::setRunNumber(RunNumberType rnt) - {
+ void LcioManager::setRunNumber(RunNumberType rnt) {
m_runNumber = rnt; log().verbose("Set starting run number <" + StringUtil::toString( (int)m_runNumber ) + ">"); }
- void LcioManager::createWriter() - {
+ void LcioManager::createWriter() {
m_writer = IOIMPL::LCFactory::getInstance()->createLCWriter(); }
- void LcioManager::deleteWriter() - {
+ void LcioManager::deleteWriter() {
if ( m_writer != 0 ) { if ( m_writerIsOpen ) { try {
@@ -188,8 +188,7 @@
} }
- string LcioManager::getFullOutputPath(bool withExtension) - {
+ string LcioManager::getFullOutputPath(bool withExtension) {
string fullPath; if (m_path.length() > 0) {
@@ -213,13 +212,12 @@
return fullPath; }
- void LcioManager::beginRun(const G4Run* aRun) - {
+ void LcioManager::beginRun(const G4Run* aRun) {
// Reset the abort run flag.
- m_abortCurrentRun = false;
+ //m_abortCurrentRun = false;
// Automatically create LCIO output file name if option was selected.
- if ( m_usingAutoname ) {
+ if (m_usingAutoname) {
makeAutoname(); }
@@ -229,42 +227,42 @@
// Open the LCIO output file for writing. openLcioFile();
+ //std::cout << "abortCurrentRun = " << m_abortCurrentRun << std::endl; +
// Run aborted, because LCIO output file already exists.
- if (m_abortCurrentRun) { - G4RunManager::GetRunManager()->AbortRun(); - } - // Setup the run header. - else {
+ if (!RunManager::instance()->isRunAborted()) { +
// create new LCRunHeader
- createRunHeader( aRun );
+ createRunHeader(aRun);
// write the run header
- m_writer->writeRunHeader( m_runHdr );
+ m_writer->writeRunHeader(m_runHdr);
// Incr run number. ++m_runNumber; } }
- void LcioManager::endRun( const G4Run* ) - {
+ void LcioManager::endRun(const G4Run*) { +
// Delete the LCIO run header object. deleteRunHeader();
- // Close the writer to flush it (could be reopened). - m_writer->close(); - m_writerIsOpen = false; -
// Set append mode for subsequent writes if interactive mode and the run was not aborted.
- if (!m_abortCurrentRun) { - if ( SlicApplication::instance()->getMode() == SlicApplication::eInteractive ) {
+ if (!RunManager::instance()->isRunAborted()) { + // If run was aborted, writer was never opened. + if (m_writer != 0) { + m_writer->close(); + m_writerIsOpen = false; + } + // Close the writer to flush it (could be reopened). + if (SlicApplication::instance()->getMode() == SlicApplication::eInteractive) {
m_fileExistsAction = eAppend; } } }
- void LcioManager::createRunHeader(const G4Run*) - {
+ void LcioManager::createRunHeader(const G4Run*) {
// create new run header m_runHdr = new LCRunHeaderImpl();
@@ -284,23 +282,20 @@
addActiveSubdetectors(); }
- void LcioManager::setDetectorName() - {
+ void LcioManager::setDetectorName() {
string det_tag = LCDDProcessor::instance()->getDetectorName(); m_runHdr->setDetectorName( det_tag ); log().okay("Detector name set to <" + det_tag + "> in run header."); }
- void LcioManager::deleteRunHeader() - {
+ void LcioManager::deleteRunHeader() {
if ( m_runHdr ) { delete m_runHdr; m_runHdr = 0; } }
- void LcioManager::addActiveSubdetectors() - {
+ void LcioManager::addActiveSubdetectors() {
LCDDProcessor::SensitiveDetectors::const_iterator iter; LCDDProcessor* lcddProc = LCDDProcessor::instance();
@@ -311,15 +306,13 @@
} }
- void LcioManager::setPath(const string& path) - {
+ void LcioManager::setPath(const string& path) {
log().okay("Set output directory to <" + path + ">."); m_path = path; }
- void LcioManager::setFilename(const string& filename) - {
+ void LcioManager::setFilename(const string& filename) {
m_filename = filename; /* If the given filename has an extension, then remove it.
@@ -333,8 +326,7 @@
log().okay("Set output file name to <" + m_filename + ">."); }
- void LcioManager::setAutonameFields(const std::vector<std::string>& fields) - {
+ void LcioManager::setAutonameFields(const std::vector<std::string>& fields) {
m_usingAutoname = true; m_currentAutonameFields.clear(); for(std::vector<std::string>::const_iterator it = fields.begin();
@@ -344,8 +336,7 @@
} }
- void LcioManager::makeAutoname() - {
+ void LcioManager::makeAutoname() {
std::string autoname = m_namer->makeFileName( m_currentAutonameFields ); if ( autoname.size() == 0 || autoname == "" ) { log().warning("Autonaming returned an empty string. Using default file name <" + m_defaultFileName + ">");
@@ -357,18 +348,15 @@
} }
- const string& LcioManager::getPath() const - {
+ const string& LcioManager::getPath() const {
return m_path; }
- const string& LcioManager::getFilename() const - {
+ const string& LcioManager::getFilename() const {
return m_filename; }
- LCEventImpl* LcioManager::createLCEvent(const G4Event* anEvent) - {
+ LCEventImpl* LcioManager::createLCEvent(const G4Event* anEvent) {
assert( anEvent ); LCEventImpl* lcevt = new LCEventImpl();
@@ -403,15 +391,13 @@
return lcevt; }
- LCEventImpl* LcioManager::createLCEvent() - {
+ LCEventImpl* LcioManager::createLCEvent() {
return createLCEvent( G4EventManager::GetEventManager() ->GetNonconstCurrentEvent() ); }
- void LcioManager::endEvent(const G4Event*) - { - if (!m_abortCurrentRun) {
+ void LcioManager::endEvent(const G4Event*) { + if (!RunManager::instance()->isRunAborted()) {
// create LCEvent createLCEvent();
@@ -423,8 +409,7 @@
createFinalMcpCollection(); // If selected, add the initial MCParticle collection to the event.
- if ( LcioMcpManager::instance()->writeInitialMCParticleCollection() ) - {
+ if ( LcioMcpManager::instance()->writeInitialMCParticleCollection() ) {
addInitialMCParticleCollection(); }
@@ -451,13 +436,11 @@
} }
- void LcioManager::setEventTimeStamp() - {
+ void LcioManager::setEventTimeStamp() {
getCurrentLCEvent()->setTimeStamp( TimeUtil::getTimeNS() ); }
- void LcioManager::createHitsCollections() - {
+ void LcioManager::createHitsCollections() {
m_HCBuilder->createHCsFromG4Event( G4EventManager::GetEventManager()->GetNonconstCurrentEvent(), m_currentLCEvent ); }
@@ -470,24 +453,20 @@
m_mcpManager->reset(); }
- void LcioManager::createFinalMcpCollection() - {
+ void LcioManager::createFinalMcpCollection() {
// add Mcp coll to current event getCurrentLCEvent()->addCollection( m_mcpManager->getFinalMcpCollection(), LCIO::MCPARTICLE ); }
- void LcioManager::addCollection( EVENT::LCEvent* event, EVENT::LCCollection* collection, const std::string& collectionName) - {
+ void LcioManager::addCollection( EVENT::LCEvent* event, EVENT::LCCollection* collection, const std::string& collectionName) {
event->addCollection( collection, collectionName ); }
- void LcioManager::addCollection( EVENT::LCCollection* collection, const std::string& collectionName ) - {
+ void LcioManager::addCollection( EVENT::LCCollection* collection, const std::string& collectionName ) {
getCurrentLCEvent()->addCollection( collection, collectionName ); }
- void LcioManager::addInitialMCParticleCollection() - {
+ void LcioManager::addInitialMCParticleCollection() {
const std::string& name = std::string(LCIO::MCPARTICLE) + std::string("Initial"); addCollection( LcioMcpManager::instance()->getInitialMcpCollection(), name ); }
diff -u -r1.34 -r1.35 --- PrimaryGeneratorAction.cc 4 Jul 2012 01:01:48 -0000 1.34 +++ PrimaryGeneratorAction.cc 2 Aug 2012 23:05:38 -0000 1.35 @@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/PrimaryGeneratorAction.cc,v 1.34 2012/07/04 01:01:48 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/PrimaryGeneratorAction.cc,v 1.35 2012/08/02 23:05:38 jeremy Exp $
#include "PrimaryGeneratorAction.hh"
@@ -7,6 +7,7 @@
// slic #include "LcioManager.hh"
+#include "RunManager.hh"
#include "SlicApplication.hh" #include "LcioMcpManager.hh" #include "LcioMcpFilter.hh"
@@ -31,6 +32,11 @@
void PrimaryGeneratorAction::GeneratePrimaries(G4Event *anEvent) {
+ // Check if run needs to be aborted. + if (RunManager::instance()->isRunAborted()) { + G4RunManager::GetRunManager()->AbortRun(); + } +
EventSourceManager* mgr = EventSourceManager::instance(); // Beginning of event message that prints the event number.
diff -u -r1.18 -r1.19 --- RunManager.cc 31 Jan 2012 18:52:30 -0000 1.18 +++ RunManager.cc 2 Aug 2012 23:05:38 -0000 1.19 @@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/RunManager.cc,v 1.18 2012/01/31 18:52:30 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/RunManager.cc,v 1.19 2012/08/02 23:05:38 jeremy Exp $
#include "RunManager.hh" // lcdd
@@ -24,14 +24,13 @@
RunManager::RunManager() : Module("RunManager", false),
- m_userActionsInitialized(false) - {}
+ m_userActionsInitialized(false) { + }
- RunManager::~RunManager() - {}
+ RunManager::~RunManager() { + }
- void RunManager::initializeUserActions() - {
+ void RunManager::initializeUserActions() {
SetUserAction(new PrimaryGeneratorAction); SetUserAction(new RunAction); SetUserAction(new EventAction);
@@ -40,8 +39,7 @@
m_userActionsInitialized = true; }
- void RunManager::Initialize() - {
+ void RunManager::Initialize() {
// This makes sure that physics initialization occurs before other user actions. G4RunManager::Initialize();
@@ -61,8 +59,7 @@
#endif }
- void RunManager::InitializePhysics() - {
+ void RunManager::InitializePhysics() {
// Initialize the physics list. PhysicsListManager::instance()->initializePhysicsList();
@@ -84,8 +81,7 @@
} }
- void RunManager::InitializeGeometry() - {
+ void RunManager::InitializeGeometry() {
if ( !LCDDParser::instance()->isValidSetup() ) { G4Exception("", "", FatalException, "Current LCDD geometry setup is not valid.");
@@ -94,11 +90,13 @@
G4RunManager::InitializeGeometry(); }
- void RunManager::BeamOn(G4int n_event, const char* macroFile, G4int n_select) - {
+ void RunManager::BeamOn(G4int n_event, const char* macroFile, G4int n_select) { + + // Reset abort run flag. + m_abortRun = false; +
// Attempt to initialize Geant4 if not in idle state.
- if ( G4StateManager::GetStateManager()->GetCurrentState() != G4State_Idle ) - {
+ if ( G4StateManager::GetStateManager()->GetCurrentState() != G4State_Idle ) {
this->Initialize(); }
@@ -107,8 +105,11 @@
G4RunManager::BeamOn(n_event, macroFile, n_select); }
- int RunManager::getNumberOfEventsToRun() - {
+ int RunManager::getNumberOfEventsToRun() {
return m_numberOfEventsToRun; }
+ + bool RunManager::isRunAborted() { + return m_abortRun; + }
}
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1