Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
testing::GlobalEngineUserTestService Class Reference

Test service registering its own ßs. More...

#include <GlobalEngineUserTestService.h>

Public Member Functions

 GlobalEngineUserTestService (fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
 

Private Member Functions

void CheckAllSeeds () const
 Checks all engines by CheckSeed() calls. More...
 
void preModuleConstruction (art::ModuleDescription const &)
 
void postModuleConstruction (art::ModuleDescription const &)
 
void preModuleBeginRun (art::ModuleContext const &)
 
void postModuleBeginRun (art::ModuleContext const &)
 
void preProcessEvent (art::Event const &evt, art::ScheduleContext)
 
void preModule (art::ModuleContext const &)
 
void postModule (art::ModuleContext const &)
 
void postProcessEvent (art::Event const &, art::ScheduleContext)
 
void preModuleEndJob (art::ModuleDescription const &)
 
void postModuleEndJob (art::ModuleDescription const &)
 

Static Private Member Functions

static void CheckSeed (TRandom const &engine)
 Throws an exception if the seed is not expected. More...
 

Private Attributes

std::vector< std::stringinstanceNames
 name of engine instances More...
 
bool perEventSeeds
 whether to skip seed check in constructor More...
 
std::vector< std::unique_ptr< TRandom > > engines
 our random generator engines More...
 

Static Private Attributes

static const std::string GlobalInstanceName { "GlobalEngineUserServiceEngine" }
 Name used for the global engine instance. More...
 

Detailed Description

Test service registering its own ßs.

The service owns all its engines and is asks NuRandomService for their seeds. NuRandomService will use global identifiers for them, that is identifiers not bound to the art execution context (that is, not bound to a specific module).

Configuration parameters

Definition at line 60 of file GlobalEngineUserTestService.h.

Constructor & Destructor Documentation

testing::GlobalEngineUserTestService::GlobalEngineUserTestService ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry reg 
)

Definition at line 36 of file GlobalEngineUserTestService_service.cc.

37  : instanceNames (pset.get<std::vector<std::string>>("instances", {}))
38  , perEventSeeds (pset.get<bool> ("perEventSeeds", false))
39 {
40 
41  //
42  // input parameters check
43  //
44  if (instanceNames.empty()) {
45  instanceNames.push_back("GlobalEngineUserTestService");
46  mf::LogInfo("GlobalEngineUserTestService")
47  << "Using a default engine instance name: '" << instanceNames.back()
48  << "'";
49  }
50 
51  //
52  // create all our engines (uninteresting temporary seeds are set)
53  //
54  for (std::string instanceName: instanceNames) {
55  engines.emplace_back(std::make_unique<TRandom3>());
56  engines.back()->SetTitle(instanceName.c_str());
57  } // for
58 
59  //
60  // register all the engines
61  //
63  // NuRandomService::createEngine() can't be called here
64  // because it needs a EngineCreator: good
65 
66  for (auto& engine: engines) {
67 
68  // NuRandomService::registerEngine() should instead succeed;
69  // rndm::NuRandomService::TRandomSeeder is optionally declared (inline)
70  // in NuRandomService.h
71  auto seed = Seeds.registerEngine
72  (rndm::NuRandomService::TRandomSeeder(engine.get()), engine->GetTitle());
73 
74  mf::LogInfo("GlobalEngineUserTestService")
75  << "Registered my random engine "
76  << engine->IsA()->GetName() << "[" << ((void*) engine.get()) << "]"
77  << " with seed " << seed;
78 
79  } // for
80 
81  //
82  // let's check that the seeds were actually set
83  //
84  if (perEventSeeds) {
85  mf::LogWarning("GlobalEngineUserTestService")
86  << "Check of seeds on construction skipped because policy is per event.";
87  }
88  else CheckAllSeeds();
89 
90  //
91  // register callbacks
92  //
103 
104 } // testing::GlobalEngineUserTestService::GlobalEngineUserTestService
void postProcessEvent(art::Event const &, art::ScheduleContext)
std::vector< std::string > instanceNames
name of engine instances
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleContext const &)> sPreModuleBeginRun
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleDescription const &)> sPreModuleConstruction
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleContext const &)> sPreModule
void preModuleConstruction(art::ModuleDescription const &)
void postModuleConstruction(art::ModuleDescription const &)
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleDescription const &)> sPostModuleConstruction
void preModuleEndJob(art::ModuleDescription const &)
std::vector< std::unique_ptr< TRandom > > engines
our random generator engines
void preProcessEvent(art::Event const &evt, art::ScheduleContext)
void postModuleEndJob(art::ModuleDescription const &)
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleContext const &)> sPostModuleBeginRun
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleDescription const &)> sPreModuleEndJob
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
bool perEventSeeds
whether to skip seed check in constructor
GlobalSignal< detail::SignalResponseType::LIFO, void(Event const &, ScheduleContext)> sPostProcessEvent
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleContext const &)> sPostModule
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleDescription const &)> sPostModuleEndJob
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, std::string instance="")
Registers an existing engine with NuRandomService.

