CMS 3D CMS Logo

DTuROSRawToDigi.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTuROSRawToDigi
4 //
5 // L1 DT uROS Raw-to-Digi
6 //
7 //
8 //
9 // Author :
10 // C. Heidemann - RWTH Aachen
11 // J. Troconiz - UAM
12 //
13 //
14 //--------------------------------------------------
15 
17 
21 
26 
27 #include <iostream>
28 
30  produces<DTDigiCollection>();
31  produces<std::vector<DTuROSFEDData>>();
32 
33  DTuROSInputTag_ = pset.getParameter<edm::InputTag>("inputLabel");
34 
35  debug_ = pset.getUntrackedParameter<bool>("debug", false);
36 
38  feds_.push_back(i);
39 
40  nfeds_ = feds_.size();
41 
42  Raw_token = consumes<FEDRawDataCollection>(DTuROSInputTag_);
43 }
44 
46 
48  DTDigiCollection digis;
49  std::vector<DTuROSFEDData> words;
50 
51  if (!fillRawData(e, c, digis, words))
52  return;
53 
54  auto uROSDTDigi_product = std::make_unique<DTDigiCollection>(digis);
55  auto uROSDTWord_product = std::make_unique<std::vector<DTuROSFEDData>>(words);
56 
57  e.put(std::move(uROSDTDigi_product));
58  e.put(std::move(uROSDTWord_product));
59 }
60 
62  const edm::EventSetup& c,
63  DTDigiCollection& digis,
64  std::vector<DTuROSFEDData>& words) {
66  e.getByToken(Raw_token, data);
67 
70 
71  for (int w_i = 0; w_i < nfeds_; ++w_i) {
72  DTuROSFEDData fwords;
73  process(feds_[w_i], data, mapping, digis, fwords);
74  if (fwords.getfed() >= 0)
75  words.push_back(fwords);
76  }
77 
78  return true;
79 }
80 
81 void DTuROSRawToDigi::process(int DTuROSFED,
84  DTDigiCollection& digis,
85  DTuROSFEDData& fwords) {
86  // Container
87  std::vector<long> DTuROSWordContainer;
88 
89  // Header constituents
90  int BOEevTy, DTuROSId;
91 
92  // Trailer constituents
93  int chkEOE, evtLgth, CRC;
94 
95  // Hit counter
96  std::map<uint32_t, int> hitOrder;
97 
98  //--> Header - line 1
99 
100  FEDRawData dturosdata = data->FEDData(DTuROSFED);
101  if (dturosdata.size() == 0)
102  return;
103 
104  lineFED = dturosdata.data();
105  long dataWord = 0;
106  int lines = 0; // counting including header
107  readline(lines, dataWord);
108  const int posBOEevTy = 60; // positions 60 -> 63
109  const int posDTuROSId = 8; // positions 8 -> 19
110  const int posNslost = 52; // positions 52 -> 55
111  const int posSlotFED = 16; // positions 16 -> 19
112 
113  BOEevTy = (dataWord >> posBOEevTy) & 0xF;
114  DTuROSId = (dataWord >> posDTuROSId) & 0xFFF;
115 
116  if ((BOEevTy != 0x5) || (DTuROSId != DTuROSFED)) {
117  if (debug_)
118  edm::LogWarning("dturos_unpacker") << "Not a DTuROS FED " << DTuROSFED << " or header " << std::hex << dataWord;
119  return;
120  }
121 
122  fwords.setfed(DTuROSId);
123  fwords.setheader1(dataWord);
124 
125  int newCRC = 0xFFFF;
126  dt_crc::calcCRC(dataWord, newCRC);
127 
128  int crate = DTuROSId;
129 
130  //--> Header - line 2
131 
132  readline(lines, dataWord);
133  dt_crc::calcCRC(dataWord, newCRC);
134 
135  int nslots = (dataWord >> posNslost) & 0xF;
136 
137  fwords.setheader2(dataWord);
138  fwords.setnslots(nslots);
139 
140  //--> AMC - line 3 to 2+nslots
141  std::map<int, int> slot_size;
142  for (int j = 0; j < nslots; ++j) {
143  readline(lines, dataWord);
144  dt_crc::calcCRC(dataWord, newCRC);
145 
146  int slot = (dataWord >> posSlotFED) & 0xF;
147 
148  if ((slot < 1) || (slot > 12)) {
149  if (debug_)
150  edm::LogWarning("dturos_unpacker") << "AMCnumber " << std::dec << slot << " out of range (1-12)";
151  return;
152  }
153 
154  slot_size[slot] = (dataWord >> 32) & 0xFFFFFF; // positions 32 -> 55
155 
156  fwords.setslotsize(slot, slot_size[slot]);
157  }
158 
159  //--> DTuROS data
160 
161  std::map<int, int>::iterator sziterator = slot_size.begin();
162  std::map<int, int>::iterator szitend = slot_size.end();
163  for (; sziterator != szitend; ++sziterator) {
164  for (int k = 0; k < sziterator->second; ++k) {
165  readline(lines, dataWord);
166  dt_crc::calcCRC(dataWord, newCRC);
167 
168  DTuROSWordContainer.push_back(dataWord);
169  }
170  }
171 
172  //--> Trailer - line 1
173 
174  readline(lines, dataWord);
175  dt_crc::calcCRC(dataWord, newCRC);
176 
177  //--> Trailer - line 2
178 
179  readline(lines, dataWord);
180 
181  const int posEOE = 60; // positions 60 -> 63
182  const int posEvtLenght = 32; // positions 33 ->55
183  const int posCRC = 16; // positions 16 ->31
184  chkEOE = (dataWord >> posEOE) & 0xF;
185 
186  if (chkEOE != 0xA) {
187  if (debug_)
188  edm::LogWarning("dturos_unpacker") << "Trailer " << std::hex << dataWord << " does not start with 0xA";
189  return;
190  }
191 
192  evtLgth = (dataWord >> posEvtLenght) & 0xFFFFFF;
193  CRC = (dataWord >> posCRC) & 0xFFFF;
194 
195  dt_crc::calcCRC(dataWord & 0xFFFFFFFF0000FFFF, newCRC);
196 
197  if (newCRC != CRC) {
198  if (debug_)
199  edm::LogWarning("dturos_unpacker") << "Calculated CRC " << std::hex << newCRC << " differs from CRC in trailer "
200  << std::hex << CRC;
201  return;
202  }
203 
204  if (lines != evtLgth) {
205  if (debug_)
206  edm::LogWarning("dturos_unpacker") << "Number of words read != event length " << std::dec << lines << " "
207  << evtLgth;
208  return;
209  }
210 
211  fwords.settrailer(dataWord);
212  fwords.setevtlgth(evtLgth);
213 
214  //--> analyze event
215 
216  std::vector<long>::iterator DTuROSiterator = DTuROSWordContainer.begin();
217  std::vector<long>::iterator DTuROSitend = DTuROSWordContainer.end();
218 
219  const int posSlot = 56; // positions 56 -> 59
220 
221  for (; DTuROSiterator != DTuROSitend; ++DTuROSiterator) {
222  DTuROSROSData rwords;
223 
224  dataWord = (*DTuROSiterator); // Header AMC 1
225 
226  int slot = (dataWord >> posSlot) & 0xF;
227 
228  if ((slot < 1) || (slot > 12)) {
229  if (debug_)
230  edm::LogWarning("dturos_unpacker") << "Slot " << std::dec << slot << " out of range (1-12) in crate " << crate;
231  break;
232  }
233 
234  rwords.setslot(slot);
235  rwords.setheader1(dataWord);
236 
237  ++DTuROSiterator;
238  dataWord = (*DTuROSiterator); // Header AMC 2
239 
240  rwords.setheader2(dataWord);
241  int slotMap = dataWord & 0xF;
242  if (slotMap == 0)
243  slotMap = slot;
244  const int posSel1 = 60; // positions 60 -> 6
245  const int posSel2 = 28; // position 28
246  const int posTDCTime = 32; // positions 32 -> 45
247  const int posTDCChannel = 46; // positions 46 -> 50
248  const int posTDCId = 51; // positions 51 -> 52
249  const int posLink = 53; // positions 53 -> 59
250  const int posTDCChannelSel2Null = 14; // positions 14 -> 18
251  const int posTDCIdSel2Null = 19; // positions 19 -> 20
252  const int posLinkSel2Null = 21; // positions 21 -> 27
253  const int posErrorSel3 = 32; // positions 32 -> 60
254 
255  for (int k = 2; k < slot_size[slot] - 1; ++k) {
256  ++DTuROSiterator;
257  dataWord = (*DTuROSiterator);
258  int selector = (dataWord >> posSel1) & 0xF;
259  int selector2 = (dataWord >> posSel2) & 0x1;
260 
261  if (selector == 4) { // OK word
262 
263  if (rwords.getokword1()) {
264  rwords.setokword2(dataWord);
265  } else {
266  rwords.setokword1(dataWord);
267  }
268 
269  } else if (selector >= 8 && selector <= 13) { // OK xword
270 
271  rwords.setokxword(selector - 8, dataWord);
272 
273  } else if (selector == 15) { // extra word
274 
275  rwords.setexword(dataWord);
276 
277  } else {
278  if (selector == 2) { // TDC word
279 
280  int tdcTime = (dataWord >> posTDCTime) & 0x3FFF;
281  int tdcChannel = (dataWord >> posTDCChannel) & 0x1F;
282  int tdcId = (dataWord >> posTDCId) & 0x3;
283  int link = (dataWord >> posLink) & 0x7F;
284 
285  int dummy = 0;
286 
287  bool tenDDU = !mapping->readOutToGeometry(779, 7, 1, 1, 1, dummy, dummy, dummy, dummy, dummy, dummy);
288 
289  int dduId = theDDU(crate, slotMap, link, tenDDU);
290  int rosId = theROS(slotMap, link);
291  int robId = theROB(slotMap, link);
292 
293  DTROChainCoding channelIndex(dduId, rosId, robId, tdcId, tdcChannel);
294  if (hitOrder.find(channelIndex.getCode()) == hitOrder.end())
295  hitOrder[channelIndex.getCode()] = 0;
296  else
297  hitOrder[channelIndex.getCode()]++;
298 
299  int wheelId, stationId, sectorId, slId, layerId, cellId;
300  if (!mapping->readOutToGeometry(
301  dduId, rosId, robId, tdcId, tdcChannel, wheelId, stationId, sectorId, slId, layerId, cellId)) {
302  DTWireId detId = DTWireId(wheelId, stationId, sectorId, slId, layerId, cellId);
303  int wire = detId.wire();
304 
305  DTDigi digi(wire, tdcTime, hitOrder[channelIndex.getCode()]);
306  digis.insertDigi(detId.layerId(), digi);
307  }
308 
309  } else if (selector == 3) { // error word
310 
311  if (debug_)
312  edm::LogWarning("dturos_unpacker") << "Error word [" << std::dec << k << "] : " << std::hex << dataWord
313  << std::dec << " in slot " << slot << " in crate " << crate;
314 
315  int error = (dataWord >> posErrorSel3) & 0x1FFFFFFF;
316  rwords.seterror(error);
317  }
318 
319  if ((dataWord & 0x1FFFFFFF) == 0x1FFFFFFF)
320  continue;
321 
322  if (selector2 == 0) { // TDC word
323 
324  int tdcTime = (dataWord)&0x3FFF; // positions 0 -> 13
325  int tdcChannel = (dataWord >> posTDCChannelSel2Null) & 0x1F;
326  int tdcId = (dataWord >> posTDCIdSel2Null) & 0x3;
327  int link = (dataWord >> posLinkSel2Null) & 0x7F; // positions 21 -> 27
328 
329  if (tdcTime == 16383)
330  continue;
331 
332  int dummy = 0;
333 
334  bool tenDDU = !mapping->readOutToGeometry(779, 7, 1, 1, 1, dummy, dummy, dummy, dummy, dummy, dummy);
335 
336  int dduId = theDDU(crate, slotMap, link, tenDDU);
337  int rosId = theROS(slotMap, link);
338  int robId = theROB(slotMap, link);
339 
340  DTROChainCoding channelIndex(dduId, rosId, robId, tdcId, tdcChannel);
341  if (hitOrder.find(channelIndex.getCode()) == hitOrder.end())
342  hitOrder[channelIndex.getCode()] = 0;
343  else
344  hitOrder[channelIndex.getCode()]++;
345 
346  int wheelId, stationId, sectorId, slId, layerId, cellId;
347  if (!mapping->readOutToGeometry(
348  dduId, rosId, robId, tdcId, tdcChannel, wheelId, stationId, sectorId, slId, layerId, cellId)) {
349  DTWireId detId = DTWireId(wheelId, stationId, sectorId, slId, layerId, cellId);
350  int wire = detId.wire();
351 
352  DTDigi digi(wire, tdcTime, hitOrder[channelIndex.getCode()]);
353  digis.insertDigi(detId.layerId(), digi);
354  }
355 
356  } else if (selector2 == 1) { // error word
357 
358  if (debug_)
359  edm::LogWarning("dturos_unpacker") << "Error word [" << std::dec << k << "] : " << std::hex << dataWord
360  << std::dec << " in slot " << slot << " in crate " << crate;
361 
362  int error = (dataWord)&0x1FFFFFFF; // positions 0 -> 28
363  rwords.seterror(error);
364  }
365  }
366  }
367 
368  ++DTuROSiterator;
369  dataWord = (*DTuROSiterator); // Trailer AMC
370 
371  rwords.settrailer(dataWord);
372  fwords.setuROS(slot, rwords);
373 
374  } // end for-loop container content
375 
376  return;
377 }
378 
379 int DTuROSRawToDigi::theDDU(int crate, int slot, int link, bool tenDDU) {
380  int ros = theROS(slot, link);
381 
382  int ddu = 772;
383 
384  //if (crate == 1368) { ddu = 775; }
386 
387  if (crate == FEDNumbering::MINDTUROSFEDID) {
388  if (slot < 7)
389  ddu = 770;
390  else
391  ddu = 771;
392  }
393 
394  if (crate == (FEDNumbering::MINDTUROSFEDID + 1)) {
395  ddu = 772;
396  }
397 
398  if (crate == FEDNumbering::MAXDTUROSFEDID) {
399  if (slot < 7)
400  ddu = 773;
401  else
402  ddu = 774;
403  }
404 
405  if (ros > 6 && tenDDU && ddu < 775)
406  ddu += 5;
407 
408  return ddu;
409 }
410 
411 int DTuROSRawToDigi::theROS(int slot, int link) {
412  if (slot % 6 == 5)
413  return link + 1;
414 
415  int ros = (link / 24) + 3 * (slot % 6) - 2;
416  return ros;
417 }
418 
419 int DTuROSRawToDigi::theROB(int slot, int link) {
420  if (slot % 6 == 5)
421  return 23;
422 
423  int rob = link % 24;
424  if (rob < 15)
425  return rob;
426  if (rob == 15)
427  return 24;
428  return rob - 1;
429 }
430 
DTuROSRawToDigi::lineFED
unsigned char * lineFED
Definition: DTuROSRawToDigi.h:59
DTWireId::wire
int wire() const
Return the wire number.
Definition: DTWireId.h:42
DTuROSFEDData::setfed
void setfed(int fed)
Definition: DTuROSControlData.h:114
mps_fire.i
i
Definition: mps_fire.py:355
DTuROSRawToDigi::~DTuROSRawToDigi
~DTuROSRawToDigi() override
Destructor.
Definition: DTuROSRawToDigi.cc:45
MessageLogger.h
DTuROSRawToDigi::DTuROSInputTag_
edm::InputTag DTuROSInputTag_
Definition: DTuROSRawToDigi.h:51
MainPageGenerator.link
link
Definition: MainPageGenerator.py:271
DTuROSROSData::setokxword
void setokxword(int i, long okxword)
Definition: DTuROSControlData.h:45
DTuROSRawToDigi::fillRawData
bool fillRawData(edm::Event &e, const edm::EventSetup &c, DTDigiCollection &digis, std::vector< DTuROSFEDData > &words)
Generate and fill FED raw data for a full event.
Definition: DTuROSRawToDigi.cc:61
DTuROSFEDData::settrailer
void settrailer(long dword)
Definition: DTuROSControlData.h:120
DTReadOutMappingRcd
Definition: DTReadOutMappingRcd.h:5
DTuROSROSData::setokword2
void setokword2(long okword)
Definition: DTuROSControlData.h:43
DTROChainCoding.h
DTuROSROSData::setexword
void setexword(long exword)
Definition: DTuROSControlData.h:47
DTuROSControlData.h
DTROChainCoding::getCode
uint32_t getCode() const
Getters ///////////////////////.
Definition: DTROChainCoding.h:57
edm::Handle
Definition: AssociativeIterator.h:50
relativeConstraints.error
error
Definition: relativeConstraints.py:53
FEDNumbering::MINDTUROSFEDID
Definition: FEDNumbering.h:111
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FEDRawData
Definition: FEDRawData.h:19
DTuROSRawToDigi::theROB
int theROB(int slot, int link)
Definition: DTuROSRawToDigi.cc:419
MakerMacros.h
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
DTuROSFEDData::getfed
int getfed() const
Definition: DTuROSControlData.h:130
DTuROSRawToDigi::feds_
std::vector< int > feds_
Definition: DTuROSRawToDigi.h:57
DTuROSRawToDigi::nfeds_
int nfeds_
Definition: DTuROSRawToDigi.h:55
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DTWireId
Definition: DTWireId.h:12
DTuROSROSData::getokword1
long getokword1() const
Definition: DTuROSControlData.h:59
DTuROSRawToDigi::Raw_token
edm::EDGetTokenT< FEDRawDataCollection > Raw_token
Definition: DTuROSRawToDigi.h:86
DTuROSROSData::setheader2
void setheader2(long dword)
Definition: DTuROSControlData.h:37
DTuROSRawToDigi.h
edm::ESHandle< DTReadOutMapping >
DTuROSROSData::setslot
void setslot(int slot)
Definition: DTuROSControlData.h:33
DTuROSROSData::settrailer
void settrailer(long dword)
Definition: DTuROSControlData.h:39
DTuROSFEDData::setheader2
void setheader2(long dword)
Definition: DTuROSControlData.h:118
dqmdumpme.k
k
Definition: dqmdumpme.py:60
DTuROSROSData::setokword1
void setokword1(long okword)
Definition: DTuROSControlData.h:41
DTuROSFEDData::setslotsize
void setslotsize(int slot, int size)
Definition: DTuROSControlData.h:126
DTuROSRawToDigi::theDDU
int theDDU(int crate, int slot, int link, bool tenDDU)
Definition: DTuROSRawToDigi.cc:379
DTuROSRawToDigi::readline
void readline(int &lines, long &dataWord)
Definition: DTuROSRawToDigi.h:72
edm::LogWarning
Definition: MessageLogger.h:141
DTCRC.h
DTReadOutMappingRcd.h
edm::ParameterSet
Definition: ParameterSet.h:36
groupFilesInBlocks.lines
lines
Definition: groupFilesInBlocks.py:95
DTuROSRawToDigi
Definition: DTuROSRawToDigi.h:36
DTuROSRawToDigi::theROS
int theROS(int slot, int link)
Definition: DTuROSRawToDigi.cc:411
DTDigiCollection
DTuROSROSData
Definition: DTuROSControlData.h:22
DTuROSFEDData
Definition: DTuROSControlData.h:103
DTuROSFEDData::setheader1
void setheader1(long dword)
Definition: DTuROSControlData.h:116
edm::EventSetup
Definition: EventSetup.h:57
RawDataTask_cfi.CRC
CRC
Definition: RawDataTask_cfi.py:59
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
get
#define get
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
DTuROSFEDData::setnslots
void setnslots(int nslots)
Definition: DTuROSControlData.h:122
DTuROSFEDData::setevtlgth
void setevtlgth(int evtLgth)
Definition: DTuROSControlData.h:124
DTuROSRawToDigi::debug_
bool debug_
Definition: DTuROSRawToDigi.h:53
DTuROSRawToDigi::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Produce digis out of raw data.
Definition: DTuROSRawToDigi.cc:47
DTROChainCoding
FIXEME:
Definition: DTROChainCoding.h:28
DTuROSRawToDigi::DTuROSRawToDigi
DTuROSRawToDigi(const edm::ParameterSet &pset)
Constructor.
Definition: DTuROSRawToDigi.cc:29
eostools.move
def move(src, dest)
Definition: eostools.py:511
dt_crc::calcCRC
void calcCRC(long, int &)
Definition: DTCRC.cc:3
DTuROSROSData::setheader1
void setheader1(long dword)
Definition: DTuROSControlData.h:35
DTWireId.h
DTDigi
Definition: DTDigi.h:17
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
DTWireId::layerId
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:45
dummy
Definition: DummySelector.h:38
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DTuROSFEDData::setuROS
void setuROS(int slot, DTuROSROSData rwords)
Definition: DTuROSControlData.h:128
DTuROSRawToDigi::process
void process(int DTuROSFED, edm::Handle< FEDRawDataCollection > data, edm::ESHandle< DTReadOutMapping > mapping, DTDigiCollection &digis, DTuROSFEDData &fwords)
Definition: DTuROSRawToDigi.cc:81
edm::Event
Definition: Event.h:73
DTuROSROSData::seterror
void seterror(int error)
Definition: DTuROSControlData.h:49
FEDNumbering::MAXDTUROSFEDID
Definition: FEDNumbering.h:112
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:28
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::InputTag
Definition: InputTag.h:15
DTReadOutMapping.h
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37