CMS 3D CMS Logo

ConcurrentIOVESSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Integration
4 // Class : ConcurrentIOVESSource
5 //
6 // Implementation:
7 // ESSource used for tests of Framework support for
8 // concurrent IOVs in the EventSetup system
9 //
10 // Original Author: W. David Dagenhart
11 // Created: 21 March 2019
12 
29 
30 #include <memory>
31 #include <vector>
32 
33 namespace edmtest {
34 
36  public:
38 
39  std::unique_ptr<IOVTestInfo> produce(ESTestRecordI const&);
40  std::unique_ptr<ESTestDataA> produceA(ESTestRecordA const&);
41 
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44  private:
46  edm::IOVSyncValue const&,
47  edm::ValidityInterval&) override;
48 
49  bool isConcurrentFinder() const override { return concurrentFinder_; }
50 
51  // These are thread safe because after the constructor we do not
52  // modify their state.
53  const bool iovIsTime_;
54  std::set<edm::IOVSyncValue> setOfIOV_;
55  std::set<edm::IOVSyncValue> setOfInvalidIOV_;
56  const bool concurrentFinder_;
58  const bool findForRecordA_;
60 
61  // Be careful with this. It is modified in setIntervalFor
62  // and the setIntervalFor function is called serially (nonconcurrent
63  // with itself). But it is not thread safe to use this data member
64  // in the produce methods unless concurrentFinder_ is false.
66  };
67 
69  : iovIsTime_(!pset.getParameter<bool>("iovIsRunNotTime")),
70  concurrentFinder_(pset.getParameter<bool>("concurrentFinder")),
71  testForceESSourceMode_(pset.getParameter<bool>("testForceESSourceMode")),
72  findForRecordA_(pset.getParameter<bool>("findForRecordA")) {
74 
75  std::vector<unsigned int> temp(pset.getParameter<std::vector<unsigned int>>("firstValidLumis"));
76  for (auto val : temp) {
77  if (iovIsTime_) {
79  } else {
81  }
82  }
83 
84  std::vector<unsigned int> tempInvalid(pset.getParameter<std::vector<unsigned int>>("invalidLumis"));
85  for (auto val : tempInvalid) {
86  if (iovIsTime_) {
88  } else {
90  }
91  }
92  this->findingRecord<ESTestRecordI>();
93  setWhatProduced(this);
94  if (findForRecordA_) {
95  this->findingRecord<ESTestRecordA>();
97  }
98  }
99 
100  std::unique_ptr<IOVTestInfo> ConcurrentIOVESSource::produce(ESTestRecordI const& record) {
101  auto data = std::make_unique<IOVTestInfo>();
102 
103  edm::ValidityInterval iov = record.validityInterval();
104  edm::LogAbsolute("ConcurrentIOVESSource")
105  << "ConcurrentIOVESSource::produce startIOV = " << iov.first().luminosityBlockNumber()
106  << " endIOV = " << iov.last().luminosityBlockNumber() << " IOV index = " << record.iovIndex()
107  << " cache identifier = " << record.cacheIdentifier() << " time = " << wallclockTimer_.realTime();
108 
109  if (!concurrentFinder_) {
110  if (validityInterval_ != iov) {
111  throw cms::Exception("TestError")
112  << "ConcurrentIOVESSource::produce, testing as nonconcurrent finder and IOV changed!";
113  }
114  }
115 
116  data->iovStartRun_ = iov.first().eventID().run();
117  data->iovEndRun_ = iov.last().eventID().run();
118  data->iovStartLumi_ = iov.first().luminosityBlockNumber();
119  data->iovEndLumi_ = iov.last().luminosityBlockNumber();
120  data->iovIndex_ = record.iovIndex();
121  data->cacheIdentifier_ = record.cacheIdentifier();
122  return data;
123  }
124 
125  std::unique_ptr<ESTestDataA> ConcurrentIOVESSource::produceA(ESTestRecordA const& record) {
126  edm::ValidityInterval iov = record.validityInterval();
127  if (!testForceESSourceMode_ && record.iovIndex() != 0) {
128  // This criteria should never fail because the EventSetupRecord class
129  // is hard coded to allow only one IOV at a time.
130  throw cms::Exception("TestError")
131  << "ConcurrentIOVESSource::produce, more than one concurrent IOV for type ESTestRecordA!";
132  }
133  edm::LogAbsolute("ConcurrentIOVESSource")
134  << "ConcurrentIOVESSource::produceA startIOV = " << iov.first().luminosityBlockNumber()
135  << " endIOV = " << iov.last().luminosityBlockNumber() << " IOV index = " << record.iovIndex()
136  << " cache identifier = " << record.cacheIdentifier() << " time = " << wallclockTimer_.realTime();
137  return std::make_unique<ESTestDataA>(0);
138  }
139 
142  std::vector<unsigned int> emptyVector;
143  desc.add<bool>("iovIsRunNotTime", true);
144  desc.add<bool>("concurrentFinder", true);
145  desc.add<bool>("testForceESSourceMode", false);
146  desc.add<bool>("findForRecordA", false);
147  desc.add<std::vector<unsigned int>>("firstValidLumis", emptyVector);
148  desc.add<std::vector<unsigned int>>("invalidLumis", emptyVector);
149  descriptions.addDefault(desc);
150  }
151 
153  edm::IOVSyncValue const& syncValue,
157 
158  for (auto const& invalidSyncValue : setOfInvalidIOV_) {
159  if (syncValue == invalidSyncValue) {
160  return;
161  }
162  }
163 
164  //if no intervals given, fail immediately
165  if (setOfIOV_.empty()) {
166  return;
167  }
168 
169  std::pair<std::set<edm::IOVSyncValue>::iterator, std::set<edm::IOVSyncValue>::iterator> itFound =
170  setOfIOV_.equal_range(syncValue);
171 
172  if (itFound.first == itFound.second) {
173  if (itFound.first == setOfIOV_.begin()) {
174  //request is before first valid interval, so fail
175  return;
176  }
177  //go back one step
178  --itFound.first;
179  }
181 
182  if (itFound.second != setOfIOV_.end()) {
183  if (iovIsTime_) {
184  endOfInterval = edm::IOVSyncValue(edm::Timestamp(itFound.second->time().value() - 1));
185  } else {
186  endOfInterval = edm::IOVSyncValue(
187  edm::EventID(1, itFound.second->eventID().luminosityBlock() - 1, edm::EventID::maxEventNumber()));
188  }
189  }
190  interval = edm::ValidityInterval(*(itFound.first), endOfInterval);
192  }
193 } // namespace edmtest
194 using namespace edmtest;
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
const IOVSyncValue & last() const
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:41
const IOVSyncValue & first() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
std::unique_ptr< ESTestDataA > produceA(ESTestRecordA const &)
std::unique_ptr< IOVTestInfo > produce(ESTestRecordI const &)
double realTime() const
void addDefault(ParameterSetDescription const &psetDescription)
bool isConcurrentFinder() const override
ConcurrentIOVESSource(edm::ParameterSet const &)
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
static EventNumber_t maxEventNumber()
Definition: EventID.h:96
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
static const ValidityInterval & invalidInterval()
Log< level::System, true > LogAbsolute
edm::ValidityInterval validityInterval_
std::set< edm::IOVSyncValue > setOfInvalidIOV_
void setIntervalFor(edm::eventsetup::EventSetupRecordKey const &, edm::IOVSyncValue const &, edm::ValidityInterval &) override
std::set< edm::IOVSyncValue > setOfIOV_