LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ArtState.h
Go to the documentation of this file.
1 
7 #ifndef NURANDOM_RANDOMUTILS_ARTSTATE_H
8 #define NURANDOM_RANDOMUTILS_ARTSTATE_H 1
9 
10 // NuRandomService libraries
12 
13 // framework libraries
19 
20 // supporting libraries
22 
23 // C/C++ standard libraries
24 #include <string>
25 
26 
27 namespace rndm {
28 
29  namespace NuRandomServiceHelper {
30 
32  class ArtState {
33  public:
34  typedef enum {
44  } state_type;
45 
47 
48 
49  ArtState(state_type start_state = unDefined)
50  : artState(start_state)
51  , lastEvent()
52  , lastModule()
53  , procName()
54  {}
55 
56  // Accept compiler written d'tor, copy c'tor and copy assignment.
57 
59  void set_state(state_type astate) { artState = astate; }
61 
63  state_type transit_to(state_type astate)
64  {
65  state_type old_state = state();
66  set_state(astate);
67  MF_LOG_DEBUG("ArtState")
68  << "NuRandomService::ArtState: transition from "
69  << stateName(old_state) << " to " << stateName();
70  return old_state;
71  } // transit_to()
72 
75 
77  void set_event(art::Event const& evt)
78  {
79  lastEvent = {
80  evt.id(), evt.time(), evt.isRealData(), evt.experimentType()
81  };
82  } // set_event()
84 
87  {
88  lastModule = desc;
89  set_process_name(desc);
90  }
92 
93  void set_process_name(std::string pn) { procName = pn; }
94  void set_process_name(art::ModuleDescription const& currentModuleDesc)
95  {
96  if (!procName.empty()
97  && (procName != currentModuleDesc.processName()))
98  {
100  << "Process name changed from '" << procName << "' to '"
101  << currentModuleDesc.processName() << "'?!?";
102  }
103  procName = currentModuleDesc.processName();
104  } // set_process_name()
105 
107 
108 
110 
112  state_type state() const { return artState; }
113 
114  std::string stateName() const { return stateName(state()); }
115 
116  art::EventID const& eventID() const { return lastEvent.id(); }
117 
118  EventInfo_t const& eventInfo() const { return lastEvent; }
119 
120  art::ModuleDescription const& moduleDesc() const { return lastModule; }
121 
122  std::string moduleLabel() const { return lastModule.moduleLabel(); }
123 
124  std::string processName() const { return procName; }
126 
127 
129  {
130  EventSeedInputData data;
131  data.runNumber = eventID().run();
132  data.subRunNumber = eventID().subRun();
133  data.eventNumber = eventID().event();
134 
135  data.time = eventInfo().time().value();
136  data.isTimeValid
138 
139  data.isData = eventInfo().isRealData();
140 
141  data.processName = processName();
142  data.moduleType = moduleDesc().moduleName();
143  data.moduleLabel = moduleLabel();
144 
145  return data;
146  } // getEventSeedInputData()
148 
149  static std::string stateName(state_type state)
150  {
151  switch (state) {
152  case unDefined: return "(not assigned yet)";
153  case inServiceConstructor: return "service construction";
154  case inModuleConstructor: return "module construction";
155  case inBeginRun: return "begin of run";
156  case inModuleBeginRun: return "begin of run for module";
157  case inEvent: return "event preparation";
158  case inModuleEvent: return "event processing by a module";
159  case inEndJob: return "end job";
160  case inOther: return "unidentified";
161  } // switch
163  << "artext::NuRandomServiceHelper::ArtState::stateName: unknown state #"
164  << ((int) state) << "\n";
165  } // stateName()
166 
167  protected:
168  state_type artState;
169 
172  std::string procName;
173  }; // end ArtState
174 
175  } // end namespace NuRandomServiceHelper
176 
177 } // namespace rndm
178 
179 #endif // NURANDOM_RANDOMUTILS_ARTSTATE_H
bool isData
whether processing real data
state_type transit_to(state_type astate)
Records the new status of ART and returns the old one.
Definition: ArtState.h:63
void reset_module()
Records the status of ART.
Definition: ArtState.h:91
std::string stateName() const
Getters.
Definition: ArtState.h:114
void reset_state()
Resets the status to "something else" (inOther)
Definition: ArtState.h:74
std::string moduleType
name of the class of the running module
static std::string stateName(state_type state)
Definition: ArtState.h:149
art::EventAuxiliary EventInfo_t
Definition: ArtState.h:46
std::string const & moduleLabel() const
state_type artState
current state of the art
Definition: ArtState.h:168
EventSeedInputData getEventSeedInputData() const
Definition: ArtState.h:128
void set_event(art::Event const &evt)
Records the specified event ID.
Definition: ArtState.h:77
ArtState(state_type start_state=unDefined)
Definition: ArtState.h:49
std::string moduleLabel() const
Getters.
Definition: ArtState.h:122
Simple data structure with data needed to extract a seed from a event.
bool isRealData() const
Definition: Event.cc:53
art::EventID const & eventID() const
Getters.
Definition: ArtState.h:116
std::string processName() const
Getters.
Definition: ArtState.h:124
void set_process_name(art::ModuleDescription const &currentModuleDesc)
Records the status of ART.
Definition: ArtState.h:94
constexpr TimeValue_t value() const
Definition: Timestamp.h:23
std::string processName
name of the running process
RunNumber_t run() const
Definition: EventID.h:98
EventInfo_t const & eventInfo() const
Getters.
Definition: ArtState.h:118
std::string const & processName() const
EventAuxiliary::ExperimentType experimentType() const
Definition: Event.cc:59
void set_state(state_type astate)
Records the status of ART.
Definition: ArtState.h:60
std::string const & moduleName() const
void set_process_name(std::string pn)
Records the status of ART.
Definition: ArtState.h:93
Describe the current state of art processing, as understood by the NuRandomService.
Definition: ArtState.h:32
in event processing by a module
Definition: ArtState.h:41
static constexpr Timestamp invalidTimestamp()
Definition: Timestamp.h:82
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::ModuleDescription lastModule
Definition: ArtState.h:171
state_type state() const
Getters.
Definition: ArtState.h:112
std::string moduleLabel
label of the running module instance
#define MF_LOG_DEBUG(id)
void reset_event()
Records the status of ART.
Definition: ArtState.h:83
Timestamp time() const
Definition: Event.cc:47
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:8
A data object holding enough data to define a event seed.
bool isRealData() const noexcept
void set_module(art::ModuleDescription const &desc)
Records the specified module description.
Definition: ArtState.h:86
art::ModuleDescription const & moduleDesc() const
Getters.
Definition: ArtState.h:120
SubRunNumber_t subRun() const
Definition: EventID.h:110
EventID id() const
Definition: Event.cc:23
EventID const & id() const noexcept
Timestamp const & time() const noexcept