Member Function Documentation

void testing::GlobalEngineUserTestService::CheckAllSeeds ( ) const
private

Checks all engines by CheckSeed() calls.

Definition at line 135 of file GlobalEngineUserTestService_service.cc.

135  {
136  mf::LogVerbatim("GlobalEngineUserTestService")
137  << "Checking all " << engines.size() << " seeds";
138  for (auto& engine: engines) CheckSeed(*engine);
139 } // testing::GlobalEngineUserTestService::CheckAllSeeds()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< std::unique_ptr< TRandom > > engines
our random generator engines
static void CheckSeed(TRandom const &engine)
Throws an exception if the seed is not expected.
void testing::GlobalEngineUserTestService::CheckSeed ( TRandom const &  engine)
staticprivate

Throws an exception if the seed is not expected.

Definition at line 109 of file GlobalEngineUserTestService_service.cc.

109  {
110 
112 
113  auto expectedSeed = Seeds.getGlobalCurrentSeed(engine.GetTitle());
114  auto actualSeed = engine.GetSeed();
115 
116  if (actualSeed != expectedSeed) {
117  mf::LogError("GlobalEngineUserTestService")
118  << "Engine " << engine.IsA()->GetName() << "[" << ((void*) &engine)
119  << "](\"" << engine.GetTitle() << "\") has seed " << actualSeed
120  << " (expected: " << expectedSeed << ")";
121  }
122  else {
123  mf::LogVerbatim("GlobalEngineUserTestService")
124  << "Engine " << engine.IsA()->GetName() << "[" << ((void*) &engine)
125  << "](\"" << engine.GetTitle() << "\") has seed " << actualSeed
126  << " (as expected)";
127  }
128  if (actualSeed != expectedSeed) {
130  << "Unexpected seed " << actualSeed << "!\n";
131  }
132 } // testing::GlobalEngineUserTestService::CheckSeed()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void testing::GlobalEngineUserTestService::postModule ( art::ModuleContext const &  )
private

Definition at line 205 of file GlobalEngineUserTestService_service.cc.

206 {
207  if (!perEventSeeds) {
208  MF_LOG_DEBUG("GlobalEngineUserTestService")
209  << "GlobalEngineUserTestService::postModule()";
210  CheckAllSeeds();
211  }
212 } // testing::GlobalEngineUserTestService::postModule()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
bool perEventSeeds
whether to skip seed check in constructor
#define MF_LOG_DEBUG(id)
void testing::GlobalEngineUserTestService::postModuleBeginRun ( art::ModuleContext const &  )
private

Definition at line 178 of file GlobalEngineUserTestService_service.cc.

179 {
180  if (!perEventSeeds) {
181  MF_LOG_DEBUG("GlobalEngineUserTestService")
182  << "GlobalEngineUserTestService::postModuleBeginRun()";
183  CheckAllSeeds();
184  }
185 } // testing::GlobalEngineUserTestService::postModuleBeginRun()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
bool perEventSeeds
whether to skip seed check in constructor
#define MF_LOG_DEBUG(id)
void testing::GlobalEngineUserTestService::postModuleConstruction ( art::ModuleDescription const &  )
private

Definition at line 156 of file GlobalEngineUserTestService_service.cc.

157 {
158  if (!perEventSeeds) {
159  MF_LOG_DEBUG("GlobalEngineUserTestService")
160  << "GlobalEngineUserTestService::postModuleConstruction()";
161  CheckAllSeeds();
162  }
163 } // testing::GlobalEngineUserTestService::postModuleConstruction()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
bool perEventSeeds
whether to skip seed check in constructor
#define MF_LOG_DEBUG(id)
void testing::GlobalEngineUserTestService::postModuleEndJob ( art::ModuleDescription const &  )
private

Definition at line 234 of file GlobalEngineUserTestService_service.cc.

