Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:23

0001 #ifndef HLTrigReport_h
0002 #define HLTrigReport_h
0003 
0004 /** \class HLTrigReport
0005  *
0006  *  
0007  *  This class is an EDAnalyzer implementing TrigReport (statistics
0008  *  printed to log file) for HL triggers
0009  *
0010  *
0011  *  \author Martin Grunewald
0012  *
0013  */
0014 
0015 #include <string>
0016 #include <vector>
0017 
0018 #include "DataFormats/Common/interface/TriggerResults.h"
0019 #include "FWCore/Common/interface/TriggerNames.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0022 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0025 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0026 
0027 //
0028 // class declaration
0029 //
0030 
0031 namespace hltrigreport {
0032   struct Accumulate {
0033     Accumulate();
0034     Accumulate(size_t numHLNames,
0035                std::vector<std::vector<unsigned int>> const& hlIndex,
0036                std::vector<std::vector<unsigned int>> const& dsIndex);
0037 
0038     unsigned int nEvents_;  // number of events processed
0039     unsigned int nWasRun_;  // # where at least one HLT was run
0040     unsigned int nAccept_;  // # of accepted events
0041     unsigned int nErrors_;  // # where at least one HLT had error
0042 
0043     std::vector<unsigned int> hlWasRun_;  // # where HLT[i] was run
0044     std::vector<unsigned int> hltL1s_;    // # of events after L1 seed
0045     std::vector<unsigned int> hltPre_;    // # of events after HLT prescale
0046     std::vector<unsigned int> hlAccept_;  // # of events accepted by HLT[i]
0047     std::vector<unsigned int> hlAccTot_;  // # of events accepted by HLT[0] OR ... OR HLT[i]
0048     std::vector<unsigned int> hlErrors_;  // # of events with error in HLT[i]
0049 
0050     std::vector<std::vector<unsigned int>>
0051         hlAccTotDS_;  // hlAccTotDS_[ds][p] stores the # of accepted events by the 0-th to p-th paths in the ds-th dataset
0052     std::vector<unsigned int> hlAllTotDS_;  // hlAllTotDS_[ds] stores the # of accepted events in the ds-th dataset
0053     std::vector<std::vector<unsigned int>>
0054         dsAccTotS_;  // dsAccTotS_[s][ds] stores the # of accepted events by the 0-th to ds-th dataset in the s-th stream
0055     std::vector<unsigned int> dsAllTotS_;  // dsAllTotS_[s] stores the # of accepted events in the s-th stream
0056 
0057     void accumulate(Accumulate const&);
0058     void reset();
0059   };
0060 
0061 }  // namespace hltrigreport
0062 
0063 class HLTrigReport
0064     : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::LuminosityBlockCache<hltrigreport::Accumulate>> {
0065 private:
0066   enum ReportEvery { NEVER = 0, EVERY_EVENT = 1, EVERY_LUMI = 2, EVERY_RUN = 3, EVERY_JOB = 4 };
0067 
0068 public:
0069   using Accumulate = hltrigreport::Accumulate;
0070 
0071   explicit HLTrigReport(const edm::ParameterSet&);
0072   ~HLTrigReport() override;
0073   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0074 
0075   static ReportEvery decode(const std::string& value);
0076 
0077   void beginJob() override;
0078   void endJob() override;
0079 
0080   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0081   void endRun(edm::Run const&, edm::EventSetup const&) override;
0082 
0083   std::shared_ptr<Accumulate> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0084                                                          edm::EventSetup const&) const override;
0085   void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0086 
0087   void analyze(const edm::Event&, const edm::EventSetup&) override;
0088 
0089   // names and event counts
0090   const std::vector<std::string>& streamNames() const;
0091   const std::vector<std::string>& datasetNames() const;
0092 
0093 private:
0094   void reset();  // reset all counters
0095 
0096   hltrigreport::Accumulate& chooseAccumulate(edm::LuminosityBlockIndex index) {
0097     if (useLumiCache()) {
0098       return *luminosityBlockCache(index);
0099     }
0100     return accumulate_;
0101   }
0102   bool useLumiCache() const { return reportBy_ == EVERY_LUMI or serviceBy_ == EVERY_LUMI or resetBy_ == EVERY_LUMI; }
0103   bool readAfterLumi() const {
0104     return (reportBy_ == EVERY_RUN or reportBy_ == EVERY_JOB or serviceBy_ == EVERY_RUN or serviceBy_ == EVERY_JOB);
0105   }
0106 
0107   void updateConfigCache();
0108 
0109   void dumpReport(hltrigreport::Accumulate const& accumulate, std::string const& header = std::string()) const;
0110   void updateService(Accumulate const& accumulate) const;
0111 
0112   const edm::InputTag hlTriggerResults_;  // Input tag for TriggerResults
0113   const edm::EDGetTokenT<edm::TriggerResults> hlTriggerResultsToken_;
0114   bool configured_;  // is HLTConfigProvider configured ?
0115 
0116   std::vector<std::string> hlNames_;  // name of each HLT algorithm
0117 
0118   std::vector<std::vector<unsigned int>>
0119       hlIndex_;  // hlIndex_[ds][p] stores the hlNames_ index of the p-th path of the ds-th dataset
0120 
0121   std::vector<int> posL1s_;  // pos # of last L1 seed
0122   std::vector<int> posPre_;  // pos # of last HLT prescale
0123 
0124   std::vector<std::string> datasetNames_;                  // list of dataset names
0125   std::vector<std::vector<std::string>> datasetContents_;  // list of path names for each dataset
0126   bool isCustomDatasets_;  // true if the user overwrote the dataset definitions of the provenance with the CustomDatasets parameter
0127   std::vector<std::vector<unsigned int>>
0128       dsIndex_;  // dsIndex_[s][ds] stores the datasetNames_ index of the ds-th dataset of the s-th stream
0129   std::vector<std::string> streamNames_;                  // list of stream names
0130   std::vector<std::vector<std::string>> streamContents_;  // list of dataset names for each stream
0131   bool isCustomStreams_;  // true if the user overwrote the stream definitions of the provenance with the CustomSterams parameter
0132   std::string refPath_;    // name of the reference path for rate calculation
0133   unsigned int refIndex_;  // index of the reference path for rate calculation
0134   const double refRate_;   // rate of the reference path, the rate of all other paths will be normalized to this
0135 
0136   const ReportEvery reportBy_;   // dump report for every never/event/lumi/run/job
0137   const ReportEvery resetBy_;    // reset counters  every never/event/lumi/run/job
0138   const ReportEvery serviceBy_;  // call to service every never/event/lumi/run/job
0139   HLTConfigProvider hltConfig_;  // to get configuration for L1s/Pre
0140 
0141   hltrigreport::Accumulate accumulate_;
0142 };
0143 
0144 #endif  //HLTrigReport_h