BLCMDtrace Class Reference

Inheritance diagram for BLCMDtrace:

BLCommand BLManager::SteppingAction BLManager::TrackingAction BLCollectiveComputation

List of all members.


Detailed Description

class BLCMDtrace implements the trace command.

Public Member Functions

 BLCMDtrace ()
 Constructor.
 BLCMDtrace (const BLCMDtrace &r)
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
void defineNamedArgs ()
void newTrace (const G4Track *firstTrack)
void UserSteppingAction (const G4Step *step)
 UserSteppingAction() from BLManager::SteppingAction.
void PreUserTrackingAction (const G4Track *track)
 PreUserTrackingAction() from BLManager::TrackingAction.
void PostUserTrackingAction (const G4Track *track)
 PostUserTrackingAction() from BLManager::TrackingAction.
virtual void beginCollectiveTracking (std::vector< BLTrackData > &v)
 from BLCollectiveComputation
virtual void collectiveStep (std::vector< BLTrackData > &v)
virtual void endCollectiveTracking (std::vector< BLTrackData > &v)

Private Attributes

int nTrace
G4String format
G4int oneNTuple
G4int primaryOnly
G4String filename
G4String require
G4String coordinates
BLCoordinateType coordinateType
bool doTrace
TraceNTupletrace
BLEvaluatoreval
bool init
BLManagermanager
BLRunManagerrunManager

Static Private Attributes

static TraceNTupleallTrace = 0

Friends

class TraceNTuple

Constructor & Destructor Documentation

BLCMDtrace::BLCMDtrace (  ) 

Constructor.

References BLCMDTYPE_DATA, BLCOORD_CENTERLINE, coordinates, coordinateType, BLCommand::description, doTrace, eval, filename, format, BLNTuple::getFormatList(), init, manager, nTrace, oneNTuple, primaryOnly, BLCommand::registerCommand(), require, runManager, BLCommand::setDescription(), BLCommand::setSynopsis(), and trace.

00120                        : BLCommand(), BLManager::SteppingAction(), 
00121             BLManager::TrackingAction(), BLCollectiveComputation(),
00122             format()
00123 {
00124         registerCommand(BLCMDTYPE_DATA);
00125         setSynopsis("Specifies tracing of tracks.");
00126         setDescription("Generates a separate NTuple for each track, with 1\n"
00127                 "row per step, unless oneNTuple is nonzero (in which case "
00128                 "all tracks are put into a single NTuple).\n"
00129                 "So format=ascii generates one file per track with names\n"
00130                 "generated by the pattern in filename (first %d is replaced "
00131                 "by event #, second %d is replaced by trackId); for "
00132                 "oneNTuple, the default filename is AllTracks.txt.\n"
00133                 "\nNote that without a trace command no traces are generated, "
00134                 "so to trace just the tune and reference particles include "
00135                 "a trace command with no arguments.\n\n"
00136                 "In collective tracking mode, oneNTuple must be nonzero, and "
00137                 "the entries will be generated only at collective steps "
00138                 "(usually at a specified deltaT).\n\n"
00139                 "Valid Formats (ignore case): ");
00140         description += BLNTuple::getFormatList(); 
00141         nTrace = 0;
00142         format = "root";
00143         oneNTuple = 0;
00144         primaryOnly = 0;
00145         filename = "";
00146         require = "";
00147         coordinates = "Centerline";
00148         coordinateType = BLCOORD_CENTERLINE;
00149         doTrace = true;
00150         trace = 0;
00151         eval = 0;
00152         init = false;
00153         manager = 0;    // too early to set these -- see command()
00154         runManager = 0;
00155 }

BLCMDtrace::BLCMDtrace ( const BLCMDtrace r  ) 

References coordinates, coordinateType, doTrace, eval, filename, format, init, manager, nTrace, oneNTuple, primaryOnly, require, runManager, and trace.

00157                                           : BLCommand(r), 
00158             BLManager::SteppingAction(), BLManager::TrackingAction(),
00159             BLCollectiveComputation(), format()
00160 {
00161         nTrace = r.nTrace;
00162         format = r.format;
00163         oneNTuple = r.oneNTuple;
00164         primaryOnly = r.primaryOnly;
00165         filename = r.filename;
00166         require = r.require;
00167         coordinates = r.coordinates;
00168         coordinateType = r.coordinateType;
00169         doTrace = r.doTrace;
00170         trace = r.trace;
00171         eval = 0;
00172         init = r.init;
00173         manager = r.manager;
00174         runManager = r.runManager;
00175 }


