Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    StatisticsFilter
0004 // Class:      StatisticsFilter
0005 //
0006 /**\class StatisticsFilter StatisticsFilter.cc MyFilter/StatisticsFilter/src/StatisticsFilter.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Gordon Kaussen,40 1-A15,+41227671647,
0015 //         Created:  Mon Nov 15 10:48:54 CET 2010
0016 // $Id$
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "DQMServices/Core/interface/DQMStore.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/Frameworkfwd.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/Framework/interface/stream/EDFilter.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/ServiceRegistry/interface/Service.h"
0031 
0032 //
0033 // class declaration
0034 //
0035 
0036 class StatisticsFilter : public edm::stream::EDFilter<> {
0037 public:
0038   typedef dqm::legacy::DQMStore DQMStore;
0039   typedef dqm::legacy::MonitorElement MonitorElement;
0040 
0041   explicit StatisticsFilter(const edm::ParameterSet&);
0042   ~StatisticsFilter() override = default;
0043 
0044 private:
0045   bool filter(edm::Event&, const edm::EventSetup&) override;
0046 
0047   // ----------member data ---------------------------
0048 
0049   DQMStore* dqmStore_;
0050 
0051   std::string filename, dirpath;
0052   int TotNumberOfEvents;
0053   int MinNumberOfEvents;
0054 };
0055 
0056 //
0057 // constructors and destructor
0058 //
0059 StatisticsFilter::StatisticsFilter(const edm::ParameterSet& iConfig)
0060     : filename(iConfig.getUntrackedParameter<std::string>("rootFilename", "")),
0061       dirpath(iConfig.getUntrackedParameter<std::string>("histoDirPath", "")),
0062       MinNumberOfEvents(iConfig.getUntrackedParameter<int>("minNumberOfEvents")) {
0063   //now do what ever initialization is needed
0064 
0065   dqmStore_ = edm::Service<DQMStore>().operator->();
0066   dqmStore_->open(filename, false);
0067 }
0068 
0069 //
0070 // member functions
0071 //
0072 
0073 // ------------ method called on each new Event  ------------
0074 bool StatisticsFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0075   TotNumberOfEvents = 0;
0076 
0077   std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(dirpath);
0078 
0079   std::vector<MonitorElement*>::const_iterator iter = MEs.begin();
0080   std::vector<MonitorElement*>::const_iterator iterEnd = MEs.end();
0081 
0082   for (; iter != iterEnd; ++iter) {
0083     std::string me_name = (*iter)->getName();
0084 
0085     if (strstr(me_name.c_str(), "TotalNumberOfCluster__T") != nullptr &&
0086         strstr(me_name.c_str(), "Profile") == nullptr) {
0087       TotNumberOfEvents = ((TH1F*)(*iter)->getTH1F())->GetEntries();
0088 
0089       break;
0090     }
0091   }
0092 
0093   if (TotNumberOfEvents < MinNumberOfEvents) {
0094     edm::LogInfo("StatisticsFilter") << "Only " << TotNumberOfEvents << " events in the run. Run will not be analyzed!";
0095 
0096     return false;
0097   }
0098 
0099   return true;
0100 }
0101 
0102 //define this as a plug-in
0103 DEFINE_FWK_MODULE(StatisticsFilter);