CMS 3D CMS Logo

DependentRecordIntervalFinder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Class : DependentRecordIntervalFinder
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Author: Chris Jones
10 // Created: Sat Apr 30 19:37:22 EDT 2005
11 //
12 
13 // system include files
14 
15 // user include files
18 #include <cassert>
19 
20 //
21 // constants, enums and typedefs
22 //
23 namespace edm {
24  namespace eventsetup {
25  //
26  // static data member definitions
27  //
28 
29  //
30  // constructors and destructor
31  //
34  }
35 
36  // DependentRecordIntervalFinder::DependentRecordIntervalFinder(const DependentRecordIntervalFinder& rhs)
37  // {
38  // // do actual copying here;
39  // }
40 
42 
43  //
44  // assignment operators
45  //
46  // const DependentRecordIntervalFinder& DependentRecordIntervalFinder::operator=(const DependentRecordIntervalFinder& rhs)
47  // {
48  // //An exception safe implementation is
49  // DependentRecordIntervalFinder temp(rhs);
50  // swap(rhs);
51  //
52  // return *this;
53  // }
54 
55  //
56  // member functions
57  //
59  std::shared_ptr<EventSetupRecordProvider> iProvider) {
60  providers_.push_back(iProvider);
61  }
62 
63  void DependentRecordIntervalFinder::setAlternateFinder(std::shared_ptr<EventSetupRecordIntervalFinder> iOther) {
64  alternate_ = iOther;
65  }
66 
68  const IOVSyncValue& iTime,
69  ValidityInterval& oInterval) {
70  //NOTE: oInterval is the last value that was used so if nothing changed do not modify oInterval
71 
72  //I am assuming that an invalidTime is always less then the first valid time
74  if (providers_.empty() && alternate_.get() == nullptr) {
76  return;
77  }
78  bool haveAValidDependentRecord = false;
79  bool allRecordsValid = true;
81 
82  if (alternate_.get() != nullptr) {
83  ValidityInterval test = alternate_->findIntervalFor(iKey, iTime);
84  if (test != ValidityInterval::invalidInterval()) {
85  haveAValidDependentRecord = true;
86  newInterval = test;
87  }
88  }
89  bool intervalsWereComparible = true;
90  for (Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
91  itProvider != itProviderEnd;
92  ++itProvider) {
93  if ((*itProvider)->setValidityIntervalFor(iTime)) {
94  haveAValidDependentRecord = true;
95  ValidityInterval providerInterval = (*itProvider)->validityInterval();
96  if ((!newInterval.first().comparable(providerInterval.first())) ||
97  (!newInterval.last().comparable(providerInterval.last()))) {
98  intervalsWereComparible = false;
99  break;
100  }
101  if (newInterval.first() < providerInterval.first()) {
102  newInterval.setFirst(providerInterval.first());
103  }
104  if (newInterval.last() > providerInterval.last()) {
105  newInterval.setLast(providerInterval.last());
106  }
107  } else {
108  allRecordsValid = false;
109  }
110  }
111  if (intervalsWereComparible) {
112  if (!haveAValidDependentRecord) {
113  //If no Finder has no valid time, then this record is also invalid for this time
114  newInterval = ValidityInterval::invalidInterval();
115  }
116  if (!allRecordsValid) {
117  //since some of the dependent providers do not have a valid IOV for this syncvalue
118  // we do not know what the true end IOV is. Therefore we must make it open ended
119  // so that we can check each time to see if those providers become valid.
121  }
122  oInterval = newInterval;
123  return;
124  }
125  //handle the case where some providers use time and others use run/lumi/event
126  // in this case all we can do is find an IOV which changed since last time
127  // and use its start time to do the synching and use an 'invalid' end time
128  // so the system always checks back to see if something has changed
129  if (previousIOVs_.empty()) {
130  std::vector<ValidityInterval> tmp(providers_.size(), ValidityInterval());
131  previousIOVs_.swap(tmp);
132  }
133 
134  //I'm using an heuristic to pick a reasonable starting point for the IOV. The idea is to
135  // assume that lumi sections are 23 seconds long and therefore if we take a difference between
136  // iTime and the beginning of a changed IOV we can pick the changed IOV with the start time
137  // closest to iTime. This doesn't have to be perfect, we just want to reduce the dependency
138  // on provider order to make the jobs more deterministic
139 
140  bool hadChangedIOV = false;
141  //both start at the smallest value
142  EventID closestID;
143  Timestamp closestTimeStamp(0);
144  std::vector<ValidityInterval>::iterator itIOVs = previousIOVs_.begin();
145  for (Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
146  itProvider != itProviderEnd;
147  ++itProvider, ++itIOVs) {
148  if ((*itProvider)->setValidityIntervalFor(iTime)) {
149  ValidityInterval providerInterval = (*itProvider)->validityInterval();
150  if (*itIOVs != providerInterval) {
151  hadChangedIOV = true;
152  if (providerInterval.first().time().value() == 0) {
153  //this is a run/lumi based one
154  if (closestID < providerInterval.first().eventID()) {
155  closestID = providerInterval.first().eventID();
156  }
157  } else {
158  if (closestTimeStamp < providerInterval.first().time()) {
159  closestTimeStamp = providerInterval.first().time();
160  }
161  }
162  *itIOVs = providerInterval;
163  }
164  }
165  }
166  if (hadChangedIOV) {
167  if (closestID.run() != 0) {
168  if (closestTimeStamp.value() == 0) {
169  //no time
171  } else {
172  if (closestID.run() == iTime.eventID().run()) {
173  //can compare time to lumi
174  const unsigned long long kLumiTimeLength = 23;
175 
176  if ((iTime.eventID().luminosityBlock() - closestID.luminosityBlock()) * kLumiTimeLength <
177  iTime.time().unixTime() - closestTimeStamp.unixTime()) {
178  //closestID was closer
180  } else {
181  oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
182  }
183  } else {
184  //since we don't know how to change run # into time we can't compare
185  // so if we have a time just use it
186  oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
187  }
188  }
189  } else {
190  oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
191  }
192  }
193  }
194 
195  //
196  // const member functions
197  //
198 
199  //
200  // static member functions
201  //
202  } // namespace eventsetup
203 } // namespace edm
RunNumber_t run() const
Definition: EventID.h:39
void setFirst(const IOVSyncValue &iTime)
const EventID & eventID() const
Definition: IOVSyncValue.h:40
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
void setIntervalFor(const EventSetupRecordKey &, const IOVSyncValue &, ValidityInterval &) override
edm::propagate_const< std::shared_ptr< EventSetupRecordIntervalFinder > > alternate_
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
const IOVSyncValue & last() const
void addProviderWeAreDependentOn(std::shared_ptr< EventSetupRecordProvider >)
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
unsigned int unixTime() const
Time in seconds since January 1, 1970.
Definition: Timestamp.h:46
void setLast(const IOVSyncValue &iTime)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
static const ValidityInterval & invalidInterval()
const Timestamp & time() const
Definition: IOVSyncValue.h:42
const IOVSyncValue & first() const
bool comparable(const IOVSyncValue &iOther) const
Definition: IOVSyncValue.h:55
void setAlternateFinder(std::shared_ptr< EventSetupRecordIntervalFinder >)
TimeValue_t value() const
Definition: Timestamp.h:56
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
static const IOVSyncValue & invalidIOVSyncValue()
Definition: IOVSyncValue.cc:78