6 modified files
slic/include
diff -u -r1.3 -r1.4
--- LcioFileNamer.hh 22 Sep 2005 21:38:58 -0000 1.3
+++ LcioFileNamer.hh 3 Oct 2005 22:25:53 -0000 1.4
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/include/LcioFileNamer.hh,v 1.3 2005/09/22 21:38:58 jeremy Exp $
+// $Header: /cvs/lcd/slic/include/LcioFileNamer.hh,v 1.4 2005/10/03 22:25:53 jeremy Exp $
#ifndef slic_LcioFileNamer_hh
#define slic_LcioFileNamer_hh 1
@@ -7,6 +7,7 @@
// std
#include <string>
+#include <vector>
namespace slic
{
@@ -17,19 +18,19 @@
*/
class LcioFileNamer
{
-
- private:
-
- LcioFileNamer() {}
-
public:
+ LcioFileNamer();
virtual ~LcioFileNamer() {}
public:
- static std::string makeFullFilename();
+ std::string makeFileName(std::vector<std::string>);
private:
+ static std::string getFieldValue(std::string);
+
+ std::string makeDefaultFileName();
+
static std::string makeEventName();
static std::string makeFileBasedName();
@@ -38,8 +39,13 @@
static std::string makeMomentumString(const G4ThreeVector& mom);
+ static std::string makeRunNumberString();
+ static std::string makeEventNumberString();
+
private:
+
static std::string m_sep;
+ std::vector<std::string> m_defaultFields;
};
};
slic/include
diff -u -r1.49 -r1.50
--- LcioManager.hh 22 Sep 2005 21:38:37 -0000 1.49
+++ LcioManager.hh 3 Oct 2005 22:25:53 -0000 1.50
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/include/LcioManager.hh,v 1.49 2005/09/22 21:38:37 jeremy Exp $
+// $Header: /cvs/lcd/slic/include/LcioManager.hh,v 1.50 2005/10/03 22:25:53 jeremy Exp $
#ifndef slic_LcioManager_hh
#define slic_LcioManager_hh 1
@@ -12,6 +12,7 @@
#include "LcioPrimaryGenerator.hh"
#include "LcioMcpManager.hh"
#include "LcioHitsCollectionBuilder.hh"
+#include "LcioFileNamer.hh"
#include "Trajectory.hh"
// lcio
@@ -77,6 +78,7 @@
// path and filename
void setPath(const std::string& path);
void setFilename(const std::string& filename);
+ void setAutonameFields(const std::vector<std::string>& fields);
const std::string& getPath() const;
const std::string& getFilename() const;
@@ -150,9 +152,9 @@
return m_HCBuilder;
}
- void useAutonaming(bool a = true)
+ inline LcioFileNamer* getFileNamer()
{
- m_useAutonaming = a;
+ return m_namer;
}
void enableDumpEvent(bool p = true)
@@ -162,6 +164,8 @@
private:
+ void makeAutoname();
+
// add HCs using builder and current ptrs
void createHitsCollections();
@@ -224,12 +228,14 @@
// starting run number
RunNumberType m_runNumber;
- // use autonaming?
- bool m_useAutonaming;
+ LcioFileNamer* m_namer;
- bool m_enableDumpEvent;
+ static std::string m_defaultFileName;
+ std::vector<std::string> m_currentAutonameFields;
+ bool m_enableDumpEvent;
bool m_writerIsOpen;
+ bool m_usingAutoname;
};
};
slic/include
diff -u -r1.18 -r1.19
--- LcioMessenger.hh 28 Sep 2005 22:21:11 -0000 1.18
+++ LcioMessenger.hh 3 Oct 2005 22:25:54 -0000 1.19
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/include/LcioMessenger.hh,v 1.18 2005/09/28 22:21:11 jeremy Exp $
+// $Header: /cvs/lcd/slic/include/LcioMessenger.hh,v 1.19 2005/10/03 22:25:54 jeremy Exp $
#ifndef slic_LcioMessenger_hh
#define slic_LcioMessenger_hh 1
@@ -45,7 +45,7 @@
G4UIcommand* m_fileExistsActionCmd;
G4UIcommand* m_mcpFilenameCmd;
G4UIcmdWithAnInteger* m_setRunNumberCmd;
- G4UIcmdWithABool* m_autonameCmd;
+ G4UIcommand* m_autonameCmd;
G4UIcmdWithABool* m_dumpEventCmd;
};
};
slic/src
diff -u -r1.9 -r1.10
--- LcioFileNamer.cc 22 Sep 2005 21:39:06 -0000 1.9
+++ LcioFileNamer.cc 3 Oct 2005 22:25:54 -0000 1.10
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/LcioFileNamer.cc,v 1.9 2005/09/22 21:39:06 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/LcioFileNamer.cc,v 1.10 2005/10/03 22:25:54 jeremy Exp $
#include "LcioFileNamer.hh"
// lcdd
@@ -10,30 +10,86 @@
#include "G4Application.hh"
#include "PackageInfo.hh"
#include "EventSourceManager.hh"
+#include "TimeUtil.hh"
+
+// geant4
+#include "G4Run.hh"
+
+using std::endl;
+using std::cout;
+using std::cerr;
namespace slic
{
std::string LcioFileNamer::m_sep = "_";
- std::string LcioFileNamer::makeFullFilename()
+ LcioFileNamer::LcioFileNamer()
{
- // app abbreviation
- std::string abbrev = PackageInfo::getAbbrevString();
+ m_defaultFields.push_back("event");
+ m_defaultFields.push_back("application");
+ m_defaultFields.push_back("version");
+ m_defaultFields.push_back("geometry");
+ }
- // app version
- std::string ver = PackageInfo::getVersionString();
+ std::string LcioFileNamer::getFieldValue(std::string field)
+ {
+ std::string value;
- // geom name
- std::string geo = LCDDProcessor::instance()->getDetectorName();
+ if ( field == "application" || field == "app" ) {
+ value = PackageInfo::getAbbrevString();
+ }
+ else if ( field == "version" || field == "ver" ) {
+ value = PackageInfo::getVersionString();
+ }
+ else if ( field == "geometry" || field == "geo" ) {
+ value = LCDDProcessor::instance()->getDetectorName();
+ }
+ else if ( field == "date" ) {
+ value = TimeUtil::getDate();
+ }
+ else if ( field == "event" || field == "evt" ) {
+ value = LcioFileNamer::makeEventName();
+ }
+ else if ( field == "eventNumber" || field == "evtNum" ) {
+ value = LcioFileNamer::makeEventNumberString();
+ }
+ else if ( field == "run" || field == "runNumber" || field == "runNum" ) {
+ value = LcioFileNamer::makeRunNumberString();
+ }
+ else {
+ cerr << "WARNING: Ignoring unknown field <" << field << ">" << endl;
+ value = "";
+ }
- // event
- std::string evt = LcioFileNamer::makeEventName();
+ return value;
+ }
- // full name
- std::string fname = evt + m_sep + abbrev + m_sep + ver + m_sep + geo;
+ std::string LcioFileNamer::makeFileName(std::vector<std::string> fieldList)
+ {
+ std::string filename = "";
+ if ( fieldList.size() != 0 ) {
+ for(std::vector<std::string>::const_iterator it = fieldList.begin();
+ it != fieldList.end();
+ it++) {
+ std::string value = getFieldValue(*it);
+ if ( value != "" ) {
+ filename = filename + value + m_sep;
+ }
+ }
+ if ( filename != "" ) {
+ filename.erase(filename.end() - 1, filename.end());
+ }
+ }
+ else {
+ filename = makeDefaultFileName();
+ }
+ return filename;
+ }
- return fname;
+ std::string LcioFileNamer::makeDefaultFileName()
+ {
+ return makeFileName(m_defaultFields);
}
std::string LcioFileNamer::makeEventName()
@@ -79,13 +135,8 @@
double ene = gps->GetCurrentSource()->GetEneDist()->GenerateOne( gps->GetParticleDefinition() );
std::string eneStr = StringUtil::toString( ene / GeV ) + "GeV";
- // momentum
- //std::cout << "mom: " << gps->GetParticleMomentumDirection() << std::endl;
- //std::string mom_str = makeMomentumString( gps->GetCurrentSource()->GetAngDist()->GenerateOne() );
-
// full string
std::string evtname = pname + m_sep + eneStr;
- //+ m_sep + mom_str;
return evtname;
}
@@ -100,12 +151,8 @@
// energy
std::string pE = StringUtil::toString( gun->GetParticleEnergy() / GeV ) + "GeV";
- // momentum
- //std::string mom_str = makeMomentumString( gun->GetParticleMomentumDirection() );
-
// full string
std::string evtname = pname + m_sep + pE;
- //+ m_sep + mom_str;
return evtname;
}
@@ -120,4 +167,14 @@
std::string mstr = "px" + px + "py" + py + "pz" + pz;
return mstr;
}
+
+ std::string LcioFileNamer::makeRunNumberString()
+ {
+ return StringUtil::toString( G4RunManager::GetRunManager()->GetCurrentRun()->GetRunID() );
+ }
+
+ std::string LcioFileNamer::makeEventNumberString()
+ {
+ return StringUtil::toString( G4Application::instance()->getRunManager()->getNumberOfEventsToRun() );
+ }
};
slic/src
diff -u -r1.64 -r1.65
--- LcioManager.cc 22 Sep 2005 21:38:37 -0000 1.64
+++ LcioManager.cc 3 Oct 2005 22:25:54 -0000 1.65
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/LcioManager.cc,v 1.64 2005/09/22 21:38:37 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/LcioManager.cc,v 1.65 2005/10/03 22:25:54 jeremy Exp $
#include "LcioManager.hh"
// slic
@@ -42,23 +42,28 @@
using EVENT::LCIO;
using UTIL::LCTOOLS;
+using std::cout;
+using std::cerr;
+using std::endl;
+using std::string;
+
namespace slic
{
LcioManager* LcioManager::m_instance = 0;
+ string LcioManager::m_defaultFileName = "outfile";
LcioManager::LcioManager()
: Module("LcioManager"),
m_McpFinalColl(0),
m_writer(0),
m_runHdr(0),
- m_filename("outfile"),
m_path("."),
m_fileExistsAction( LcioManager::eFail ),
m_runNumber(0),
- m_useAutonaming(false),
m_enableDumpEvent(false),
- m_writerIsOpen(false)
+ m_writerIsOpen(false),
+ m_usingAutoname(false)
{
// messenger
m_messenger = new LcioMessenger(this);
@@ -74,6 +79,10 @@
// create LCWriter
createWriter();
+
+ m_namer = new LcioFileNamer();
+
+ m_filename = m_defaultFileName;
}
LcioManager::~LcioManager()
@@ -108,7 +117,7 @@
void LcioManager::openLcioFile()
{
// get full output path with extension to check its existence
- std::string fullFilename = getFullOutputPath( true );
+ string fullFilename = getFullOutputPath( true );
// default to writing a new file
int writeMode = LCIO::WRITE_NEW;
@@ -125,22 +134,22 @@
else if ( m_fileExistsAction == eDelete ) {
if ( FileUtil::removeFile( fullFilename ) != 0 ) {
// could not remove it!
- std::cerr << "Unable to delete old LCIO file <" << fullFilename << ">." << std::endl;
+ std::cerr << "Unable to delete old LCIO file <" << fullFilename << ">" << std::endl;
G4Exception("Unable to delete old LCIO file.");
}
else {
- std::cout << "Deleted old LCIO file <" << fullFilename << ">." << std::endl;
+ std::cout << "Deleted old LCIO file <" << fullFilename << ">" << std::endl;
}
}
// or append to it
else if ( m_fileExistsAction == eAppend ) {
- std::cout << "Appending to existing LCIO file <" << fullFilename << ">." << std::endl;
+ std::cout << "Appending to existing LCIO file <" << fullFilename << ">" << std::endl;
writeMode = LCIO::WRITE_APPEND;
}
}
// create a new file
else {
- std::cout << "Creating new Lcio file <" << fullFilename << ">." << std::endl;
+ std::cout << "Creating new Lcio file <" << fullFilename << ">" << std::endl;
}
// open the file using the writer with the full path and no extension
@@ -153,9 +162,9 @@
}
}
- LcioManager::EFileExistsAction LcioManager::getFileExistsActionFromString( const std::string& feaStr)
+ LcioManager::EFileExistsAction LcioManager::getFileExistsActionFromString( const string& feaStr)
{
- std::string s = StringUtil::toLower( feaStr );
+ string s = StringUtil::toLower( feaStr );
EFileExistsAction fea = eInvalid;
if ( s == "fail" ) {
fea = eFail;
@@ -179,7 +188,7 @@
#ifdef SLIC_VERBOSE
if ( verbose() > 0 ) {
- std::cout << "Set starting run number <" << m_runNumber << ">." << std::endl;
+ std::cout << "Set starting run number <" << m_runNumber << ">" << std::endl;
}
#endif
}
@@ -204,9 +213,9 @@
}
}
- std::string LcioManager::getFullOutputPath(bool withExtension)
+ string LcioManager::getFullOutputPath(bool withExtension)
{
- std::string fullPath = m_path + "/" + m_filename;
+ string fullPath = m_path + "/" + m_filename;
if ( withExtension ) {
fullPath += ".slcio";
}
@@ -218,10 +227,8 @@
// create new LCRunHeader
createRunHeader( aRun );
- // set automatic output filename if using this option
- if ( m_useAutonaming ) {
- m_filename = LcioFileNamer::makeFullFilename();
- }
+ /* Make autoname from stored fields. This way get correct run and event numbers. */
+ makeAutoname();
// open the Lcio output file for writing
openLcioFile();
@@ -268,7 +275,7 @@
void LcioManager::setDetectorName()
{
- std::string det_tag = LCDDProcessor::instance()->getDetectorName();
+ string det_tag = LCDDProcessor::instance()->getDetectorName();
#ifdef SLIC_VERBOSE
if ( verbose() > 0 ) {
@@ -299,7 +306,7 @@
}
}
- void LcioManager::setPath(const std::string& path)
+ void LcioManager::setPath(const string& path)
{
#ifdef SLIC_VERBOSE
if ( verbose() > 0 ) {
@@ -310,7 +317,7 @@
m_path = path;
}
- void LcioManager::setFilename(const std::string& filename)
+ void LcioManager::setFilename(const string& filename)
{
#ifdef SLIC_VERBOSE
if ( verbose() > 0 ) {
@@ -321,12 +328,36 @@
m_filename = filename;
}
- const std::string& LcioManager::getPath() const
+ 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();
+ it != fields.end();
+ it++) {
+ m_currentAutonameFields.push_back(*it);
+ }
+ }
+
+ void LcioManager::makeAutoname()
+ {
+ std::string autoname = m_namer->makeFileName( m_currentAutonameFields );
+ if ( autoname.size() == 0 || autoname == "" ) {
+ cerr << "WARNING: Autonaming returned an empty string. Using default file name <" << m_defaultFileName << ">" << endl;
+ setFilename( m_defaultFileName );
+ }
+ else {
+ setFilename( autoname );
+ cout << "Autoname set file name to <" << autoname << ">" << endl;
+ }
+ }
+
+ const string& LcioManager::getPath() const
{
return m_path;
}
- const std::string& LcioManager::getFilename() const
+ const string& LcioManager::getFilename() const
{
return m_filename;
}
slic/src
diff -u -r1.28 -r1.29
--- LcioMessenger.cc 28 Sep 2005 22:21:12 -0000 1.28
+++ LcioMessenger.cc 3 Oct 2005 22:25:54 -0000 1.29
@@ -1,9 +1,10 @@
-// $Header: /cvs/lcd/slic/src/LcioMessenger.cc,v 1.28 2005/09/28 22:21:12 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/LcioMessenger.cc,v 1.29 2005/10/03 22:25:54 jeremy Exp $
#include "LcioMessenger.hh"
// slic
#include "LcioManager.hh"
#include "LcioMcpManager.hh"
+#include "LcioFileNamer.hh"
#include "TrajectoryManager.hh"
// lcdd
@@ -67,14 +68,11 @@
}
// autoname
else if ( cmd == m_autonameCmd ) {
- bool an = true;
-
- if ( newVals != G4String("") ) {
- an = G4UIcmdWithABool::GetNewBoolValue( newVals );
- }
-
- m_mgr->useAutonaming( an );
+ std::vector<std::string> fields;
+ StringUtil::split(newVals, " ", fields);
+ m_mgr->setAutonameFields(fields);
}
+ /* dump event */
else if ( cmd == m_dumpEventCmd ) {
m_mgr->enableDumpEvent( m_dumpEventCmd->GetNewBoolValue( newVals.c_str() ) );
}
@@ -165,10 +163,11 @@
m_setRunNumberCmd->SetParameterName( "RunNumber", false );
// enable autonaming
- m_autonameCmd = new G4UIcmdWithABool( "/lcio/autoname", this );
- m_autonameCmd->SetGuidance( "Use automatic file naming." );
- m_autonameCmd->SetParameterName( "enable", 'b', true );
- m_autonameCmd->SetDefaultValue( true );
+ m_autonameCmd = new G4UIcommand( "/lcio/autoname", this );
+ m_autonameCmd->SetGuidance( "Set autonaming parameters." );
+ m_autonameCmd->SetGuidance("Valid autoname fields: application version geometry event date");
+ p = new G4UIparameter("autoname", 's', true );
+ m_autonameCmd->SetParameter(p);
/* dumping of event data */
m_dumpEventCmd = new G4UIcmdWithABool( "/lcio/dumpEvent", this );
CVSspam 0.2.8