#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 (double data[], int n)=0 |
appendRow() adds a row to an NTuple created for writing. NOTE: data[] must contain n doubles, and n must be the same as the number of fields in the NTuple. | |
virtual bool | readRow (double 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 (double 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 ("" => 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 ("" => 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 BLCMDspacechargelw::beginCollectiveTracking(), BLCMDtracker::callback(), BLCMDfieldntuple::callback(), BLCMDmovie::command(), BLCMDcollective::command(), BLTrackNTuple::create(), BLCMDcollective::setupFieldPoint(), and BLCMDntuple::setupFirstEvent().
00081 { 00082 if(type == "") type = defaultType; 00083 if(!enableOutput) type = "Dummy"; 00084 00085 G4String fullName=category+"/"+name; 00086 if(category == "") fullName=name; 00087 if(!isUniqueName(fullName)) 00088 BLCommand::printError("BLNTuple::create Duplicate NTuple '%s'", 00089 fullName.c_str()); 00090 00091 BLNTupleHandler *h = getHandler(type); 00092 if(h) { 00093 BLNTuple *p = h->create(type,category,name,fields,filename); 00094 if(p) list.push_back(p); 00095 return p; 00096 } 00097 00098 char tmp[128]; 00099 sprintf(tmp,"unknown format '%s'",type.c_str()); 00100 G4Exception("BLNTuple",tmp,FatalException, ""); 00101 00102 return 0; 00103 }
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().
00107 { 00108 if(type == "") type = defaultType; 00109 00110 BLNTupleHandler *h = getHandler(type); 00111 if(h) { 00112 BLNTuple *p = h->read(type,category,name,fields,filename); 00113 return p; 00114 } 00115 00116 char tmp[128]; 00117 sprintf(tmp,"unknown format '%s'",type.c_str()); 00118 G4Exception("BLNTuple",tmp,FatalException, ""); 00119 00120 return 0; 00121 }
virtual void BLNTuple::appendRow | ( | double | data[], | |
int | n | |||
) | [pure virtual] |
appendRow() adds a row to an NTuple created for writing. NOTE: data[] must contain n doubles, 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(), BLCMDspacechargelw::beginTrack(), BLCMDfieldntuple::callback(), BLCMDcollective::collectiveStep(), BLCMDmovie::dumpGeometry(), BLCMDntuple::EndOfEventAction(), BLCMDtracker::fitTrack(), BLCMDmovie::generateFakeReference(), BLCMDtracker::PostUserTrackingAction(), BLCMDmovie::referenceStep(), and BLCMDtracker::UserZSteppingAction().
virtual bool BLNTuple::readRow | ( | double | 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(), and BLCMDntuple::setupFirstEvent().
00096 { return nData; }
void BLNTuple::doCallbacks | ( | double | data[], | |
int | ndata | |||
) |
doCallbacks() will call all registered callbacks
References callback.
Referenced by AsciiNTuple::appendRow(), FOR009NTuple::appendRow(), TrackFileNTuple::appendRow(), and BLTrackNTuple::appendTrack().
00167 { 00168 for(unsigned i=0; i<callback.size(); ++i) 00169 callback[i]->ntupleCallback(this,data,ndata); 00170 }
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().
00056 { 00057 // permit this to be called during initializations, without 00058 // worrying about ordering. 00059 if(!handler) 00060 handler = new std::map<G4String,BLNTupleHandler*>(); 00061 00062 for(unsigned i=0; i<typeName.size(); ++i) 00063 typeName[i] = tolower(typeName[i]); 00064 00065 (*handler)[typeName] = h; 00066 }
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().
00069 { 00070 if(forceHandler) return forceHandler; 00071 00072 for(unsigned i=0; i<type.size(); ++i) 00073 type[i] = tolower(type[i]); 00074 00075 if(!handler) return 0; 00076 return (*handler)[type]; // returns 0 for unknown type 00077 }
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().
00147 { 00148 G4String ret; 00149 if(handler == 0) return ret; 00150 std::map<G4String,BLNTupleHandler*>::iterator i; 00151 for(i=(*handler).begin(); i!=(*handler).end(); ++i) { 00152 if(i->first == "Dummy") continue; 00153 if(i != (*handler).begin()) ret += " "; 00154 ret += i->first; 00155 } 00156 return ret; 00157 }
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] |
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().