Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "FWCore/Framework/interface/DependentRecordIntervalFinder.h"
00018 #include "FWCore/Framework/interface/EventSetupRecordProvider.h"
00019
00020
00021
00022
00023 namespace edm {
00024 namespace eventsetup {
00025
00026
00027
00028
00029
00030
00031
00032 DependentRecordIntervalFinder::DependentRecordIntervalFinder(const EventSetupRecordKey& iKey) :
00033 providers_()
00034 {
00035 findingRecordWithKey(iKey);
00036 }
00037
00038
00039
00040
00041
00042
00043 DependentRecordIntervalFinder::~DependentRecordIntervalFinder()
00044 {
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 void
00063 DependentRecordIntervalFinder::addProviderWeAreDependentOn(boost::shared_ptr<EventSetupRecordProvider> iProvider)
00064 {
00065 providers_.push_back(iProvider);
00066 }
00067
00068 void
00069 DependentRecordIntervalFinder::setAlternateFinder(boost::shared_ptr<EventSetupRecordIntervalFinder> iOther)
00070 {
00071 alternate_ = iOther;
00072 }
00073
00074 void
00075 DependentRecordIntervalFinder::setIntervalFor(const EventSetupRecordKey& iKey,
00076 const IOVSyncValue& iTime,
00077 ValidityInterval& oInterval)
00078 {
00079
00080
00081
00082 assert(IOVSyncValue::invalidIOVSyncValue() < IOVSyncValue::beginOfTime());
00083 if(providers_.size() == 0 && alternate_.get() == 0 ) {
00084 oInterval = ValidityInterval::invalidInterval();
00085 return;
00086 }
00087 bool haveAValidDependentRecord = false;
00088 bool allRecordsValid = true;
00089 ValidityInterval newInterval(IOVSyncValue::beginOfTime(), IOVSyncValue::endOfTime());
00090
00091 if (alternate_.get() != 0) {
00092 ValidityInterval test = alternate_->findIntervalFor(iKey, iTime);
00093 if ( test != ValidityInterval::invalidInterval() ) {
00094 haveAValidDependentRecord =true;
00095 newInterval = test;
00096 }
00097 }
00098 bool intervalsWereComparible = true;
00099 for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
00100 itProvider != itProviderEnd;
00101 ++itProvider) {
00102 if((*itProvider)->setValidityIntervalFor(iTime)) {
00103 haveAValidDependentRecord=true;
00104 ValidityInterval providerInterval = (*itProvider)->validityInterval();
00105 if( (!newInterval.first().comparable(providerInterval.first())) ||
00106 (!newInterval.last().comparable(providerInterval.last()))) {
00107 intervalsWereComparible=false;
00108 break;
00109 }
00110 if(newInterval.first() < providerInterval.first()) {
00111 newInterval.setFirst(providerInterval.first());
00112 }
00113 if(newInterval.last() > providerInterval.last()) {
00114 newInterval.setLast(providerInterval.last());
00115 }
00116 } else {
00117 allRecordsValid = false;
00118 }
00119 }
00120 if(intervalsWereComparible) {
00121 if(!haveAValidDependentRecord) {
00122
00123 newInterval = ValidityInterval::invalidInterval();
00124 }
00125 if(!allRecordsValid) {
00126
00127
00128
00129 newInterval.setLast(IOVSyncValue::invalidIOVSyncValue());
00130 }
00131 oInterval = newInterval;
00132 return;
00133 }
00134
00135
00136
00137
00138 if (previousIOVs_.empty()) {
00139 std::vector<ValidityInterval> tmp(providers_.size(),ValidityInterval());
00140 previousIOVs_.swap(tmp);
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 bool hadChangedIOV = false;
00150
00151 EventID closestID;
00152 Timestamp closestTimeStamp(0);
00153 std::vector<ValidityInterval>::iterator itIOVs = previousIOVs_.begin();
00154 for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
00155 itProvider != itProviderEnd;
00156 ++itProvider, ++itIOVs) {
00157 if((*itProvider)->setValidityIntervalFor(iTime)) {
00158 ValidityInterval providerInterval = (*itProvider)->validityInterval();
00159 if(*itIOVs != providerInterval) {
00160 hadChangedIOV = true;
00161 if(providerInterval.first().time().value() == 0) {
00162
00163 if( closestID < providerInterval.first().eventID()) {
00164 closestID = providerInterval.first().eventID();
00165 }
00166 } else {
00167 if(closestTimeStamp < providerInterval.first().time()) {
00168 closestTimeStamp = providerInterval.first().time();
00169 }
00170 }
00171 *itIOVs = providerInterval;
00172 }
00173 }
00174 }
00175 if(hadChangedIOV) {
00176 if(closestID.run() !=0) {
00177 if(closestTimeStamp.value() == 0) {
00178
00179 oInterval = ValidityInterval(IOVSyncValue(closestID), IOVSyncValue::invalidIOVSyncValue());
00180 } else {
00181 if(closestID.run() == iTime.eventID().run()) {
00182
00183 const unsigned long long kLumiTimeLength = 23;
00184
00185 if( (iTime.eventID().luminosityBlock() - closestID.luminosityBlock())*kLumiTimeLength <
00186 iTime.time().unixTime() - closestTimeStamp.unixTime() ) {
00187
00188 oInterval = ValidityInterval(IOVSyncValue(closestID), IOVSyncValue::invalidIOVSyncValue());
00189 } else {
00190 oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
00191 }
00192 } else {
00193
00194
00195 oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
00196 }
00197 }
00198 } else {
00199 oInterval = ValidityInterval( IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
00200 }
00201 }
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211 }
00212 }