CMS 3D CMS Logo

DTuROSDigiToRaw.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTuROSDigiToRaw
4 //
5 // L1 DT uROS Raw-to-Digi
6 //
7 //
8 //
9 // Author :
10 // J. Troconiz - UAM
11 //
12 //
13 //--------------------------------------------------
14 
17 
21 
22 #include <iostream>
23 
25  produces<FEDRawDataCollection>();
26 
27  DTDigiInputTag_ = pset.getParameter<edm::InputTag>("digiColl");
28 
29  debug_ = pset.getUntrackedParameter<bool>("debug", false);
30 
32  feds_.push_back(i);
33 
34  nfeds_ = feds_.size();
35 
36  Raw_token = consumes<DTDigiCollection>(DTDigiInputTag_);
37  mapping_token_ = esConsumes<DTReadOutMapping, DTReadOutMappingRcd>();
38 }
39 
41 
44 
45  if (!fillRawData(e, c, data))
46  return;
47 
48  auto fed_product = std::make_unique<FEDRawDataCollection>(data);
49 
50  e.put(std::move(fed_product));
51 }
52 
54  eventNum = e.id().event();
55 
57  e.getByToken(Raw_token, digis);
58 
60 
61  for (int w_i = 0; w_i < nfeds_; ++w_i) {
62  process(feds_[w_i], digis, mapping, data);
63  }
64 
65  return true;
66 }
67 
68 void DTuROSDigiToRaw::process(int DTuROSFED,
72  clear();
73 
74  //--> DTDigi analysis
75 
77  for (dttax = digis->begin(); dttax != digis->end(); ++dttax) {
78  const DTDigiCollection::Range& dttar = (*dttax).second;
79  const DTLayerId dttal = (*dttax).first;
80  for (DTDigiCollection::const_iterator ta = dttar.first; ta != dttar.second; ++ta) {
81  int wheelId = dttal.wheel();
82  int sectorId = dttal.sector();
83  int stationId = dttal.station();
84  int slId = dttal.superlayer();
85  int layerId = dttal.layer();
86  int cellId = (*ta).wire();
87 
88  int dduId, rosId, robId, tdcId, tdcChannel;
89  if (!mapping->geometryToReadOut(
90  wheelId, stationId, sectorId, slId, layerId, cellId, dduId, rosId, robId, tdcId, tdcChannel)) {
91  int crate = theCRT(dduId, rosId);
92 
93  if (crate != DTuROSFED)
94  continue;
95 
96  int slot = theSLT(dduId, rosId, robId);
97  int link = theLNK(dduId, rosId, robId);
98 
99  int tdcTime = (*ta).countsTDC();
100 
101  bslts[slot - 1]++;
102 
103  int word = ((link & 0x7F) << 21) + ((tdcId & 0x03) << 19) + ((tdcChannel & 0x1F) << 14) + (tdcTime & 0x3FFF);
104 
105  wslts[slot - 1].push_back(word);
106  }
107  }
108  }
109 
110  int lines = 4;
111  int nslts = 0;
112 
113  for (int sltit = 0; sltit < DOCESLOTS; sltit++) {
114  if (bslts[sltit] == 0)
115  continue;
116  nslts += 1;
117  lines += 1;
118 
119  dslts[sltit] = ((bslts[sltit] + 1) / 2) + 5;
120  lines += dslts[sltit];
121  }
122 
123  FEDRawData& dttfdata = data.FEDData(DTuROSFED);
124  dttfdata.resize(lines * 8); // size in bytes
125  unsigned char* lineFED = dttfdata.data();
126 
127  int dataWord1, dataWord2;
128 
129  //--> Header
130 
131  dataWord1 = 0x50000000 + (eventNum & 0xFFFFFF);
132  dataWord2 = (DTuROSFED & 0xFFF) << 8;
133 
134  int newCRC = 0xFFFF;
135  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
136 
137  *((int*)lineFED) = dataWord2;
138  lineFED += 4;
139  *((int*)lineFED) = dataWord1;
140 
141  //--> AMC sizes
142 
143  dataWord1 = (nslts & 0xF) << 20;
144  dataWord2 = 0;
145 
146  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
147 
148  lineFED += 4;
149  *((int*)lineFED) = dataWord2;
150  lineFED += 4;
151  *((int*)lineFED) = dataWord1;
152 
153  for (int sltit = 0; sltit < DOCESLOTS; sltit++) {
154  if (bslts[sltit] == 0)
155  continue;
156 
157  dataWord1 = (dslts[sltit] & 0xFFFFFF);
158  dataWord2 = ((sltit + 1) & 0xF) << 16;
159 
160  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
161 
162  lineFED += 4;
163  *((int*)lineFED) = dataWord2;
164  lineFED += 4;
165  *((int*)lineFED) = dataWord1;
166  }
167 
168  //--> AMC data
169 
170  for (int sltit = 0; sltit < DOCESLOTS; sltit++) {
171  if (bslts[sltit] == 0)
172  continue;
173 
174  dataWord1 = ((sltit + 1) & 0xF) << 24;
175  dataWord2 = 0;
176 
177  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
178 
179  lineFED += 4;
180  *((int*)lineFED) = dataWord2;
181  lineFED += 4;
182  *((int*)lineFED) = dataWord1;
183 
184  dataWord1 = 0;
185  dataWord2 = 0;
186 
187  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
188 
189  lineFED += 4;
190  *((int*)lineFED) = dataWord2;
191  lineFED += 4;
192  *((int*)lineFED) = dataWord1;
193 
194  for (int nhit = 0; nhit < bslts[sltit] / 2; nhit++) {
195  dataWord1 = 0x20000000 + wslts[sltit].at(nhit * 2);
196  dataWord2 = wslts[sltit].at(nhit * 2 + 1);
197 
198  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
199 
200  lineFED += 4;
201  *((int*)lineFED) = dataWord2;
202  lineFED += 4;
203  *((int*)lineFED) = dataWord1;
204  }
205 
206  if (bslts[sltit] % 2 == 1) {
207  dataWord1 = 0x20000000 + wslts[sltit].at(bslts[sltit] - 1);
208  dataWord2 = 0x1FFFFFFF;
209 
210  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
211 
212  lineFED += 4;
213  *((int*)lineFED) = dataWord2;
214  lineFED += 4;
215  *((int*)lineFED) = dataWord1;
216  }
217 
218  dataWord1 = 0x40000000;
219  dataWord2 = 0;
220 
221  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
222 
223  lineFED += 4;
224  *((int*)lineFED) = dataWord2;
225  lineFED += 4;
226  *((int*)lineFED) = dataWord1;
227 
228  dataWord1 = 0x40000000;
229  dataWord2 = 0;
230 
231  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
232 
233  lineFED += 4;
234  *((int*)lineFED) = dataWord2;
235  lineFED += 4;
236  *((int*)lineFED) = dataWord1;
237 
238  dataWord1 = 0;
239  dataWord2 = (dslts[sltit] & 0xFFFFF);
240 
241  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
242 
243  lineFED += 4;
244  *((int*)lineFED) = dataWord2;
245  lineFED += 4;
246  *((int*)lineFED) = dataWord1;
247  }
248 
249  //--> Trailer - line 1
250 
251  dataWord1 = 0;
252  dataWord2 = 0;
253 
254  dt_crc::calcCRC(dataWord1, dataWord2, newCRC);
255 
256  lineFED += 4;
257  *((int*)lineFED) = dataWord2;
258  lineFED += 4;
259  *((int*)lineFED) = dataWord1;
260 
261  //--> Trailer - line 2
262 
263  dataWord1 = 0xA0000000 + (lines & 0xFFFFFF);
264  dataWord2 = 0;
265 
266  dt_crc::calcCRC(dataWord1, dataWord2 & 0xFFFF, newCRC);
267 
268  dataWord2 += (newCRC & 0xFFFF) << 16;
269 
270  lineFED += 4;
271  *((int*)lineFED) = dataWord2;
272  lineFED += 4;
273  *((int*)lineFED) = dataWord1;
274 
275  return;
276 }
277 
279  for (int sltit = 0; sltit < DOCESLOTS; sltit++) {
280  bslts[sltit] = 0;
281  dslts[sltit] = 0;
282  wslts[sltit].clear();
283  }
284 
285  return;
286 }
287 
288 int DTuROSDigiToRaw::theCRT(int ddu, int ros) {
289  if (ros > 6 && ddu > 774)
290  ddu = ddu - 5;
291 
292  if (ddu == 770)
294  else if (ddu == 771)
296  else if (ddu == 772)
297  return FEDNumbering::MINDTUROSFEDID + 1;
299 }
300 
301 int DTuROSDigiToRaw::theSLT(int ddu, int ros, int rob) {
302  if (ros > 6 && ddu > 774)
303  ddu = ddu - 5;
304 
305  int slot = ((ros - 1) / 3) + 1;
306  if (rob == 23)
307  slot = 5;
308  if (ddu == 771)
309  slot += 6;
310  else if (ddu == 774)
311  slot += 6;
312  return slot;
313 }
314 
315 int DTuROSDigiToRaw::theLNK(int ddu, int ros, int rob) {
316  int link = rob;
317  if (rob > 14)
318  link = rob + 1;
319  if (rob == 24)
320  link = 15;
321  link += ((ros - 1) % 3) * 24;
322  if (rob == 23)
323  link = ros - 1;
324  return link;
325 }
326 
mps_fire.i
i
Definition: mps_fire.py:428
DTuROSDigiToRaw::theLNK
int theLNK(int ddu, int ros, int rob)
Definition: DTuROSDigiToRaw.cc:315
MessageLogger.h
DTuROSDigiToRaw::dslts
int dslts[DOCESLOTS]
Definition: DTuROSDigiToRaw.h:62
MainPageGenerator.link
link
Definition: MainPageGenerator.py:271
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
DTuROSDigiToRaw::nfeds_
int nfeds_
Definition: DTuROSDigiToRaw.h:58
DTROChainCoding.h
DTSuperLayerId::superlayer
int superlayer() const
Return the superlayer number (deprecated method name)
Definition: DTSuperLayerId.h:42
DTuROSDigiToRaw::fillRawData
bool fillRawData(edm::Event &e, const edm::EventSetup &c, FEDRawDataCollection &data)
Generate and fill FED raw data for a full event.
Definition: DTuROSDigiToRaw.cc:53
edm::Handle< DTDigiCollection >
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
MuonDigiCollection::const_iterator
std::vector< DigiType >::const_iterator const_iterator
Definition: MuonDigiCollection.h:94
FEDRawData
Definition: FEDRawData.h:19
DTuROSDigiToRaw::Raw_token
edm::EDGetTokenT< DTDigiCollection > Raw_token
Definition: DTuROSDigiToRaw.h:86
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
MakerMacros.h
DTuROSDigiToRaw.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ESHandle< DTReadOutMapping >
DTuROSDigiToRaw::feds_
std::vector< int > feds_
Definition: DTuROSDigiToRaw.h:60
DTuROSDigiToRaw::debug_
bool debug_
Definition: DTuROSDigiToRaw.h:56
DTLayerId
Definition: DTLayerId.h:12
DTCRC.h
edm::ParameterSet
Definition: ParameterSet.h:47
groupFilesInBlocks.lines
lines
Definition: groupFilesInBlocks.py:95
DTuROSDigiToRaw::DTuROSDigiToRaw
DTuROSDigiToRaw(const edm::ParameterSet &pset)
Constructor.
Definition: DTuROSDigiToRaw.cc:24
DTuROSDigiToRaw::mapping_token_
edm::ESGetToken< DTReadOutMapping, DTReadOutMappingRcd > mapping_token_
Definition: DTuROSDigiToRaw.h:87
DTuROSDigiToRaw::process
void process(int DTuROSFED, edm::Handle< DTDigiCollection > digis, edm::ESHandle< DTReadOutMapping > mapping, FEDRawDataCollection &data)
Definition: DTuROSDigiToRaw.cc:68
DOCESLOTS
static const int DOCESLOTS
Definition: DTuROSControlData.h:19
DTuROSDigiToRaw::bslts
int bslts[DOCESLOTS]
Definition: DTuROSDigiToRaw.h:62
edm::EventSetup
Definition: EventSetup.h:58
DTuROSDigiToRaw
Definition: DTuROSDigiToRaw.h:37
DTChamberId::sector
int sector() const
Definition: DTChamberId.h:49
eostools.move
def move(src, dest)
Definition: eostools.py:511
dt_crc::calcCRC
void calcCRC(long, int &)
Definition: DTCRC.cc:3
DTWireId.h
DTuROSDigiToRaw::theSLT
int theSLT(int ddu, int ros, int rob)
Definition: DTuROSDigiToRaw.cc:301
DTuROSDigiToRaw::theCRT
int theCRT(int ddu, int ros)
Definition: DTuROSDigiToRaw.cc:288
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
DTuROSDigiToRaw::DTDigiInputTag_
edm::InputTag DTDigiInputTag_
Definition: DTuROSDigiToRaw.h:54
DTuROSDigiToRaw::eventNum
unsigned int eventNum
Definition: DTuROSDigiToRaw.h:52
MuonDigiCollection::Range
std::pair< const_iterator, const_iterator > Range
Definition: MuonDigiCollection.h:95
DTuROSDigiToRaw::clear
void clear()
Definition: DTuROSDigiToRaw.cc:278
DTuROSDigiToRaw::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Produce digis out of raw data.
Definition: DTuROSDigiToRaw.cc:42
DTuROSDigiToRaw::wslts
std::vector< int > wslts[DOCESLOTS]
Definition: DTuROSDigiToRaw.h:64
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
DTuROSDigiToRaw::~DTuROSDigiToRaw
~DTuROSDigiToRaw() override
Destructor.
Definition: DTuROSDigiToRaw.cc:40
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
DigiContainerIterator
Definition: MuonDigiCollection.h:30
edm::Event
Definition: Event.h:73
DTLayerId::layer
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
FEDNumbering::MAXDTUROSFEDID
Definition: FEDNumbering.h:112
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:29
DTChamberId::wheel
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
edm::InputTag
Definition: InputTag.h:15
DTChamberId::station
int station() const
Return the station number.
Definition: DTChamberId.h:42
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37