#include <BLCollectiveComputation.hh>
Normally a command class that implements a collective computation will be derived from this class as well as BLCommand. Its command() function should register itself with BLRunManager::getObject()->registerCollectiveComputation(this); and then call BLRunManager::getObject()->setCollectiveMode(true);
If steps in time are also desired, it should call BLRunManager::getObject()->setDeltaT(0.1*ns); (with desired delta-T). Note that steps in time are not exact, so the computation should probably check that the variation in time among the tracks is small enough (in practive, 1 ps accuracy is normal).
Note that setDeltaT() can be called at any time, and will affect the next step. It is probably desirable to adjust deltaT depending on the importance of the collective computation (when the bunch is diffuse, bigger deltaT won't affect the accuracy but will reduce the CPU time). Caveat: if steps in time are to be used, setDeltaT() must be called before tracking begins, and should never be <= 0.0 (values <= 0.0 means each track takes individual steps in space, which is probably not useful).
Note that runmanager->rejectCollectiveStep() can be called during tracking or in collectiveStep() to reject the current step and re-process it. This only makes sense if setDeltaT() has been called with a smaller value of deltaT. Attempts to reject the very first step are silently ignored (that step is used to process all tracks to the same time).
The basic sequence of collective tracking, including callbacks from BLRunManger to each registered collective computation is:
(generate beam tracks from beam commands, filling trackVector) stepTime = (largest time from beam tracks) beginCollectiveTracking() first=true loop over steps { rejected=false nActive=0 loop over tracks in trackVector { if(rejected && !first) break; beginTrack() (discard remaining secondaries, if any) process track to stepTime or killed if(track is active) ++nActive if(keepSecondaries) append secondaries to trackVector else discard secondaries } if(!rejected || first) collectiveStep() if(rejected && !first) { restore saved tracks and stepTime } else { save tracks and stepTime stepTime += deltaT } first=false } while(nActive > 0) endCollectiveTracking()
Note: if multiple BLCollectiveComputation instances are registered with BLRUnManager, the callbacks to them will occur in the order in which they were registered (normally the order in which their commands appear in the input file).
Public Member Functions | |
BLCollectiveComputation () | |
virtual | ~BLCollectiveComputation () |
virtual void | beginCollectiveTracking (std::vector< BLTrackData > &v) |
beginCollectiveTracking() is called after the track vector is constructed but before trackng begins. Can be used to allocate internal arrays or create NTuple-s. Note that additional tracks can be added to v as tracking proceeds; no tracks are ever removed (but they will change status). The vector v will not change during the run. | |
virtual void | beginTrack (std::vector< BLTrackData > &v, int index) |
beginTrack() is called just before the track v[index] is tracked for the next step. Note that the user class can be derived from G4UserTrackingAction and registered to be called at the start and end of tracking for each track. The difference is this routine relates the track to the entry in v[], and also: BLRunManager::processOneTrack() can be called here, but not in PreUserTrackingAction(). | |
virtual void | collectiveStep (std::vector< BLTrackData > &v)=0 |
collectiveStep() is called after each collective step to perform the computation. It can store data for later use, and can modify the tracks. Note that collectiveStep() is not called until after the first step is taken, so you might want to call your collectiveStep() function at the end of beginCollectiveTracking() to store the state of tracks at the earliest time. Note: collectiveStep() can call runmanager->rejectCollectiveStep(), in which case the tracking since the previous return from collectiveStep() will be discarded and re-done; for this to make sense, runmanager->setDeltaT() should also be called with a smaller value -- this is one way to adapt deltaT dynamically. | |
virtual void | endCollectiveTracking (std::vector< BLTrackData > &v) |
endCollectiveTracking() is called after tracking is complete. Can be used to delete internal arrays and print a summary. |
virtual void BLCollectiveComputation::beginCollectiveTracking | ( | std::vector< BLTrackData > & | v | ) | [inline, virtual] |
beginCollectiveTracking() is called after the track vector is constructed but before trackng begins. Can be used to allocate internal arrays or create NTuple-s. Note that additional tracks can be added to v as tracking proceeds; no tracks are ever removed (but they will change status). The vector v will not change during the run.
Reimplemented in BLCMDcollective, BLCMDspacecharge, BLCMDspacechargelw, and BLCMDtrace.
virtual void BLCollectiveComputation::beginTrack | ( | std::vector< BLTrackData > & | v, | |
int | index | |||
) | [inline, virtual] |
beginTrack() is called just before the track v[index] is tracked for the next step. Note that the user class can be derived from G4UserTrackingAction and registered to be called at the start and end of tracking for each track. The difference is this routine relates the track to the entry in v[], and also: BLRunManager::processOneTrack() can be called here, but not in PreUserTrackingAction().
Reimplemented in BLCMDspacechargelw.
virtual void BLCollectiveComputation::collectiveStep | ( | std::vector< BLTrackData > & | v | ) | [pure virtual] |
collectiveStep() is called after each collective step to perform the computation. It can store data for later use, and can modify the tracks. Note that collectiveStep() is not called until after the first step is taken, so you might want to call your collectiveStep() function at the end of beginCollectiveTracking() to store the state of tracks at the earliest time. Note: collectiveStep() can call runmanager->rejectCollectiveStep(), in which case the tracking since the previous return from collectiveStep() will be discarded and re-done; for this to make sense, runmanager->setDeltaT() should also be called with a smaller value -- this is one way to adapt deltaT dynamically.
Implemented in BLCMDcollective, BLCMDspacecharge, BLCMDspacechargelw, and BLCMDtrace.
virtual void BLCollectiveComputation::endCollectiveTracking | ( | std::vector< BLTrackData > & | v | ) | [inline, virtual] |
endCollectiveTracking() is called after tracking is complete. Can be used to delete internal arrays and print a summary.
Reimplemented in BLCMDcollective, BLCMDspacecharge, BLCMDspacechargelw, and BLCMDtrace.