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 
29 int NLumiSec = 0;
30 int TrigNameIndex = 0;
31 
33  fVerbosity = ps.getUntrackedParameter<int>("debug", 0);
34  subsystemname_ =
35  ps.getUntrackedParameter<std::string>("subSystemFolder", "Castor");
36  inputTokenRaw_ = consumes<FEDRawDataCollection>(
37  ps.getParameter<edm::InputTag>("rawLabel"));
38  inputTokenReport_ = consumes<HcalUnpackerReport>(
39  ps.getParameter<edm::InputTag>("unpackerReportLabel"));
40  inputTokenDigi_ = consumes<CastorDigiCollection>(
41  ps.getParameter<edm::InputTag>("digiLabel"));
42  inputTokenRecHitCASTOR_ = consumes<CastorRecHitCollection>(
43  ps.getParameter<edm::InputTag>("CastorRecHitLabel"));
44  inputTokenCastorTowers_ = consumes<CastorTowerCollection>(
45  ps.getParameter<edm::InputTag>("CastorTowerLabel"));
46  JetAlgorithm = consumes<BasicJetCollection>(
47  ps.getParameter<edm::InputTag>("CastorBasicJetsLabel"));
48  tokenTriggerResults = consumes<edm::TriggerResults>(
49  ps.getParameter<edm::InputTag>("tagTriggerResults"));
50 
51  showTiming_ = ps.getUntrackedParameter<bool>("showTiming", false);
52 
53  irun_ = ilumisec_ = ievent_ = ibunch_ = 0;
54  TrigNameIndex = 0;
55 
56  DigiMon_ = nullptr;
57  RecHitMon_ = nullptr;
58  LedMon_ = nullptr;
59 
60  if (ps.getUntrackedParameter<bool>("DigiMonitor", false))
61  DigiMon_ = new CastorDigiMonitor(ps);
62 
63  if (ps.getUntrackedParameter<bool>("RecHitMonitor", false))
64  RecHitMon_ = new CastorRecHitMonitor(ps);
65 
66  if (ps.getUntrackedParameter<bool>("LEDMonitor", false))
67  LedMon_ = new CastorLEDMonitor(ps);
68 
69  ievt_ = 0;
70 }
71 
73  if (DigiMon_ != nullptr) delete DigiMon_;
74  if (RecHitMon_ != nullptr) delete RecHitMon_;
75  if (LedMon_ != nullptr) delete LedMon_;
76 }
77 
79  const edm::EventSetup& iSetup) {
80  if (fVerbosity > 0) LogPrint("CastorMonitorModule") << "dqmBeginRun(start)";
81  NLumiSec = 0;
82 
83  iSetup.get<CastorDbRecord>().get(conditions_);
84 }
85 
87  const edm::Run& iRun,
88  const edm::EventSetup& iSetup) {
89  if (DigiMon_ != nullptr) {
90  DigiMon_->bookHistograms(ibooker, iRun, iSetup);
91  }
92  if (RecHitMon_ != nullptr) {
93  RecHitMon_->bookHistograms(ibooker, iRun, iSetup);
94  }
95  if (LedMon_ != nullptr) {
96  LedMon_->bookHistograms(ibooker, iRun, iSetup);
97  }
98 
99  ibooker.setCurrentFolder(subsystemname_);
100  char s[60];
101  sprintf(s, "CastorEventProducts");
102  CastorEventProduct = ibooker.book1DD(s, s, 6, -0.5, 5.5);
103  CastorEventProduct->getTH1D()->GetYaxis()->SetTitle("Events");
104  TAxis* xa = CastorEventProduct->getTH1D()->GetXaxis();
105  xa->SetBinLabel(1, "FEDs/3");
106  xa->SetBinLabel(2, "RawData");
107  xa->SetBinLabel(3, "Digi");
108  xa->SetBinLabel(4, "RecHits");
109  xa->SetBinLabel(5, "Towers");
110  xa->SetBinLabel(6, "Jets");
111 
112  sprintf(s, "CASTORUnpackReport");
113  hunpkrep = ibooker.bookProfile(s, s, 6, -0.5, 5.5, 100, 0, 1.e10, "");
114  xa = hunpkrep->getTProfile()->GetXaxis();
115  xa->SetBinLabel(1, "N_FEDs");
116  xa->SetBinLabel(2, "SPIGOT_Err");
117  xa->SetBinLabel(3, "empty");
118  xa->SetBinLabel(4, "busy");
119  xa->SetBinLabel(5, "OvF");
120  xa->SetBinLabel(6, "BadDigis");
121  return;
122 }
123 
125  const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& context) {
126  ++NLumiSec;
127  if (fVerbosity > 0)
128  LogPrint("CastorMonitorModule")
129  << "beginLuminosityBlock(start): " << NLumiSec << "(" << ilumisec_
130  << ")";
131 }
132 
134  const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& context) {}
135 
137  const edm::EventSetup& context) {
138  if (DigiMon_ != nullptr) {
139  DigiMon_->endRun();
140  }
141 }
142 
144  const edm::EventSetup& eventSetup) {
145  if (fVerbosity > 1) LogPrint("CastorMonitorModule") << "analyze (start)";
146 
147  irun_ = iEvent.id().run();
148  ilumisec_ = iEvent.luminosityBlock();
149  ievent_ = iEvent.id().event();
150  ibunch_ = iEvent.bunchCrossing();
151 
152  ievt_++;
153 
154  bool rawOK_ = true;
155  bool digiOK_ = true;
156  bool rechitOK_ = true, towerOK_ = true, jetsOK_ = true;
157  int nDigi = 0, nrecHits = 0, nTowers = 0, nJets = 0;
158 
160  iEvent.getByToken(tokenTriggerResults, TrigResults);
161 
163  iEvent.getByToken(inputTokenRaw_, RawData);
164  if (!RawData.isValid()) rawOK_ = false;
165 
166  float fedsUnpacked = 0.;
168  iEvent.getByToken(inputTokenReport_, report);
169  if (!report.isValid())
170  rawOK_ = false;
171  else {
172  const std::vector<int> feds = (*report).getFedsUnpacked();
173  fedsUnpacked = float(feds.size());
174  hunpkrep->Fill(0, fedsUnpacked);
175  hunpkrep->Fill(1, report->spigotFormatErrors());
176  hunpkrep->Fill(2, report->emptyEventSpigots());
177  hunpkrep->Fill(3, report->busySpigots());
178  hunpkrep->Fill(4, report->OFWSpigots());
179  hunpkrep->Fill(5, report->badQualityDigis());
180  }
181 
183  iEvent.getByToken(inputTokenDigi_, CastorDigi);
184  if (CastorDigi.isValid())
185  nDigi = CastorDigi->size();
186  else
187  digiOK_ = false;
188 
190  iEvent.getByToken(inputTokenRecHitCASTOR_, CastorHits);
191  if (CastorHits.isValid())
192  nrecHits = CastorHits->size();
193  else
194  rechitOK_ = false;
195 
197  iEvent.getByToken(inputTokenCastorTowers_, castorTowers);
198  if (castorTowers.isValid())
199  nTowers = castorTowers->size();
200  else
201  towerOK_ = false;
202 
204  iEvent.getByToken(JetAlgorithm, jets);
205  if (jets.isValid())
206  nJets = jets->size();
207  else
208  jetsOK_ = false;
209 
210  if (fVerbosity > 0)
211  LogPrint("CastorMonitorModule")
212  << "CastorProductValid(size): RawDataValid=" << RawData.isValid()
213  << " Digi=" << digiOK_ << "(" << nDigi << ") Hits=" << rechitOK_ << "("
214  << nrecHits << ")"
215  << " Towers=" << towerOK_ << "(" << nTowers << ")"
216  << " Jets=" << jetsOK_ << "(" << nJets << ")";
217 
218  CastorEventProduct->Fill(0, fedsUnpacked / 3.);
219  CastorEventProduct->Fill(1, rawOK_);
220  CastorEventProduct->Fill(2, digiOK_);
221  CastorEventProduct->Fill(3, rechitOK_);
222  CastorEventProduct->Fill(4, towerOK_);
223  CastorEventProduct->Fill(5, jetsOK_);
224 
225  if (digiOK_)
226  DigiMon_->processEvent(iEvent, *CastorDigi, *TrigResults, *conditions_);
227  if (showTiming_) {
228  cpu_timer.stop();
229  if (DigiMon_ != nullptr)
230  std::cout << "TIMER:: DIGI MONITOR ->" << cpu_timer.cpuTime()
231  << std::endl;
232  cpu_timer.reset();
233  cpu_timer.start();
234  }
235 
236  if (rechitOK_) RecHitMon_->processEvent(*CastorHits);
237  if (showTiming_) {
238  cpu_timer.stop();
239  if (RecHitMon_ != nullptr)
240  std::cout << "TIMER:: RECHIT MONITOR->" << cpu_timer.cpuTime()
241  << std::endl;
242  cpu_timer.reset();
243  cpu_timer.start();
244  }
245 
246  if (towerOK_) RecHitMon_->processEventTowers(*castorTowers);
247  if (jetsOK_) RecHitMon_->processEventJets(*jets);
248 
249  if (fVerbosity > 0 && ievt_ % 100 == 0)
250  LogPrint("CastorMonitorModule") << "processed " << ievt_ << " events";
251  return;
252 }
253 
RunNumber_t run() const
Definition: EventID.h:39
TProfile * getTProfile() const
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int spigotFormatErrors() const
int emptyEventSpigots() const
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void endRun(const edm::Run &run, const edm::EventSetup &eventSetup) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &eventSetup) override
int bunchCrossing() const
Definition: EventBase.h:66
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
int TrigNameIndex
int iEvent
Definition: GenABIO.cc:230
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
int NLumiSec
CastorMonitorModule(const edm::ParameterSet &ps)
vector< PseudoJet > jets
bool isValid() const
Definition: HandleBase.h:74
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &eventSetup) override
int badQualityDigis() const
void analyze(const edm::Event &iEvent, const edm::EventSetup &eventSetup) override
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:62
TH1D * getTH1D() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * book1DD(Args &&...args)
Definition: DQMStore.h:108
int busySpigots() const
Definition: Run.h:44