BLCMDntuple Class Reference

Inheritance diagram for BLCMDntuple:

BLCommand BLManager::EventAction

List of all members.


Detailed Description

class BLCMDntuple - implements an ntuple.

An ntuple holds the data from multiple virtualdetector-s in a single NTuple, with one row per event. If multiple tracks hit a given virtual detector in the ntuple, only the first one is kept.

Public Member Functions

 BLCMDntuple ()
 Default constructor.
virtual ~BLCMDntuple ()
 Destructor.
 BLCMDntuple (const BLCMDntuple &r)
 Copy constructor.
G4String commandName ()
 commandName() returns "ntuple".
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the ntuple command.
void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for the command.
bool addDetector (void *caller, G4String name, G4String detFields)
 addDetector will add a detector to this object. Returns true if the detector was added.
void setupFirstEvent ()
 setupFirstEvent() will setup the NTuple (called at first event)
void BeginOfEventAction (const G4Event *event)
 from BLManager::EventAction
void EndOfEventAction (const G4Event *event)

Static Public Member Functions

static int setDetector (void *caller, G4String name, G4String detFields)
 setDetector is called by BLCMDvirtualdetector as each instance is placed. Returns # NTuples this virtualdetector is part of. Called by construct() of each BLCMDvirtualdetector.
static void appendRow (void *caller, float *data, int ndata)
 appendRow is called by BLCMDvirtualdetector as each virtualdetector is hit by a track. Called by UserSteppingAction() of each BLCMDvirtualdetector when a track enters its physical volume.
static bool matches (G4String s, G4String pattern)
 returns true if the string s matches one of the patterns in pattern.

Private Attributes

G4String name
G4String category
G4String detectors
G4String required
G4String format
G4int minHit
G4String fields
BLNTuplentuple
float * data
int ndata
std::map< void *, int > place
std::vector< int > start
Bitmask need
Bitmask got
int nHit

Static Private Attributes

static std::vector< BLCMDntuple * > list
static G4String possibilities


Constructor & Destructor Documentation

BLCMDntuple::BLCMDntuple (  ) 

Default constructor.

References BLCMDTYPE_DATA, category, data, BLCommand::description, detectors, fields, format, BLNTuple::getFormatList(), got, minHit, name, ndata, need, nHit, ntuple, BLCommand::registerCommand(), required, BLCommand::setDescription(), and BLCommand::setSynopsis().

Referenced by command().

00113                          : BLCommand(), BLManager::EventAction(),
00114                                                 place(), start()
00115 {
00116         registerCommand(BLCMDTYPE_DATA);
00117         setSynopsis("Define a per-event NTuple containing multiple detectors.");
00118         setDescription("An ntuple holds the data from multiple "
00119                 "virtualdetector-s in a single NTuple, with one row per event. "
00120                 "Up to 64 virtualdetector-s can be used. "
00121                 "If multiple tracks hit a given virtual detector during the "
00122                 "event, only the first one is kept in this ntuple. "
00123                 "virtualdetector-s are specified by patterns identical to "
00124                 "UNIX file-matching, so '*Det*' matches any virtualdetector "
00125                 "with 'Det' anywhere in its name, etc. The 'required' argument "
00126                 "permits events to be omitted unless all of the matching "
00127                 "virtualdetector-s were hit at least once in the event. The "
00128                 "patterns in 'required' are applied only to virtualdetectors "
00129                 "in the ntuple, so a simple '*' requires a hit in every one.\n"
00130                 "\nNOTE: the name of a virtualdetector is by default the "
00131                 "concatenation of its ancestors' names before its own (except "
00132                 "World), unless "
00133                 "rename=NAME was used in its place command. The patterns are "
00134                 "applied to the names of the virtualdetectors as they were "
00135                 "placed (including rename), not the bare name of the "
00136                 "virtualdetector command. If 'rename=det#' was used to place "
00137                 "the virtualdetector-s, you probably want a * to match the # "
00138                 "or list them individually (det1,det2,det3...).\n\n"
00139                 "Valid Formats (ignore case): ");
00140         description += BLNTuple::getFormatList(); 
00141         // initial default values:
00142         name = "";
00143         category = "NTuple";
00144         detectors = "";
00145         required = "*";
00146         format = "";
00147         minHit = 0;
00148         fields = "";
00149         ntuple = 0;
00150         data = 0;
00151         ndata = 0;
00152         need = 0;
00153         got = 0;
00154         nHit = 0;
00155 }