235 {
236  if (!perEventSeeds) {
237  MF_LOG_DEBUG("GlobalEngineUserTestService")
238  << "GlobalEngineUserTestService::postModuleEndJob()";
239  CheckAllSeeds();
240  }
241 } // testing::GlobalEngineUserTestService::preModuleBeginRun()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
bool perEventSeeds
whether to skip seed check in constructor
#define MF_LOG_DEBUG(id)
void testing::GlobalEngineUserTestService::postProcessEvent ( art::Event const &  ,
art::ScheduleContext   
)
private

Definition at line 215 of file GlobalEngineUserTestService_service.cc.

215  {
216  MF_LOG_DEBUG("GlobalEngineUserTestService")
217  << "GlobalEngineUserTestService::postProcessEvent()";
218  CheckAllSeeds();
219 } // testing::GlobalEngineUserTestService::postProcessEvent()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
#define MF_LOG_DEBUG(id)
void testing::GlobalEngineUserTestService::preModule ( art::ModuleContext const &  )
private

Definition at line 196 of file GlobalEngineUserTestService_service.cc.

197 {
198  MF_LOG_DEBUG("GlobalEngineUserTestService")
199  << "GlobalEngineUserTestService::preModule()";
200  CheckAllSeeds();
201 } // testing::GlobalEngineUserTestService::preModule()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
#define MF_LOG_DEBUG(id)
void testing::GlobalEngineUserTestService::preModuleBeginRun ( art::ModuleContext const &  )
private

Definition at line 167 of file GlobalEngineUserTestService_service.cc.

168 {
169  if (!perEventSeeds) {
170  MF_LOG_DEBUG("GlobalEngineUserTestService")
171  << "GlobalEngineUserTestService::preModuleBeginRun()";
172  CheckAllSeeds();
173  }
174 } // testing::GlobalEngineUserTestService::preModuleBeginRun()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
bool perEventSeeds
whether to skip seed check in constructor
#define MF_LOG_DEBUG(id)
void testing::GlobalEngineUserTestService::preModuleConstruction ( art::ModuleDescription const &  )
private

Definition at line 145 of file GlobalEngineUserTestService_service.cc.

146 {
147  if (!perEventSeeds) {
148  MF_LOG_DEBUG("GlobalEngineUserTestService")
149  << "GlobalEngineUserTestService::preModuleConstruction()";
150  CheckAllSeeds();
151  }
152 } // testing::GlobalEngineUserTestService::preModuleConstruction()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
bool perEventSeeds
whether to skip seed check in constructor
#define MF_LOG_DEBUG(id)
void testing::GlobalEngineUserTestService::preModuleEndJob ( art::ModuleDescription const &  )
private

Definition at line 223 of file GlobalEngineUserTestService_service.cc.

224 {
225  if (!perEventSeeds) {
226  MF_LOG_DEBUG("GlobalEngineUserTestService")
227  << "GlobalEngineUserTestService::preModuleEndJob()";
228  CheckAllSeeds();
229  }
230 } // testing::GlobalEngineUserTestService::preModuleBeginRun()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
bool perEventSeeds
whether to skip seed check in constructor
#define MF_LOG_DEBUG(id)
void testing::GlobalEngineUserTestService::preProcessEvent ( art::Event const &  evt,
art::ScheduleContext   
)
private

Definition at line 188 of file GlobalEngineUserTestService_service.cc.

188  {
189  MF_LOG_DEBUG("GlobalEngineUserTestService")
190  << "GlobalEngineUserTestService::preProcessEvent()";
191  CheckAllSeeds();
192 } // testing::GlobalEngineUserTestService::preProcessEvent()
void CheckAllSeeds() const
Checks all engines by CheckSeed() calls.
#define MF_LOG_DEBUG(id)

Member Data Documentation

std::vector<std::unique_ptr<TRandom> > testing::GlobalEngineUserTestService::engines
private

our random generator engines

Definition at line 72 of file GlobalEngineUserTestService.h.

const std::string testing::GlobalEngineUserTestService::GlobalInstanceName { "GlobalEngineUserServiceEngine" }
staticprivate

Name used for the global engine instance.

Definition at line 81 of file GlobalEngineUserTestService.h.

std::vector<std::string> testing::GlobalEngineUserTestService::instanceNames
private

name of engine instances

Definition at line 67 of file GlobalEngineUserTestService.h.

bool testing::GlobalEngineUserTestService::perEventSeeds
private

whether to skip seed check in constructor

Definition at line 69 of file GlobalEngineUserTestService.h.


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