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