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. | |
void | setupFirstEvent () |
setupFirstEvent() will setup the NTuple (called at first event) Done here to be sure all other NTUples have been created (e.g. in callbacks). | |
void | BeginOfEventAction (const G4Event *event) |
from BLManager::EventAction | |
void | EndOfEventAction (const G4Event *event) |
virtual void | ntupleCallback (BLNTuple *caller, float data[], int ndata) |
from BLNTupleCallback | |
Static Public Member Functions | |
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 |
BLNTuple * | ntuple |
float * | data |
int | ndata |
std::map< BLNTuple *, int > | place |
std::vector< int > | start |
Bitmask | need |
Bitmask | got |
int | nHit |
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().
00094 : BLCommand(), BLManager::EventAction(), 00095 place(), start() 00096 { 00097 registerCommand(BLCMDTYPE_DATA); 00098 setSynopsis("Define a per-event NTuple containing multiple detectors."); 00099 setDescription("An ntuple holds the data from multiple " 00100 "virtualdetector-s in a single NTuple, with one row per event. " 00101 "Up to 64 virtualdetector-s can be used. " 00102 "If multiple tracks hit a given virtual detector during the " 00103 "event, only the first one is kept in this ntuple. " 00104 "virtualdetector-s are specified by patterns identical to " 00105 "UNIX file-matching, so '*Det*' matches any virtualdetector " 00106 "with 'Det' anywhere in its name, etc. The 'required' argument " 00107 "permits events to be omitted unless all of the matching " 00108 "virtualdetector-s were hit at least once in the event. The " 00109 "patterns in 'required' are applied only to virtualdetectors " 00110 "in the ntuple, so a simple '*' requires a hit in every one.\n" 00111 "\nNOTE: the name of a virtualdetector is by default the " 00112 "concatenation of its ancestors' names before its own (except " 00113 "World), unless " 00114 "rename=NAME was used in its place command. The patterns are " 00115 "applied to the names of the virtualdetectors as they were " 00116 "placed (including rename), not the bare name of the " 00117 "virtualdetector command. If 'rename=det#' was used to place " 00118 "the virtualdetector-s, you probably want a * to match the # " 00119 "or list them individually (det1,det2,det3...).\n\n" 00120 "Valid Formats (ignore case): "); 00121 description += BLNTuple::getFormatList(); 00122 // initial default values: 00123 name = ""; 00124 category = "NTuple"; 00125 detectors = ""; 00126 required = "*"; 00127 format = ""; 00128 minHit = 0; 00129 fields = ""; 00130 ntuple = 0; 00131 data = 0; 00132 ndata = 0; 00133 need = 0; 00134 got = 0; 00135 nHit = 0; 00136 }
BLCMDntuple::BLCMDntuple | ( | const BLCMDntuple & | r | ) |
Copy constructor.
References category, data, detectors, fields, format, got, minHit, name, ndata, need, nHit, ntuple, and required.
00138 : BLCommand(r), 00139 BLManager::EventAction(), BLNTupleCallback(),place(), start() 00140 { 00141 name = ""; 00142 category = r.category; 00143 detectors = r.detectors; 00144 required = r.required; 00145 format = r.format; 00146 minHit = r.minHit; 00147 fields = r.fields; 00148 ntuple = 0; 00149 data = 0; 00150 ndata = 0; 00151 need = r.need; 00152 got = 0; 00153 nHit = 0; 00154 }
G4String BLCMDntuple::commandName | ( | ) | [inline, virtual] |
int BLCMDntuple::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
command() implements the ntuple command.
Implements BLCommand.
References BLCMDntuple(), BLManager::getObject(), BLCommand::handleNamedArgs(), name, BLCommand::print(), BLCommand::printError(), and BLManager::registerEventAction().
00158 { 00159 if(argv.size() != 1) { 00160 printError("Invalid ntuple command -- need name"); 00161 return -1; 00162 } 00163 00164 if(argv[0] == "default") { 00165 handleNamedArgs(namedArgs); 00166 return -1; 00167 } 00168 00169 BLCMDntuple *t = new BLCMDntuple(defaultNtuple); 00170 int retval = t->handleNamedArgs(namedArgs); 00171 00172 t->name = argv[0]; 00173 00174 t->print(argv[0]); 00175 00176 BLManager::getObject()->registerEventAction(t,false); 00177 00178 return retval; 00179 }
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.
00182 { 00183 argString(category,"category","The category of the NTuple."); 00184 argString(detectors,"detectors","A comma-separated list of detector patterns."); 00185 argString(required,"required","A comma-separated list of required detector patterns(default=*)."); 00186 argString(format,"format","NTuple format (see above for list)."); 00187 argInt(minHit,"minHit","Minimum number of detectors hit (default 0)."); 00188 argString(required,"require","Synonym for required."); 00189 argInt(minHit,"minHits","Synonym for minHit."); 00190 }
void BLCMDntuple::setupFirstEvent | ( | ) |
setupFirstEvent() will setup the NTuple (called at first event) Done here to be sure all other NTUples have been created (e.g. in callbacks).
References Bit, category, BLNTuple::create(), data, detectors, fields, format, BLNTuple::getFields(), BLNTuple::getList(), BLNTuple::getName(), matches(), name, ndata, need, ntuple, place, BLCommand::printError(), BLNTuple::registerCallback(), required, and start.
Referenced by BeginOfEventAction().
00194 { 00195 std::vector<BLNTuple*> list = BLNTuple::getList(); 00196 for(unsigned i=0; i<list.size(); ++i) { 00197 BLNTuple *detNtuple = list[i]; 00198 G4String detName = detNtuple->getName(); 00199 if(!matches(detName,detectors)) continue; 00200 G4String detFields = detNtuple->getFields(); 00201 00202 detNtuple->registerCallback(this); 00203 00204 int j = start.size(); 00205 place[detNtuple] = j; 00206 start.push_back(ndata); 00207 00208 if(matches(detName,required)) { 00209 need |= (Bit<<j); 00210 } 00211 00212 unsigned place = 0; 00213 while(place != detFields.npos) { 00214 unsigned next = detFields.find(":",place); 00215 G4String word = detFields.substr(place, 00216 (next==detFields.npos ? detFields.npos : next-place)); 00217 if(fields.size() != 0) fields += ":"; 00218 fields += detName; 00219 fields += "_"; 00220 fields += word; 00221 ++ndata; 00222 place = next; 00223 if(next != detFields.npos) place = next + 1; 00224 } 00225 } 00226 00227 if(ndata <= 0) { 00228 printError("ntuple: no detectors in ntuple '%s'! " 00229 "Possibilities are:",name.c_str()); 00230 for(unsigned i=0; i<list.size(); ++i) { 00231 G4String detName = list[i]->getName(); 00232 printf("%s ",detName.c_str()); 00233 } 00234 printf("\n"); 00235 data = new float[1]; 00236 need = ~(Bitmask)0; 00237 return; 00238 } 00239 00240 data = new float[ndata]; 00241 ntuple = BLNTuple::create(format,category,name,fields,""); 00242 }
void BLCMDntuple::BeginOfEventAction | ( | const G4Event * | event | ) | [virtual] |
Implements BLManager::EventAction.
References data, got, ndata, nHit, and setupFirstEvent().
00245 { 00246 if(!data) 00247 setupFirstEvent(); 00248 00249 got = (Bitmask)0; 00250 nHit = 0; 00251 00252 for(int i=0; i<ndata; ++i) 00253 data[i] = 0.0; 00254 }
void BLCMDntuple::EndOfEventAction | ( | const G4Event * | event | ) | [virtual] |
virtual void BLCMDntuple::ntupleCallback | ( | BLNTuple * | caller, | |
float | data[], | |||
int | ndata | |||
) | [virtual] |
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 setupFirstEvent().
00281 { 00282 unsigned place = 0; 00283 00284 while(place != pattern.npos) { 00285 unsigned next = pattern.find(",",place); 00286 G4String word = pattern.substr(place, 00287 (next==pattern.npos ? pattern.npos : next-place)); 00288 if(fnmatch(word.c_str(),s.c_str(),0) == 0) 00289 return true; 00290 place = next; 00291 if(next != pattern.npos) place = next + 1; 00292 } 00293 00294 return false; 00295 }
G4String BLCMDntuple::name [private] |
Referenced by BLCMDntuple(), command(), and setupFirstEvent().
G4String BLCMDntuple::category [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4String BLCMDntuple::detectors [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4String BLCMDntuple::required [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4String BLCMDntuple::format [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4int BLCMDntuple::minHit [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and EndOfEventAction().
G4String BLCMDntuple::fields [private] |
Referenced by BLCMDntuple(), and setupFirstEvent().
BLNTuple* BLCMDntuple::ntuple [private] |
Referenced by BLCMDntuple(), EndOfEventAction(), and setupFirstEvent().
float* BLCMDntuple::data [private] |
Referenced by BeginOfEventAction(), BLCMDntuple(), EndOfEventAction(), and setupFirstEvent().
int BLCMDntuple::ndata [private] |
Referenced by BeginOfEventAction(), BLCMDntuple(), EndOfEventAction(), and setupFirstEvent().
std::map<BLNTuple*,int> BLCMDntuple::place [private] |
Referenced by matches(), and setupFirstEvent().
std::vector<int> BLCMDntuple::start [private] |
Referenced by setupFirstEvent().
Bitmask BLCMDntuple::need [private] |
Referenced by BLCMDntuple(), EndOfEventAction(), and setupFirstEvent().
Bitmask BLCMDntuple::got [private] |
Referenced by BeginOfEventAction(), BLCMDntuple(), and EndOfEventAction().
int BLCMDntuple::nHit [private] |
Referenced by BeginOfEventAction(), BLCMDntuple(), and EndOfEventAction().