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