CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESIntegrityClient.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <iostream>
3 #include <fstream>
4 #include <iomanip>
5 
7 
9 
10 using namespace edm;
11 using namespace std;
12 
14 
15  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
16  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
17  debug_ = ps.getUntrackedParameter<bool>("debug", false);
18  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
19  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
20  lookup_ = ps.getUntrackedParameter<FileInPath>("LookupTable", edm::FileInPath("EventFilter/ESDigiToRaw/data/ES_lookup_table.dat"));
21 
22  // read in look-up table
23  for (int i=0; i<2; ++i)
24  for (int j=0; j<2; ++j)
25  for (int k=0; k<40; ++k)
26  for (int m=0; m<40; ++m) {
27  fed_[i][j][k][m] = -1;
28  kchip_[i][j][k][m] = -1;
29  }
30 
31  for (int i=0; i<56; ++i) {
32  fedStatus_[i] = -1;
33  syncStatus_[i] = -1;
34  slinkCRCStatus_[i] = -1;
35  for (int j=0; j<36; ++j)
36  fiberStatus_[i][j] = -1;
37  }
38 
39  int nLines_, z, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
40  ifstream file;
41  file.open(lookup_.fullPath().c_str());
42  if( file.is_open() ) {
43 
44  file >> nLines_;
45 
46  for (int i=0; i<nLines_; ++i) {
47  file>> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
48 
49  z = (iz==-1) ? 2:iz;
50  fed_[z-1][ip-1][ix-1][iy-1] = fed;
51  kchip_[z-1][ip-1][ix-1][iy-1] = kchip;
52  fiber_[z-1][ip-1][ix-1][iy-1] = (fiber-1)+(optorx-1)*12;
53  }
54  }
55  else {
56  cout<<"ESIntegrityClient : Look up table file can not be found in "<<lookup_.fullPath().c_str()<<endl;
57  }
58 
59  hFED_ = 0;
60  hFiberOff_ = 0;
61  hFiberBadStatus_ = 0;
62  hKF1_ = 0;
63  hKF2_ = 0;
64  hKBC_ = 0;
65  hKEC_ = 0;
66  hL1ADiff_ = 0;
67  hBXDiff_ = 0;
68  hOrbitNumberDiff_ = 0;
69  hSLinkCRCErr_ = 0;
70 
71  ievt_ = 0;
72  jevt_ = 0;
73 }
74 
76 }
77 
79 
80  dqmStore_ = dqmStore;
81 
82  if ( debug_ ) cout << "ESIntegrityClient: beginJob" << endl;
83 
84  ievt_ = 0;
85  jevt_ = 0;
86 }
87 
89 
90  if ( debug_ ) cout << "ESIntegrityClient: beginRun" << endl;
91 
92  jevt_ = 0;
93 
94  this->setup();
95 
96 }
97 
99 
100  if ( debug_ ) cout << "ESIntegrityClient: endJob, ievt = " << ievt_ << endl;
101 
102  this->cleanup();
103 
104 }
105 
107 
108  if ( debug_ ) cout << "ESIntegrityClient: endRun, jevt = " << jevt_ << endl;
109 
110  this->cleanup();
111 
112 }
113 
115 
116  char histo[200];
117 
118  dqmStore_->setCurrentFolder( prefixME_ + "/ESIntegrityClient" );
119 
120  for (int i=0 ; i<2; ++i)
121  for (int j=0 ; j<2; ++j) {
122  int iz = (i==0)? 1:-1;
123  snprintf(histo, 200, "ES Integrity Summary 1 Z %d P %d", iz, j+1);
124  meFED_[i][j] = dqmStore_->book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
125  meFED_[i][j]->setAxisTitle("Si X", 1);
126  meFED_[i][j]->setAxisTitle("Si Y", 2);
127 
128  snprintf(histo, 200, "ES Integrity Summary 2 Z %d P %d", iz, j+1);
129  meKCHIP_[i][j] = dqmStore_->book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
130  meKCHIP_[i][j]->setAxisTitle("Si X", 1);
131  meKCHIP_[i][j]->setAxisTitle("Si Y", 2);
132  }
133 }
134 
136 
137  if ( ! enableCleanup_ ) return;
138 
139 }
140 
142 
143  double nDI_FedErr[56];
144  for (int i=0; i<56; ++i) nDI_FedErr[i] = 0;
145 
146  MonitorElement* me = 0;
147 
148  me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES FEDs used for data taking");
149  hFED_ = getHisto(me, cloneME_, hFED_);
150 
151  me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES Fiber Off");
152  hFiberOff_ = getHisto(me, cloneME_, hFiberOff_);
153 
154  me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES Fiber Bad Status");
155  hFiberBadStatus_ = getHisto(me, cloneME_, hFiberBadStatus_);
156 
157  me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES SLink CRC Errors");
158  hSLinkCRCErr_ = getHisto(me, cloneME_, hSLinkCRCErr_);
159 
160  int xval = 0;
161  int nevFEDs = 0;
162  if (hFED_) {
163  for (int i=1; i<=56; ++i)
164  if (nevFEDs < hFED_->GetBinContent(i))
165  nevFEDs = (int) hFED_->GetBinContent(i);
166  }
167 
168  // FED integrity
169  for (int i=1; i<=56; ++i) {
170  if (hFED_) {
171  if (hFED_->GetBinContent(i) > 0)
172  fedStatus_[i-1] = 1;
173  }
174  if (hSLinkCRCErr_) {
175  if (hSLinkCRCErr_->GetBinContent(i) > 0)
176  slinkCRCStatus_[i-1] = 1;
177  }
178  for (int j=0; j<36; ++j) {
179  if (hFiberBadStatus_) {
180  if (hFiberBadStatus_->GetBinContent(i, j+1) > 0)
181  fiberStatus_[i-1][j] = 2; // bad
182  else
183  fiberStatus_[i-1][j] = 1; // good
184  }
185  if (hFiberOff_)
186  if (hFiberOff_->GetBinContent(i, j+1) > 0) {
187  fiberStatus_[i-1][j] = 0; // off
188  }
189  }
190  }
191 
192  // obtain MEs from ESRawDataTask
193  me = dqmStore_->get(prefixME_ + "/ESRawDataTask/ES L1A DCC errors");
194  hL1ADiff_ = getHisto(me, cloneME_, hL1ADiff_);
195 
196  me = dqmStore_->get(prefixME_ + "/ESRawDataTask/ES BX DCC errors");
197  hBXDiff_ = getHisto(me, cloneME_, hBXDiff_);
198 
199  me = dqmStore_->get(prefixME_ + "/ESRawDataTask/ES Orbit Number DCC errors");
200  hOrbitNumberDiff_ = getHisto(me, cloneME_, hOrbitNumberDiff_);
201 
202  for (int i=1; i<=56; ++i) {
203  if (hL1ADiff_ && hBXDiff_) {
204  if (hL1ADiff_->GetBinContent(i) > 0 || hBXDiff_->GetBinContent(i) > 0) {
205  syncStatus_[i-1] = 1;
206  if (hL1ADiff_->GetBinContent(i) > nDI_FedErr[i-1]) nDI_FedErr[i-1] = hL1ADiff_->GetBinContent(i);
207  if (hBXDiff_->GetBinContent(i) > nDI_FedErr[i-1]) nDI_FedErr[i-1] = hBXDiff_->GetBinContent(i);
208  }
209  }
210  //if (hOrbitNumberDiff_->GetBinContent(i) > 0) syncStatus_[i-1] = 1;
211  }
212 
213  // KCHIP integrity
214  me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES KChip Flag 1 Error codes");
215  hKF1_ = getHisto(me, cloneME_, hKF1_);
216 
217  me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES KChip Flag 2 Error codes");
218  hKF2_ = getHisto(me, cloneME_, hKF2_);
219 
220  me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES KChip BC mismatch with OptoRX");
221  hKBC_ = getHisto(me, cloneME_, hKBC_);
222 
223  me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES KChip EC mismatch with OptoRX");
224  hKEC_ = getHisto(me, cloneME_, hKEC_);
225 
226  Int_t kchip_xval[1550];
227  for (int i=0; i<1550; ++i) {
228 
229  xval = 3;
230  Int_t kErr = 0;
231  for (int j=1; j<16; ++j) {
232  if (hKF1_) {
233  if (hKF1_->GetBinContent(i, j+1)>0) {
234  xval = 2;
235  kErr++;
236  }
237  }
238  if (hKF2_) {
239  if (hKF2_->GetBinContent(i, j+1)>0) {
240  xval = 4;
241  kErr++;
242  }
243  }
244  }
245  if (hKBC_) {
246  if (hKBC_->GetBinContent(i)>0) {
247  xval = 5;
248  kErr++;
249  }
250  }
251  if (hKEC_) {
252  if (hKEC_->GetBinContent(i)>0) {
253  xval = 6;
254  kErr++;
255  }
256  }
257  if (kErr>1) xval = 7;
258  kchip_xval[i] = xval;
259  }
260 
261  // detailed KCHIP summary (i.e. summary 2)
262  for (int iz=0; iz<2; ++iz)
263  for (int ip=0; ip<2; ++ip)
264  for (int ix=0; ix<40; ++ix)
265  for (int iy=0; iy<40; ++iy) {
266  if (fed_[iz][ip][ix][iy] == -1) continue;
267  if (fedStatus_[fed_[iz][ip][ix][iy]-520]==-1 || fiberStatus_[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] == 0)
268  kchip_xval[kchip_[iz][ip][ix][iy]-1] = 0;
269  if ((kchip_[iz][ip][ix][iy]-2) >= 0)
270  meKCHIP_[iz][ip]->setBinContent(ix+1, iy+1, kchip_xval[kchip_[iz][ip][ix][iy]-2]);
271  }
272 
273  // FED, Fiber, KCHIP summary (i.e. summary 1)
274  Int_t nErr = 0;
275  for (int iz=0; iz<2; ++iz)
276  for (int ip=0; ip<2; ++ip)
277  for (int ix=0; ix<40; ++ix)
278  for (int iy=0; iy<40; ++iy) {
279 
280  if (fed_[iz][ip][ix][iy] == -1) continue;
281  nErr = 0;
282 
283  if (fedStatus_[fed_[iz][ip][ix][iy]-520] == 1) {
284 
285  if (hFED_) {
286  if (hFED_->GetBinContent(fed_[iz][ip][ix][iy]-520+1) == nevFEDs)
287  xval = 3;
288  else {
289  xval = 4; // FED problem
290  nErr++;
291  }
292  }
293 
294  if (fiberStatus_[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] == 2) {
295  xval = 2; // fiber problem
296  nErr++;
297  }
298  if (fiberStatus_[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] == 0) {
299  xval = 0; // fiber off
300  }
301  if (kchip_xval[kchip_[iz][ip][ix][iy]-1] != 3 && kchip_xval[kchip_[iz][ip][ix][iy]-1] != 0) {
302  xval = 5; // kchip problem
303  nErr++;
304  }
305  if (syncStatus_[fed_[iz][ip][ix][iy]-520] == 1) {
306  xval = 6;
307  nErr++;
308  }
309  if (slinkCRCStatus_[fed_[iz][ip][ix][iy]-520] == 1) {
310  xval = 8;
311  nErr++;
312  }
313  if (nErr > 1) xval = 7;
314  } else if (fedStatus_[fed_[iz][ip][ix][iy]-520] == -1) {
315  xval = 0;
316  }
317 
318  meFED_[iz][ip]->setBinContent(ix+1, iy+1, xval);
319  }
320 
321 }
322 
324 
325 }
326 
327 
void softReset(bool flag)
SoftReset.
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void beginRun(void)
BeginRun.
static void cleanup(const Factory::MakerMap::value_type &v)
Definition: Factory.cc:12
void setup(void)
Setup.
float float float z
virtual ~ESIntegrityClient()
Destructor.
void cleanup(void)
Cleanup.
void beginJob(DQMStore *dqmStore)
BeginJob.
int j
Definition: DBlmapReader.cc:9
int k[5][pyjets_maxn]
ESIntegrityClient(const edm::ParameterSet &ps)
Constructor.
tuple cout
Definition: gather_cfg.py:121
void endRun(void)
EndRun.
TH1F * getHisto(std::string name, std::string process, DQMStore *dbe_, bool verb=false, bool clone=false)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void endJob(void)
EndJob.
void analyze(void)
Analyze.