#include <BLNTuple.hh>
..).
Each type of NTuple will derive a class from this one, and implement the virtual functions.
Public Member Functions | |
virtual | ~BLNTuple () |
Destructor. | |
virtual void | appendRow (float data[], int n)=0 |
appendRow() adds a row to an NTuple created for writing. NOTE: data[] must contain n floats, and n must be the same as the number of fields in the NTuple. | |
virtual bool | readRow (float data[], int ndata)=0 |
readRow() reads a row from an NTuple open for reading. returns true if valid row, false if EOF or error. ndata must be equal to the value of getNData(), and data[] must be at least that long. | |
virtual int | getNData ()=0 |
getNData() returns the # data items required. | |
virtual G4String | getFieldNames () |
getFieldNames() returns a colon-separated list of the field names for each row. Returns an empty string if not supported. | |
virtual void | annotate (G4String line) |
annotate() will add an annotation line to any ASCII format. Normally line should begin with a "#", and have no "\r" or "\n". line == "" will output an empty line to ASCII files. Ignored for NTuples that don't support annotations. | |
virtual bool | needsReference () |
needsReference() returns true if this NTuple needs the Reference particle. | |
virtual void | flush ()=0 |
flush() will flush the NTuple to disk, if supported. | |
virtual void | close ()=0 |
close() will close the NTuple. | |
virtual void | doSummary ()=0 |
do Summary() will print a 1-line summary to stdout, if supported. | |
Static Public Member Functions | |
static BLNTuple * | create (G4String type, G4String category, G4String name, G4String fields, G4String filename) |
create() will create a new NTuple for writing. type must be a known type of NTuple implementation ("" is default). "category/name" is the name of the NTuple (the "/" may be omitted if category is null, depending on type). fields is a : separated list of the field names. filename is a hint, and is not used by all types. | |
static BLNTuple * | read (G4String type, G4String category, G4String name, G4String fields, G4String filename) |
read() will open an NTuple for reading. type must be a known type of NTuple implementation ("" is default). "category/name" is the name of the NTuple (the "/" may be omitted if category is null, depending on type). fields is a : separated list of the field names (not used by all types, in which case it is up to the user to make sure the file fields match the required ones). filename is a hint, and is not used by all types. The NTuple should be explicitly closed by calling its close(). | |
static void | noOutputFiles () |
noOutputFiles() prevents any output files from being written. | |
static bool | getEnableOutput () |
getEnableOutput() returns enableOutput; | |
static void | registerHandler (G4String typeName, BLNTupleHandler *h) |
registerHandler() registers a BLNTupleHandler. This defines a new type of NTuple that can be created. Can be called in static initializers without worrying about ordering. | |
static BLNTupleHandler * | getHandler (G4String type) |
getHandler() returns the BLNTupleHandler for a given type. | |
static void | flushAll () |
flushAll() writes all NTuples to file(s). This is a "checkpoint dump". Loops over all NTuples in the order they were created. Ignores NTuples open for reading. | |
static void | closeAll () |
closeAll() writes all NTuples to file(s) and closes them. Loops over all NTuples in the order they were created. Ignores NTuples open for reading. | |
static void | summary () |
summary() will summarize the NTuples to stdout Loops over all NTuples in the order they were created. Ignores NTuples open for reading. | |
static void | update () |
update() will update real-time histogram interface(s) | |
static void | setDefaultType (G4String name) |
setDefaultType() sets the default type for NTuples | |
static G4String | getFormatList () |
getFormatList() returns a list of known formats. | |
static BLNTupleHandler * | getForceHandler () |
getForceHandler() will return the forced handler (NULL if none). | |
static void | setForceHandler (BLNTupleHandler *f) |
setForceHandler() will force the specified handler to be used, regardless of type. Used to force an MPI handler when in MPI mode. | |
Protected Member Functions | |
BLNTuple () | |
Constructor. | |
Static Protected Attributes | |
static bool | enableOutput = true |
static std::map< G4String, BLNTupleHandler * > * | handler = 0 |
static std::vector< BLNTuple * > | list |
static G4String | defaultType = "root" |
static BLNTupleHandler * | forceHandler = 0 |
Friends | |
class | BLNTupleHandler |
BLNTuple * BLNTuple::create | ( | G4String | type, | |
G4String | category, | |||
G4String | name, | |||
G4String | fields, | |||
G4String | filename | |||
) | [static] |
create() will create a new NTuple for writing. type must be a known type of NTuple implementation ("" is default). "category/name" is the name of the NTuple (the "/" may be omitted if category is null, depending on type). fields is a : separated list of the field names. filename is a hint, and is not used by all types.
References BLNTupleHandler::create(), defaultType, enableOutput, getHandler(), and list.
Referenced by BLCMDcollective::beginCollectiveTracking(), BLVirtualDetectorNTuple::BLVirtualDetectorNTuple(), BLCMDtracker::callback(), BLCMDnewparticlentuple::command(), BLCMDmovie::command(), BLCMDbeamlossntuple::command(), BLCMDzntuple::Entry::Entry(), BLCMDntuple::setupFirstEvent(), TimeNTuple::TimeNTuple(), and TraceNTuple::TraceNTuple().
00067 { 00068 if(type == "") type = defaultType; 00069 if(!enableOutput) type = "Dummy"; 00070 00071 BLNTupleHandler *h = getHandler(type); 00072 if(h) { 00073 BLNTuple *p = h->create(type,category,name,fields,filename); 00074 if(p) list.push_back(p); 00075 return p; 00076 } 00077 00078 char tmp[128]; 00079 sprintf(tmp,"unknown format '%s'",type.c_str()); 00080 G4Exception("BLNTuple",tmp,FatalException, ""); 00081 00082 return 0; 00083 }
BLNTuple * BLNTuple::read | ( | G4String | type, | |
G4String | category, | |||
G4String | name, | |||
G4String | fields, | |||
G4String | filename | |||
) | [static] |
read() will open an NTuple for reading. type must be a known type of NTuple implementation ("" is default). "category/name" is the name of the NTuple (the "/" may be omitted if category is null, depending on type). fields is a : separated list of the field names (not used by all types, in which case it is up to the user to make sure the file fields match the required ones). filename is a hint, and is not used by all types. The NTuple should be explicitly closed by calling its close().
References defaultType, getHandler(), and BLNTupleHandler::read().
Referenced by BLCMDtracker::handlePreviousTracks(), and BLCMDbeam::init().
00087 { 00088 if(type == "") type = defaultType; 00089 00090 BLNTupleHandler *h = getHandler(type); 00091 if(h) { 00092 BLNTuple *p = h->read(type,category,name,fields,filename); 00093 return p; 00094 } 00095 00096 char tmp[128]; 00097 sprintf(tmp,"unknown format '%s'",type.c_str()); 00098 G4Exception("BLNTuple",tmp,FatalException, ""); 00099 00100 return 0; 00101 }
virtual void BLNTuple::appendRow | ( | float | data[], | |
int | n | |||
) | [pure virtual] |
appendRow() adds a row to an NTuple created for writing. NOTE: data[] must contain n floats, and n must be the same as the number of fields in the NTuple.
Implemented in DummyNTuple, TrackFileNTuple, FOR009NTuple, and AsciiNTuple.
Referenced by TraceNTuple::appendTrace(), BLCMDmovie::beamStep(), BLCMDcollective::collectiveStep(), BLCMDmovie::dumpGeometry(), BLCMDntuple::EndOfEventAction(), BLCMDtracker::fitTrack(), BLCMDmovie::generateFakeReference(), BLCMDtracker::PostUserTrackingAction(), BLCMDbeamlossntuple::PostUserTrackingAction(), BLCMDnewparticlentuple::PreUserTrackingAction(), BLCMDmovie::referenceStep(), BLVirtualDetectorNTuple::UserSteppingAction(), TimeNTuple::UserSteppingAction(), BLCMDzntuple::Entry::UserZSteppingAction(), and BLCMDtracker::UserZSteppingAction().
virtual bool BLNTuple::readRow | ( | float | data[], | |
int | ndata | |||
) | [pure virtual] |
readRow() reads a row from an NTuple open for reading. returns true if valid row, false if EOF or error. ndata must be equal to the value of getNData(), and data[] must be at least that long.
Implemented in DummyNTuple, TrackFileNTuple, FOR009NTuple, and AsciiNTuple.
Referenced by BLCMDbeam::nextBeamEvent().
virtual int BLNTuple::getNData | ( | ) | [pure virtual] |
getNData() returns the # data items required.
Implemented in DummyNTuple, TrackFileNTuple, FOR009NTuple, and AsciiNTuple.
Referenced by BLCMDbeam::init(), BLVirtualDetectorNTuple::UserSteppingAction(), and BLCMDzntuple::Entry::UserZSteppingAction().
virtual G4String BLNTuple::getFieldNames | ( | ) | [inline, virtual] |
getFieldNames() returns a colon-separated list of the field names for each row. Returns an empty string if not supported.
Reimplemented in AsciiNTuple.
virtual void BLNTuple::annotate | ( | G4String | line | ) | [inline, virtual] |
annotate() will add an annotation line to any ASCII format. Normally line should begin with a "#", and have no "\r" or "\n". line == "" will output an empty line to ASCII files. Ignored for NTuples that don't support annotations.
Reimplemented in AsciiNTuple.
Referenced by TraceNTuple::annotate().
virtual bool BLNTuple::needsReference | ( | ) | [inline, virtual] |
needsReference() returns true if this NTuple needs the Reference particle.
Reimplemented in FOR009NTuple.
Referenced by BLCMDzntuple::callback(), and BLVirtualDetectorNTuple::needsReference().
virtual void BLNTuple::flush | ( | ) | [pure virtual] |
flush() will flush the NTuple to disk, if supported.
Implemented in DummyNTuple, TrackFileNTuple, FOR009NTuple, and AsciiNTuple.
Referenced by flushAll().
virtual void BLNTuple::close | ( | ) | [pure virtual] |
close() will close the NTuple.
Implemented in DummyNTuple, TrackFileNTuple, FOR009NTuple, and AsciiNTuple.
Referenced by TraceNTuple::close(), closeAll(), and TrackFileNTuple::~TrackFileNTuple().
virtual void BLNTuple::doSummary | ( | ) | [pure virtual] |
do Summary() will print a 1-line summary to stdout, if supported.
Implemented in DummyNTuple, TrackFileNTuple, FOR009NTuple, and AsciiNTuple.
Referenced by summary().
static void BLNTuple::noOutputFiles | ( | ) | [inline, static] |
noOutputFiles() prevents any output files from being written.
References enableOutput.
Referenced by main().
00109 { enableOutput = false; }
static bool BLNTuple::getEnableOutput | ( | ) | [inline, static] |
void BLNTuple::registerHandler | ( | G4String | typeName, | |
BLNTupleHandler * | h | |||
) | [static] |
registerHandler() registers a BLNTupleHandler. This defines a new type of NTuple that can be created. Can be called in static initializers without worrying about ordering.
References handler.
Referenced by AsciiNTupleHandler::AsciiNTupleHandler(), DummyNTupleHandler::DummyNTupleHandler(), FOR009NTupleHandler::FOR009NTupleHandler(), and TrackFileNTupleHandler::TrackFileNTupleHandler().
00042 { 00043 // permit this to be called during initializations, without 00044 // worrying about ordering. 00045 if(!handler) 00046 handler = new std::map<G4String,BLNTupleHandler*>(); 00047 00048 for(unsigned i=0; i<typeName.size(); ++i) 00049 typeName[i] = tolower(typeName[i]); 00050 00051 (*handler)[typeName] = h; 00052 }
BLNTupleHandler * BLNTuple::getHandler | ( | G4String | type | ) | [static] |
getHandler() returns the BLNTupleHandler for a given type.
References forceHandler, and handler.
Referenced by create(), and read().
00055 { 00056 if(forceHandler) return forceHandler; 00057 00058 for(unsigned i=0; i<type.size(); ++i) 00059 type[i] = tolower(type[i]); 00060 00061 if(!handler) return 0; 00062 return (*handler)[type]; // returns 0 for unknown type 00063 }
void BLNTuple::flushAll | ( | ) | [static] |
flushAll() writes all NTuples to file(s). This is a "checkpoint dump". Loops over all NTuples in the order they were created. Ignores NTuples open for reading.
Referenced by BLManager::EndOfEventAction().
void BLNTuple::closeAll | ( | ) | [static] |
closeAll() writes all NTuples to file(s) and closes them. Loops over all NTuples in the order they were created. Ignores NTuples open for reading.
Referenced by BLManager::handleCallbacks(), main(), and BLManager::Notify().
void BLNTuple::summary | ( | ) | [static] |
summary() will summarize the NTuples to stdout Loops over all NTuples in the order they were created. Ignores NTuples open for reading.
References doSummary(), and list.
Referenced by BLManager::handleCallbacks(), main(), and BLManager::Notify().
void BLNTuple::update | ( | ) | [static] |
static void BLNTuple::setDefaultType | ( | G4String | name | ) | [inline, static] |
setDefaultType() sets the default type for NTuples
References defaultType.
00142 { defaultType = name; }
G4String BLNTuple::getFormatList | ( | ) | [static] |
getFormatList() returns a list of known formats.
References handler.
Referenced by BLCMDbeamlossntuple::BLCMDbeamlossntuple(), BLCMDnewparticlentuple::BLCMDnewparticlentuple(), BLCMDntuple::BLCMDntuple(), BLCMDtimentuple::BLCMDtimentuple(), BLCMDtrace::BLCMDtrace(), BLCMDvirtualdetector::BLCMDvirtualdetector(), BLCMDzntuple::BLCMDzntuple(), and BLCommand::help().
00127 { 00128 G4String ret; 00129 if(handler == 0) return ret; 00130 std::map<G4String,BLNTupleHandler*>::iterator i; 00131 for(i=(*handler).begin(); i!=(*handler).end(); ++i) { 00132 if(i->first == "Dummy") continue; 00133 if(i != (*handler).begin()) ret += " "; 00134 ret += i->first; 00135 } 00136 return ret; 00137 }
static BLNTupleHandler* BLNTuple::getForceHandler | ( | ) | [inline, static] |
getForceHandler() will return the forced handler (NULL if none).
References forceHandler.
00148 { return forceHandler; }
static void BLNTuple::setForceHandler | ( | BLNTupleHandler * | f | ) | [inline, static] |
setForceHandler() will force the specified handler to be used, regardless of type. Used to force an MPI handler when in MPI mode.
References forceHandler.
00152 { forceHandler = f; }
friend class BLNTupleHandler [friend] |
bool BLNTuple::enableOutput = true [static, protected] |
Referenced by create(), getEnableOutput(), and noOutputFiles().
std::map< G4String, BLNTupleHandler * > * BLNTuple::handler = 0 [static, protected] |
Referenced by getFormatList(), getHandler(), BLNTupleHandler::handler(), and registerHandler().
std::vector< BLNTuple * > BLNTuple::list [static, protected] |
G4String BLNTuple::defaultType = "root" [static, protected] |
Referenced by create(), read(), and setDefaultType().
BLNTupleHandler * BLNTuple::forceHandler = 0 [static, protected] |
Referenced by getForceHandler(), getHandler(), and setForceHandler().