ArtState.h
Go to the documentation of this file.
1 /**
2  * @file ArtState.h
3  * @brief Class holding the current state of art processing
4  * @author Rob Kutschke (kutschke@fnal.gov)
5  */
6 
7 #ifndef NUTOOLS_RANDOMUTILS_ARTSTATE_H
8 #define NUTOOLS_RANDOMUTILS_ARTSTATE_H 1
9 
10 // NuRandomService libraries
11 #include "nutools/RandomUtils/Providers/EventSeedInputData.h"
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 
31  /// Describe the current state of art processing, as understood by the NuRandomService.
32  class ArtState {
33  public:
34  typedef enum {
35  unDefined, ///< not assigned yet
36  inServiceConstructor, ///< in service construction phase
37  inModuleConstructor, ///< in module construction phase
38  inBeginRun, ///< in begin of run phase
39  inModuleBeginRun, ///< in begin of run for a module
40  inEvent, ///< in event phase
41  inModuleEvent, ///< in event processing by a module
42  inEndJob, ///< in end job
43  inOther ///< none of the above
44  } state_type; ///< type of state of art (what's doing)
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 
58  //@{
59  /// Records the status of ART
60  void set_state(state_type astate) { artState = astate; }
61 
62  /// Records the new status of ART and returns the old one
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 
73  /// Resets the status to "something else" (inOther)
75 
76  /// Records the specified event ID
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 
85  /// Records the specified module description
87  {
88  lastModule = desc;
89  set_process_name(desc);
90  }
92 
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 
106  //@}
107 
108 
109  //@{
110  /// Getters
111 
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 
123 
124  std::string processName() const { return procName; }
125  //@}
126 
127 
129  {
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()
147  /// @}
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; ///< current state of the art
169 
173  }; // end ArtState
174 
175  } // end namespace NuRandomServiceHelper
176 
177 } // namespace rndm
178 
179 #endif // NUTOOLS_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
std::string stateName() const
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 string
Definition: nybbler.cc:12
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
Definition: ArtState.h:122
Simple data structure with data needed to extract a seed from a event.
art::EventID const & eventID() const
Definition: ArtState.h:116
std::string processName() const
Definition: ArtState.h:124
void set_process_name(art::ModuleDescription const &currentModuleDesc)
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
Definition: ArtState.h:118
EventAuxiliary::ExperimentType experimentType() const
std::string const & processName() const
void set_state(state_type astate)
Records the status of ART.
Definition: ArtState.h:60
bool isRealData() const
std::string const & moduleName() const
Timestamp time() const
void set_process_name(std::string pn)
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)
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:7
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
Definition: ArtState.h:120
SubRunNumber_t subRun() const
Definition: EventID.h:110
EventID id() const
Definition: Event.cc:37
EventID const & id() const noexcept
Timestamp const & time() const noexcept