LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
evgb::EvtTimeShiftI Class Referenceabstract

interface for event time distribution More...

#include "EvtTimeShiftI.h"

Inheritance diagram for evgb::EvtTimeShiftI:
evgb::EvtTimeFlat evgb::EvtTimeFNALBeam evgb::EvtTimeNone

Public Member Functions

 EvtTimeShiftI (const std::string &config)
 
virtual ~EvtTimeShiftI ()
 
virtual void Config (const std::string &config)=0
 
virtual double TimeOffset ()=0
 
virtual double TimeOffset (std::vector< double > v)=0
 
virtual void PrintConfig (bool verbose=true)=0
 provide a means of printing the configuration More...
 
TRandom * GetRandomGenerator () const
 
bool IsRandomGeneratorOwned () const
 
bool IsRandomGeneratorSeeded () const
 
void SetRandomGenerator (TRandom *gen, bool isOwned)
 

Protected Member Functions

std::vector< std::string > GetConfigTokens (const std::string &config)
 

Protected Attributes

TRandom * fRndmGen
 
bool fIsOwned
 
bool fIsSeeded
 

Detailed Description

interface for event time distribution

Specific implementations of this class when are used to generate appropriate times relative to the t0 of a 'record' (spill/snarl/trigger...).

Concrete instances of this interface must be configurable from a string.

Author
Robert Hatcher <rhatcher fnal.gov> Fermi National Accelerator Laboratory

2015-06-22

Version
Id
EvtTimeShiftI.h,v 1.1 2015/06/30 18:01:24 rhatcher Exp

Definition at line 29 of file EvtTimeShiftI.h.

Constructor & Destructor Documentation

evgb::EvtTimeShiftI::EvtTimeShiftI ( const std::string &  config)

Definition at line 27 of file EvtTimeShiftI.cxx.

References fIsSeeded, fRndmGen, GetConfigTokens(), and seed.

