GlobalEngineUserTestService.h
Go to the documentation of this file.
1 /**
2  * @file GlobalEngineUserTestService.h
3  * @brief Test service registering its own engine
4  * @author Gianluca Petrillo
5  * @see GlobalEngineUserService_service.cc
6  *
7  */
8 
9 #ifndef ARTEXT_SEEDSERVICE_TEST_GLOBALENGINEUSERSERVICE_H
10 #define ARTEXT_SEEDSERVICE_TEST_GLOBALENGINEUSERSERVICE_H
11 
12 
13 // NuRandomService
14 #define NUTOOLS_RANDOMUTILS_NuRandomService_USEROOT 1 // get testing::TRandomSeeder (it's a test...)
15 #include "nutools/RandomUtils/NuRandomService.h"
16 
17 // From art and its tool chain.
18 #include "fhiclcpp/ParameterSet.h"
21 
22 // ROOT libraries
23 #include "TRandom.h"
24 
25 // C/C++ standard libraries
26 #include <string>
27 #include <vector>
28 #include <memory> // std::unique_ptr<>
29 
30 
31 // Forward declarations
32 namespace art {
33  class ActivityRegistry;
34  class ModuleContext;
35  class ModuleDescription;
36 }
37 
38 namespace testing {
39 
40  /**
41  * @brief Test service registering its own ßs
42  *
43  * The service owns all its engines and is asks NuRandomService for their seeds.
44  * NuRandomService will use global identifiers for them, that is identifiers not
45  * bound to the art execution context (that is, not bound to a specific
46  * module).
47  *
48  *
49  * Configuration parameters
50  * -------------------------
51  *
52  * * *instances* (list of strings, default: empty): list of names of the
53  * engines this service is going to own; if it results in an empty list,
54  * a single instance will be created.
55  * * *perEventSeeds* (boolean, default: false): don't check that seeds
56  * match expectations on construction; this is needed in per-event policies
57  * where the seed is not known until the events are available
58  *
59  */
61  public:
64 
65  private:
66 
67  std::vector<std::string> instanceNames; ///< name of engine instances
68 
69  bool perEventSeeds; ///< whether to skip seed check in constructor
70 
71  /// our random generator engines
72  std::vector<std::unique_ptr<TRandom>> engines;
73 
74  /// Checks all engines by CheckSeed() calls
75  void CheckAllSeeds() const;
76 
77  /// Throws an exception if the seed is not expected
78  static void CheckSeed(TRandom const& engine);
79 
80  /// Name used for the global engine instance
82 
83 
84  // callbacks
85  void preModuleConstruction (art::ModuleDescription const&);
86  void postModuleConstruction(art::ModuleDescription const&);
87  void preModuleBeginRun (art::ModuleContext const&);
88  void postModuleBeginRun (art::ModuleContext const&);
89  void preProcessEvent (art::Event const& evt, art::ScheduleContext);
90  void preModule (art::ModuleContext const&);
91  void postModule (art::ModuleContext const&);
92  void postProcessEvent (art::Event const&, art::ScheduleContext);
93  void preModuleEndJob (art::ModuleDescription const&);
94  void postModuleEndJob (art::ModuleDescription const&);
95 
96  }; // class GlobalEngineUserTestService
97 
98 } // namespace testing
99 
100 
102 
103 
104 #endif // ARTEXT_SEEDSERVICE_TEST_GLOBALENGINEUSERSERVICE_H
std::vector< std::string > instanceNames
name of engine instances
Test service registering its own ßs.
LArSoft test utilities.
static const std::string GlobalInstanceName
Name used for the global engine instance.
std::string string
Definition: nybbler.cc:12
#define DECLARE_ART_SERVICE(svc, scope)
Definition: ServiceMacros.h:86
std::vector< std::unique_ptr< TRandom > > engines
our random generator engines
bool perEventSeeds
whether to skip seed check in constructor
TCEvent evt
Definition: DataStructs.cxx:7