File indexing completed on 2024-04-06 12:03:17
0001 #ifndef CondTools_RunInfo_LumiSectionFilter_h
0002 #define CondTools_RunInfo_LumiSectionFilter_h
0003
0004 #include "CondFormats/Common/interface/TimeConversions.h"
0005 #include "CondCore/CondDB/interface/Time.h"
0006 #include <vector>
0007 #include <memory>
0008
0009 template <class T>
0010 struct LumiSectionFilter {
0011 LumiSectionFilter(const std::vector<std::pair<cond::Time_t, std::shared_ptr<T>>>& samples)
0012 : currLow(samples.begin()), currUp(samples.begin()), end(samples.end()) {
0013 currUp++;
0014 }
0015
0016 void reset(const std::vector<std::pair<cond::Time_t, std::shared_ptr<T>>>& samples) {
0017 currLow = samples.begin();
0018 currUp = samples.begin();
0019 currUp++;
0020 end = samples.end();
0021 currentDipTime = 0;
0022 }
0023
0024 bool process(cond::Time_t dipTime) {
0025 if (currLow == end)
0026 return false;
0027 bool search = false;
0028 if (currentDipTime == 0) {
0029 search = true;
0030 } else {
0031 if (dipTime == currentDipTime)
0032 return true;
0033 else {
0034 cond::Time_t upper = cond::time::MAX_VAL;
0035 if (currUp != end)
0036 upper = currUp->first;
0037 if (dipTime < upper && currentDipTime >= currLow->first)
0038 return false;
0039 else {
0040 search = true;
0041 }
0042 }
0043 }
0044 if (search) {
0045 while (currUp != end and currUp->first < dipTime) {
0046 currLow++;
0047 currUp++;
0048 }
0049 currentDipTime = dipTime;
0050 return currLow != end;
0051 }
0052 return false;
0053 }
0054
0055 cond::Time_t currentSince() { return currLow->first; }
0056 T& currentPayload() { return *currLow->second; }
0057
0058 typename std::vector<std::pair<cond::Time_t, std::shared_ptr<T>>>::const_iterator current() { return currLow; }
0059 typename std::vector<std::pair<cond::Time_t, std::shared_ptr<T>>>::const_iterator currLow;
0060 typename std::vector<std::pair<cond::Time_t, std::shared_ptr<T>>>::const_iterator currUp;
0061 typename std::vector<std::pair<cond::Time_t, std::shared_ptr<T>>>::const_iterator end;
0062 cond::Time_t currentDipTime = 0;
0063 };
0064
0065 #endif