Member Function Documentation

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

Implements BLCommand.

00095 { return "trace"; }

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

void BLCMDtrace::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argInt(), BLCommand::argString(), coordinates, filename, format, nTrace, oneNTuple, primaryOnly, and require.

00203 {
00204         argInt(nTrace,"nTrace","Number of tracks to trace.");
00205         argString(format,"format","Format of the NTuple (see above for list).");
00206         argInt(oneNTuple,"oneNTuple","Nonzero to put all traces into a single NTuple.");
00207         argInt(primaryOnly,"primaryOnly","Nonzero to trace only primary tracks.");
00208         argString(filename,"filename","Filename (Ev%dTrk%d.txt or AllTracks.txt).");
00209         argString(filename,"file","synonym for filename.");
00210         argString(require,"require","Expression which must be nonzero to trace the track (default=1)",false);
00211         argString(coordinates,"coordinates","Coordinates: global, centerline, or reference (default=c).");
00212 }

void BLCMDtrace::newTrace ( const G4Track *  firstTrack  ) 

References allTrace, TraceNTuple::close(), coordinateType, eval, BLEvaluator::evaluate(), filename, format, BLManager::getExternalTrackID(), BLEvaluator::isOK(), manager, oneNTuple, BLCommand::printError(), require, BLEvaluator::setTrackVariables(), trace, and TraceNTuple.

Referenced by PreUserTrackingAction().

00215 {
00216         static int prevEvNum = -999;
00217 
00218         int evNum = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
00219         int trkId = manager->getExternalTrackID(firstTrack);
00220 
00221         if(oneNTuple != 0) {
00222                 if(!allTrace) allTrace = new TraceNTuple(format,"AllTracks",
00223                                                 filename, coordinateType);
00224         } else {
00225                 if(trace) trace->close();
00226         }
00227         trace = 0;
00228 
00229         if(eval) {
00230                 eval->setTrackVariables(firstTrack,coordinateType);
00231                 G4double v = eval->evaluate(require);
00232                 if(!eval->isOK()) {
00233                         BLCommand::printError("trace: invalid expression require='%s'\n",
00234                                 require.c_str());
00235                         delete eval;
00236                         eval = 0;
00237                         v = 1.0;
00238                 }
00239                 if(v == 0.0) return;
00240         }
00241 
00242         if(oneNTuple != 0) {
00243                 trace = allTrace;
00244         } else if(evNum < 0) {
00245                 if(evNum != prevEvNum) {
00246                         prevEvNum = evNum;
00247                         char tmp[128];
00248                         if(evNum == -2)
00249                                 trace = new TraceNTuple(format,"TuneParticle",
00250                                         "TuneParticle",coordinateType);
00251                         else if(evNum == -1)
00252                                 trace = new TraceNTuple(format,"ReferenceParticle",
00253                                         "ReferenceParticle",coordinateType);
00254                         else
00255                                 trace = 0;
00256                 } 
00257         } else {
00258                 char tmp[128];
00259                 sprintf(tmp,filename.c_str(),evNum,trkId);
00260                 trace = new TraceNTuple(format,tmp,tmp,coordinateType);
00261         }
00262 }

void BLCMDtrace::UserSteppingAction ( const G4Step *  step  )  [virtual]

UserSteppingAction() from BLManager::SteppingAction.

Implements BLManager::SteppingAction.

References TraceNTuple::appendTrace(), doTrace, BLRunManager::getCollectiveMode(), BLManager::getState(), manager, runManager, SPECIAL, and trace.

00266 {
00267         if(manager->getState() == SPECIAL || runManager->getCollectiveMode())
00268                 return;
00269 
00270         if(!trace || !doTrace) return;
00271 
00272         G4Track *track = step->GetTrack();
00273         trace->appendTrace(track);
00274 }

void BLCMDtrace::PreUserTrackingAction ( const G4Track *  track  )  [virtual]

PreUserTrackingAction() from BLManager::TrackingAction.

Implements BLManager::TrackingAction.

References TraceNTuple::annotate(), BLCOORD_REFERENCE, TraceNTuple::close(), coordinateType, doTrace, BLRunManager::getCollectiveMode(), manager, newTrace(), nTrace, oneNTuple, primaryOnly, runManager, and trace.