28  : fRndmGen(new TRandom3), fIsOwned(true), fIsSeeded(false)
29  {
30  // user should call Config(config) in their constructor
31  // but setting the random seed should be common
32 
33  // not the most sophisticated of parsing ... but FHICL would be overkill
34  std::vector<std::string> strs = GetConfigTokens(config);
35  size_t nstrs = strs.size();
36  for (size_t i=0; i<nstrs; ++i) {
37  if ( strs[i] == "seed" ) {
38  if ( i+1 >= nstrs ) {
39  mf::LogError("EvtTime")
40  << "EvtTimeShiftI sorry too few values for '" << strs[i] << "'";
41  continue;
42  }
43  const char* arg = strs[i+1].c_str();
44  UInt_t seed = atoi(arg);
45  mf::LogInfo("EvtTime")
46  << "EvtTimeShiftI set seed to " << seed;
47  fRndmGen->SetSeed(seed);
48  fIsSeeded = true;
49  ++i; // used up an argument
50  }
51  }
52 
53  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
long seed
Definition: chem4.cc:67
std::vector< std::string > GetConfigTokens(const std::string &config)
evgb::EvtTimeShiftI::~EvtTimeShiftI ( )
virtual

Definition at line 55 of file EvtTimeShiftI.cxx.

References fIsOwned, and fRndmGen.

56  {
57  if (fIsOwned) delete fRndmGen;
58  fRndmGen = 0;
59  }

Member Function Documentation

virtual void evgb::EvtTimeShiftI::Config ( const std::string &  config)
pure virtual

each schema must take a string that configures it it is up to the individual model to parse said string and extract parameters

Implemented in evgb::EvtTimeFlat, evgb::EvtTimeFNALBeam, and evgb::EvtTimeNone.

std::vector< std::string > evgb::EvtTimeShiftI::GetConfigTokens ( const std::string &  config)
protected

Definition at line 69 of file EvtTimeShiftI.cxx.

References x.

Referenced by evgb::EvtTimeFNALBeam::Config(), EvtTimeShiftI(), and IsRandomGeneratorSeeded().

70  {
71 
72  std::vector<std::string> strs;
73  if ( config == "" ) return strs;
74 
75  std::string configLocal = config;
76 
77  // blindly reduced UPPER -> lower case above to make this easier
78  // convert string to lowercase
79  std::transform(configLocal.begin(),configLocal.end(),
80  configLocal.begin(),::tolower);
81 
82  // for now make use of GENIE utilities
83  strs = genie::utils::str::Split(configLocal,"\t\n ,;=(){}[]");
84 
85  // weed out blank ones
86  strs.erase(std::remove_if(strs.begin(), strs.end(),
87  [](const std::string& x) {
88  return ( x == "") ; // put your condition here
89  }), strs.end());
90 
91  // debugging info
92  std::ostringstream msgx;
93  msgx << "Config elements:" << std::endl;
94  for (size_t j=0; j<strs.size(); ++j) {
95  msgx << " [" << std::setw(3) << j << "] -->" << strs[j] << "<--\n";
96  }
97  // this should end up as LogDebug
98  mf::LogDebug("EvtTime") << msgx.str() << std::flush;
99 
100  return strs;
101  }
Float_t x
Definition: compare.C:6
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
TRandom* evgb::EvtTimeShiftI::GetRandomGenerator ( ) const
inline

Allow users some control over random # sequences An "owned" object is expected to be deleted by the EvtTimeShift obj

Definition at line 61 of file EvtTimeShiftI.h.

References fRndmGen.

Referenced by evgb::GENIEHelper::GENIEHelper().

61 { return fRndmGen; }
bool evgb::EvtTimeShiftI::IsRandomGeneratorOwned ( ) const
inline

Definition at line 62 of file EvtTimeShiftI.h.

References fIsOwned.

62 { return fIsOwned; }
bool evgb::EvtTimeShiftI::IsRandomGeneratorSeeded ( ) const
inline

Definition at line 63 of file EvtTimeShiftI.h.

References fIsSeeded, GetConfigTokens(), and SetRandomGenerator().

Referenced by evgb::GENIEHelper::GENIEHelper().

63 { return fIsSeeded; }
virtual void evgb::EvtTimeShiftI::PrintConfig ( bool  verbose = true)
pure virtual

provide a means of printing the configuration

Implemented in evgb::EvtTimeFlat, evgb::EvtTimeFNALBeam, and evgb::EvtTimeNone.

Referenced by evgb::GENIEHelper::GENIEHelper(), and evg::AddGenieEventsToArt::ParseTimeConfig().

void evgb::EvtTimeShiftI::SetRandomGenerator ( TRandom *  gen,
bool  isOwned 
)

Definition at line 60 of file EvtTimeShiftI.cxx.

References fIsOwned, and fRndmGen.

Referenced by IsRandomGeneratorSeeded().

61  {
62  // deal with what we might already have
63  if ( fIsOwned ) { delete fRndmGen; fRndmGen = 0; fIsOwned = false; }
64 
65  fRndmGen = gen;
66  fIsOwned = isOwned;
67  }
virtual double evgb::EvtTimeShiftI::TimeOffset ( )
pure virtual

return time (in nanoseconds) for an interaction/event within a record/spill/snarl

version taking array might be used for relative batch fractions that vary on a record-by-record basis

Implemented in evgb::EvtTimeFlat, evgb::EvtTimeFNALBeam, and evgb::EvtTimeNone.

Referenced by evg::AddGenieEventsToArt::produce(), and evgb::GENIEHelper::Sample().

virtual double evgb::EvtTimeShiftI::TimeOffset ( std::vector< double >  v)
pure virtual

Member Data Documentation

bool evgb::EvtTimeShiftI::fIsOwned
protected

Definition at line 72 of file EvtTimeShiftI.h.

Referenced by IsRandomGeneratorOwned(), SetRandomGenerator(), and ~EvtTimeShiftI().

bool evgb::EvtTimeShiftI::fIsSeeded
protected

Definition at line 73 of file EvtTimeShiftI.h.

Referenced by EvtTimeShiftI(), and IsRandomGeneratorSeeded().

TRandom* evgb::EvtTimeShiftI::fRndmGen
protected

The documentation for this class was generated from the following files: