#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 = "ascii" |
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(), BLCMDtracker::callback(), BLCMDfieldntuple::callback(), BLCMDmovie::command(), BLTrackNTuple::create(), and BLCMDntuple::setupFirstEvent().
00079 { 00080 if(type == "") type = defaultType; 00081 if(!enableOutput) type = "Dummy"; 00082 00083 G4String fullName=category+"/"+name; 00084 if(category == "") fullName=name; 00085 if(!isUniqueName(fullName)) 00086 BLCommand::printError("BLNTuple::create Duplicate NTuple '%s'", 00087 fullName.c_str()); 00088 00089 BLNTupleHandler *h = getHandler(type); 00090 if(h) { 00091 BLNTuple *p = h->create(type,category,name,fields,filename); 00092 if(p) list.push_back(p); 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 }
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().
00105 { 00106 if(type == "") type = defaultType; 00107 00108 BLNTupleHandler *h = getHandler(type); 00109 if(h) { 00110 BLNTuple *p = h->read(type,category,name,fields,filename); 00111 return p; 00112 } 00113 00114 char tmp[128]; 00115 sprintf(tmp,"unknown format '%s'",type.c_str()); 00116 G4Exception("BLNTuple",tmp,FatalException, ""); 00117 00118 return 0; 00119 }
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 BLTrackNTuple::appendTrack(), BLCMDmovie::beamStep(), BLCMDfieldntuple::callback(), BLCMDcollective::collectiveStep(), BLCMDmovie::dumpGeometry(), BLCMDntuple::EndOfEventAction(), BLCMDtracker::fitTrack(), BLCMDmovie::generateFakeReference(), BLCMDtracker::PostUserTrackingAction(), BLCMDmovie::referenceStep(), 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 BLTrackNTuple::getName(), and BLCMDntuple::setupFirstEvent().
00090 { return name; }
G4String BLNTuple::getFields | ( | ) | const [inline] |
getFields() returns a colon-separated list of the fields.
References fields.
Referenced by BLTrackNTuple::getFields(), and BLCMDntuple::setupFirstEvent().
00093 { return fields; }
int BLNTuple::getNData | ( | ) | const [inline] |
getNData() returns the # data items required.
References nData.
Referenced by BLCMDbeam::init().
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(), and BLTrackNTuple::appendTrack().
00165 { 00166 for(unsigned i=0; i<callback.size(); ++i) 00167 callback[i]->ntupleCallback(this,data,ndata); 00168 }
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 BLTrackNTuple::annotate().
virtual bool BLNTuple::needsReference | ( | ) | [inline, virtual] |
needsReference() returns true if this NTuple needs the Reference particle.
Reimplemented in FOR009NTuple.
Referenced by BLTrackNTuple::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 BLTrackNTuple::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().
00054 { 00055 // permit this to be called during initializations, without 00056 // worrying about ordering. 00057 if(!handler) 00058 handler = new std::map<G4String,BLNTupleHandler*>(); 00059 00060 for(unsigned i=0; i<typeName.size(); ++i) 00061 typeName[i] = tolower(typeName[i]); 00062 00063 (*handler)[typeName] = h; 00064 }
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().
00067 { 00068 if(forceHandler) return forceHandler; 00069 00070 for(unsigned i=0; i<type.size(); ++i) 00071 type[i] = tolower(type[i]); 00072 00073 if(!handler) return 0; 00074 return (*handler)[type]; // returns 0 for unknown type 00075 }
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 BLCMDntuple::BLCMDntuple(), BLTrackNTuple::getFormatList(), and BLCommand::help().
00145 { 00146 G4String ret; 00147 if(handler == 0) return ret; 00148 std::map<G4String,BLNTupleHandler*>::iterator i; 00149 for(i=(*handler).begin(); i!=(*handler).end(); ++i) { 00150 if(i->first == "Dummy") continue; 00151 if(i != (*handler).begin()) ret += " "; 00152 ret += i->first; 00153 } 00154 return ret; 00155 }
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 = "ascii" [static, protected] |
Referenced by create(), read(), and setDefaultType().
BLNTupleHandler * BLNTuple::forceHandler = 0 [static, protected] |
Referenced by getForceHandler(), getHandler(), and setForceHandler().