CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorMonitorModule.cc
Go to the documentation of this file.
6 
7 //**************************************************************//
8 //***************** CastorMonitorModule ******************//
9 //***************** Author: Dmytro Volyanskyy ******************//
10 //***************** Date : 22.11.2008 (first version) *********//
16 //**************************************************************//
17 
18 //---- critical revision 26.06.2014 (Vladimir Popov)
19 
20 //==================================================================//
21 //======================= Constructor ==============================//
23  fVerbosity{ps.getUntrackedParameter<int>("debug", 0)}
24 {
25  if(fVerbosity>0) std::cout<<"CastorMonitorModule Constructor(start)"<<std::endl;
26 
27  inputTokenRaw_ = consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("rawLabel"));
28  inputTokenReport_ = consumes<HcalUnpackerReport>(ps.getParameter<edm::InputTag>("unpackerReportLabel"));
29  inputTokenDigi_ = consumes<CastorDigiCollection>(ps.getParameter<edm::InputTag>("digiLabel"));
30  inputTokenRecHitCASTOR_ = consumes<CastorRecHitCollection>(ps.getParameter<edm::InputTag>("CastorRecHitLabel"));
31  NBunchesOrbit = ps.getUntrackedParameter<int>("nBunchesOrbit",3563);
32  showTiming_ = ps.getUntrackedParameter<bool>("showTiming",false);
33 //inputTokenCastorTowers_ = consumes<CastorTowerCollection>(ps.getParameter<edm::InputTag>("CastorTowerLabel"));
34 //dump2database_ = ps.getUntrackedParameter<bool>("dump2database",false);
35 
36  irun_=0;
37  ilumisec_=0;
38  ievent_=0;
39  itime_=0;
40  ibunch_=0;
41 
42  DigiMon_ = NULL;
43  RecHitMon_ = NULL;
44  LedMon_ = NULL;
45 
46  //---------------------- DigiMonitor ----------------------//
47  if ( ps.getUntrackedParameter<bool>("DigiMonitor", false) ) {
48  if(fVerbosity>0) std::cout << "CastorMonitorModule: Digi monitor flag is on...." << std::endl;
49  DigiMon_ = new CastorDigiMonitor(ps);
50 // DigiMon_ = new CastorDigiMonitor();
51  DigiMon_->setup(ps);
52  }
53 
55  if ( ps.getUntrackedParameter<bool>("RecHitMonitor", false) ) {
56  if(fVerbosity>0) std::cout << "CastorMonitorModule: RecHit monitor flag is on...." << std::endl;
58  RecHitMon_->setup(ps);
59  }
61  if ( ps.getUntrackedParameter<bool>("LEDMonitor", false) ) {
62  if(fVerbosity>0) std::cout << "CastorMonitorModule: LED monitor flag is on...." << std::endl;
63  LedMon_ = new CastorLEDMonitor(ps);
64  LedMon_->setup(ps);
65  }
66  //-------------------------------------------------------------//
67 
68  std::string subsystemname = ps.getUntrackedParameter<std::string>("subSystemFolder","Castor");
69  if(fVerbosity>1) std::cout << "===>CastorMonitor name = " << subsystemname << std::endl;
70 
71  ievt_ = 0;
72 
73  if(fVerbosity>0) std::cout<<"CastorMonitorModule Constructor(end)"<< std::endl;
74 }
75 
76 //======================= Destructor ===============================//
78  if (DigiMon_ != NULL) { delete DigiMon_; }
79  if (RecHitMon_ != NULL) { delete RecHitMon_; }
80  if (LedMon_ != NULL) { delete LedMon_; }
81 }
82 
84  const edm::EventSetup& iSetup) {
85  iSetup.get<CastorDbRecord>().get(conditions_);
86 
88  iSetup.get<CastorPedestalsRcd>().get(dbPedestals);
89  if(!dbPedestals.isValid() && fVerbosity>0) {
90  std::cout<<"CASTOR has no CastorPedestals in the CondDB"<<std::endl;
91  }
92 }
93 
94 //=============== bookHistograms =================//
96  const edm::Run& iRun, const edm::EventSetup& iSetup)
97 {
98  if(fVerbosity>0) std::cout<<"CastorMonitorModule::beginRun (start)" << std::endl;
99 
100  if (DigiMon_ != NULL) { DigiMon_->bookHistograms(ibooker,iRun,iSetup);}
101  if (RecHitMon_ != NULL) { RecHitMon_->bookHistograms(ibooker,iRun,iSetup); }
102  if (LedMon_ != NULL) { LedMon_->bookHistograms(ibooker,iRun,iSetup); }
103 
104 //std::cout<<"CastorMonitorModule::bookHist(): CastorCurrentFolder:"<<rootFolder_<<std::endl;
105  ibooker.setCurrentFolder(rootFolder_ + "CastorEventProducts");
106  char s[60];
107  sprintf(s,"CastorEventProducts");
108  CastorEventProduct = ibooker.book1D(s,s,4,-0.5,3.5);
109  CastorEventProduct->getTH1F()->GetXaxis()->SetBinLabel(1,"FEDs/3");
110  CastorEventProduct->getTH1F()->GetXaxis()->SetBinLabel(2,"RawData");
111  CastorEventProduct->getTH1F()->GetXaxis()->SetBinLabel(3,"CastorDigi");
112  CastorEventProduct->getTH1F()->GetXaxis()->SetBinLabel(4,"CastorRecHits");
113 
114 // reset();
115  if(fVerbosity>0)
116  std::cout<<"CastorMonitorModule::bookHistogram(end)"<< std::endl;
117  return;
118 }
119 
121  const edm::EventSetup& context) { }
122 
124  const edm::EventSetup& context) {}
125 
127 {}
128 
129 //========================== analyze ===============================//
131 {
132  if (fVerbosity>0) std::cout <<" "<<std::endl;
133  if (fVerbosity>0) std::cout <<"CastorMonitorModule::analyze (start)"<<std::endl;
134 
135  using namespace edm;
136 
137  irun_ = iEvent.id().run();
138  ilumisec_ = iEvent.luminosityBlock();
139  ievent_ = iEvent.id().event();
140  itime_ = iEvent.time().value();
141  ibunch_ = iEvent.bunchCrossing() % NBunchesOrbit;
142 
143  if (fVerbosity>1) {
144 //std::cout << " CastorMonitorModule: evts: "<<nevt_ <<", run: "<<irun_<<", LS: "<<ilumisec_<<std::endl;
145  std::cout <<" evt:"<<ievent_<<", time: "<<itime_ <<"\t total count = "<<ievt_<<std::endl;
146  }
147 
148  ievt_++;
149 
150  bool rawOK_ = true;
151  bool digiOK_ = true;
152  bool rechitOK_ = true;
153 
155  iEvent.getByToken(inputTokenRaw_,RawData);
156  if (!RawData.isValid()) {
157  rawOK_=false;
158  if (fVerbosity>0) std::cout << "RAW DATA NOT FOUND!" << std::endl;
159  }
160 
163  if (!report.isValid()) {
164  rawOK_=false;
165  if (fVerbosity>0) std::cout << "UNPACK REPORT HAS FAILED!" << std::endl;
166  }
167  else
168  {
169  const std::vector<int> feds = (*report).getFedsUnpacked();
170  fedsUnpacked = float(feds.size())/3.;
171  }
172 
174  iEvent.getByToken(inputTokenDigi_,CastorDigi);
175  if (!CastorDigi.isValid()) {
176  digiOK_=false;
177  if (fVerbosity>0) std::cout << "DIGI DATA NOT FOUND!" << std::endl;
178  }
179 
181  iEvent.getByToken(inputTokenRecHitCASTOR_,CastorHits);
182  if (!CastorHits.isValid()) {
183  rechitOK_ = false;
184  if (fVerbosity>0) std::cout << "RECO DATA NOT FOUND!" << std::endl;
185  }
186 
188  CastorEventProduct->Fill(1,int(rawOK_));
191 
192  // if((DigiMon_!=NULL) && (evtMask&DO_CASTOR_PED_CALIBMON) && digiOK_)
193  if(digiOK_) DigiMon_->processEvent(*CastorDigi,*conditions_,ibunch_);
194  if (showTiming_){
195  cpu_timer.stop();
196  if (DigiMon_!=NULL) std::cout <<"TIMER:: DIGI MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
198  }
199 
200  if(rechitOK_) RecHitMon_->processEvent(*CastorHits);
201  if (showTiming_){
202  cpu_timer.stop();
203  if (RecHitMon_!=NULL) std::cout <<"TIMER:: RECHIT MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
205  }
206 
207  if(digiOK_) LedMon_->processEvent(*CastorDigi,*conditions_);
208  if (showTiming_){
209  cpu_timer.stop();
210  if (LedMon_!=NULL) std::cout <<"TIMER:: LED MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
212  }
213 
214  if(fVerbosity>1 && ievt_%100 == 0)
215  std::cout << "CastorMonitorModule: processed "<<ievt_<<" events"<<std::endl;
216  if (fVerbosity>0) std::cout <<"CastorMonitorModule::analyze (end)"<<std::endl;
217  return;
218 }
219 
223 
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
void setup(const edm::ParameterSet &ps)
void endRun(const edm::Run &run, const edm::EventSetup &eventSetup)
void start()
Definition: CPUTimer.cc:74
void setup(const edm::ParameterSet &ps)
edm::EDGetTokenT< FEDRawDataCollection > inputTokenRaw_
void analyze(const edm::Event &iEvent, const edm::EventSetup &eventSetup)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &eventSetup)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::ESHandle< CastorDbService > conditions_
int bunchCrossing() const
Definition: EventBase.h:66
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
CastorLEDMonitor * LedMon_
void reset()
Definition: CPUTimer.cc:107
#define NULL
Definition: scimark2.h:8
edm::ESHandle< CastorPedestals > dbPedestals
void Fill(long long x)
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
edm::EDGetTokenT< CastorDigiCollection > inputTokenDigi_
tuple report
Definition: zeeHLT_cff.py:9
int iEvent
Definition: GenABIO.cc:230
void processEvent(const CastorDigiCollection &cast, const CastorDbService &cond, int bunch)
CastorMonitorModule(const edm::ParameterSet &ps)
void processEvent(const CastorDigiCollection &cast, const CastorDbService &cond)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
CastorDigiMonitor * DigiMon_
void setup(const edm::ParameterSet &ps)
Times stop()
Definition: CPUTimer.cc:94
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
double cpuTime() const
Definition: CPUTimer.cc:158
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
const T & get() const
Definition: EventSetup.h:55
TH1F * getTH1F(void) const
MonitorElement * CastorEventProduct
edm::EventID id() const
Definition: EventBase.h:60
edm::EDGetTokenT< HcalUnpackerReport > inputTokenReport_
CastorRecHitMonitor * RecHitMon_
tuple cout
Definition: gather_cfg.py:121
void processEvent(const CastorRecHitCollection &castorHits)
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &eventSetup)
bool isValid() const
Definition: ESHandle.h:47
edm::EDGetTokenT< CastorRecHitCollection > inputTokenRecHitCASTOR_
TimeValue_t value() const
Definition: Timestamp.h:56
edm::Timestamp time() const
Definition: EventBase.h:61
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
Definition: Run.h:41