CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTBDaqFormatter.cc
Go to the documentation of this file.
1 /*
2  *
3  * $Date: 2010/08/06 20:24:29 $
4  * $Revision: 1.75 $
5  * \author N. Marinelli IASA
6  * \author G. Della Ricca
7  * \author G. Franzoni
8  * \author A. Ghezzi
9  *
10  */
11 
12 #include "EcalTBDaqFormatter.h"
18 
22 
23 #include "DCCDataParser.h"
24 #include "DCCEventBlock.h"
25 #include "DCCTowerBlock.h"
26 #include "DCCTCCBlock.h"
27 #include "DCCXtalBlock.h"
28 #include "DCCDataMapper.h"
29 
30 
31 #include <iostream>
32 
34 
35  LogDebug("EcalTBRawToDigi") << "@SUB=EcalTBDaqFormatter";
36  std::vector<uint32_t> parameters;
37  parameters.push_back(10); // parameters[0] is the xtal samples
38  parameters.push_back(1); // parameters[1] is the number of trigger time samples for TPG's
39  parameters.push_back(68); // parameters[2] is the number of TT
40  parameters.push_back(68); // parameters[3] is the number of SR Flags
41  parameters.push_back(1); // parameters[4] is the dcc id
42  parameters.push_back(1); // parameters[5] is the sr id
43  parameters.push_back(1); // parameters[6] is the tcc1 id
44  parameters.push_back(2); // parameters[7] is the tcc2 id
45  parameters.push_back(3); // parameters[8] is the tcc3 id
46  parameters.push_back(4); // parameters[9] is the tcc4 id
47 
48  theParser_ = new DCCTBDataParser(parameters);
49 
50 }
51 
53  EBDigiCollection& digicollection, EcalPnDiodeDigiCollection & pndigicollection ,
54  EcalRawDataCollection& DCCheaderCollection,
55  EBDetIdCollection & dccsizecollection,
56  EcalElectronicsIdCollection & ttidcollection , EcalElectronicsIdCollection & blocksizecollection,
57  EBDetIdCollection & chidcollection , EBDetIdCollection & gaincollection,
58  EBDetIdCollection & gainswitchcollection,
59  EcalElectronicsIdCollection & memttidcollection, EcalElectronicsIdCollection & memblocksizecollection,
60  EcalElectronicsIdCollection & memgaincollection, EcalElectronicsIdCollection & memchidcollection,
61  EcalTrigPrimDigiCollection &tpcollection)
62 {
63 
64 
65  const unsigned char * pData = fedData.data();
66  int length = fedData.size();
67  bool shit=true;
68  unsigned int tower=0;
69  int ch=0;
70  int strip=0;
71 
72  LogDebug("EcalTBRawToDigi") << "@SUB=EcalTBDaqFormatter::interpretRawData"
73  << "size " << length;
74 
75 
76  // mean + 3sigma estimation needed when switching to 0suppressed data
77  digicollection.reserve(kCrystals);
78  pnAllocated = false;
79 
80 
81  theParser_->parseBuffer( reinterpret_cast<uint32_t*>(const_cast<unsigned char*>(pData)), static_cast<uint32_t>(length), shit );
82 
83  std::vector< DCCTBEventBlock * > & dccEventBlocks = theParser_->dccEvents();
84 
85  // Access each DCCTB block
86  for( std::vector< DCCTBEventBlock * >::iterator itEventBlock = dccEventBlocks.begin();
87  itEventBlock != dccEventBlocks.end();
88  itEventBlock++){
89 
90  bool _displayParserMessages = false;
91  if( (*itEventBlock)->eventHasErrors() && _displayParserMessages)
92  {
93  edm::LogWarning("EcalTBRawToDigi") << "@SUB=EcalTBDaqFormatter::interpretRawData"
94  << "errors found from parser... ";
95  edm::LogWarning("EcalTBRawToDigi") << (*itEventBlock)->eventErrorString();
96  edm::LogWarning("EcalTBRawToDigi") << "@SUB=EcalTBDaqFormatter::interpretRawData"
97  << "... errors from parser notified";
98  }
99 
100  // getting the fields of the DCC header
101  EcalDCCHeaderBlock theDCCheader;
102 
103  theDCCheader.setId(28); // tb unpacker: forced to 28 to get first geom slot in EB
104  int fedId = (*itEventBlock)->getDataField("FED/DCC ID");
105  theDCCheader.setFedId( fedId ); // fed id as found in raw data (0... 35 at tb )
106 
107  theDCCheader.setRunNumber((*itEventBlock)->getDataField("RUN NUMBER"));
108  short trigger_type = (*itEventBlock)->getDataField("TRIGGER TYPE");
109  short zs = (*itEventBlock)->getDataField("ZS");
110  short tzs = (*itEventBlock)->getDataField("TZS");
111  short sr = (*itEventBlock)->getDataField("SR");
112  bool dataIsSuppressed;
113 
114  // if zs&&tzs the suppression algo is used in DCC, the data are not suppressed and zs-bits are set
115  if ( zs && !(tzs) ) dataIsSuppressed = true;
116  else dataIsSuppressed = false;
117 
118  if(trigger_type >0 && trigger_type <5){theDCCheader.setBasicTriggerType(trigger_type);}
119  else{ edm::LogWarning("EcalTBRawToDigiTriggerType") << "@SUB=EcalTBDaqFormatter::interpretRawData"
120  << "unrecognized TRIGGER TYPE: "<<trigger_type;}
121  theDCCheader.setLV1((*itEventBlock)->getDataField("LV1"));
122  theDCCheader.setOrbit((*itEventBlock)->getDataField("ORBIT COUNTER"));
123  theDCCheader.setBX((*itEventBlock)->getDataField("BX"));
124  theDCCheader.setErrors((*itEventBlock)->getDataField("DCC ERRORS"));
125  theDCCheader.setSelectiveReadout( sr );
126  theDCCheader.setZeroSuppression( zs );
127  theDCCheader.setTestZeroSuppression( tzs );
128  theDCCheader.setSrpStatus((*itEventBlock)->getDataField("SR_CHSTATUS"));
129 
130 
131 
132 
133  std::vector<short> theTCCs;
134  for(int i=0; i<MAX_TCC_SIZE; i++){
135 
136  char TCCnum[20]; sprintf(TCCnum,"TCC_CHSTATUS#%d",i+1); std::string TCCnumS(TCCnum);
137  theTCCs.push_back ((*itEventBlock)->getDataField(TCCnumS) );
138  }
139  theDCCheader.setTccStatus(theTCCs);
140 
141 
142  std::vector< DCCTBTCCBlock * > tccBlocks = (*itEventBlock)->tccBlocks();
143 
144  for( std::vector< DCCTBTCCBlock * >::iterator itTCCBlock = tccBlocks.begin();
145  itTCCBlock != tccBlocks.end();
146  itTCCBlock ++)
147  {
148 
149  std::vector< std::pair<int,bool> > TpSamples = (* itTCCBlock) -> triggerSamples() ;
150  // std::vector of 3 bits
151  std::vector<int> TpFlags = (* itTCCBlock) -> triggerFlags() ;
152 
153  // there have always to be 68 primitives and flags, per FED
154  if (TpSamples.size()==68 && TpFlags.size()==68)
155  {
156  for(int i=0; i<((int)TpSamples.size()); i++)
157  {
158 
159  int etaTT = (i) / kTowersInPhi +1;
160  int phiTT = (i) % kTowersInPhi +1;
161 
162  // follow HB convention in iphi
163  phiTT=3-phiTT;
164  if(phiTT<=0)phiTT=phiTT+72;
165 
166  EcalTriggerPrimitiveSample theSample(TpSamples[i].first, TpSamples[i].second, TpFlags[i]);
167 
168  EcalTrigTowerDetId idtt(1, EcalBarrel, etaTT, phiTT, 0);
169 
170  EcalTriggerPrimitiveDigi thePrimitive(idtt);
171  thePrimitive.setSize(1); // hard coded
172  thePrimitive.setSample(0, theSample);
173 
174  tpcollection.push_back(thePrimitive);
175 
176  LogDebug("EcalTBRawToDigiTpg") << "@SUBS=EcalTBDaqFormatter::interpretRawData"
177  << "tower: " << (i+1)
178  << " primitive: " << TpSamples[i].first
179  << " flag: " << TpSamples[i].second;
180 
181  LogDebug("EcalTBRawToDigiTpg") << "@SUBS=EcalTBDaqFormatter::interpretRawData"<<
182  "tower: " << (i+1) << " flag: " << TpFlags[i];
183  }// end loop on tower primitives
184 
185  }// end if
186  else
187  {
188  edm::LogWarning("EcalTBRawToDigiTpg") << "68 elements not found for TpFlags or TpSamples, collection will be empty";
189  }
190  }
191 
192 
193 
194 
195  short TowerStatus[MAX_TT_SIZE+1];
196  char buffer[20];
197  std::vector<short> theTTstatus;
198  for(int i=1;i<MAX_TT_SIZE+1;i++)
199  {
200  sprintf(buffer, "FE_CHSTATUS#%d", i);
201  std::string Tower(buffer);
202  TowerStatus[i]= (*itEventBlock)->getDataField(Tower);
203  theTTstatus.push_back(TowerStatus[i]);
204  //std::cout << "tower " << i << " has status " << TowerStatus[i] << std::endl;
205  }
206 
207  theDCCheader.setFEStatus(theTTstatus);
208 
209  EcalDCCTBHeaderRuntypeDecoder theRuntypeDecoder;
210  uint32_t DCCruntype = (*itEventBlock)->getDataField("RUN TYPE");
211  theRuntypeDecoder.Decode(DCCruntype, &theDCCheader);
212  //DCCHeader filled!
213  DCCheaderCollection.push_back(theDCCheader);
214 
215  std::vector< DCCTBTowerBlock * > dccTowerBlocks = (*itEventBlock)->towerBlocks();
216  LogDebug("EcalTBRawToDigi") << "@SUBS=EcalTBDaqFormatter::interpretRawData"
217  << "dccTowerBlocks size " << dccTowerBlocks.size();
218 
219 
220 
222  for (int v=0; v<71; v++){
223  _ExpectedTowers[v]=99999;
224  }
225 
226  // note: these are the tower statuses handled at the moment - to be completed
227  // staus==0: tower expected;
228  // staus==9: Synk error LV1, tower expected;
229  // staus==10: Synk error BX, tower expected;
230  // status==1, 2, 3, 4, 5: tower not expected
231  for (int u=1; u< (kTriggerTowersAndMem+1); u++)
232  {
233  if( TowerStatus[u] ==0 || TowerStatus[u] ==9 || TowerStatus[u] ==10 )
235  _expTowersIndex++;
237  }
238  }
239  // resetting counter of expected towers
240  _expTowersIndex=0;
241 
242 
243  // if number of dccEventBlocks NOT same as expected stop
244  if (! (dccTowerBlocks.size() == _numExpectedTowers) )
245  {
246  // we probably always want to know if this happens
247  edm::LogWarning("EcalTBRawToDigiNumTowerBlocks") << "@SUB=EcalTBDaqFormatter::interpretRawData"
248  << "number of TowerBlocks found (" << dccTowerBlocks.size()
249  << ") differs from expected (" << _numExpectedTowers
250  << ") skipping event";
251 
252  EBDetId idsm(1, 1);
253  dccsizecollection.push_back(idsm);
254 
255  return;
256 
257  }
258 
259 
260 
261 
262 
263  // Access the Tower block
264  for( std::vector< DCCTBTowerBlock * >::iterator itTowerBlock = dccTowerBlocks.begin();
265  itTowerBlock!= dccTowerBlocks.end();
266  itTowerBlock++){
267 
268  tower=(*itTowerBlock)->towerID();
269 
270  // checking if tt in data is the same as tt expected
271  // else skip tower and increment problem counter
272 
273  // compute eta/phi in order to have iTT = _ExpectedTowers[_expTowersIndex]
274  // for the time being consider only zside>0
275 
277 
278  if ( !(tower == _ExpectedTowers[_expTowersIndex]) )
279  {
280 
281  if (_ExpectedTowers[_expTowersIndex] <= 68){
282  edm::LogWarning("EcalTBRawToDigiTowerId") << "@SUBS=EcalTBDaqFormatter::interpretRawData"
283  << "TTower id found (=" << tower
284  << ") different from expected (=" << _ExpectedTowers[_expTowersIndex]
285  << ") " << (_expTowersIndex+1) << "-th tower checked";
286 
287  // report on failed tt_id for regular tower block
288  ttidcollection.push_back(idtt);
289  }
290  else
291  {
292  edm::LogWarning("EcalTBRawToDigiTowerId") << "@SUB=EcalTBDaqFormatter:interpretRawData"
293  << "DecodeMEM: tower " << tower
294  << " is not the same as expected " << ((int)_ExpectedTowers[_expTowersIndex])
295  << " (according to DCC header channel status)";
296 
297  // report on failed tt_id for mem tower block
298  // chosing channel 1 as representative
299  EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], 1, 1);
300  memttidcollection.push_back(id);
301  }
302 
303  ++ _expTowersIndex;
304  continue;
305  }// if TT id found different than expected
306 
307 
308 
309 
310  /*********************************
311  // tt: 1 ... 68: crystal data
312  *********************************/
313  if ( 0< (*itTowerBlock)->towerID() &&
314  (*itTowerBlock)->towerID() < (kTriggerTowers+1) )
315  {
316 
317  std::vector<DCCTBXtalBlock * > & xtalDataBlocks = (*itTowerBlock)->xtalBlocks();
318 
319  // if there is no zero suppression, tower block must have have 25 channels in it
320  if ( (!dataIsSuppressed) && (xtalDataBlocks.size() != kChannelsPerTower) )
321  {
322  edm::LogWarning("EcalTBRawToDigiTowerSize") << "EcalTBDaqFormatter::interpretRawData, no zero suppression "
323  << "wrong tower block size is: " << xtalDataBlocks.size()
324  << " at LV1 " << (*itEventBlock)->getDataField("LV1")
325  << " for TT " << _ExpectedTowers[_expTowersIndex];
326  // report on wrong tt block size
327  blocksizecollection.push_back(idtt);
328 
329  ++ _expTowersIndex; continue;
330 
331  }
332 
333 
334  short cryInTower =0;
335 
336  short expStripInTower;
337  short expCryInStrip;
338  short expCryInTower =0;
339 
340  // Access the Xstal data
341  for( std::vector< DCCTBXtalBlock * >::iterator itXtalBlock = xtalDataBlocks.begin();
342  itXtalBlock!= xtalDataBlocks.end();
343  itXtalBlock++){ //loop on crys of a tower
344 
345  strip =(*itXtalBlock)->stripID();
346  ch =(*itXtalBlock)->xtalID();
347  cryInTower =(strip-1)* kChannelsPerCard + (ch -1);
348 
349  expStripInTower = expCryInTower/5 +1;
350  expCryInStrip = expCryInTower%5 +1;
351 
352 
353  // FIXME: waiting for geometry to do (TT, strip,chNum) <--> (SMChId)
354  // short abscissa = (_ExpectedTowers[_expTowersIndex]-1) /4;
355  // short ordinate = (_ExpectedTowers[_expTowersIndex]-1) %4;
356  // temporarily choosing central crystal in trigger tower
357  // int cryIdInSM = 45 + ordinate*5 + abscissa * 100;
358 
359 
360  // in case of 0 zuppressed data, check that cryInTower constantly grows
361  if (dataIsSuppressed)
362  {
363 
364  if ( strip < 1 || 5<strip || ch <1 || 5 < ch)
365  {
366  int sm = 1; // hardcoded because of test beam
367  for (int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
368  for (int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
369  int ic = cryIc(tower, StripInTower_, CryInStrip_) ;
370  EBDetId idExp(sm, ic,1);
371  chidcollection.push_back(idExp);
372  }
373  }
374 
375  edm::LogWarning("EcalTBRawToDigiChId") << "EcalTBDaqFormatter::interpretRawData with zero suppression, "
376  << " wrong channel id, since out of range: "
377  << "\t strip: " << strip << "\t channel: " << ch
378  << "\t in TT: " << _ExpectedTowers[_expTowersIndex]
379  << "\t at LV1 : " << (*itEventBlock)->getDataField("LV1");
380 
381  expCryInTower++;
382  continue;
383  }
384 
385 
386  // correct ordering
387  if( cryInTower >= expCryInTower ){
388  expCryInTower = cryInTower +1;
389  }
390 
391 
392  // cry_id wrong because of incorrect ordering within trigger tower
393  else
394  {
395  edm::LogWarning("EcalTBRawToDigiChId") << "EcalTBDaqFormatter::interpretRawData with zero suppression, "
396  << " based on ch ordering within tt, wrong channel id: "
397  << "\t strip: " << strip << "\t channel: " << ch
398  << "\t cryInTower " << cryInTower
399  << "\t expCryInTower: " << expCryInTower
400  << "\t in TT: " << _ExpectedTowers[_expTowersIndex]
401  << "\t at LV1: " << (*itEventBlock)->getDataField("LV1");
402 
403  int sm = 1; // hardcoded because of test beam
404  for (int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
405  for (int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
406  int ic = cryIc(tower, StripInTower_, CryInStrip_) ;
407  EBDetId idExp(sm, ic,1);
408  chidcollection.push_back(idExp);
409  }
410  }
411 
412  // chennel with id which does not follow correct odering
413  expCryInTower++; continue;
414 
415  }// end 'ch_id does not respect growing order'
416 
417  }// end if zero supression
418 
419 
420 
421  else {
422 
423  // checking that ch and strip are within range and cryInTower is as expected
424  if( cryInTower != expCryInTower ||
425  strip < 1 || kStripsPerTower <strip ||
426  ch <1 || kChannelsPerStrip < ch )
427  {
428 
429  int ic = cryIc(tower, expStripInTower, expCryInStrip) ;
430  int sm = 1; // hardcoded because of test beam
431  EBDetId idExp(sm, ic,1);
432 
433  edm::LogWarning("EcalTBRawToDigiChId") << "EcalTBDaqFormatter::interpretRawData no zero suppression "
434  << " wrong channel id for channel: " << expCryInStrip
435  << "\t strip: " << expStripInTower
436  << "\t in TT: " << _ExpectedTowers[_expTowersIndex]
437  << "\t at LV1: " << (*itEventBlock)->getDataField("LV1")
438  << "\t (in the data, found channel: " << ch
439  << "\t strip: " << strip << " ).";
440 
441 
442  // report on wrong channel id
443  chidcollection.push_back(idExp);
444 
445  // there has been unexpected crystal id, dataframe not to go to the Event
446  expCryInTower++; continue;
447 
448  } // if channel in data does not equal expected channel
449 
450  expCryInTower++;
451 
452  } // end 'not zero suppression'
453 
454 
455 
456  // data to be stored in EBDataFrame, identified by EBDetId
457  int ic = cryIc(tower, strip, ch) ;
458  int sm = 1;
459  EBDetId id(sm, ic,1);
460 
461  // here data frame go into the Event
462  // removed later on (with a pop_back()) if gain==0 or if forbidden-gain-switch
463  digicollection.push_back( id );
464  EBDataFrame theFrame ( digicollection.back() );
465  std::vector<int> xtalDataSamples = (*itXtalBlock)->xtalDataSamples();
466  //theFrame.setSize(xtalDataSamples.size()); // if needed, to be changed when constructing digicollection
467 
468 
469 
470  // gain cannot be 0, checking for that
471  bool gainIsOk =true;
472  unsigned gain_mask = 12288; //12th and 13th bit
473  std::vector <int> xtalGain;
474 
475  for (unsigned short i=0; i<xtalDataSamples.size(); ++i ) {
476 
477  theFrame.setSample (i, xtalDataSamples[i] );
478 
479  if((xtalDataSamples[i] & gain_mask) == 0){gainIsOk =false;}
480 
481  xtalGain.push_back(0);
482  xtalGain[i] |= (xtalDataSamples[i] >> 12);
483  }
484 
485  if (! gainIsOk) {
486 
487  edm::LogWarning("EcalTBRawToDigiGainZero") << "@SUB=EcalTBDaqFormatter::interpretRawData"
488  << " gain==0 for strip: " << expStripInTower
489  << "\t channel: " << expCryInStrip
490  << "\t in TT: " << _ExpectedTowers[_expTowersIndex]
491  << "\t ic: " << ic
492  << "\t at LV1: " << (*itEventBlock)->getDataField("LV1");
493  // report on gain==0
494  gaincollection.push_back(id);
495 
496  // there has been a gain==0, dataframe not to go to the Event
497  digicollection.pop_back();
498  continue; // expCryInTower already incremented
499  }
500 
501 
502 
503 
504  // looking for forbidden gain transitions
505 
506  short firstGainWrong=-1;
507  short numGainWrong=0;
508 
509  for (unsigned short i=0; i<xtalGain.size(); i++ ) {
510 
511  if (i>0 && xtalGain[i-1]>xtalGain[i]) {
512 
513  numGainWrong++;// counting forbidden gain transitions
514 
515  if (firstGainWrong == -1) {
516  firstGainWrong=i;
517  edm::LogWarning("EcalTBRawToDigiGainSwitch") << "@SUB=EcalTBDaqFormatter::interpretRawData"
518  << "channelHasGainSwitchProblem: crystal eta = "
519  << id.ieta() << " phi = " << id.iphi();
520  }
521  edm::LogWarning("EcalTBRawToDigiGainSwitch") << "@SUB=EcalTBDaqFormatter::interpretRawData"
522  << "channelHasGainSwitchProblem: sample = " << (i-1)
523  << " gain: " << xtalGain[i-1] << " sample: "
524  << i << " gain: " << xtalGain[i];
525  }
526  }
527 
528  if (numGainWrong>0) {
529  gainswitchcollection.push_back(id);
530 
531  edm::LogWarning("EcalTBRawToDigiGainSwitch") << "@SUB=EcalTBDaqFormatter:interpretRawData"
532  << "channelHasGainSwitchProblem: more than 1 wrong transition";
533 
534  for (unsigned short i1=0; i1<xtalDataSamples.size(); ++i1 ) {
535  int countADC = 0x00000FFF;
536  countADC &= xtalDataSamples[i1];
537  LogDebug("EcalTBRawToDigi") << "Sample " << i1 << " ADC " << countADC << " Gain " << xtalGain[i1];
538 
539  }
540 
541  // there has been a forbidden gain transition, dataframe not to go to the Event
542  digicollection.pop_back();
543  continue; // expCryInTower already incremented
544 
545  }// END of: 'if there is a forbidden gain transition'
546 
547  }// end loop on crystals within a tower block
548 
549  _expTowersIndex++;
550  }// end: tt1 ... tt68, crystal data
551 
552 
553 
554 
555 
556  /******************************************************************
557  // tt 69 and 70: two mem boxes, holding PN0 ... PN9
558  ******************************************************************/
559  else if ( (*itTowerBlock)->towerID() == 69
560  || (*itTowerBlock)->towerID() == 70 )
561  {
562 
563  LogDebug("EcalTBRawToDigi") << "@SUB=EcalTBDaqFormatter::interpretRawData"
564  << "processing mem box num: " << (*itTowerBlock)->towerID();
565 
566  // if tt 69 or 70 found, allocate Pn digi collection
567  if(! pnAllocated)
568  {
569  pndigicollection.reserve(kPns);
570  pnAllocated = true;
571  }
572 
573  DecodeMEM( (*itTowerBlock), pndigicollection ,
574  memttidcollection, memblocksizecollection,
575  memgaincollection, memchidcollection);
576 
577  }// end of < if it is a mem box>
578 
579 
580 
581 
582 
583  // wrong tt id
584  else {
585  edm::LogWarning("EcalTBRawToDigiTowerId") <<"@SUB=EcalTBDaqFormatter::interpretRawData"
586  << " processing tt with ID not existing ( "
587  << (*itTowerBlock)->towerID() << ")";
588  ++ _expTowersIndex;continue;
589  }// end: tt id error
590 
591  }// end loop on trigger towers
592 
593  }// end loop on events
594 }
595 
596 
597 
598 
599 
600 
601 
602 
604  EcalElectronicsIdCollection & memttidcollection, EcalElectronicsIdCollection & memblocksizecollection,
605  EcalElectronicsIdCollection & memgaincollection, EcalElectronicsIdCollection & memchidcollection)
606 {
607 
608  LogDebug("EcalTBRawToDigi") << "@SUB=EcalTBDaqFormatter::DecodeMEM"
609  << "in mem " << towerblock->towerID();
610 
611  int tower_id = towerblock ->towerID() ;
612  int mem_id = tower_id-69;
613 
614  // initializing container
615  for (int st_id=0; st_id< kStripsPerTower; st_id++){
616  for (int ch_id=0; ch_id<kChannelsPerStrip; ch_id++){
617  for (int sa=0; sa<11; sa++){
618  memRawSample_[st_id][ch_id][sa] = -1;} } }
619 
620 
621  // check that tower block id corresponds to mem boxes
622  if(tower_id != 69 && tower_id != 70)
623  {
624  edm::LogWarning("EcalTBRawToDigiTowerId") << "@SUB=EcalTBDaqFormatter:decodeMem"
625  << "DecodeMEM: this is not a mem box tower (" << tower_id << ")";
626  ++ _expTowersIndex;
627  return;
628  }
629 
630 
631  /******************************************************************************
632  // getting the raw hits from towerBlock while checking tt and ch data structure
633  ******************************************************************************/
634  std::vector<DCCTBXtalBlock *> & dccXtalBlocks = towerblock->xtalBlocks();
635  std::vector<DCCTBXtalBlock*>::iterator itXtal;
636 
637  // checking mem tower block fo size
638  if (dccXtalBlocks.size() != kChannelsPerTower)
639  {
640  LogDebug("EcalTBRawToDigiDccBlockSize") << "@SUB=EcalTBDaqFormatter:decodeMem"
641  << " wrong dccBlock size, namely: " << dccXtalBlocks.size()
642  << ", for mem " << _ExpectedTowers[_expTowersIndex];
643 
644  // reporting mem-tt block size problem
645  // chosing channel 1 as representative as a dummy...
647  memblocksizecollection.push_back(id);
648 
649  ++ _expTowersIndex;
650  return; // if mem tt block size not ok - do not build any Pn digis
651  }
652 
653 
654  // loop on channels of the mem block
655  int cryCounter = 0; int strip_id = 0; int xtal_id = 0;
656 
657  for ( itXtal = dccXtalBlocks.begin(); itXtal < dccXtalBlocks.end(); itXtal++ ) {
658  strip_id = (*itXtal) ->getDataField("STRIP ID");
659  xtal_id = (*itXtal) ->getDataField("XTAL ID");
660  int wished_strip_id = cryCounter/ kStripsPerTower;
661  int wished_ch_id = cryCounter% kStripsPerTower;
662 
663  if( (wished_strip_id+1) != ((int)strip_id) ||
664  (wished_ch_id+1) != ((int)xtal_id) )
665  {
666 
667  LogDebug("EcalTBRawToDigiChId") << "@SUB=EcalTBDaqFormatter:decodeMem"
668  << " in mem " << towerblock->towerID()
669  << ", expected:\t strip"
670  << (wished_strip_id+1) << " cry " << (wished_ch_id+1) << "\tfound: "
671  << " strip " << strip_id << " cry " << xtal_id;
672 
673  // report on crystal with unexpected indices
674  EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], wished_strip_id, wished_ch_id);
675  memchidcollection.push_back(id);
676  }
677 
678 
679  // Accessing the 10 time samples per Xtal:
680  memRawSample_[wished_strip_id][wished_ch_id][1] = (*itXtal)->getDataField("ADC#1");
681  memRawSample_[wished_strip_id][wished_ch_id][2] = (*itXtal)->getDataField("ADC#2");
682  memRawSample_[wished_strip_id][wished_ch_id][3] = (*itXtal)->getDataField("ADC#3");
683  memRawSample_[wished_strip_id][wished_ch_id][4] = (*itXtal)->getDataField("ADC#4");
684  memRawSample_[wished_strip_id][wished_ch_id][5] = (*itXtal)->getDataField("ADC#5");
685  memRawSample_[wished_strip_id][wished_ch_id][6] = (*itXtal)->getDataField("ADC#6");
686  memRawSample_[wished_strip_id][wished_ch_id][7] = (*itXtal)->getDataField("ADC#7");
687  memRawSample_[wished_strip_id][wished_ch_id][8] = (*itXtal)->getDataField("ADC#8");
688  memRawSample_[wished_strip_id][wished_ch_id][9] = (*itXtal)->getDataField("ADC#9");
689  memRawSample_[wished_strip_id][wished_ch_id][10] = (*itXtal)->getDataField("ADC#10");
690 
691  cryCounter++;
692  }// end loop on crystals of mem dccXtalBlock
693 
694  // tower accepted and digi read from all 25 channels.
695  // Increase counter of expected towers before unpacking in the 5 PNs
696  ++ _expTowersIndex;
697 
698 
699 
700  /************************************************************
701  // unpacking and 'cooking' the raw numbers to get PN sample
702  ************************************************************/
703  int tempSample=0;
704  int memStoreIndex=0;
705  int ipn=0;
706  for (memStoreIndex=0; memStoreIndex<500; memStoreIndex++) {
707  data_MEM[memStoreIndex]= -1; }
708 
709 
710  for(int strip=0; strip<kStripsPerTower; strip++) {// loop on strips
711  for(int channel=0; channel<kChannelsPerStrip; channel++) {// loop on channels
712 
713  if(strip%2 == 0)
714  {ipn= mem_id*5+channel;}
715  else
716  {ipn=mem_id*5+4-channel;}
717 
718  for(int sample=0;sample< kSamplesPerChannel ;sample++) {
719  tempSample= memRawSample_[strip][channel][sample+1];
720 
721  int new_data=0;
722  if(strip%2 == 1) {
723  // 1) if strip number is even, 14 bits are reversed in order
724  for(int ib=0;ib<14;ib++)
725  {
726  new_data <<= 1;
727  new_data=new_data | (tempSample&1);
728  tempSample >>= 1;
729  }
730  } else {
731  new_data=tempSample;
732  }
733 
734  // 2) flip 11th bit for AD9052 still there on MEM !
735  // 3) mask with 1 1111 1111 1111
736  new_data = (new_data ^ 0x800) & 0x3fff; // (new_data XOR 1000 0000 0000) & 11 1111 1111 1111
737  // new_data = (new_data ^ 0x800) & 0x1fff; // (new_data XOR 1000 0000 0000) & 1 1111 1111 1111
738 
739  //(Bit 12) == 1 -> Gain 16; (Bit 12) == 0 -> Gain 1
740  // gain in mem can be 1 or 16 encoded resp. with 0 ir 1 in the 13th bit.
741  // checking and reporting if there is any sample with gain==2,3
742  short sampleGain = (new_data &0x3000)/4096;
743  if ( sampleGain==2 || sampleGain==3)
744  {
745  EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], strip, channel);
746  memgaincollection.push_back(id);
747 
748  edm::LogWarning("EcalTBRawToDigiGainZero") << "@SUB=EcalTBDaqFormatter:decodeMem"
749  << "in mem " << towerblock->towerID()
750  << " :\t strip: "
751  << (strip +1) << " cry: " << (channel+1)
752  << " has 14th bit non zero! Gain results: "
753  << sampleGain << ".";
754 
755  continue;
756  }// end 'if gain is zero'
757 
758  memStoreIndex= ipn*50+strip*kSamplesPerChannel+sample;
759  // storing in data_MEM also the gain bits
760  data_MEM[memStoreIndex]= new_data & 0x3fff;
761 
762  }// loop on samples
763  }// loop on strips
764  }// loop on channels
765 
766 
767 
768 
769  for (int pnId=0; pnId<kPnPerTowerBlock; pnId++) pnIsOkInBlock[pnId]=true;
770  // if anything was wrong with mem_tt_id or mem_tt_size: you would have already exited
771  // otherwise, if any problem with ch_gain or ch_id: must not produce digis for the pertaining Pn
772 
773  if (! (memgaincollection.size()==0 && memchidcollection.size()==0) )
774  {
775  for ( EcalElectronicsIdCollection::const_iterator idItr = memgaincollection.begin();
776  idItr != memgaincollection.end();
777  ++ idItr ) {
778  int ch = (*idItr).channelId();
779  ch = (ch-1)/5;
780  pnIsOkInBlock [ch] = false;
781  }
782 
783  for ( EcalElectronicsIdCollection::const_iterator idItr = memchidcollection.begin();
784  idItr != memchidcollection.end();
785  ++ idItr ) {
786  int ch = (*idItr).channelId();
787  ch = (ch-1)/5;
788  pnIsOkInBlock [ch] = false;
789  }
790 
791  }// end: if any ch_gain or ch_id problems exclude the Pn's from digi production
792 
793 
794 
795 
796  // looping on PN's of current mem box
797  for (int pnId = 1; pnId < (kPnPerTowerBlock+1); pnId++){
798 
799  // if present Pn has any of its 5 channels with problems, do not produce digi for it
800  if (! pnIsOkInBlock [pnId-1] ) continue;
801 
802  // DccId set to 28 to be consistent with ism==1
803  EcalPnDiodeDetId PnId(1, 28, pnId + kPnPerTowerBlock*mem_id);
804  EcalPnDiodeDigi thePnDigi(PnId );
805 
806  thePnDigi.setSize(kSamplesPerPn);
807 
808  for (int sample =0; sample<kSamplesPerPn; sample++)
809  {
810  EcalFEMSample thePnSample( data_MEM[(mem_id)*250 + (pnId-1)*kSamplesPerPn + sample ] );
811  thePnDigi.setSample(sample, thePnSample );
812  }
813  pndigicollection.push_back(thePnDigi);
814  }
815 
816 
817 }
818 
819 
820 
821 
822 
823 
824 
825 
826 
827 
828 
829 
830 
831 
832 std::pair<int,int> EcalTBDaqFormatter::cellIndex(int tower_id, int strip, int ch) {
833 
834  int xtal= (strip-1)*5+ch-1;
835  // std::cout << " cellIndex input xtal " << xtal << std::endl;
836  std::pair<int,int> ind;
837 
838  int eta = (tower_id - 1)/kTowersInPhi*kCardsPerTower;
839  int phi = (tower_id - 1)%kTowersInPhi*kChannelsPerCard;
840 
841  if (rightTower(tower_id))
842  eta += xtal/kCardsPerTower;
843  else
844  eta += (kCrystalsPerTower - 1 - xtal)/kCardsPerTower;
845 
846  if ((rightTower(tower_id) && (xtal/kCardsPerTower)%2 == 1) ||
847  (!rightTower(tower_id) && (xtal/kCardsPerTower)%2 == 0))
848 
849  phi += (kChannelsPerCard - 1 - xtal%kChannelsPerCard);
850  else
851  phi += xtal%kChannelsPerCard;
852 
853 
854  ind.first =eta+1;
855  ind.second=phi+1;
856 
857  // std::cout << " EcalTBDaqFormatter::cell_index eta " << ind.first << " phi " << ind.second << " " << std::endl;
858 
859  return ind;
860 
861 }
862 
863 
864 
865 int EcalTBDaqFormatter::cryIc(int tower, int strip, int ch) {
866 
867  if ( strip < 1 || 5<strip || ch <1 || 5 < ch || 68<tower)
868  {
869  edm::LogWarning("EcalTBRawToDigiChId") << "EcalTBDaqFormatter::interpretRawData (cryIc) "
870  << " wrong channel id, since out of range: "
871  << "\t strip: " << strip << "\t channel: " << ch
872  << "\t in TT: " << tower;
873  return -1;
874  }
875 
876  std::pair<int,int> cellInd= EcalTBDaqFormatter::cellIndex(tower, strip, ch);
877  return cellInd.second + (cellInd.first-1)*kCrystalsInPhi;
878 }
879 
880 
881 
882 bool EcalTBDaqFormatter::rightTower(int tower) const {
883 
884  if ((tower>12 && tower<21) || (tower>28 && tower<37) ||
885  (tower>44 && tower<53) || (tower>60 && tower<69))
886  return true;
887  else
888  return false;
889 }
890 
891 
892 
893 bool EcalTBDaqFormatter::leftTower(int tower) const
894 {
895  return !rightTower(tower);
896 }
897 
898 
#define LogDebug(id)
size_type size() const
Definition: EDCollection.h:98
bool Decode(unsigned long headerWord, EcalDCCHeaderBlock *theHeader)
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
bool rightTower(int tower) const
int ib
Definition: cuy.py:660
void setSelectiveReadout(const bool &selectiveReadout)
std::vector< DCCTBXtalBlock * > & xtalBlocks()
Definition: DCCTowerBlock.h:57
void setFedId(const int &fedId)
DCCTBDataParser * theParser_
const_iterator end() const
Definition: EDCollection.h:154
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
void setBasicTriggerType(const short &triggerType)
void setSize(int size)
int cryIc(int tower_id, int strip, int xtal)
void interpretRawData(const FEDRawData &data, EBDigiCollection &digicollection, EcalPnDiodeDigiCollection &pndigicollection, EcalRawDataCollection &DCCheaderCollection, EBDetIdCollection &dccsizecollection, EcalElectronicsIdCollection &ttidcollection, EcalElectronicsIdCollection &blocksizecollection, EBDetIdCollection &chidcollection, EBDetIdCollection &gaincollection, EBDetIdCollection &gainswitchcollection, EcalElectronicsIdCollection &memttidcollection, EcalElectronicsIdCollection &memblocksizecollection, EcalElectronicsIdCollection &memgaincollection, EcalElectronicsIdCollection &memchidcollection, EcalTrigPrimDigiCollection &tpcollection)
void push_back(T const &t)
void push_back(T const &t)
Definition: EDCollection.h:68
std::vector< DCCTBEventBlock * > & dccEvents()
void DecodeMEM(DCCTBTowerBlock *towerblock, EcalPnDiodeDigiCollection &pndigicollection, EcalElectronicsIdCollection &memttidcollection, EcalElectronicsIdCollection &memblocksizecollection, EcalElectronicsIdCollection &memgaincollection, EcalElectronicsIdCollection &memchidcollection)
bool leftTower(int tower) const
T eta() const
void setFEStatus(const std::vector< short > &feStatus)
void setRunNumber(const int &run)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
U second(std::pair< T, U > const &p)
void setZeroSuppression(const bool &zeroSuppression)
std::pair< int, int > cellIndex(int tower_id, int strip, int xtal)
bool pnIsOkInBlock[kPnPerTowerBlock]
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
void setTestZeroSuppression(const bool &testZeroSuppression)
bool first
Definition: L1TdeRCT.cc:94
void setTccStatus(const std::vector< short > &tccStatus)
void reserve(size_t isize)
unsigned _ExpectedTowers[71]
const_iterator begin() const
Definition: EDCollection.h:147
void setErrors(const int &dccErrors)
void setSrpStatus(const short &srpStatus)
void push_back(id_type iid, data_type const *idata)
void parseBuffer(uint32_t *buffer, uint32_t bufferSize, bool singleEvent=false)
void setOrbit(const int &orbit)
void setSample(int i, EcalMGPASample sam)
Definition: EcalDataFrame.h:44
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
int memRawSample_[kStripsPerTower][kChannelsPerStrip][kSamplesPerChannel+1]
#define MAX_TCC_SIZE
void reserve(size_type n)
void setId(const int &dccId)
void setLV1(const int &LV1)
void setBX(const int &BX)
void setSample(int i, const EcalFEMSample &sam)
#define MAX_TT_SIZE
std::vector< T >::const_iterator const_iterator
Definition: EDCollection.h:20
Definition: DDAxes.h:10