File indexing completed on 2024-04-06 12:12:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include "FWCore/Framework/interface/DependentRecordIntervalFinder.h"
0014 #include "FWCore/Framework/interface/EventSetupRecordProvider.h"
0015 #include "FWCore/Utilities/interface/EDMException.h"
0016
0017 #include <cassert>
0018
0019 namespace edm {
0020 namespace eventsetup {
0021
0022 DependentRecordIntervalFinder::DependentRecordIntervalFinder(const EventSetupRecordKey& iKey) : providers_() {
0023 findingRecordWithKey(iKey);
0024 }
0025
0026 DependentRecordIntervalFinder::~DependentRecordIntervalFinder() {}
0027
0028 void DependentRecordIntervalFinder::addProviderWeAreDependentOn(
0029 std::shared_ptr<EventSetupRecordProvider> iProvider) {
0030 providers_.push_back(iProvider);
0031 }
0032
0033 void DependentRecordIntervalFinder::setAlternateFinder(std::shared_ptr<EventSetupRecordIntervalFinder> iOther) {
0034 alternate_ = iOther;
0035 }
0036
0037 void DependentRecordIntervalFinder::setIntervalFor(const EventSetupRecordKey& iKey,
0038 const IOVSyncValue& iTime,
0039 ValidityInterval& oInterval) {
0040
0041
0042
0043 assert(IOVSyncValue::invalidIOVSyncValue() < IOVSyncValue::beginOfTime());
0044 if (providers_.empty() && alternate_.get() == nullptr) {
0045 oInterval = ValidityInterval::invalidInterval();
0046 return;
0047 }
0048 bool haveAValidDependentRecord = false;
0049 bool allRecordsValid = true;
0050 ValidityInterval newInterval(IOVSyncValue::beginOfTime(), IOVSyncValue::endOfTime());
0051
0052 if (alternate_.get() != nullptr) {
0053 ValidityInterval test = alternate_->findIntervalFor(iKey, iTime);
0054 if (test != ValidityInterval::invalidInterval()) {
0055 haveAValidDependentRecord = true;
0056 newInterval = test;
0057 }
0058 }
0059 bool intervalsWereComparible = true;
0060 for (Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
0061 itProvider != itProviderEnd;
0062 ++itProvider) {
0063 if ((*itProvider)->setValidityIntervalFor(iTime)) {
0064 haveAValidDependentRecord = true;
0065 ValidityInterval providerInterval = (*itProvider)->validityInterval();
0066 if ((!newInterval.first().comparable(providerInterval.first())) ||
0067 (!newInterval.last().comparable(providerInterval.last()))) {
0068 intervalsWereComparible = false;
0069 break;
0070 }
0071 if (newInterval.first() < providerInterval.first()) {
0072 newInterval.setFirst(providerInterval.first());
0073 }
0074 if (newInterval.last() > providerInterval.last()) {
0075 newInterval.setLast(providerInterval.last());
0076 }
0077 } else {
0078 allRecordsValid = false;
0079 }
0080 }
0081 if (intervalsWereComparible) {
0082 if (!haveAValidDependentRecord) {
0083
0084 newInterval = ValidityInterval::invalidInterval();
0085 }
0086 if (!allRecordsValid) {
0087
0088
0089
0090 newInterval.setLast(IOVSyncValue::invalidIOVSyncValue());
0091 }
0092 oInterval = newInterval;
0093 return;
0094 }
0095
0096
0097
0098
0099 if (previousIOVs_.empty()) {
0100 std::vector<ValidityInterval> tmp(providers_.size(), ValidityInterval());
0101 previousIOVs_.swap(tmp);
0102 }
0103
0104
0105
0106
0107
0108
0109
0110 bool hadChangedIOV = false;
0111
0112 EventID closestID;
0113 Timestamp closestTimeStamp(0);
0114 std::vector<ValidityInterval>::iterator itIOVs = previousIOVs_.begin();
0115 for (Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
0116 itProvider != itProviderEnd;
0117 ++itProvider, ++itIOVs) {
0118 if ((*itProvider)->setValidityIntervalFor(iTime)) {
0119 ValidityInterval providerInterval = (*itProvider)->validityInterval();
0120 if (*itIOVs != providerInterval) {
0121 hadChangedIOV = true;
0122 if (providerInterval.first().time().value() == 0) {
0123
0124 if (closestID < providerInterval.first().eventID()) {
0125 closestID = providerInterval.first().eventID();
0126 }
0127 } else {
0128 if (closestTimeStamp < providerInterval.first().time()) {
0129 closestTimeStamp = providerInterval.first().time();
0130 }
0131 }
0132 *itIOVs = providerInterval;
0133 }
0134 }
0135 }
0136 if (hadChangedIOV) {
0137 if (closestID.run() != 0) {
0138 if (closestTimeStamp.value() == 0) {
0139
0140 oInterval = ValidityInterval(IOVSyncValue(closestID), IOVSyncValue::invalidIOVSyncValue());
0141 } else {
0142 if (closestID.run() == iTime.eventID().run()) {
0143
0144 const unsigned long long kLumiTimeLength = 23;
0145
0146 if ((iTime.eventID().luminosityBlock() - closestID.luminosityBlock()) * kLumiTimeLength <
0147 iTime.time().unixTime() - closestTimeStamp.unixTime()) {
0148
0149 oInterval = ValidityInterval(IOVSyncValue(closestID), IOVSyncValue::invalidIOVSyncValue());
0150 } else {
0151 oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
0152 }
0153 } else {
0154
0155
0156 oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
0157 }
0158 }
0159 } else {
0160 oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
0161 }
0162 }
0163 }
0164
0165 void DependentRecordIntervalFinder::doResetInterval(const eventsetup::EventSetupRecordKey& key) {
0166 if (alternate_.get()) {
0167 alternate_->resetInterval(key);
0168 }
0169 previousIOVs_.clear();
0170 }
0171
0172 bool DependentRecordIntervalFinder::isConcurrentFinder() const {
0173 throw Exception(errors::LogicError)
0174 << "DependentRecordIntervalFinder::isConcurrentFinder() should never be called.\n"
0175 << "Contact a Framework developer\n";
0176 return true;
0177 }
0178
0179 bool DependentRecordIntervalFinder::isNonconcurrentAndIOVNeedsUpdate(const EventSetupRecordKey& iKey,
0180 const IOVSyncValue& iTime) const {
0181
0182
0183
0184 if (alternate_.get()) {
0185 return alternate_->nonconcurrentAndIOVNeedsUpdate(iKey, iTime);
0186 }
0187 return false;
0188 }
0189
0190 }
0191 }