00277 {
00278         int evNum = runManager->GetCurrentEvent()->GetEventID();
00279 
00280         doTrace = false;
00281 
00282         if(evNum < 0) {
00283                 // cannot use reference coordinates for tune or reference
00284                 doTrace = (coordinateType != BLCOORD_REFERENCE);
00285                 if(doTrace) newTrace(track);
00286         } else if(runManager->getCollectiveMode() && nTrace > 0) {
00287                 if(oneNTuple == 0) {
00288                         G4Exception("trace","Collective mode, oneNTuple=0",
00289                                 FatalException,"oneNTuple must be nonzero");
00290                 }
00291                 newTrace(track);
00292         } else if(nTrace > 0) {
00293                 doTrace = ((primaryOnly == 0) || (track->GetParentID() == 0));
00294                 if(doTrace) {
00295                         --nTrace;
00296                         newTrace(track);
00297                 }
00298         } else {
00299                 if(trace) {
00300                         trace->close();
00301                         trace = 0;
00302                 }
00303         }
00304 
00305         if(trace && doTrace && 
00306                         !runManager->getCollectiveMode()) {
00307                 char tmp[64];
00308                 sprintf(tmp,"# Event %d Track %d",evNum,manager->
00309                                 getExternalTrackID(track));
00310                 trace->annotate(tmp);
00311         }
00312 }

void BLCMDtrace::PostUserTrackingAction ( const G4Track *  track  )  [virtual]

PostUserTrackingAction() from BLManager::TrackingAction.

Implements BLManager::TrackingAction.

References TraceNTuple::annotate(), TraceNTuple::close(), doTrace, BLRunManager::getCollectiveMode(), oneNTuple, runManager, and trace.

00315 {
00316         if(!trace) return;
00317 
00318         if(doTrace && !runManager->getCollectiveMode())
00319                 trace->annotate("");
00320 
00321         int evNum = G4RunManager::GetRunManager()->GetCurrentEvent()->
00322                                                                 GetEventID();
00323         if(oneNTuple == 0 && evNum >= 0) {
00324                 trace->close();
00325                 trace = 0;
00326         }
00327 }

void BLCMDtrace::beginCollectiveTracking ( std::vector< BLTrackData > &  v  )  [virtual]

from BLCollectiveComputation

Reimplemented from BLCollectiveComputation.

00330 {
00331         (void)v;
00332 }

void BLCMDtrace::collectiveStep ( std::vector< BLTrackData > &  v  )  [virtual]

Implements BLCollectiveComputation.

References TraceNTuple::appendTrace(), primaryOnly, runManager, BLRunManager::setCurrentEvent(), and trace.

00335 {
00336         if(trace) {
00337                 for(unsigned i=0; i<v.size(); ++i) {
00338                         G4Track *track = v[i].track;
00339                         G4Event *event = v[i].event;
00340                         runManager->setCurrentEvent(event);
00341                         G4TrackStatus trackStatus = track->GetTrackStatus();
00342                         if(trackStatus != fAlive && 
00343                                                 trackStatus != fStopButAlive)
00344                                 continue;
00345                         if(primaryOnly != 0 && track->GetParentID() > 0)
00346                                 continue;
00347                         trace->appendTrace(track);
00348                 }
00349         }
00350 }

void BLCMDtrace::endCollectiveTracking ( std::vector< BLTrackData > &  v  )  [virtual]

Reimplemented from BLCollectiveComputation.

00353 {
00354         (void)v;
00355 }


Friends And Related Function Documentation

friend class TraceNTuple [friend]

Referenced by newTrace().


Member Data Documentation

int BLCMDtrace::nTrace [private]

G4String BLCMDtrace::format [private]

G4int BLCMDtrace::oneNTuple [private]

G4int BLCMDtrace::primaryOnly [private]

G4String BLCMDtrace::filename [private]

G4String BLCMDtrace::require [private]

G4String BLCMDtrace::coordinates [private]

bool BLCMDtrace::doTrace [private]

Referenced by BLCMDtrace(), command(), and newTrace().

bool BLCMDtrace::init [private]

Referenced by BLCMDtrace(), and command().

TraceNTuple * BLCMDtrace::allTrace = 0 [static, private]

Referenced by newTrace().


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