CMS 3D CMS Logo

CastorMonitorModule.cc
Go to the documentation of this file.
8 //#include "CondFormats/CastorObjects/interface/CastorChannelQuality.h"
9 #include <string>
10 
11 //**************************************************************//
12 //***************** CastorMonitorModule ******************//
13 //***************** Author: Dmytro Volyanskyy ******************//
14 //***************** Date : 22.11.2008 (first version) *********//
20 //**************************************************************//
21 
22 //---- critical revision 26.06.2014 (Vladimir Popov)
23 
24 //**************************************************************//
25 
26 using namespace std;
27 using namespace edm;
28 
30  fVerbosity = ps.getUntrackedParameter<int>("debug", 0);
31  subsystemname_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "Castor");
32  inputTokenRaw_ = consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("rawLabel"));
33  inputTokenReport_ = consumes<HcalUnpackerReport>(ps.getParameter<edm::InputTag>("unpackerReportLabel"));
34  inputTokenDigi_ = consumes<CastorDigiCollection>(ps.getParameter<edm::InputTag>("digiLabel"));
35  inputTokenRecHitCASTOR_ = consumes<CastorRecHitCollection>(ps.getParameter<edm::InputTag>("CastorRecHitLabel"));
36  inputTokenCastorTowers_ = consumes<CastorTowerCollection>(ps.getParameter<edm::InputTag>("CastorTowerLabel"));
37  JetAlgorithm = consumes<BasicJetCollection>(ps.getParameter<edm::InputTag>("CastorBasicJetsLabel"));
38  tokenTriggerResults = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("tagTriggerResults"));
39 
40  showTiming_ = ps.getUntrackedParameter<bool>("showTiming", false);
41 
42  if (ps.getUntrackedParameter<bool>("DigiMonitor", false))
43  DigiMon_ = std::make_unique<CastorDigiMonitor>(ps);
44 
45  if (ps.getUntrackedParameter<bool>("RecHitMonitor", false))
46  RecHitMon_ = std::make_unique<CastorRecHitMonitor>(ps);
47 
48  if (ps.getUntrackedParameter<bool>("LEDMonitor", false))
49  LedMon_ = std::make_unique<CastorLEDMonitor>(ps);
50 
51  ievt_ = 0;
52 }
53 
55 
56 void CastorMonitorModule::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
57  if (fVerbosity > 0)
58  LogPrint("CastorMonitorModule") << "dqmBeginRun(start)";
59 }
60 
62  const edm::Run &iRun,
63  const edm::EventSetup &iSetup) {
64  if (DigiMon_) {
65  DigiMon_->bookHistograms(ibooker, iRun, iSetup);
66  }
67  if (RecHitMon_) {
68  RecHitMon_->bookHistograms(ibooker, iRun, iSetup);
69  }
70  if (LedMon_) {
71  LedMon_->bookHistograms(ibooker, iRun, iSetup);
72  }
73 
74  ibooker.setCurrentFolder(subsystemname_);
75  char s[60];
76  sprintf(s, "CastorEventProducts");
77  CastorEventProduct = ibooker.book1DD(s, s, 6, -0.5, 5.5);
78  CastorEventProduct->setAxisTitle("Events", /* axis */ 2);
79  CastorEventProduct->setBinLabel(1, "FEDs/3");
80  CastorEventProduct->setBinLabel(2, "RawData");
81  CastorEventProduct->setBinLabel(3, "Digi");
82  CastorEventProduct->setBinLabel(4, "RecHits");
83  CastorEventProduct->setBinLabel(5, "Towers");
84  CastorEventProduct->setBinLabel(6, "Jets");
85 
86  sprintf(s, "CASTORUnpackReport");
87  hunpkrep = ibooker.bookProfile(s, s, 6, -0.5, 5.5, 100, 0, 1.e10, "");
88  hunpkrep->setBinLabel(1, "N_FEDs");
89  hunpkrep->setBinLabel(2, "SPIGOT_Err");
90  hunpkrep->setBinLabel(3, "empty");
91  hunpkrep->setBinLabel(4, "busy");
92  hunpkrep->setBinLabel(5, "OvF");
93  hunpkrep->setBinLabel(6, "BadDigis");
94  return;
95 }
96 
98  if (DigiMon_) {
99  DigiMon_->endRun();
100  }
101 }
102 
104  if (fVerbosity > 1)
105  LogPrint("CastorMonitorModule") << "analyze (start)";
106 
107  ievt_++;
108 
109  bool rawOK_ = true;
110  bool digiOK_ = true;
111  bool rechitOK_ = true, towerOK_ = true, jetsOK_ = true;
112  int nDigi = 0, nrecHits = 0, nTowers = 0, nJets = 0;
113 
115  iEvent.getByToken(tokenTriggerResults, TrigResults);
116 
118  iEvent.getByToken(inputTokenRaw_, RawData);
119  if (!RawData.isValid())
120  rawOK_ = false;
121 
122  float fedsUnpacked = 0.;
124  iEvent.getByToken(inputTokenReport_, report);
125  if (!report.isValid())
126  rawOK_ = false;
127  else {
128  const std::vector<int> feds = (*report).getFedsUnpacked();
129  fedsUnpacked = float(feds.size());
130  hunpkrep->Fill(0, fedsUnpacked);
131  hunpkrep->Fill(1, report->spigotFormatErrors());
132  hunpkrep->Fill(2, report->emptyEventSpigots());
133  hunpkrep->Fill(3, report->busySpigots());
134  hunpkrep->Fill(4, report->OFWSpigots());
135  hunpkrep->Fill(5, report->badQualityDigis());
136  }
137 
139  iEvent.getByToken(inputTokenDigi_, CastorDigi);
140  if (CastorDigi.isValid())
141  nDigi = CastorDigi->size();
142  else
143  digiOK_ = false;
144 
146  iEvent.getByToken(inputTokenRecHitCASTOR_, CastorHits);
147  if (CastorHits.isValid())
148  nrecHits = CastorHits->size();
149  else
150  rechitOK_ = false;
151 
153  iEvent.getByToken(inputTokenCastorTowers_, castorTowers);
154  if (castorTowers.isValid())
155  nTowers = castorTowers->size();
156  else
157  towerOK_ = false;
158 
160  iEvent.getByToken(JetAlgorithm, jets);
161  if (jets.isValid())
162  nJets = jets->size();
163  else
164  jetsOK_ = false;
165 
166  if (fVerbosity > 0)
167  LogPrint("CastorMonitorModule") << "CastorProductValid(size): RawDataValid=" << RawData.isValid()
168  << " Digi=" << digiOK_ << "(" << nDigi << ") Hits=" << rechitOK_ << "(" << nrecHits
169  << ")"
170  << " Towers=" << towerOK_ << "(" << nTowers << ")"
171  << " Jets=" << jetsOK_ << "(" << nJets << ")";
172 
173  CastorEventProduct->Fill(0, fedsUnpacked / 3.);
174  CastorEventProduct->Fill(1, rawOK_);
175  CastorEventProduct->Fill(2, digiOK_);
176  CastorEventProduct->Fill(3, rechitOK_);
177  CastorEventProduct->Fill(4, towerOK_);
178  CastorEventProduct->Fill(5, jetsOK_);
179 
180  if (digiOK_) {
182  iSetup.get<CastorDbRecord>().get(conditions);
183 
184  DigiMon_->processEvent(iEvent, *CastorDigi, *TrigResults, *conditions);
185  }
186  if (showTiming_) {
187  cpu_timer.stop();
188  if (DigiMon_ != nullptr)
189  std::cout << "TIMER:: DIGI MONITOR ->" << cpu_timer.cpuTime() << std::endl;
190  cpu_timer.reset();
191  cpu_timer.start();
192  }
193 
194  if (rechitOK_)
195  RecHitMon_->processEvent(*CastorHits);
196  if (showTiming_) {
197  cpu_timer.stop();
198  if (RecHitMon_ != nullptr)
199  std::cout << "TIMER:: RECHIT MONITOR->" << cpu_timer.cpuTime() << std::endl;
200  cpu_timer.reset();
201  cpu_timer.start();
202  }
203 
204  if (towerOK_)
205  RecHitMon_->processEventTowers(*castorTowers);
206  if (jetsOK_)
207  RecHitMon_->processEventJets(*jets);
208 
209  if (fVerbosity > 0 && ievt_ % 100 == 0)
210  LogPrint("CastorMonitorModule") << "processed " << ievt_ << " events";
211  return;
212 }
213 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int spigotFormatErrors() const
int emptyEventSpigots() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
MonitorElement * book1DD(TString const &name, TString const &title, int nchX, double lowX, double highX)
Definition: DQMStore.cc:257
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CastorMonitorModule(const edm::ParameterSet &ps)
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:333
bool isValid() const
Definition: HandleBase.h:70
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
int badQualityDigis() const
void analyze(const edm::Event &iEvent, const edm::EventSetup &eventSetup) override
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:73
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void dqmEndRun(const edm::Run &run, const edm::EventSetup &eventSetup) override
int busySpigots() const
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)