CMS 3D CMS Logo

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