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 
22 #include "IOVTestInfo.h"
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->iovStartLumi_ = iov.first().luminosityBlockNumber();
117  data->iovEndLumi_ = iov.last().luminosityBlockNumber();
118  data->iovIndex_ = record.iovIndex();
119  data->cacheIdentifier_ = record.cacheIdentifier();
120  return data;
121  }
122 
123  std::unique_ptr<ESTestDataA> ConcurrentIOVESSource::produceA(ESTestRecordA const& record) {
124  edm::ValidityInterval iov = record.validityInterval();
125  if (!testForceESSourceMode_ && record.iovIndex() != 0) {
126  // This criteria should never fail because the EventSetupRecord class
127  // is hard coded to allow only one IOV at a time.
128  throw cms::Exception("TestError")
129  << "ConcurrentIOVESSource::produce, more than one concurrent IOV for type ESTestRecordA!";
130  }
131  edm::LogAbsolute("ConcurrentIOVESSource")
132  << "ConcurrentIOVESSource::produceA startIOV = " << iov.first().luminosityBlockNumber()
133  << " endIOV = " << iov.last().luminosityBlockNumber() << " IOV index = " << record.iovIndex()
134  << " cache identifier = " << record.cacheIdentifier() << " time = " << wallclockTimer_.realTime();
135  return std::make_unique<ESTestDataA>(0);
136  }
137 
140  std::vector<unsigned int> emptyVector;
141  desc.add<bool>("iovIsRunNotTime", true);
142  desc.add<bool>("concurrentFinder", true);
143  desc.add<bool>("testForceESSourceMode", false);
144  desc.add<bool>("findForRecordA", false);
145  desc.add<std::vector<unsigned int>>("firstValidLumis", emptyVector);
146  desc.add<std::vector<unsigned int>>("invalidLumis", emptyVector);
147  descriptions.addDefault(desc);
148  }
149 
151  edm::IOVSyncValue const& syncValue,
155 
156  for (auto const& invalidSyncValue : setOfInvalidIOV_) {
157  if (syncValue == invalidSyncValue) {
158  return;
159  }
160  }
161 
162  //if no intervals given, fail immediately
163  if (setOfIOV_.empty()) {
164  return;
165  }
166 
167  std::pair<std::set<edm::IOVSyncValue>::iterator, std::set<edm::IOVSyncValue>::iterator> itFound =
168  setOfIOV_.equal_range(syncValue);
169 
170  if (itFound.first == itFound.second) {
171  if (itFound.first == setOfIOV_.begin()) {
172  //request is before first valid interval, so fail
173  return;
174  }
175  //go back one step
176  --itFound.first;
177  }
179 
180  if (itFound.second != setOfIOV_.end()) {
181  if (iovIsTime_) {
182  endOfInterval = edm::IOVSyncValue(edm::Timestamp(itFound.second->time().value() - 1));
183  } else {
184  endOfInterval = edm::IOVSyncValue(
185  edm::EventID(1, itFound.second->eventID().luminosityBlock() - 1, edm::EventID::maxEventNumber()));
186  }
187  }
188  interval = edm::ValidityInterval(*(itFound.first), endOfInterval);
190  }
191 } // namespace edmtest
192 using namespace edmtest;
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
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 &)
#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:79
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_