Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:36

0001 /****************************************************************************
0002  * Authors:
0003  *   Jan Kašpar
0004  *   Grzegorz Sroka
0005  ****************************************************************************/
0006 
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Framework/interface/SourceFactory.h"
0009 #include "FWCore/Framework/interface/ModuleFactory.h"
0010 
0011 #include "FWCore/Framework/interface/ESProducer.h"
0012 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0013 #include "FWCore/Framework/interface/ESProducts.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0016 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 
0019 #include "CondFormats/PPSObjects/interface/PPSAssociationCuts.h"
0020 #include "CondFormats/DataRecord/interface/PPSAssociationCutsRcd.h"
0021 #include <vector>
0022 
0023 using namespace std;
0024 
0025 class PPSAssociationCutsESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0026 public:
0027   PPSAssociationCutsESSource(const edm::ParameterSet &);
0028 
0029   ~PPSAssociationCutsESSource() override = default;
0030 
0031   std::shared_ptr<PPSAssociationCuts> produce(const PPSAssociationCutsRcd &);
0032 
0033   static void fillDescriptions(edm::ConfigurationDescriptions &);
0034 
0035 protected:
0036   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0037                       const edm::IOVSyncValue &,
0038                       edm::ValidityInterval &) override;
0039 
0040 private:
0041   static edm::ParameterSetDescription getIOVDefaultParameters();
0042   bool currentAssociationCutValid_;
0043   unsigned int currentAssociationCutIdx_;
0044   std::vector<std::shared_ptr<PPSAssociationCuts>> ppsAssociationCuts_;
0045   std::vector<edm::EventRange> validityRanges_;
0046 };
0047 
0048 //----------------------------------------------------------------------------------------------------
0049 
0050 PPSAssociationCutsESSource::PPSAssociationCutsESSource(const edm::ParameterSet &iConfig) {
0051   for (const auto &interval : iConfig.getParameter<std::vector<edm::ParameterSet>>("configuration")) {
0052     ppsAssociationCuts_.push_back(make_shared<PPSAssociationCuts>(interval));
0053     validityRanges_.push_back(interval.getParameter<edm::EventRange>("validityRange"));
0054   }
0055 
0056   setWhatProduced(this);
0057   findingRecord<PPSAssociationCutsRcd>();
0058 }
0059 
0060 //----------------------------------------------------------------------------------------------------
0061 
0062 void PPSAssociationCutsESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key,
0063                                                 const edm::IOVSyncValue &iosv,
0064                                                 edm::ValidityInterval &oValidity) {
0065   for (unsigned int idx = 0; idx < ppsAssociationCuts_.size(); ++idx) {
0066     // is within an entry ?
0067     if (edm::contains(validityRanges_[idx], iosv.eventID())) {
0068       currentAssociationCutValid_ = true;
0069       currentAssociationCutIdx_ = idx;
0070       oValidity = edm::ValidityInterval(edm::IOVSyncValue(validityRanges_[idx].startEventID()),
0071                                         edm::IOVSyncValue(validityRanges_[idx].endEventID()));
0072       return;
0073     }
0074   }
0075 
0076   currentAssociationCutValid_ = false;
0077   currentAssociationCutIdx_ = 0;
0078 
0079   edm::LogInfo("PPSAssociationCutsESSource")
0080       << ">> PPSAssociationCutsESSource::setIntervalFor(" << key.name() << ")\n"
0081       << "    run=" << iosv.eventID().run() << ", event=" << iosv.eventID().event();
0082 
0083   const edm::EventID start(iosv.eventID().run(), iosv.eventID().luminosityBlock(), iosv.eventID().event());
0084   const edm::EventID end(iosv.eventID().run(), iosv.eventID().luminosityBlock(), iosv.eventID().event());
0085   oValidity = edm::ValidityInterval(edm::IOVSyncValue(start), edm::IOVSyncValue(end));
0086 }
0087 
0088 //----------------------------------------------------------------------------------------------------
0089 
0090 std::shared_ptr<PPSAssociationCuts> PPSAssociationCutsESSource::produce(const PPSAssociationCutsRcd &) {
0091   auto output = std::make_shared<PPSAssociationCuts>();
0092 
0093   if (currentAssociationCutValid_) {
0094     const auto &associationCut = ppsAssociationCuts_[currentAssociationCutIdx_];
0095     output = associationCut;
0096   }
0097 
0098   return output;
0099 }
0100 
0101 //----------------------------------------------------------------------------------------------------
0102 
0103 void PPSAssociationCutsESSource::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0104   edm::ParameterSetDescription desc;
0105   desc.add<std::string>("ppsAssociationCutsLabel", "");
0106 
0107   edm::ParameterSetDescription validator = PPSAssociationCutsESSource::getIOVDefaultParameters();
0108 
0109   std::vector<edm::ParameterSet> vDefaults;
0110   desc.addVPSet("configuration", validator, vDefaults);
0111 
0112   descriptions.add("ppsAssociationCutsESSource", desc);
0113 }
0114 
0115 edm::ParameterSetDescription PPSAssociationCutsESSource::getIOVDefaultParameters() {
0116   edm::ParameterSetDescription desc;
0117   desc.add<edm::EventRange>("validityRange", edm::EventRange())->setComment("interval of validity");
0118 
0119   for (auto &sector : {"45", "56"}) {
0120     desc.add<edm::ParameterSetDescription>("association_cuts_" + std::string(sector),
0121                                            PPSAssociationCuts::getDefaultParameters())
0122         ->setComment("track-association cuts for sector " + std::string(sector));
0123   }
0124 
0125   return desc;
0126 }
0127 
0128 //----------------------------------------------------------------------------------------------------
0129 
0130 DEFINE_FWK_EVENTSETUP_SOURCE(PPSAssociationCutsESSource);