test
CMS 3D CMS Logo

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