CMS 3D CMS Logo

CheckTransitions.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Services
4 // Class : CheckTransitions
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Sep 8 14:17:58 EDT 2005
11 //
13 
16 
19 
24 
31 
32 #include <vector>
33 #include <string>
34 #include "tbb/concurrent_vector.h"
35 #include <iostream>
36 
37 namespace edm {
38 
39  namespace service {
41  public:
43 
45 
47  ~CheckTransitions() noexcept(false);
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
52 
54  void postEndJob();
55 
56  void preOpenFile(std::string const&, bool);
57 
58  void preCloseFile(std::string const& lfn, bool primary);
59 
61 
63 
65 
67 
69 
71 
73 
75 
77 
78  private:
79  tbb::concurrent_vector<std::tuple<Phase, edm::EventID, int>> m_seenTransitions;
81  int m_nstreams = 0;
82  bool m_failed = false;
83  };
84  } // namespace service
85 } // namespace edm
86 using namespace edm::service;
87 
88 namespace {
91 
92  Transition stringToType(const std::string& iTrans) {
93  if (iTrans == "IsStop") {
94  return Transition::IsStop;
95  }
96  if (iTrans == "IsFile") {
97  return Transition::IsFile;
98  }
99  if (iTrans == "IsRun") {
100  return Transition::IsRun;
101  }
102  if (iTrans == "IsLumi") {
103  return Transition::IsLumi;
104  }
105  if (iTrans == "IsEvent") {
106  return Transition::IsEvent;
107  }
108 
109  throw edm::Exception(edm::errors::Configuration) << "Unknown transition type \'" << iTrans << "\'";
110 
111  return Transition::IsInvalid;
112  }
113 
114  std::vector<std::tuple<Phase, edm::EventID, int>> expectedValues(
115  std::vector<std::pair<Transition, edm::EventID>> const& iTrans, int iNStreams) {
116  std::vector<std::tuple<Phase, edm::EventID, int>> returnValue;
117  returnValue.reserve(iTrans.size());
118 
119  const edm::RunNumber_t maxIDValue = edm::EventID::maxRunNumber();
120  edm::EventID lastRun = {maxIDValue, 0, 0};
121  edm::EventID lastLumi = {maxIDValue, maxIDValue, 0};
122  for (auto const& tran : iTrans) {
123  switch (tran.first) {
124  case Transition::IsFile: {
125  break;
126  }
127  case Transition::IsRun: {
128  if (tran.second != lastRun) {
129  if (lastRun.run() != maxIDValue) {
130  //end transitions
131  for (int i = 0; i < iNStreams; ++i) {
132  returnValue.emplace_back(Phase::kEndRun, lastRun, i);
133  }
134  returnValue.emplace_back(Phase::kEndRun, lastRun, 1000);
135  }
136  //begin transitions
137  returnValue.emplace_back(Phase::kBeginRun, tran.second, -1);
138  for (int i = 0; i < iNStreams; ++i) {
139  returnValue.emplace_back(Phase::kBeginRun, tran.second, i);
140  }
141  lastRun = tran.second;
142  }
143  break;
144  }
145  case Transition::IsLumi: {
146  if (tran.second != lastLumi) {
147  if (lastLumi.run() != maxIDValue) {
148  //end transitions
149  for (int i = 0; i < iNStreams; ++i) {
150  returnValue.emplace_back(Phase::kEndLumi, lastLumi, i);
151  }
152  returnValue.emplace_back(Phase::kEndLumi, lastLumi, 1000);
153  }
154  //begin transitions
155  returnValue.emplace_back(Phase::kBeginLumi, tran.second, -1);
156  for (int i = 0; i < iNStreams; ++i) {
157  returnValue.emplace_back(Phase::kBeginLumi, tran.second, i);
158  }
159  lastLumi = tran.second;
160  }
161  break;
162  }
163  case Transition::IsEvent: {
164  returnValue.emplace_back(Phase::kEvent, tran.second, -2);
165  }
166  case Transition::IsStop:
167  case Transition::IsInvalid: {
168  break;
169  }
170  }
171  }
172  if (lastLumi.run() != maxIDValue) {
173  //end transitions
174  for (int i = 0; i < iNStreams; ++i) {
175  returnValue.emplace_back(Phase::kEndLumi, lastLumi, i);
176  }
177  returnValue.emplace_back(Phase::kEndLumi, lastLumi, 1000);
178  }
179  if (lastRun.run() != maxIDValue) {
180  //end transitions
181  for (int i = 0; i < iNStreams; ++i) {
182  returnValue.emplace_back(Phase::kEndRun, lastRun, i);
183  }
184  returnValue.emplace_back(Phase::kEndRun, lastRun, 1000);
185  }
186  return returnValue;
187  }
188 
189 } // namespace
190 
192  for (auto const& p : iPS.getUntrackedParameter<std::vector<edm::ParameterSet>>("transitions")) {
193  m_expectedTransitions.emplace_back(stringToType(p.getUntrackedParameter<std::string>("type")),
194  p.getUntrackedParameter<EventID>("id"));
195  }
196 
198 
200 
202 
204 
206 
208 
210 
212 
214 
216 
218 
220 
221  iRegistry.watchPreEvent(this, &CheckTransitions::preEvent);
222 }
223 
225  if (m_failed) {
226  throw edm::Exception(errors::EventProcessorFailure) << "incorrect transtions";
227  }
228 }
229 
232  desc.setComment("Checks that the transitions specified occur during the job.");
233 
235  trans.addUntracked<std::string>("type");
236  trans.addUntracked<edm::EventID>("id");
237  desc.addVPSetUntracked("transitions", trans, {{}});
238  descriptions.add("CheckTransitions", desc);
239 }
240 
242 
244  auto expectedV = expectedValues(m_expectedTransitions, m_nstreams);
245 
246  std::vector<std::tuple<Phase, edm::EventID, int>> orderedSeen;
247  orderedSeen.reserve(m_seenTransitions.size());
248  for (auto const& i : m_seenTransitions) {
249  // std::cout <<i.first.m_run<<" "<<i.first.m_lumi<<" "<<i.first.m_event<<" "<<i.second<<std::endl;
250  auto s = std::get<2>(i);
251  if (std::get<1>(i).event() > 0) {
252  s = -2;
253  }
254  orderedSeen.emplace_back(std::get<0>(i), std::get<1>(i), s);
255  }
256  std::sort(orderedSeen.begin(), orderedSeen.end());
257 
258  auto orderedExpected = expectedV;
259  std::sort(orderedExpected.begin(), orderedExpected.end());
260  /* for(auto const& i: expectedV) {
261  std::cout <<i.first.m_run<<" "<<i.first.m_lumi<<" "<<i.first.m_event<<" "<<i.second<<std::endl;
262  } */
263 
264  auto itOS = orderedSeen.begin();
265  for (auto itOE = orderedExpected.begin(); itOE != orderedExpected.end(); ++itOE) {
266  if (itOS == orderedSeen.end()) {
267  break;
268  }
269  if (*itOE != *itOS) {
270  auto syncOE = std::get<1>(*itOE);
271  auto syncOS = std::get<1>(*itOS);
272  std::cout << "Different ordering " << syncOE << " " << std::get<2>(*itOE) << "\n"
273  << " " << syncOS << " " << std::get<2>(*itOS) << "\n";
274  m_failed = true;
275  }
276  ++itOS;
277  }
278 
279  if (orderedSeen.size() != orderedExpected.size()) {
280  std::cout << "Wrong number of transition " << orderedSeen.size() << " " << orderedExpected.size() << std::endl;
281  m_failed = true;
282  return;
283  }
284 }
285 
286 void CheckTransitions::preOpenFile(std::string const& lfn, bool b) {}
287 
289 
291  auto id = gc.luminosityBlockID();
292  m_seenTransitions.emplace_back(Phase::kBeginRun, edm::EventID{id.run(), 0, 0}, -1);
293 }
294 
296  auto id = gc.luminosityBlockID();
297  m_seenTransitions.emplace_back(Phase::kEndRun, edm::EventID{id.run(), 0, 0}, 1000);
298 }
299 
301  m_seenTransitions.emplace_back(Phase::kBeginRun, sc.eventID(), sc.streamID());
302 }
303 
305  m_seenTransitions.emplace_back(Phase::kEndRun, sc.eventID(), sc.streamID());
306 }
307 
309  auto id = gc.luminosityBlockID();
310  m_seenTransitions.emplace_back(Phase::kBeginLumi, edm::EventID{id.run(), id.luminosityBlock(), 0}, -1);
311 }
312 
314  auto id = gc.luminosityBlockID();
315  m_seenTransitions.emplace_back(Phase::kEndLumi, edm::EventID{id.run(), id.luminosityBlock(), 0}, 1000);
316 }
317 
319  m_seenTransitions.emplace_back(Phase::kBeginLumi, sc.eventID(), sc.streamID());
320 }
321 
323  m_seenTransitions.emplace_back(Phase::kEndLumi, sc.eventID(), sc.streamID());
324 }
325 
327  m_seenTransitions.emplace_back(Phase::kEvent, sc.eventID(), sc.streamID());
328 }
329 
ConfigurationDescriptions.h
edm::GlobalContext::luminosityBlockID
LuminosityBlockID const & luminosityBlockID() const
Definition: GlobalContext.h:60
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
service
Definition: service.py:1
mps_fire.i
i
Definition: mps_fire.py:428
edm::service::CheckTransitions::Transition::IsFile
funct::false
false
Definition: Factorize.h:29
edm::service::CheckTransitions::m_nstreams
int m_nstreams
Definition: CheckTransitions.cc:81
edm::service::CheckTransitions::preGlobalEndLumi
void preGlobalEndLumi(GlobalContext const &)
Definition: CheckTransitions.cc:313
edm::service::CheckTransitions::preStreamBeginLumi
void preStreamBeginLumi(StreamContext const &)
Definition: CheckTransitions.cc:318
edm::service::CheckTransitions::preGlobalBeginLumi
void preGlobalBeginLumi(GlobalContext const &)
Definition: CheckTransitions.cc:308
edm::EventID::maxRunNumber
static RunNumber_t maxRunNumber()
Definition: EventID.h:92
edm::service::CheckTransitions::Phase::kEndRun
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ProcessContext
Definition: ProcessContext.h:27
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::service::CheckTransitions::Phase
Phase
Definition: CheckTransitions.cc:42
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
DEFINE_FWK_SERVICE
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:96
edm::service::CheckTransitions::Transition
Transition
Definition: CheckTransitions.cc:44
edm::service::CheckTransitions::preGlobalBeginRun
void preGlobalBeginRun(GlobalContext const &)
Definition: CheckTransitions.cc:290
edm::service::CheckTransitions::preallocate
void preallocate(service::SystemBounds const &)
Definition: CheckTransitions.cc:241
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::ActivityRegistry::watchPreStreamBeginRun
void watchPreStreamBeginRun(PreStreamBeginRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:367
watchdog.const
const
Definition: watchdog.py:83
edm::service::CheckTransitions::m_failed
bool m_failed
Definition: CheckTransitions.cc:82
LuminosityBlockID.h
edm::service::CheckTransitions::preCloseFile
void preCloseFile(std::string const &lfn, bool primary)
Definition: CheckTransitions.cc:288
BeamSpotPI::lastLumi
Definition: BeamSpotPayloadInspectorHelper.h:39
edm::service::CheckTransitions::preGlobalEndRun
void preGlobalEndRun(GlobalContext const &)
Definition: CheckTransitions.cc:295
ActivityRegistry.h
edm::service::CheckTransitions::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: CheckTransitions.cc:230
edm::ActivityRegistry::watchPreCloseFile
void watchPreCloseFile(PreCloseFile::slot_type const &iSlot)
Definition: ActivityRegistry.h:235
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::ActivityRegistry::watchPostEndJob
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
Definition: ActivityRegistry.h:170
edm::ActivityRegistry::watchPreStreamBeginLumi
void watchPreStreamBeginLumi(PreStreamBeginLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:431
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::StreamContext
Definition: StreamContext.h:31
edm::service::CheckTransitions::preBeginJob
void preBeginJob(PathsAndConsumesOfModulesBase const &, ProcessContext const &)
EventID.h
edm::ActivityRegistry::watchPreEvent
void watchPreEvent(PreEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:458
edm::ActivityRegistry
Definition: ActivityRegistry.h:134
edm::service::CheckTransitions::Phase::kEvent
edm::service::CheckTransitions::preStreamBeginRun
void preStreamBeginRun(StreamContext const &)
Definition: CheckTransitions.cc:300
ParameterSetDescription.h
b
double b
Definition: hdecay.h:118
edm::service::CheckTransitions
Definition: CheckTransitions.cc:40
edm::ActivityRegistry::watchPreGlobalEndRun
void watchPreGlobalEndRun(PreGlobalEndRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:329
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
ServiceMaker.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
BeamSpotPI::lastRun
Definition: BeamSpotPayloadInspectorHelper.h:40
edm::service::CheckTransitions::preOpenFile
void preOpenFile(std::string const &, bool)
Definition: CheckTransitions.cc:286
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
edm::GlobalContext
Definition: GlobalContext.h:29
edm::service::SystemBounds
Definition: SystemBounds.h:29
edm::errors::EventProcessorFailure
Definition: EDMException.h:46
edm::ParameterSet
Definition: ParameterSet.h:47
GlobalContext.h
Timestamp.h
edm::StreamContext::streamID
StreamID const & streamID() const
Definition: StreamContext.h:54
edm::ActivityRegistry::watchPreStreamEndLumi
void watchPreStreamEndLumi(PreStreamEndLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:445
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
edmPickEvents.event
event
Definition: edmPickEvents.py:273
edm::service::CheckTransitions::Transition::IsRun
edm::service::SystemBounds::maxNumberOfStreams
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:35
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::service::CheckTransitions::preStreamEndLumi
void preStreamEndLumi(StreamContext const &)
Definition: CheckTransitions.cc:322
edm::service::CheckTransitions::Phase::kBeginRun
PathContext.h
edm::service::CheckTransitions::CheckTransitions
CheckTransitions(const ParameterSet &, ActivityRegistry &)
Definition: CheckTransitions.cc:191
edm::service::CheckTransitions::preStreamEndRun
void preStreamEndRun(StreamContext const &)
Definition: CheckTransitions.cc:304
edm::service::CheckTransitions::m_seenTransitions
tbb::concurrent_vector< std::tuple< Phase, edm::EventID, int > > m_seenTransitions
Definition: CheckTransitions.cc:79
edm::service::CheckTransitions::Transition::IsStop
edm::ActivityRegistry::watchPreGlobalEndLumi
void watchPreGlobalEndLumi(PreGlobalEndLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:405
edm::ActivityRegistry::watchPreallocate
void watchPreallocate(Preallocate::slot_type const &iSlot)
Definition: ActivityRegistry.h:144
edm::service::CheckTransitions::Phase::kEndLumi
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
edm::ActivityRegistry::watchPreGlobalBeginLumi
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:391
edm::ActivityRegistry::watchPreOpenFile
void watchPreOpenFile(PreOpenFile::slot_type const &iSlot)
Definition: ActivityRegistry.h:220
edm::ActivityRegistry::watchPreStreamEndRun
void watchPreStreamEndRun(PreStreamEndRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:379
edm::PathsAndConsumesOfModulesBase
Definition: PathsAndConsumesOfModulesBase.h:35
edm::service::CheckTransitions::Transition::IsLumi
Exception
Definition: hltDiff.cc:245
edm::service::CheckTransitions::postEndJob
void postEndJob()
Definition: CheckTransitions.cc:243
Exception.h
edm::ActivityRegistry::watchPreGlobalBeginRun
void watchPreGlobalBeginRun(PreGlobalBeginRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:317
ParameterSet.h
StreamContext.h
edm::service::CheckTransitions::Phase::kBeginLumi
edm::EventID
Definition: EventID.h:31
edm::service::CheckTransitions::Transition::IsEvent
ProcessContext.h
edm::service::CheckTransitions::Transition::IsInvalid
edm::errors::Configuration
Definition: EDMException.h:36
SystemBounds.h
RunID.h
edm::service::CheckTransitions::~CheckTransitions
~CheckTransitions() noexcept(false)
Definition: CheckTransitions.cc:224
edm::service::CheckTransitions::m_expectedTransitions
std::vector< std::pair< Transition, edm::EventID > > m_expectedTransitions
Definition: CheckTransitions.cc:80
edm::StreamContext::eventID
EventID const & eventID() const
Definition: StreamContext.h:59
edm::service::CheckTransitions::preEvent
void preEvent(StreamContext const &)
Definition: CheckTransitions.cc:326