#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. | |
G4String | getName () const |
getName() returns the name of the NTuple (not including category) | |
G4String | getFields () const |
getFields() returns a colon-separated list of the fields. | |
int | getNData () const |
getNData() returns the # data items required. | |
void | doCallbacks (float data[], int ndata) |
doCallbacks() will call all registered callbacks | |
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. | |
void | registerCallback (BLNTupleCallback *cb) |
registerCallback() registers a callback with this BLNTuple. | |
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 std::vector< BLNTuple * > | getList () |
getList() returns the list of all BLNTuples. | |
static bool | isUniqueName (G4String name) |
isUniqueName() returns true if the name is unique. Also enters the name into the nameSet. | |
static void | disableOutputFiles () |
disableOutputFiles() 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. returns 0 for unknown 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 (G4String _name, G4String _fields) | |
Constructor. | |
Protected Attributes | |
G4String | name |
G4String | fields |
int | nData |
std::vector< BLNTupleCallback * > | callback |
Static Protected Attributes | |
static bool | enableOutput = true |
static std::map< G4String, BLNTupleHandler * > * | handler = 0 |
static std::vector< BLNTuple * > | list |
static std::set< G4String > | nameSet |
static G4String | defaultType = "root" |
static BLNTupleHandler * | forceHandler = 0 |
Friends | |
class | BLNTupleHandler |
BLNTuple::BLNTuple | ( | G4String | _name, | |
G4String | _fields | |||
) | [inline, protected] |
virtual BLNTuple::~BLNTuple | ( | ) | [inline, virtual] |
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 defaultType, enableOutput, getHandler(), isUniqueName(), list, and BLCommand::printError().
Referenced by BLCMDcollective::beginCollectiveTracking(), BLVirtualDetectorNTuple::BLVirtualDetectorNTuple(), BLCMDtracker::callback(), BLCMDfieldntuple::callback(), BLCMDnewparticlentuple::command(), BLCMDmovie::command(), BLCMDbeamlossntuple::command(), BLCMDzntuple::Entry::Entry(), BLCMDntuple::setupFirstEvent(), TimeNTuple::TimeNTuple(), and TraceNTuple::TraceNTuple().
00075 { 00076 if(type == "") type = defaultType; 00077 if(!enableOutput) type = "Dummy"; 00078 00079 G4String fullName=category+"/"+name; 00080 if(category == "") fullName=name; 00081 if(!isUniqueName(fullName)) 00082 BLCommand::printError("BLNTuple::create Duplicate NTuple '%s'", 00083 fullName.c_str()); 00084 00085 BLNTupleHandler *h = getHandler(type); 00086 if(h) { 00087 BLNTuple *p = h->create(type,category,name,fields,filename); 00088 if(p) list.push_back(p); 00089 return p; 00090 } 00091 00092 char tmp[128]; 00093 sprintf(tmp,"unknown format '%s'",type.c_str()); 00094 G4Exception("BLNTuple",tmp,FatalException, ""); 00095 00096 return 0; 00097 }
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().
00101 { 00102 if(type == "") type = defaultType; 00103 00104 BLNTupleHandler *h = getHandler(type); 00105 if(h) { 00106 BLNTuple *p = h->read(type,category,name,fields,filename); 00107 return p; 00108 } 00109 00110 char tmp[128]; 00111 sprintf(tmp,"unknown format '%s'",type.c_str()); 00112 G4Exception("BLNTuple",tmp,FatalException, ""); 00113 00114 return 0; 00115 }
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(), BLCMDfieldntuple::callback(), 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().
G4String BLNTuple::getName | ( | ) | const [inline] |
getName() returns the name of the NTuple (not including category)
References name.
Referenced by BLCMDntuple::setupFirstEvent().
00090 { return name; }
G4String BLNTuple::getFields | ( | ) | const [inline] |
getFields() returns a colon-separated list of the fields.
References fields.
Referenced by BLCMDntuple::setupFirstEvent().
00093 { return fields; }
int BLNTuple::getNData | ( | ) | const [inline] |
getNData() returns the # data items required.
References nData.
Referenced by BLCMDbeam::init(), BLVirtualDetectorNTuple::UserSteppingAction(), and BLCMDzntuple::Entry::UserZSteppingAction().
00096 { return nData; }
void BLNTuple::doCallbacks | ( | float | data[], | |
int | ndata | |||
) |
doCallbacks() will call all registered callbacks
References callback.
Referenced by AsciiNTuple::appendRow(), FOR009NTuple::appendRow(), TrackFileNTuple::appendRow(), BLVirtualDetectorNTuple::UserSteppingAction(), and BLCMDzntuple::Entry::UserZSteppingAction().
00161 { 00162 for(unsigned i=0; i<callback.size(); ++i) 00163 callback[i]->ntupleCallback(this,data,ndata); 00164 }
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 BLCMDfieldntuple::callback(), and 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().
void BLNTuple::registerCallback | ( | BLNTupleCallback * | cb | ) | [inline] |
registerCallback() registers a callback with this BLNTuple.
References callback.
Referenced by BLCMDntuple::setupFirstEvent().
00121 { callback.push_back(cb); }
static std::vector<BLNTuple*> BLNTuple::getList | ( | ) | [inline, static] |
getList() returns the list of all BLNTuples.
References list.
Referenced by BLCMDntuple::setupFirstEvent().
00124 { return list; }
bool BLNTuple::isUniqueName | ( | G4String | name | ) | [static] |
static void BLNTuple::disableOutputFiles | ( | ) | [inline, static] |
disableOutputFiles() prevents any output files from being written.
References enableOutput.
Referenced by main().
00131 { 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().
00050 { 00051 // permit this to be called during initializations, without 00052 // worrying about ordering. 00053 if(!handler) 00054 handler = new std::map<G4String,BLNTupleHandler*>(); 00055 00056 for(unsigned i=0; i<typeName.size(); ++i) 00057 typeName[i] = tolower(typeName[i]); 00058 00059 (*handler)[typeName] = h; 00060 }
BLNTupleHandler * BLNTuple::getHandler | ( | G4String | type | ) | [static] |
getHandler() returns the BLNTupleHandler for a given type. returns 0 for unknown type.
References forceHandler, and handler.
Referenced by create(), and read().
00063 { 00064 if(forceHandler) return forceHandler; 00065 00066 for(unsigned i=0; i<type.size(); ++i) 00067 type[i] = tolower(type[i]); 00068 00069 if(!handler) return 0; 00070 return (*handler)[type]; // returns 0 for unknown type 00071 }
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 BLCMDfieldntuple::callback(), 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.
00165 { 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().
00141 { 00142 G4String ret; 00143 if(handler == 0) return ret; 00144 std::map<G4String,BLNTupleHandler*>::iterator i; 00145 for(i=(*handler).begin(); i!=(*handler).end(); ++i) { 00146 if(i->first == "Dummy") continue; 00147 if(i != (*handler).begin()) ret += " "; 00148 ret += i->first; 00149 } 00150 return ret; 00151 }
static BLNTupleHandler* BLNTuple::getForceHandler | ( | ) | [inline, static] |
getForceHandler() will return the forced handler (NULL if none).
References forceHandler.
00171 { 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.
00175 { forceHandler = f; }
friend class BLNTupleHandler [friend] |
G4String BLNTuple::name [protected] |
Referenced by getName().
G4String BLNTuple::fields [protected] |
Referenced by getFields().
int BLNTuple::nData [protected] |
Referenced by AsciiNTuple::AsciiNTuple(), BLNTuple(), FOR009NTuple::FOR009NTuple(), getNData(), and TrackFileNTuple::TrackFileNTuple().
std::vector<BLNTupleCallback*> BLNTuple::callback [protected] |
Referenced by doCallbacks(), registerCallback(), and ~BLNTuple().
bool BLNTuple::enableOutput = true [static, protected] |
Referenced by create(), disableOutputFiles(), and getEnableOutput().
std::map< G4String, BLNTupleHandler * > * BLNTuple::handler = 0 [static, protected] |
Referenced by getFormatList(), getHandler(), BLNTupleHandler::handler(), and registerHandler().
std::vector< BLNTuple * > BLNTuple::list [static, protected] |
Reimplemented in TrackFileNTuple.
Referenced by closeAll(), create(), flushAll(), getList(), and summary().
std::set< G4String > BLNTuple::nameSet [static, protected] |
Referenced by isUniqueName().
G4String BLNTuple::defaultType = "root" [static, protected] |
Referenced by create(), read(), and setDefaultType().
BLNTupleHandler * BLNTuple::forceHandler = 0 [static, protected] |
Referenced by getForceHandler(), getHandler(), and setForceHandler().