virtual BLCMDntuple::~BLCMDntuple (  )  [inline, virtual]

Destructor.

00067 { }

BLCMDntuple::BLCMDntuple ( const BLCMDntuple r  ) 

Copy constructor.

References category, data, detectors, fields, format, got, minHit, name, ndata, need, nHit, ntuple, and required.

00157                                              : BLCommand(r), BLManager::EventAction(),
00158                                                 place(), start()
00159 {
00160         name = "";
00161         category = r.category;
00162         detectors = r.detectors;
00163         required = r.required;
00164         format = r.format;
00165         minHit = r.minHit;
00166         fields = r.fields;
00167         ntuple = 0;
00168         data = 0;
00169         ndata = 0;
00170         need = r.need;
00171         got = 0;
00172         nHit = 0;
00173 }


Member Function Documentation

G4String BLCMDntuple::commandName (  )  [inline, virtual]

commandName() returns "ntuple".

Implements BLCommand.

00073 { return "ntuple"; }

int BLCMDntuple::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

command() implements the ntuple command.

Implements BLCommand.

References BLCMDntuple(), BLManager::getObject(), BLCommand::handleNamedArgs(), list, name, BLCommand::print(), BLCommand::printError(), and BLManager::registerEventAction().

00177 {
00178         if(argv.size() != 1) {
00179                 printError("Invalid ntuple command -- need name");
00180                 return -1;
00181         }
00182 
00183         if(argv[0] == "default") {
00184                 handleNamedArgs(namedArgs);
00185                 return -1;
00186         }
00187 
00188         BLCMDntuple *t = new BLCMDntuple(defaultNtuple);
00189         int retval = t->handleNamedArgs(namedArgs);
00190 
00191         t->name = argv[0];
00192 
00193         t->print(argv[0]);
00194 
00195         BLManager::getObject()->registerEventAction(t,false);
00196 
00197         list.push_back(t);
00198 
00199         return retval;
00200 }

void BLCMDntuple::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for the command.

Reimplemented from BLCommand.

References BLCommand::argInt(), BLCommand::argString(), category, detectors, format, minHit, and required.

00203 {
00204         argString(category,"category","The category of the NTuple.");
00205         argString(detectors,"detectors","A comma-separated list of detector patterns.");
00206         argString(required,"required","A comma-separated list of required detector patterns(default=*).");
00207         argString(format,"format","NTuple format (see above for list).");
00208         argInt(minHit,"minHit","Minimum number of detectors hit (default 0).");
00209         argString(required,"require","Synonym for required.");
00210         argInt(minHit,"minHits","Synonym for minHit.");
00211 }

bool BLCMDntuple::addDetector ( void *  caller,
G4String  name,
G4String  detFields 
)

addDetector will add a detector to this object. Returns true if the detector was added.

References Bit, detectors, fields, matches(), ndata, need, place, required, and start.

Referenced by setDetector().

00214 {
00215         if(!matches(name,detectors)) return false;
00216 
00217         int j = start.size();
00218         place[caller] = j;
00219         start.push_back(ndata);
00220 
00221         if(matches(name,required))
00222                 need |= (Bit<<j);
00223 
00224         unsigned place = 0;
00225         while(place != detFields.npos) {
00226                 unsigned next = detFields.find(":",place);
00227                 G4String word = detFields.substr(place,
00228                          (next==detFields.npos ? detFields.npos : next-place));
00229                 if(fields.size() != 0) fields += ":";
00230                 fields += name;
00231                 fields += "_";
00232                 fields += word;
00233                 ++ndata;
00234                 place = next;
00235                 if(next != detFields.npos) place = next + 1;
00236         }
00237 
00238         return true;
00239 }

void BLCMDntuple::setupFirstEvent (  ) 

setupFirstEvent() will setup the NTuple (called at first event)

References category, BLNTuple::create(), data, fields, format, name, ndata, need, ntuple, possibilities, and BLCommand::printError().

Referenced by BeginOfEventAction().

00242 {
00243         if(ndata <= 0) {
00244                 printError("ntuple: no detectors in ntuple '%s'!  "
00245                            "Possibilities are:\n%s\n",name.c_str(),
00246                            possibilities.c_str());
00247                 data = new float[1];
00248                 need = ~(Bitmask)0;
00249                 return;
00250         }
00251 
00252         data = new float[ndata];
00253         ntuple = BLNTuple::create(format,category,name,fields,"");
00254 }

void BLCMDntuple::BeginOfEventAction ( const G4Event *  event  )  [virtual]

