LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
EvtTimeShiftI.cxx
Go to the documentation of this file.
1 
12 #include "EvtTimeShiftI.h"
13 #include "TRandom3.h"
14 
15 //GENIE includes
16 #ifdef GENIE_PRE_R3
17  #include "GENIE/Utils/StringUtils.h"
18 #else
19  #include "GENIE/Framework/Utils/StringUtils.h"
20 #endif
22 #include "cetlib_except/exception.h"
23 #include <iomanip>
24 
25 namespace evgb {
26 
27  EvtTimeShiftI::EvtTimeShiftI(const std::string& config)
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  }
54 
56  {
57  if (fIsOwned) delete fRndmGen;
58  fRndmGen = 0;
59  }
60  void EvtTimeShiftI::SetRandomGenerator(TRandom* gen, bool isOwned)
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  }
68 
69  std::vector<std::string> EvtTimeShiftI::GetConfigTokens(const std::string& config)
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  }
102 
103 } // namespace evgb
Float_t x
Definition: compare.C:6
void SetRandomGenerator(TRandom *gen, bool isOwned)
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)
EvtTimeShiftI(const std::string &config)
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
Physics generators for neutrinos, cosmic rays, and others.
Definition: CRYHelper.cxx:33