CMS 3D CMS Logo

SiPixelFedFillerWordEventNumber.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelFedFillerWordEventNumber
4 // Class: SiPixelFedFillerWordEventNumber
5 //
13 //
14 // Original Author: Andres Carlos FLOREZ B
15 // Created: Thu Jun 26 09:02:02 CEST 2008
16 //
17 //
18 
19 // system include files
20 #include <memory>
22 
23 //======= constructors and destructor
25  SaveFillerWordsbool = iConfig.getParameter<bool>("SaveFillerWords");
26  label = iConfig.getUntrackedParameter<std::string>("InputLabel", "source");
27  instance = iConfig.getUntrackedParameter<std::string>("InputInstance", "");
28  produces<std::vector<uint32_t>>("FillerWordEventNumber1");
29  produces<std::vector<uint32_t>>("FillerWordEventNumber2");
30  if (SaveFillerWordsbool == true) {
31  produces<std::vector<uint32_t>>("SaveFillerWord");
32  }
33  consumes<FEDRawDataCollection>(label);
34 }
35 
37 unsigned int SiPixelFedFillerWordEventNumber ::CalibStatFillWord(unsigned int totword, int status) {
38  //===== Variables to get each filler word out of the totword and
39  // to conform the last 16 bit filler word if Filler3 is zero.
40  unsigned int Filler1 = (totword)&0x000000ff;
41  unsigned int Filler2 = ((totword)&0x0000ff00) >> 8;
42  unsigned int Filler3 = ((totword)&0x00ff0000) >> 16;
43  unsigned int Filler4 = ((totword)&0xffff0000) >> 16;
44  unsigned int maskFiller4 = ((totword)&0xff000000) >> 16;
45  unsigned int Filler14 = (Filler1 & maskFiller4);
46  unsigned int Filler24 = (Filler2 & maskFiller4);
47  unsigned int CalibFiller1 = 0;
48  unsigned int CalibFiller2 = 0;
49  bool BoolStat = false;
50  //=====Possible cases for the totword. "CalibFiller1" and "CalibFiller2" take their valur
51  // according to the value of the totword.
52  if ((status == 0x1) || (status == 0x9)) {
53  CalibFiller1 = Filler1;
54  if (status == 0x9) {
55  CalibFiller2 = Filler14;
56  }
57  }
58  if ((status == 0x2) || (status == 0xa)) {
59  CalibFiller1 = Filler2;
60  if (status == 0xa) {
61  CalibFiller2 = Filler24;
62  }
63  }
64  if ((status == 0x4) || (status == 0xc)) {
65  CalibFiller1 = Filler3;
66  if (status == 0xc) {
67  CalibFiller2 = Filler4;
68  }
69  }
70  if (status == 0x8) {
71  CalibFiller2 = Filler4;
72  }
73  if ((status == 0x7) || (status == 0xf)) {
74  if ((Filler1 == Filler2) && (Filler1 == Filler3) && (Filler2 == Filler3)) {
75  CalibFiller1 = Filler1;
76  BoolStat = true;
77  if (status == 0xf) {
78  CalibFiller2 = Filler4;
79  }
80  } else {
81  edm::LogError("AnazrFedFillerWords")
82  << "Status: " << status << "Event ID in Filler words don't match" << '\t' << "Filler1: " << (Filler1 % 256)
83  << '\t' << "Filler2: " << (Filler2 % 256) << '\t' << "Filler3: " << (Filler3 % 256) << std::endl;
84  }
85  }
86  if ((status == 0x3) || (status == 0xb)) {
87  if (Filler1 == Filler2) {
88  CalibFiller1 = Filler1;
89  BoolStat = true;
90  if (status == 0xb) {
91  CalibFiller2 = Filler14;
92  }
93  } else {
94  edm::LogError("AnazrFedFillerWords")
95  << "Status: " << status << "Event ID in Filler words don't match" << '\t' << "Filler1: " << (Filler1 % 256)
96  << '\t' << "Filler2: " << (Filler2 % 256) << std::endl;
97  }
98  }
99  if ((status == 0x5) || (status == 0xd)) {
100  if (Filler1 == Filler3) {
101  CalibFiller1 = Filler1;
102  BoolStat = true;
103  if (status == 0xd) {
104  CalibFiller2 = Filler4;
105  }
106  } else {
107  edm::LogError("AnazrFedFillerWords")
108  << "Status: " << status << "Event ID in Filler words don't match" << '\t' << "Filler1: " << (Filler1 % 256)
109  << '\t' << "Filler3: " << (Filler3 % 256) << std::endl;
110  }
111  }
112  if ((status == 0x6) || (status == 0xe)) {
113  if (Filler2 == Filler3) {
114  CalibFiller1 = Filler2;
115  BoolStat = true;
116  if (status == 0xe) {
117  CalibFiller2 = Filler4;
118  }
119  } else {
120  edm::LogError("AnazrFedFillerWords")
121  << "Status: " << status << "Event ID Filler words don't match" << '\t' << "Filler2: " << (Filler2 % 256)
122  << '\t' << "Filler3: " << (Filler3 % 256) << std::endl;
123  }
124  }
125  //===== Using the Event number from CMSSW to get a value to compare with the value encoded
126  // in the filler words.
127  unsigned int CalibEvtNum = ((EventNum - 1) / 10);
128  if ((CalibFiller1 != 0) && (CalibEvtNum != CalibFiller1)) {
129  edm::LogError("AnazrFedFillerWords") << "Error, Event ID Numbers Don't match---->"
130  << "Filler1 Event ID: " << CalibFiller1 << '\t'
131  << "Run Event ID: " << CalibEvtNum << '\t' << std::endl;
132  } else if ((CalibFiller1 != 0) && (CalibEvtNum == CalibFiller1)) {
133  vecFillerWordsEventNumber1.push_back((CalibFiller1 % 256));
134  edm::LogInfo("AnazrFedFillerWords") << "Filler1 Event ID: " << (CalibFiller1 % 256) << std::endl;
135  } else if ((CalibFiller2 != 0) && (BoolStat == true)) {
136  vecFillerWordsEventNumber2.push_back((((CalibFiller2 % 65536) & (0xff00)) >> 8));
137  edm::LogInfo("AnazrFedFillerWords") << "Filler2 Event ID:" << (((CalibFiller2 % 65536) & (0xff00)) >> 8)
138  << std::endl;
139  } else if ((CalibFiller2 != 0) && (BoolStat == false)) {
140  if ((status == 0x9) || (status == 0xa) || (status == 0xc)) {
141  vecFillerWordsEventNumber2.push_back((((CalibFiller2 % 65536) & (0xff00)) >> 8));
142  edm::LogInfo("AnazrFedFillerWords")
143  << "Filler2 Event ID:" << (((CalibFiller2 % 65536) & (0xff00)) >> 8) << std::endl;
144  } else if (status == 0x8) {
145  edm::LogError("AnazrFedFillerWords")
146  << "Status: " << status << " No Filler1 found, is not possible get any Event ID Number" << std::endl;
147  }
148  }
149 
150  return 0;
151 }
152 //========== Function to decode data words ==================================================
153 int SiPixelFedFillerWordEventNumber ::PwordSlink64(uint64_t* ldata, const int length, uint32_t& totword) {
154  edm::LogInfo("FedFillerWords") << "Begin of data" << std::endl;
155 
156  if ((ldata[0] & 0xf000000000000000LL) != 0x5000000000000000LL) //header
157  {
158  return 0;
159  }
160 
161  //========= analyze the data buffer to find private words ================================
162  int fif2cnt = 0;
163  int dumcnt = 0;
164  int gapcnt = 0;
165 
166  uint32_t gap[8];
167  uint32_t dum[8];
168  uint32_t word1 = 0;
169  uint32_t word2 = 0;
170 
171  uint32_t chan = 0;
172  uint32_t roc = 0;
173 
174  const uint32_t rocmsk = 0x3e00000;
175  const uint32_t chnlmsk = 0xfc000000;
176 
177  for (int jk = 0; jk < 8; jk++)
178  gap[jk] = 0;
179  for (int jk = 0; jk < 8; jk++)
180  dum[jk] = 0;
181  totword = 0;
182  int fifcnt = 1;
183  for (int kk = 1; kk < length - 1; kk++) {
184  //======= if statement to make analize just data with the right format ===================
185  if ((((ldata[kk] & 0xff00000000000000LL) >> 32) == 0xa0000000) &&
186  (((ldata[kk] & 0xffffff00000000LL) >> 32) == (uint64_t)(kk + 1))) {
187  break;
188  }
189 
190  word2 = (uint32_t)ldata[kk];
191  word1 = (uint32_t)(ldata[kk] >> 32);
192 
193  //======= 1st word ======================================================================
194 
195  chan = ((word1 & chnlmsk) >> 26);
196  roc = ((word1 & rocmsk) >> 21);
197 
198  //======count non-error words
199  if (roc < 25) {
200  if (dumcnt > 0) {
201  dumcnt = 0;
202  } //stale dummy!
203  if ((chan < 5) && (fifcnt != 1)) {
204  edm::LogError("FedFillerWords") << " error in fifo counting!" << std::endl;
205  }
206  if ((chan > 4) && (chan < 10) && (fifcnt != 2)) {
207  fif2cnt = 0;
208  fifcnt = 2;
209  }
210  if ((chan > 9) && (chan < 14) && (fifcnt != 3)) {
211  fif2cnt = 0;
212  fifcnt = 3;
213  }
214  if ((chan > 13) && (chan < 19) && (fifcnt != 4)) {
215  fif2cnt = 0;
216  fifcnt = 4;
217  }
218  if ((chan > 18) && (chan < 23) && (fifcnt != 5)) {
219  fif2cnt = 0;
220  fifcnt = 5;
221  }
222  if ((chan > 22) && (chan < 28) && (fifcnt != 6)) {
223  fif2cnt = 0;
224  fifcnt = 6;
225  }
226  if ((chan > 27) && (chan < 32) && (fifcnt != 7)) {
227  fif2cnt = 0;
228  fifcnt = 7;
229  }
230  if ((chan > 31) && (fifcnt != 8)) {
231  fif2cnt = 0;
232  fifcnt = 8;
233  }
234  fif2cnt++;
235  }
236  //====== Gap Word
237  if (roc == 26) {
238  gap[fifcnt - 1] = (0x1000 + (word1 & 0xff));
239  gapcnt++;
240  }
241  //====== Dummy Word
242  if ((roc == 27) && ((fif2cnt + dumcnt) < 6)) {
243  dum[fifcnt - 1] = (0x1000 + (word1 & 0xff));
244  dumcnt++;
245  } else if ((roc == 27) && ((fif2cnt + dumcnt) > 6)) {
246  dumcnt = 1;
247  fif2cnt = 0;
248  fifcnt++;
249  }
250 
251  //======== 2nd word ============================================================
252 
253  chan = ((word2 & chnlmsk) >> 26);
254  roc = ((word2 & rocmsk) >> 21);
255 
256  if (roc < 25) {
257  if (dumcnt > 0) {
258  dumcnt = 0;
259  edm::LogInfo("FedFillerWords") << " ***Stale dummy!" << std::endl;
260  } //stale dummy!
261  if ((chan < 5) && (fifcnt != 1)) {
262  edm::LogError("FedFillerWords") << " error in fifo counting!" << std::endl;
263  }
264  if ((chan > 4) && (chan < 10) && (fifcnt != 2)) {
265  fif2cnt = 0;
266  fifcnt = 2;
267  }
268  if ((chan > 9) && (chan < 14) && (fifcnt != 3)) {
269  fif2cnt = 0;
270  fifcnt = 3;
271  }
272  if ((chan > 13) && (chan < 19) && (fifcnt != 4)) {
273  fif2cnt = 0;
274  fifcnt = 4;
275  }
276  if ((chan > 18) && (chan < 23) && (fifcnt != 5)) {
277  fif2cnt = 0;
278  fifcnt = 5;
279  }
280  if ((chan > 22) && (chan < 28) && (fifcnt != 6)) {
281  fif2cnt = 0;
282  fifcnt = 6;
283  }
284  if ((chan > 27) && (chan < 32) && (fifcnt != 7)) {
285  fif2cnt = 0;
286  fifcnt = 7;
287  }
288  if ((chan > 31) && (fifcnt != 8)) {
289  fif2cnt = 0;
290  fifcnt = 8;
291  }
292  fif2cnt++;
293  }
294  if (roc == 26) {
295  gap[fifcnt - 1] = (0x1000 + (word2 & 0xff));
296  gapcnt++;
297  }
298  if ((roc == 27) && ((fif2cnt + dumcnt) < 6)) {
299  dum[fifcnt - 1] = (0x1000 + (word1 & 0xff));
300  dumcnt++;
301  } else if ((roc == 27) && ((fif2cnt + dumcnt) > 6)) {
302  dumcnt = 1;
303  fif2cnt = 0;
304  fifcnt++;
305  }
306 
307  //word check complete
308  if (((fif2cnt + dumcnt) == 6) && (dumcnt > 0)) { //done with this fifo
309  dumcnt = 0;
310  fif2cnt = 0;
311  fifcnt++;
312  }
313  if ((gapcnt > 0) && ((dumcnt + fif2cnt) > 5)) { //done with this fifo
314  gapcnt = 0;
315  fifcnt++;
316  fif2cnt = 0;
317  dumcnt = 0;
318  } else if ((gapcnt > 0) && ((dumcnt + fif2cnt) < 6)) {
319  gapcnt = 0;
320  }
321 
322  } //==End of fifo-3 word loop
323  //========== FPGAs Status ==================================================
324  status = 0;
325 
326  if (gap[0] > 0) {
327  totword = (gap[0] & 0xff);
328  status = 1;
329  } else if (gap[1] > 0) {
330  totword = (gap[1] & 0xff);
331  status = 1;
332  } else if (dum[0] > 0) {
333  totword = (dum[0] & 0xff);
334  status = 1;
335  } else if (dum[1] > 0) {
336  totword = (dum[1] & 0xff);
337  status = 1;
338  }
339 
340  if (gap[2] > 0) {
341  totword = totword | ((gap[2] & 0xff) << 8);
342  status = status | 0x2;
343  } else if (gap[3] > 0) {
344  totword = totword | ((gap[3] & 0xff) << 8);
345  status = status | 0x2;
346  } else if (dum[2] > 0) {
347  totword = totword | ((dum[2] & 0xff) << 8);
348  status = status | 0x2;
349  } else if (dum[3] > 0) {
350  totword = totword | ((dum[3] & 0xff) << 8);
351  status = status | 0x2;
352  }
353 
354  if (gap[4] > 0) {
355  totword = totword | ((gap[4] & 0xff) << 16);
356  status = status | 0x4;
357  } else if (gap[5] > 0) {
358  totword = totword | ((gap[5] & 0xff) << 16);
359  status = status | 0x4;
360  } else if (dum[4] > 0) {
361  totword = totword | ((dum[4] & 0xff) << 16);
362  status = status | 0x4;
363  } else if (dum[5] > 0) {
364  totword = totword | ((dum[5] & 0xff) << 16);
365  status = status | 0x4;
366  }
367 
368  if (gap[6] > 0) {
369  totword = totword | ((gap[6] & 0xff) << 24);
370  status = status | 0x8;
371  } else if (gap[7] > 0) {
372  totword = totword | ((gap[7] & 0xff) << 24);
373  status = status | 0x8;
374  } else if (dum[6] > 0) {
375  totword = totword | ((dum[6] & 0xff) << 24);
376  status = status | 0x8;
377  } else if (dum[7] > 0) {
378  totword = totword | ((dum[7] & 0xff) << 24);
379  status = status | 0x8;
380  }
381  vecSaveFillerWords.push_back(totword);
382  if ((EventNum % 10) == 0) {
384  }
385  edm::LogInfo("FedFillerWords") << "total word = 0x" << std::hex << totword << std::hex << " Status = 0x" << status
386  << std::dec << std::endl;
387  return (status);
388 }
389 
391  EventNum = iEvent.id().event();
393  iEvent.getByLabel(label, instance, buffers);
394  auto FillerWordEventNumbers1 = std::make_unique<std::vector<uint32_t>>();
395  auto FillerWordEventNumbers2 = std::make_unique<std::vector<uint32_t>>();
396  auto SaveFillerWords = std::make_unique<std::vector<uint32_t>>();
397  //===== Loop over all the FEDs ========================================================
398  std::pair<int, int> fedIds;
399  fedIds.first = 0;
400  fedIds.second = 39;
401 
402  for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
403  edm::LogInfo("FedFillerWords") << " examining FED: " << fedId << std::endl;
404  const FEDRawData& fedRawData = buffers->FEDData(fedId); //get event data for this fed
405  //======== Run the fill word finder...
406  if (fedRawData.size() != 0) {
407  uint32_t totword;
408  int value = PwordSlink64((uint64_t*)fedRawData.data(), (int)fedRawData.size(), totword);
409  if (value != 0) {
410  //====== Verify that the vector is not empty
411  if (!vecSaveFillerWords.empty()) {
414  SaveFillerWords->push_back(*vecSaveFillerWords_It);
415  }
416  } else {
417  edm::LogWarning("FedFillerWords") << "========= Filler Words Vector is empty! ==========" << std::endl;
418  }
419  }
420  edm::LogInfo("FedFillerWords") << "Found " << value << " filler words in FED " << fedId << std::endl;
424  FillerWordEventNumbers1->push_back(*vecFillerWordsEventNumber1_It);
425  }
429  FillerWordEventNumbers2->push_back(*vecFillerWordsEventNumber2_It);
430  }
431  }
432  }
433  iEvent.put(std::move(FillerWordEventNumbers1), "FillerWordEventNumber1");
434  iEvent.put(std::move(FillerWordEventNumbers2), "FillerWordEventNumber2");
435  //====== bool variable to be controled in the config file, allows the user to put or
436  // the filler words inside the output root file
437  if (SaveFillerWordsbool == true) {
438  iEvent.put(std::move(SaveFillerWords), "SaveFillerWord");
439  }
442 }
443 
444 // ------------ method called once each job just before starting event loop ------------
446 
447 // ------------ method called once each job just after ending the event loop ------------
449 //===== define this as a plug-in
SiPixelFedFillerWordEventNumber::CalibStatFillWord
unsigned int CalibStatFillWord(unsigned int, int)
Definition: SiPixelFedFillerWordEventNumber.cc:37
SiPixelFedFillerWordEventNumber::vecFillerWordsEventNumber2
std::vector< uint32_t > vecFillerWordsEventNumber2
Definition: SiPixelFedFillerWordEventNumber.h:46
SiPixelFedFillerWordEventNumber::SaveFillerWordsbool
bool SaveFillerWordsbool
Definition: SiPixelFedFillerWordEventNumber.h:28
mps_update.status
status
Definition: mps_update.py:69
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
SiPixelFedFillerWordEventNumber::endJob
void endJob() override
Definition: SiPixelFedFillerWordEventNumber.cc:448
SiPixelFedFillerWordEventNumber::~SiPixelFedFillerWordEventNumber
~SiPixelFedFillerWordEventNumber() override
Definition: SiPixelFedFillerWordEventNumber.cc:36
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
SiPixelFedFillerWordEventNumber::vecSaveFillerWords_It
std::vector< uint32_t >::iterator vecSaveFillerWords_It
Definition: SiPixelFedFillerWordEventNumber.h:43
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
FEDRawData
Definition: FEDRawData.h:19
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiPixelFedFillerWordEventNumber::instance
std::string instance
Definition: SiPixelFedFillerWordEventNumber.h:27
SiPixelFedFillerWordEventNumber.h
SiPixelFedFillerWordEventNumber::vecFillerWordsEventNumber2_It
std::vector< uint32_t >::iterator vecFillerWordsEventNumber2_It
Definition: SiPixelFedFillerWordEventNumber.h:47
SiPixelFedFillerWordEventNumber
Definition: SiPixelFedFillerWordEventNumber.h:22
GetRecoTauVFromDQM_MC_cff.kk
kk
Definition: GetRecoTauVFromDQM_MC_cff.py:84
SiPixelFedFillerWordEventNumber::CalibStatFill
unsigned int CalibStatFill
Definition: SiPixelFedFillerWordEventNumber.h:41
SiPixelFedFillerWordEventNumber::vecFillerWordsEventNumber1
std::vector< uint32_t > vecFillerWordsEventNumber1
Definition: SiPixelFedFillerWordEventNumber.h:44
HLT_FULL_cff.gap
gap
Definition: HLT_FULL_cff.py:8498
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
SiPixelFedFillerWordEventNumber::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: SiPixelFedFillerWordEventNumber.cc:390
SiPixelFedFillerWordEventNumber::beginJob
void beginJob() override
Definition: SiPixelFedFillerWordEventNumber.cc:445
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
value
Definition: value.py:1
SiPixelFedFillerWordEventNumber::label
std::string label
Definition: SiPixelFedFillerWordEventNumber.h:26
edm::EventSetup
Definition: EventSetup.h:57
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:88
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
SiPixelFedFillerWordEventNumber::EventNum
unsigned int EventNum
Definition: SiPixelFedFillerWordEventNumber.h:36
eostools.move
def move(src, dest)
Definition: eostools.py:511
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
SiPixelFedFillerWordEventNumber::vecSaveFillerWords
std::vector< uint32_t > vecSaveFillerWords
Definition: SiPixelFedFillerWordEventNumber.h:42
PixelMapPlotter.roc
roc
Definition: PixelMapPlotter.py:498
L1TStage2BMTF_cff.fedIds
fedIds
Definition: L1TStage2BMTF_cff.py:10
SiPixelFedFillerWordEventNumber::SiPixelFedFillerWordEventNumber
SiPixelFedFillerWordEventNumber(const edm::ParameterSet &)
Definition: SiPixelFedFillerWordEventNumber.cc:24
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
SiPixelFedFillerWordEventNumber::vecFillerWordsEventNumber1_It
std::vector< uint32_t >::iterator vecFillerWordsEventNumber1_It
Definition: SiPixelFedFillerWordEventNumber.h:45
SiPixelFedFillerWordEventNumber::PwordSlink64
int PwordSlink64(uint64_t *, const int, uint32_t &)
Definition: SiPixelFedFillerWordEventNumber.cc:153
edm::Event
Definition: Event.h:73
SiPixelFedFillerWordEventNumber::status
int status
Definition: SiPixelFedFillerWordEventNumber.h:35
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143