from BLManager::EventAction

Implements BLManager::EventAction.

References data, got, ndata, nHit, and setupFirstEvent().

00293 {
00294         if(!data)
00295                 setupFirstEvent();
00296 
00297         got = (Bitmask)0;
00298         nHit = 0;
00299 
00300         for(int i=0; i<ndata; ++i)
00301                 data[i] = 0.0;
00302 }

void BLCMDntuple::EndOfEventAction ( const G4Event *  event  )  [virtual]

Implements BLManager::EventAction.

References BLNTuple::appendRow(), data, got, minHit, ndata, need, nHit, and ntuple.

00305 {
00306         if((need&got) == need && nHit >= minHit)
00307                 ntuple->appendRow(data,ndata);
00308 }

int BLCMDntuple::setDetector ( void *  caller,
G4String  name,
G4String  detFields 
) [static]

setDetector is called by BLCMDvirtualdetector as each instance is placed. Returns # NTuples this virtualdetector is part of. Called by construct() of each BLCMDvirtualdetector.

References addDetector(), list, and possibilities.

Referenced by BLVirtualDetectorNTuple::BLVirtualDetectorNTuple(), and BLCMDzntuple::Entry::Entry().

00257 {
00258         int n = 0;
00259 
00260         for(unsigned i=0; i<list.size(); ++i) {
00261                 if(list[i]->addDetector(caller,name,detFields))
00262                         ++n;
00263         }
00264 
00265         if(possibilities.size() > 0) possibilities += ",";
00266         possibilities += name;
00267 
00268         return n;
00269 }

void BLCMDntuple::appendRow ( void *  caller,
float *  data,
int  ndata 
) [static]

appendRow is called by BLCMDvirtualdetector as each virtualdetector is hit by a track. Called by UserSteppingAction() of each BLCMDvirtualdetector when a track enters its physical volume.

References Bit, data, got, list, ndata, nHit, place, and start.

Referenced by BLVirtualDetectorNTuple::UserSteppingAction(), and BLCMDzntuple::Entry::UserZSteppingAction().

00272 {
00273         for(unsigned i=0; i<list.size(); ++i) {
00274                 BLCMDntuple *p = list[i];
00275                 if(p->place.count(caller) > 0) {
00276                         unsigned j = p->place[caller];
00277                         assert(j < p->start.size());
00278                         Bitmask me = (Bit<<j);
00279                         if((p->got&me) == 0) {  // keep the first track
00280                                 p->got |= me;
00281                                 ++p->nHit;
00282                                 int k = p->start[j];
00283                                 for(int l=0; l<ndetData; ++l) {
00284                                         assert(k >= 0 && k < p->ndata);
00285                                         p->data[k++] = detData[l];
00286                                 }
00287                         }
00288                 }
00289         }
00290 }

bool BLCMDntuple::matches ( G4String  s,
G4String  pattern 
) [static]

returns true if the string s matches one of the patterns in pattern.

References fnmatch(), and place.

Referenced by addDetector().

00311 {
00312         unsigned place = 0;
00313 
00314         while(place != pattern.npos) {
00315                 unsigned next = pattern.find(",",place);
00316                 G4String word = pattern.substr(place,
00317                             (next==pattern.npos ? pattern.npos : next-place));
00318                 if(fnmatch(word.c_str(),s.c_str(),0) == 0)
00319                         return true;
00320                 place = next;
00321                 if(next != pattern.npos) place = next + 1;
00322         }
00323 
00324         return false;
00325 }


Member Data Documentation

G4String BLCMDntuple::name [private]

G4String BLCMDntuple::category [private]

G4String BLCMDntuple::detectors [private]

G4String BLCMDntuple::required [private]

G4String BLCMDntuple::format [private]

G4int BLCMDntuple::minHit [private]

G4String BLCMDntuple::fields [private]

float* BLCMDntuple::data [private]

int BLCMDntuple::ndata [private]

std::map<void*,int> BLCMDntuple::place [private]

Referenced by addDetector(), appendRow(), and matches().

std::vector<int> BLCMDntuple::start [private]

Referenced by addDetector(), and appendRow().

int BLCMDntuple::nHit [private]

std::vector< BLCMDntuple * > BLCMDntuple::list [static, private]

Referenced by appendRow(), command(), and setDetector().

G4String BLCMDntuple::possibilities [static, private]

Referenced by setDetector(), and setupFirstEvent().


The documentation for this class was generated from the following file:
g4beamline