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 }
DCCMemBlock::invalidMemTtIds_
std::unique_ptr< EcalElectronicsIdCollection > * invalidMemTtIds_
Definition: DCCMemBlock.h:71
DCCDataBlockPrototype::dwToEnd_
unsigned int * dwToEnd_
Definition: DCCDataBlockPrototype.h:74
DCCDataUnpacker.h
DCCEventBlock
Definition: DCCEventBlock.h:29
mps_fire.i
i
Definition: mps_fire.py:428
TOWER_XTALID_MASK
Definition: DCCRawDataDefinitions.h:165
SKIP_BLOCK_UNPACKING
Definition: DCCRawDataDefinitions.h:7
DCCMemBlock::expTowerID_
unsigned int expTowerID_
Definition: DCCMemBlock.h:52
DCCMemBlock::pnDiodeDigis_
std::unique_ptr< EcalPnDiodeDigiCollection > * pnDiodeDigis_
Definition: DCCMemBlock.h:73
simplePhotonAnalyzer_cfi.sample
sample
Definition: simplePhotonAnalyzer_cfi.py:12
DCCMemBlock::expXtalTSamples_
unsigned int expXtalTSamples_
Definition: DCCMemBlock.h:53
DCCDataBlockPrototype::data_
const uint64_t * data_
Definition: DCCDataBlockPrototype.h:73
isSynced
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)
Definition: DCCEventBlock.cc:228
TOWER_ID_MASK
Definition: DCCRawDataDefinitions.h:149
TOWER_XTALID_B
Definition: DCCRawDataDefinitions.h:166
EcalPnDiodeDigi::setSize
void setSize(int size)
Definition: EcalPnDiodeDigi.cc:6
H_FOV_MASK
Definition: DCCRawDataDefinitions.h:102
DCCMemBlock::bx_
unsigned int bx_
Definition: DCCMemBlock.h:66
EcalElectronicsMapper::getActiveSM
unsigned int getActiveSM()
Definition: EcalElectronicsMapper.h:128
NUMB_SM_EE_PLU_MAX
Definition: DCCRawDataDefinitions.h:59
NUMB_SM_EB_MIN_MIN
Definition: DCCRawDataDefinitions.h:54
DCCEventBlock::setFESyncNumbers
void setFESyncNumbers(short l1, short bx, short id)
Definition: DCCEventBlock.h:65
DCCDataUnpacker
Definition: DCCDataUnpacker.h:49
DCCDataBlockPrototype::updateEventPointers
virtual void updateEventPointers()
Definition: DCCDataBlockPrototype.h:51
DCCMemBlock::numbDWInXtalBlock_
unsigned int numbDWInXtalBlock_
Definition: DCCMemBlock.h:61
DCCDataUnpacker::silentMode_
static std::atomic< bool > silentMode_
Definition: DCCDataUnpacker.h:185
DCCDataUnpacker::invalidMemGainsCollection
std::unique_ptr< EcalElectronicsIdCollection > * invalidMemGainsCollection()
Definition: DCCDataUnpacker.h:158
EcalElectronicsMapper::numbXtalTSamples
unsigned int numbXtalTSamples()
Definition: EcalElectronicsMapper.h:130
EcalPnDiodeDetId
Definition: EcalPnDiodeDetId.h:22
DCCDataBlockPrototype::error_
bool error_
Definition: DCCDataBlockPrototype.h:68
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
DCCDataBlockPrototype
Definition: DCCDataBlockPrototype.h:28
TOWER_L1_MASK
Definition: DCCRawDataDefinitions.h:157
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
EcalElectronicsMapper.h
DCCEventBlock::fov
unsigned int fov()
Definition: DCCEventBlock.h:55
EcalBarrel
Definition: EcalSubdetector.h:10
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
DCCMemBlock::kSamplesPerPn_
unsigned int kSamplesPerPn_
Definition: DCCMemBlock.h:54
TOWER_DIGI_MASK
Definition: DCCRawDataDefinitions.h:161
DCCMemBlock::lastStripId_
unsigned int lastStripId_
Definition: DCCMemBlock.h:56
DCCMemBlock::invalidMemBlockSizes_
std::unique_ptr< EcalElectronicsIdCollection > * invalidMemBlockSizes_
Definition: DCCMemBlock.h:70
NUMB_SM_EE_PLU_MIN
Definition: DCCRawDataDefinitions.h:58
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
DCCDataBlockPrototype::unpacker_
DCCDataUnpacker * unpacker_
Definition: DCCDataBlockPrototype.h:67
DCCEventBlock::bx
unsigned int bx()
Definition: DCCEventBlock.h:58
DCCMemBlock::pn_
std::vector< short > pn_
Definition: DCCMemBlock.h:50
FE_MEM
Definition: DCCEventBlock.h:138
DCCDataUnpacker::invalidMemTtIdsCollection
std::unique_ptr< EcalElectronicsIdCollection > * invalidMemTtIdsCollection()
Definition: DCCDataUnpacker.h:152
EcalElectronicsMapper::getActiveDCC
unsigned int getActiveDCC()
Definition: EcalElectronicsMapper.h:126
DCCMemBlock::lastTowerBeforeMem_
unsigned int lastTowerBeforeMem_
Definition: DCCMemBlock.h:58
EcalElectronicsId
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
Definition: EcalElectronicsId.h:18
EcalEndcap
Definition: EcalSubdetector.h:10
TOWER_NSAMP_MASK
Definition: DCCRawDataDefinitions.h:151
STOP_EVENT_UNPACKING
Definition: DCCRawDataDefinitions.h:8
DCCMemBlock::unfilteredTowerBlockLength_
unsigned int unfilteredTowerBlockLength_
Definition: DCCMemBlock.h:64
NUMB_SM_EB_PLU_MAX
Definition: DCCRawDataDefinitions.h:57
DCCEventBlock.h
DCCDataBlockPrototype::sync_
bool sync_
Definition: DCCDataBlockPrototype.h:78
TOWER_BX_MASK
Definition: DCCRawDataDefinitions.h:154
DCCDataBlockPrototype::event_
DCCEventBlock * event_
Definition: DCCDataBlockPrototype.h:70
EcalPnDiodeDigi::setSample
void setSample(int i, const EcalFEMSample &sam)
Definition: EcalPnDiodeDigi.h:27
DCCMemBlock::nTSamples_
unsigned int nTSamples_
Definition: DCCMemBlock.h:63
DCCDataUnpacker::pnDiodeDigisCollection
std::unique_ptr< EcalPnDiodeDigiCollection > * pnDiodeDigisCollection()
Definition: DCCDataUnpacker.h:160
cuy.ib
ib
Definition: cuy.py:661
DCCMemBlock::unpackMemTowerData
void unpackMemTowerData()
Definition: DCCMemBlock.cc:158
DCCEventBlock::l1A
unsigned int l1A()
Definition: DCCEventBlock.h:57
DCCMemBlock::display
void display(std::ostream &o) override
Definition: DCCMemBlock.cc:315
EcalFEMSample
Definition: EcalFEMSample.h:14
NUMB_SM_EE_MIN_MIN
Definition: DCCRawDataDefinitions.h:52
EcalElectronicsMapper
Definition: EcalElectronicsMapper.h:36
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
DCCMemBlock::invalidMemChIds_
std::unique_ptr< EcalElectronicsIdCollection > * invalidMemChIds_
Definition: DCCMemBlock.h:69
NUMB_SM_EE_MIN_MAX
Definition: DCCRawDataDefinitions.h:53
DCCDataBlockPrototype::mapper_
EcalElectronicsMapper * mapper_
Definition: DCCDataBlockPrototype.h:69
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
DCCMemBlock::updateCollectors
void updateCollectors() override
Definition: DCCMemBlock.cc:26
DCCDataBlockPrototype::datap_
const uint64_t ** datap_
Definition: DCCDataBlockPrototype.h:72
DCCMemBlock::unpack
int unpack(const uint64_t **data, unsigned int *dwToEnd, unsigned int expectedTowerID)
Definition: DCCMemBlock.cc:34
TOWER_STRIPID_MASK
Definition: DCCRawDataDefinitions.h:163
DCCMemBlock::lastXtalId_
unsigned int lastXtalId_
Definition: DCCMemBlock.h:57
DCCMemBlock::DCCMemBlock
DCCMemBlock(DCCDataUnpacker *u, EcalElectronicsMapper *m, DCCEventBlock *e)
Definition: DCCMemBlock.cc:7
DCCMemBlock.h
TOWER_BX_B
Definition: DCCRawDataDefinitions.h:155
DCCMemBlock::l1_
unsigned int l1_
Definition: DCCMemBlock.h:67
TOWER_LENGTH_MASK
Definition: DCCRawDataDefinitions.h:168
DCCMemBlock::fillPnDiodeDigisCollection
void fillPnDiodeDigisCollection()
Definition: DCCMemBlock.cc:260
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
DCCDataUnpacker::invalidMemChIdsCollection
std::unique_ptr< EcalElectronicsIdCollection > * invalidMemChIdsCollection()
Definition: DCCDataUnpacker.h:156
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
EcalElectronicsMapper::getUnfilteredTowerBlockLength
unsigned int getUnfilteredTowerBlockLength()
Definition: EcalElectronicsMapper.h:134
DCCMemBlock::towerId_
unsigned int towerId_
Definition: DCCMemBlock.h:60
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
DCCMemBlock::invalidMemGains_
std::unique_ptr< EcalElectronicsIdCollection > * invalidMemGains_
Definition: DCCMemBlock.h:72
DCCDataBlockPrototype::blockLength_
unsigned int blockLength_
Definition: DCCDataBlockPrototype.h:76
TOWER_LENGTH_B
Definition: DCCRawDataDefinitions.h:169
EcalPnDiodeDigi
Definition: EcalPnDiodeDigi.h:13
DCCMemBlock::xtalBlockSize_
unsigned int xtalBlockSize_
Definition: DCCMemBlock.h:62
TOWER_NSAMP_B
Definition: DCCRawDataDefinitions.h:152
BLOCK_UNPACKED
Definition: DCCRawDataDefinitions.h:6
TOWER_L1_B
Definition: DCCRawDataDefinitions.h:158
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
DCCDataUnpacker::invalidMemBlockSizesCollection
std::unique_ptr< EcalElectronicsIdCollection > * invalidMemBlockSizesCollection()
Definition: DCCDataUnpacker.h:154