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:55
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
service
Definition: service.py:1
mps_fire.i
i
Definition: mps_fire.py:355
edm::service::CheckTransitions::Transition::IsFile
funct::false
false
Definition: Factorize.h:34
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::ParameterSetDescription::addVPSetUntracked
ParameterDescriptionBase * addVPSetUntracked(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
Definition: ParameterSetDescription.h:156
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
SiStripBadComponentsDQMServiceTemplate_cfg.lastRun
lastRun
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:27
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
DEFINE_FWK_SERVICE
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:105
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:309
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
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:233
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::ActivityRegistry::watchPostEndJob
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
Definition: ActivityRegistry.h:168
edm::ActivityRegistry::watchPreStreamBeginLumi
void watchPreStreamBeginLumi(PreStreamBeginLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:373
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:400
edm::ActivityRegistry
Definition: ActivityRegistry.h:132
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:285
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
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:36
edm::ParameterSetDescription::setComment
void setComment(std::string const &value)
Definition: ParameterSetDescription.cc:33
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:387
edm::service::CheckTransitions::Transition::IsRun
edm::service::SystemBounds::maxNumberOfStreams
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:35
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:347
edm::ActivityRegistry::watchPreallocate
void watchPreallocate(Preallocate::slot_type const &iSlot)
Definition: ActivityRegistry.h:142
edm::service::CheckTransitions::Phase::kEndLumi
std
Definition: JetResolutionObject.h:76
edm::ActivityRegistry::watchPreGlobalBeginLumi
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:333
edm::ActivityRegistry::watchPreOpenFile
void watchPreOpenFile(PreOpenFile::slot_type const &iSlot)
Definition: ActivityRegistry.h:218
edm::ActivityRegistry::watchPreStreamEndRun
void watchPreStreamEndRun(PreStreamEndRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:321
edm::PathsAndConsumesOfModulesBase
Definition: PathsAndConsumesOfModulesBase.h:34
edm::service::CheckTransitions::Transition::IsLumi
Exception
Definition: hltDiff.cc:246
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:273
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
event
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of "!*" before the partial wildcard feature was incorporated). The per-event "cost" of each negative criterion with multiple relevant triggers is about the same as ! *was in the past
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