CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DCCMemBlock.cc
Go to the documentation of this file.
4 #include <stdio.h>
6 
7 
8 
11 {
12 
15 
19 
20  unsigned int numbOfXtalBlocks = (unfilteredTowerBlockLength_-1)/numbDWInXtalBlock_;
21  unsigned int numbOfPnBlocks = numbOfXtalBlocks/5; //change 5 by a variable
22  unsigned int vectorSize = numbOfPnBlocks*10*expXtalTSamples_;
23 
24  //Build pnDiodevector
25  for(unsigned int i =0; i< vectorSize; i++){ pn_.push_back(-1);}
26 
27 }
28 
30 
36 
37 }
38 
39 
40 
41 int DCCMemBlock::unpack(const uint64_t ** data, unsigned int * dwToEnd, unsigned int expectedTowerID){
42 
43  error_ = false;
44  datap_ = data;
45  data_ = *data;
46  dwToEnd_ = dwToEnd;
47 
48 
49  if( (*dwToEnd_)<1){
51  edm::LogWarning("IncorrectEvent")
52  <<"\nUnable to unpack MEM block for event "<<event_->l1A()<<" in fed "<<mapper_->getActiveDCC()
53  <<"\nThe end of event was reached !";
54  }
55  return STOP_EVENT_UNPACKING;
56  }
57 
58  lastStripId_ = 0;
59  lastXtalId_ = 0;
60  expTowerID_ = expectedTowerID;
61 
62 
63  //Point to begin of block
64  data_++;
65 
66  towerId_ = ( *data_ ) & TOWER_ID_MASK;
71 
72  event_->setFESyncNumbers(l1_,bx_,short(expectedTowerID-1));
73 
74 
75  //debugging
76  //display(cout);
77 
78  // Block Length Check (1)
80 
81  // chosing channel 1 as representative of a dummy...
83  (*invalidMemBlockSizes_)->push_back(id);
85  edm::LogWarning("IncorrectEvent")
86  <<"\nFor event "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower block "<<towerId_
87  <<"\nExpected mem block size is "<<(unfilteredTowerBlockLength_*8)<<" bytes while "<<(blockLength_*8)<<" was found";
88  }
89  return STOP_EVENT_UNPACKING;
90 
91  }
92 
93  // Block Length Check (2)
94  if((*dwToEnd_)<blockLength_){
96  edm::LogWarning("IncorrectEvent")
97  <<"\nUnable to unpack MEM block for event "<<event_->l1A()<<" in fed "<<mapper_->getActiveDCC()
98  <<"\n Only "<<((*dwToEnd_)*8)<<" bytes are available while "<<(blockLength_*8)<<" are needed!";
99  // chosing channel 1 as representative of a dummy...
100  }
102  (*invalidMemBlockSizes_)->push_back(id);
103  return STOP_EVENT_UNPACKING;
104  }
105 
106  // Synchronization Check
107  if(sync_){
108  const unsigned int dccBx = ( event_->bx()) & TOWER_BX_MASK;
109  const unsigned int dccL1 = ( event_->l1A() ) & TOWER_L1_MASK;
110  const unsigned int fov = ( event_->fov() ) & H_FOV_MASK;
111 
112  if (! isSynced(dccBx, bx_, dccL1, l1_, FE_MEM, fov)) {
114  edm::LogWarning("IncorrectEvent")
115  << "Synchronization error for Mem block"
116  << " (L1A " << event_->l1A() << " bx " << event_->bx() << " fed " << mapper_->getActiveDCC() << ")\n"
117  << " dccBx = " << dccBx << " bx_ = " << bx_ << " dccL1 = " << dccL1 << " l1_ = " << l1_ << "\n"
118  << " => Stop event unpacking";
119  }
120  //Note : add to error collection ?
121  // need of a new collection
122  return STOP_EVENT_UNPACKING;
123  }
124  }
125 
126  // Number Of Samples Check
127  if( nTSamples_ != expXtalTSamples_ ){
129  edm::LogWarning("IncorrectEvent")
130  <<"\nUnable to unpack MEM block for event "<<event_->l1A()<<" in fed "<<mapper_->getActiveDCC()
131  <<"\nNumber of time samples "<<nTSamples_<<" is not the same as expected ("<<expXtalTSamples_<<")";
132  }
133  //Note : add to error collection ?
134  return STOP_EVENT_UNPACKING;
135  }
136 
137 
138  //Channel Id Check
139  if( expTowerID_ != towerId_){
140 
141  // chosing channel 1 as representative as a dummy...
143  (*invalidMemTtIds_)->push_back(id);
145  edm::LogWarning("IncorrectBlock")
146  <<"For event "<<event_->l1A()<<" and fed "<<mapper_->getActiveDCC() << " and sm: " << mapper_->getActiveSM()
147  <<"\nExpected mem tower block is "<<expTowerID_<<" while "<<towerId_<<" was found ";
148  }
149 
151 
152  // todo : go to the next mem
153  error_= true;
154 
156  return SKIP_BLOCK_UNPACKING;
157  }
158 
159 
160  //point to xtal data
161  data_++;
162 
163 
165 
167 
169 
170  return BLOCK_UNPACKED;
171 
172 }
173 
174 
175 
177 
178 
179  //todo: move EcalPnDiodeDetId to electronics mapper
180 
181 
183  // differentiating the barrel and the endcap case
184  if (9 < mapper_->getActiveSM() || mapper_->getActiveSM() < 46){
185  lastTowerBeforeMem_ = 69; }
186  else {
187  lastTowerBeforeMem_ = 69; }
188 
189 
190  for(unsigned int expStripId = 1; expStripId<= 5; expStripId++){
191 
192  for(unsigned int expXtalId = 1; expXtalId <= 5; expXtalId++){
193 
194  const uint16_t * xData_= reinterpret_cast<const uint16_t *>(data_);
195 
196  // Get xtal data ids
197  unsigned int stripId = (*xData_) & TOWER_STRIPID_MASK;
198  unsigned int xtalId =((*xData_)>>TOWER_XTALID_B ) & TOWER_XTALID_MASK;
199 
200  bool errorOnDecoding(false);
201 
202  if(expStripId != stripId || expXtalId != xtalId){
203 
204  // chosing channel and strip as EcalElectronicsId
205  EcalElectronicsId id( mapper_->getActiveSM() , towerId_, expStripId, expXtalId);
206  (*invalidMemChIds_)->push_back(id);
207 
209  edm::LogWarning("IncorrectBlock")
210  <<"For event "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower mem block "<<towerId_
211  <<"\nThe expected strip is "<<expStripId<<" and "<<stripId<<" was found"
212  <<"\nThe expected xtal is "<<expXtalId <<" and "<<xtalId<<" was found";
213  }
214 
215  stripId = expStripId;
216  xtalId = expXtalId;
217 
218 
219 
220  errorOnDecoding = true;
221 
222  //Note : move to the next ...
223 
224  }
225 
226  unsigned int ipn, index;
227 
228  if((stripId-1)%2==0){ ipn = (towerId_-lastTowerBeforeMem_)*5 + xtalId - 1; }
229  else { ipn = (towerId_-lastTowerBeforeMem_)*5 + 5 - xtalId; }
230 
231 
232  //Cooking samples
233  for(unsigned int i =0; i< nTSamples_ ;i++){
234 
235  xData_++;
236 
237  index = ipn*50 + (stripId-1)*nTSamples_+i;
238 
239  //edm::LogDebug("EcalRawToDigiMemChId")<<"\n Strip id "<<std::dec<<stripId<<" Xtal id "<<xtalId
240  // <<" tsamp = "<<i<<" 16b = 0x "<<std::hex<<(*xData_)<<dec;
241 
242  unsigned int temp = (*xData_)&TOWER_DIGI_MASK;
243 
244  short sample(0);
245 
246 
247  if( (stripId-1)%2 ) {
248 
249  // If strip number is even, 14 bits are reversed in order
250  for(int ib=0;ib<14;ib++){
251  sample <<= 1;
252  sample |= (temp&1);
253  temp >>= 1;
254  }
255 
256  } else { sample=temp;}
257 
258  sample ^= 0x800;
259  unsigned int gain = sample>>12;
260 
261  if( gain >= 2 ){
262 
263  EcalElectronicsId id(mapper_->getActiveSM() , towerId_, stripId,xtalId);
264  (*invalidMemGains_)->push_back(id);
265 
267  edm::LogWarning("IncorrectBlock")
268  <<"For event "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" , mem tower block "<<towerId_
269  <<"\nIn strip "<<stripId<<" xtal "<<xtalId<<" the gain is "<<gain<<" in sample "<<(i+1);
270  }
271 
272  errorOnDecoding=true;
273  }
274 
275  if( !errorOnDecoding && !error_){pn_[index]=sample;} //Note : move to the next versus flag...
276 
277  }// loop over samples ended
278 
280  }//loop over xtals
281  }// loop over strips
282 
283 
284 }
285 
287 
288  //todo change pnId max
289  for (int pnId=1; pnId<=5; pnId++){
290  bool errorOnPn(false);
291  unsigned int realPnId = pnId;
292 
293  if(towerId_==70){ realPnId += 5;}
294 
295  // Note : we are assuming always 5 VFE channels enabled
296  // This means we all have 5 pns per tower
297 
298  // solution before sending creation of PnDigi's in mapper as done with crystals
299  // mapper_->getActiveSM() : this is the 'dccid'
300  // number ranging internally in ECAL from 1 to 54, according convention specified here:
301  // http://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=11621
302 
303  // mapper_->getActiveDCC() : this is the FED_id (601 - 654 for ECAL at CMS)
304 
305  const int activeSM = mapper_->getActiveSM();
306  int subdet(0);
307  if (NUMB_SM_EB_MIN_MIN <= activeSM && activeSM <= NUMB_SM_EB_PLU_MAX) {
308  subdet = EcalBarrel;
309  }
310  else if( (NUMB_SM_EE_MIN_MIN <= activeSM && activeSM <= NUMB_SM_EE_MIN_MAX) ||
311  (NUMB_SM_EE_PLU_MIN <= activeSM && activeSM <= NUMB_SM_EE_PLU_MAX) ) {
312  subdet = EcalEndcap;
313  }
314  else {
316  edm::LogWarning("IncorrectMapping")
317  <<"\n mapper points to non existing dccid: " << activeSM;
318  }
319  }
320 
321 
322  EcalPnDiodeDetId PnId(subdet, activeSM, realPnId );
323 
324  EcalPnDiodeDigi thePnDigi(PnId );
325  thePnDigi.setSize(kSamplesPerPn_);
326 
327 
328  for (unsigned int ts =0; ts <kSamplesPerPn_; ts++){
329 
330  short pnDiodeData = pn_[(towerId_-lastTowerBeforeMem_)*250 + (pnId-1)*kSamplesPerPn_ + ts];
331  if( pnDiodeData == -1){
332  errorOnPn=true;
333  break;
334  }
335 
336  EcalFEMSample thePnSample(pnDiodeData );
337  thePnDigi.setSample(ts, thePnSample );
338  }
339 
340  if(!errorOnPn){ (*pnDiodeDigis_)->push_back(thePnDigi);}
341 
342  }
343 
344 }
345 
346 
347 
348 void DCCMemBlock::display(std::ostream& o){
349 
350  o<<"\n Unpacked Info for DCC MEM Block"
351  <<"\n DW1 ============================="
352  <<"\n Mem Tower Block Id "<<towerId_
353  <<"\n Numb Samp "<<nTSamples_
354  <<"\n Bx "<<bx_
355  <<"\n L1 "<<l1_
356  <<"\n blockLength "<<blockLength_;
357 }
358 
359 
360 
361 
unsigned int expTowerID_
Definition: DCCMemBlock.h:57
int i
Definition: DBlmapReader.cc:9
bool isSynced(const unsigned int dccBx, const unsigned int bx, const unsigned int dccL1, const unsigned int l1, const BlockType type, const unsigned int fov)
std::auto_ptr< EcalElectronicsIdCollection > * invalidMemBlockSizesCollection()
std::auto_ptr< EcalElectronicsIdCollection > * invalidMemChIdsCollection()
unsigned int bx_
Definition: DCCMemBlock.h:71
std::auto_ptr< EcalElectronicsIdCollection > * invalidMemTtIds_
Definition: DCCMemBlock.h:76
unsigned int kSamplesPerPn_
Definition: DCCMemBlock.h:59
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
unsigned int numbDWInXtalBlock_
Definition: DCCMemBlock.h:66
void setSize(int size)
std::auto_ptr< EcalElectronicsIdCollection > * invalidMemGains_
Definition: DCCMemBlock.h:77
unsigned int lastStripId_
Definition: DCCMemBlock.h:61
unsigned int expXtalTSamples_
Definition: DCCMemBlock.h:58
static bool silentMode_
unsigned int unfilteredTowerBlockLength_
Definition: DCCMemBlock.h:69
std::vector< short > pn_
Definition: DCCMemBlock.h:55
unsigned int bx()
Definition: DCCEventBlock.h:57
void updateCollectors()
Definition: DCCMemBlock.cc:29
unsigned int lastTowerBeforeMem_
Definition: DCCMemBlock.h:63
unsigned int fov()
Definition: DCCEventBlock.h:54
void setFESyncNumbers(short l1, short bx, short id)
Definition: DCCEventBlock.h:61
std::auto_ptr< EcalElectronicsIdCollection > * invalidMemTtIdsCollection()
std::auto_ptr< EcalElectronicsIdCollection > * invalidMemChIds_
Definition: DCCMemBlock.h:74
void display(std::ostream &o)
Definition: DCCMemBlock.cc:348
std::auto_ptr< EcalElectronicsIdCollection > * invalidMemGainsCollection()
unsigned int nTSamples_
Definition: DCCMemBlock.h:68
unsigned long long uint64_t
Definition: Time.h:15
void fillPnDiodeDigisCollection()
Definition: DCCMemBlock.cc:286
unsigned int xtalBlockSize_
Definition: DCCMemBlock.h:67
DCCDataUnpacker * unpacker_
std::auto_ptr< EcalPnDiodeDigiCollection > * pnDiodeDigis_
Definition: DCCMemBlock.h:78
unsigned int getUnfilteredTowerBlockLength()
unsigned int l1_
Definition: DCCMemBlock.h:72
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual void updateEventPointers()
void unpackMemTowerData()
Definition: DCCMemBlock.cc:176
std::auto_ptr< EcalPnDiodeDigiCollection > * pnDiodeDigisCollection()
unsigned int lastXtalId_
Definition: DCCMemBlock.h:62
DCCMemBlock(DCCDataUnpacker *u, EcalElectronicsMapper *m, DCCEventBlock *e)
Definition: DCCMemBlock.cc:9
EcalElectronicsMapper * mapper_
void setSample(int i, const EcalFEMSample &sam)
unsigned int towerId_
Definition: DCCMemBlock.h:65
std::auto_ptr< EcalElectronicsIdCollection > * invalidMemBlockSizes_
Definition: DCCMemBlock.h:75
int unpack(const uint64_t **data, unsigned int *dwToEnd, unsigned int expectedTowerID)
Definition: DCCMemBlock.cc:41
unsigned int l1A()
Definition: DCCEventBlock.h:56