File indexing completed on 2024-04-06 12:09:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022
0023
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
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
0048
0049 DQMStore* dqmStore_;
0050
0051 std::string filename, dirpath;
0052 int TotNumberOfEvents;
0053 int MinNumberOfEvents;
0054 };
0055
0056
0057
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
0064
0065 dqmStore_ = edm::Service<DQMStore>().operator->();
0066 dqmStore_->open(filename, false);
0067 }
0068
0069
0070
0071
0072
0073
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
0103 DEFINE_FWK_MODULE(StatisticsFilter);