Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:48

0001 #include <set>
0002 #include <sstream>
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Utilities/interface/EDMException.h"
0006 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0007 #include "FWCore/Framework/interface/SourceFactory.h"
0008 
0009 namespace edm {
0010 
0011   class EmptyESSource : public EventSetupRecordIntervalFinder {
0012   public:
0013     EmptyESSource(ParameterSet const&);
0014     EmptyESSource(EmptyESSource const&) = delete;                   // stop default
0015     EmptyESSource const& operator=(EmptyESSource const&) = delete;  // stop default
0016 
0017     // ---------- const member functions ---------------------
0018 
0019     // ---------- static member functions --------------------
0020 
0021     // ---------- member functions ---------------------------
0022     void setIntervalFor(eventsetup::EventSetupRecordKey const&,
0023                         IOVSyncValue const& iTime,
0024                         ValidityInterval& oInterval) override;
0025 
0026     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0027 
0028   private:
0029     void delaySettingRecords() override;
0030     // ---------- member data --------------------------------
0031     std::string recordName_;
0032     std::set<IOVSyncValue> setOfIOV_;
0033     bool iovIsTime_;
0034   };
0035 
0036   EmptyESSource::EmptyESSource(ParameterSet const& pset)
0037       : recordName_(pset.getParameter<std::string>("recordName")),
0038         iovIsTime_(!pset.getParameter<bool>("iovIsRunNotTime")) {
0039     std::vector<unsigned int> temp(pset.getParameter<std::vector<unsigned int>>("firstValid"));
0040     for (std::vector<unsigned int>::iterator itValue = temp.begin(), itValueEnd = temp.end(); itValue != itValueEnd;
0041          ++itValue) {
0042       if (iovIsTime_) {
0043         setOfIOV_.insert(IOVSyncValue(Timestamp(*itValue)));
0044       } else {
0045         setOfIOV_.insert(IOVSyncValue(EventID(*itValue, 0, 0)));
0046       }
0047     }
0048     //copy_all(temp, inserter(setOfIOV_ , setOfIOV_.end()));
0049   }
0050 
0051   void EmptyESSource::delaySettingRecords() {
0052     eventsetup::EventSetupRecordKey recordKey = eventsetup::EventSetupRecordKey::TypeTag::findType(recordName_);
0053     if (recordKey == eventsetup::EventSetupRecordKey()) {
0054       throw edm::Exception(errors::Configuration)
0055           << " The Record type named \"" << recordName_ << "\" could not be found. Please check the spelling. \n"
0056           << "If the spelling is fine, then no module in the job requires this Record and therefore EmptyESSource can "
0057              "not function.\n"
0058              "In such a case please either remove the EmptyESSource with label'"
0059           << descriptionForFinder().label_ << "' from your job or add a module which needs the Record to your job.";
0060     }
0061     findingRecordWithKey(recordKey);
0062   }
0063 
0064   void EmptyESSource::setIntervalFor(eventsetup::EventSetupRecordKey const&,
0065                                      IOVSyncValue const& iTime,
0066                                      ValidityInterval& oInterval) {
0067     oInterval = ValidityInterval::invalidInterval();
0068     //if no intervals given, fail immediately
0069     if (setOfIOV_.empty()) {
0070       return;
0071     }
0072 
0073     std::pair<std::set<IOVSyncValue>::iterator, std::set<IOVSyncValue>::iterator> itFound =
0074         setOfIOV_.equal_range(iTime);
0075 
0076     //we have overshot
0077     if (itFound.first == itFound.second) {
0078       if (itFound.first == setOfIOV_.begin()) {
0079         //request is before first valid interval, so fail
0080         return;
0081       }
0082       //go back one step
0083       --itFound.first;
0084     }
0085     if (itFound.first == setOfIOV_.end()) {
0086       return;
0087     }
0088 
0089     IOVSyncValue endOfInterval = IOVSyncValue::endOfTime();
0090 
0091     if (itFound.second != setOfIOV_.end()) {
0092       if (iovIsTime_) {
0093         endOfInterval = IOVSyncValue(Timestamp(itFound.second->time().value() - 1));
0094       } else {
0095         endOfInterval = IOVSyncValue(itFound.second->eventID().previousRunLastEvent(0));
0096       }
0097     }
0098     oInterval = ValidityInterval(*(itFound.first), endOfInterval);
0099   }
0100 
0101   void EmptyESSource::fillDescriptions(ConfigurationDescriptions& descriptions) {
0102     edm::ParameterSetDescription desc;
0103     desc.add<std::string>("recordName")
0104         ->setComment(
0105             "The name of the EventSetup Record for which intervals are to be generated.\n The record type must be used "
0106             "by some module in the job else an exception will occur.");
0107     desc.add<bool>("iovIsRunNotTime", true)->setComment("Sets how to interpret integer values used in 'firstValid'");
0108     desc.add<std::vector<unsigned int>>("firstValid")
0109         ->setComment(
0110             "Sets the beginning point of an IOV. The end point is assumed to be the next entry in the list. If there "
0111             "are no further entries than 'end of time' is used.");
0112 
0113     descriptions.addDefault(desc);
0114   }
0115 
0116 }  // namespace edm
0117 using edm::EmptyESSource;
0118 DEFINE_FWK_EVENTSETUP_SOURCE(EmptyESSource);