CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TTwinMuxRawToDigi.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTTM7FEDReader
4 //
5 // L1 DT TwinMux Raw-to-Digi
6 //
7 //
8 //
9 // Author :
10 // C. F. Bedoya - CIEMAT
11 // G. Codispoti -- INFN Bologna
12 // J. Pazzini -- INFN Padova
13 //
14 //--------------------------------------------------
15 
16 #include "L1TTwinMuxRawToDigi.h"
17 
21 
22 #include <iostream>
23 #include <fstream>
24 
26 
27  debug_( pset.getUntrackedParameter<bool>("debug", false) ),
28  nfeds_(0),
29  DTTM7InputTag_( pset.getParameter<edm::InputTag>("DTTM7_FED_Source") ),
30  feds_( pset.getUntrackedParameter<std::vector<int> >("feds", std::vector<int>()) ),
31  wheels_( pset.getUntrackedParameter<std::vector<int> >("wheels", std::vector<int>())),
32  amcsecmap_( pset.getUntrackedParameter<std::vector<long long int> >("amcsecmap", std::vector<long long int>()))
33 
34 {
35 
36  produces<L1MuDTChambPhContainer>("PhIn").setBranchAlias("PhIn");
37  produces<L1MuDTChambThContainer>("ThIn").setBranchAlias("ThIn");
38  produces<L1MuDTChambPhContainer>("PhOut").setBranchAlias("PhOut");
39 
40  Raw_token = consumes<FEDRawDataCollection> (DTTM7InputTag_);
41 
42  nfeds_ = feds_.size();
43 
44  if ( nfeds_ != wheels_.size() )
45  throw cms::Exception("TwinMux_unpacker") << "Configuration file error. Size of \'wheels\' and \'feds\' differs.\n";
46 
47  if ( amcsecmap_.size() != wheels_.size() )
48  throw cms::Exception("TwinMux_unpacker") << "Configuration file error. Size of \'wheels\' and \'amcsecmap\' differs.\n";
49 
50  for (size_t wh_i = 0; wh_i < amcsecmap_.size(); ++wh_i){
51  std::array<short, 12> whmap;
52  for (size_t amc_i = 1; amc_i < 13; ++amc_i ){
53  short shift = (12-amc_i)*4;
54  whmap[amc_i-1] = ( amcsecmap_[wh_i] >> shift ) & 0xF;
55  }
56  amcsec_.push_back(whmap);
57  }
58 
59 }
60 
62 
64  const edm::EventSetup& c) {
65 
66  std::auto_ptr<L1MuDTChambPhContainer> TM7phi_product(new L1MuDTChambPhContainer);
67  std::auto_ptr<L1MuDTChambThContainer> TM7the_product(new L1MuDTChambThContainer);
68  std::auto_ptr<L1MuDTChambPhContainer> TM7phi_out_product(new L1MuDTChambPhContainer);
69 
73 
74  if ( !fillRawData(e, phi_data, the_data, phi_out_data) ) return;
75 
76  TM7phi_product->setContainer(phi_data);
77  TM7the_product->setContainer(the_data);
78  TM7phi_out_product->setContainer(phi_out_data);
79 
80  e.put(TM7phi_product, "PhIn");
81  e.put(TM7the_product, "ThIn");
82  e.put(TM7phi_out_product, "PhOut");
83 
84 }
85 
86 
91 
93  e.getByToken( Raw_token, data );
94 
95  for ( size_t w_i = 0; w_i < nfeds_; ++w_i ) {
96  processFed( feds_[w_i], wheels_[w_i], amcsec_[w_i], data, phi_data, the_data, phi_out_data );
97  }
98 
99  return true;
100 }
101 
103  int bxCnt_ ){
104 
105  int bxNorm_ = bx_ - bxCnt_;
106  if ( abs( bxNorm_ ) < 3000 ) return bxNorm_;
107 
108  if ( bxNorm_ > 0 ) return bxNorm_ - 3564;
109  if ( bxNorm_ < 0 ) return bxNorm_ + 3564;
110 
111  return -99;
112 
113 }
114 
116 
117  if (radAng_>2047)
118  return radAng_-4096;
119 
120  return radAng_;
121 
122 }
123 
125 
126  if (benAng_>511)
127  return benAng_-1024;
128 
129  return benAng_;
130 
131 }
132 
133 void L1TTwinMuxRawToDigi::processFed( int twinMuxFed,
134  int twinMuxWheel,
135  std::array<short, 12> twinMuxAmcSec,
139  L1MuDTChambPhContainer::Phi_Container& phioutSegments ) {
140 
142  std::vector<long> DTTM7WordContainer;
143 
145  std::ofstream logfile;
146  if ( debug_ ) {
147  std::ostringstream fname;
148  fname << "eventDump_" << twinMuxFed << ".txt";
149  logfile.open( fname.str() );
150  }
151 
153  FEDRawData TM7data = data->FEDData(twinMuxFed);
154  if ( TM7data.size() == 0 ) return;
155 
157  LineFED_ = TM7data.data();
158  int nline = 0; // counting already include header
159  long dataWord = 0;
160  int newCRC = 0xFFFF;
161 
163  readline( nline, dataWord );
164  calcCRC( dataWord, newCRC );
165 
166  int TM7fedId = ( dataWord >> 8 ) & 0xFFF; // positions 8 -> 19
167  /*** NOT UNPACKED
168  int bunchCnt = ( dataWord >> 20 ) & 0xFFF; // positions 20 -> 31
169  int eventCnt = ( dataWord >> 32 ) & 0xFFFFFF; // positions 32 -> 55
170  ***/
171  int BOEevTy = ( dataWord >> 60 ) & 0xF; // positions 60 -> 63
172 
173  int linecounter = 0;
174  if ( debug_ ) logfile << '[' << ++linecounter << "]\t"
175  << std::hex << dataWord << std::dec << "\t|\t"
176  << "BOEevTy " << BOEevTy << '\t'
177  << "TM7fedId " << TM7fedId << '\n';
178 
179  if ( (BOEevTy != 0x5) || ( TM7fedId != twinMuxFed ) ) {
180 
181  edm::LogWarning("TwinMux_unpacker") << "Not a TM7 of FED "
182  << twinMuxFed << " header "
183  << std::hex << dataWord;
184  return;
185 
186  }
187 
189  readline( nline, dataWord );
190  calcCRC( dataWord, newCRC );
191 
192  std::map<int, int> AMCsizes;
193  /*** NOT UNPACKED
194  int orbit = ( dataWord >> 4 ) & 0xFFFFFFFF; // positions 4 -> 35
195  ***/
196  int nAMC = ( dataWord >> 52 ) & 0xF; // positions 52 -> 55
197 
198  if ( debug_ ) logfile << '[' << ++linecounter << "]\t" << std::hex
199  << dataWord << std::dec << "\t|\t"
200  << "nAMC " << nAMC << '\n';
201 
203  for ( int j = 0; j < nAMC; ++j ) {
204 
205  readline( nline, dataWord );
206  calcCRC( dataWord, newCRC );
207 
208  int AMCno = (dataWord >> 16 ) & 0xF; // positions 16 -> 19
209  /*** NOT UNPACKED
210  int TM7boardID = dataWord & 0xFFFF; // positions 0 -> 15
211  int bulkno = (dataWord >> 20 ) & 0xFF; // positions 20 -> 27
212  ***/
213  if ( (AMCno < 1) || (AMCno > 12) ) {
214  edm::LogWarning("TwinMux_unpacker") << "AMCnumber " << std::dec << AMCno
215  << " out of range (1-12)";
216  return;
217  }
218 
219  AMCsizes[AMCno] = ( dataWord >> 32 ) & 0xFFFFFF; // positions 32 -> 55
220 
221  if ( debug_ ) logfile << '[' << ++linecounter << "]\t"
222  << std::hex << dataWord
223  << std::dec << "\t|\t"
224  << "AMCsizes[" << AMCno << "] "
225  << AMCsizes[AMCno]
226  << std::dec << '\n';
227  }
228 
230  std::map<int,int>::iterator AMCiterator = AMCsizes.begin();
231  std::map<int,int>::iterator AMCitend = AMCsizes.end();
232  for ( ; AMCiterator != AMCitend; ++AMCiterator ) {
233 
234  for ( int k=0; k<AMCiterator->second; ++k) {
235 
236  readline( nline, dataWord );
237  calcCRC( dataWord, newCRC);
238  DTTM7WordContainer.push_back( dataWord );
239  }
240  }
241 
243  readline( nline, dataWord );
244  calcCRC( dataWord, newCRC);
245 
247 
248  readline( nline, dataWord );
249  calcCRC( dataWord & 0xFFFFFFFF0000FFFF, newCRC);
250 
252  int chkEOE = (dataWord >> 60 ) & 0xF; // positions 60 -> 63
253  int CRC = ( dataWord >> 16 ) & 0xFFFF; // positions 17 ->32
254  int evtLgth = ( dataWord >> 32 ) & 0xFFFFFF; // positions 33 ->56
255 
256  if ( chkEOE != 0xA ) {
257  edm::LogWarning("TwinMux_unpacker") << "AMC block closing line " << std::hex << dataWord
258  << std::dec << " does not start with 0xA";
259  return;
260  }
261 
262  if ( debug_ ) logfile << "\tevtLgth " << std::hex
263  << evtLgth << "\tCRC " << CRC << std::dec << '\n';
264 
265  if ( nline != evtLgth ) {
266  edm::LogWarning("TwinMux_unpacker") << "Number of words read " << std::dec << nline
267  << " and event length " << std::dec << evtLgth
268  << " differ ";
269  return;
270  }
271 
272  if ( newCRC != CRC ) {
273  edm::LogWarning("TwinMux_unpacker") << "Calculated CRC " << std::hex << newCRC
274  << " differs from CRC in trailer " << std::hex << CRC;
275  return;
276  }
277 
278  // --> Analyze event
279  std::vector<long>::iterator DTTM7iterator = DTTM7WordContainer.begin();
280  std::vector<long>::iterator DTTM7itend = DTTM7WordContainer.end();
281 
282  int lcounter = 0;
283  for ( ; DTTM7iterator != DTTM7itend; ++DTTM7iterator ) {
284 
285  dataWord = (*DTTM7iterator);
286  int dataLenght = (dataWord & 0xFFFFF); // positions 0 -> 19
287  int bxCounter = (dataWord >> 20 ) & 0xFFF; // positions 20 -> 31
288  int event = (dataWord >> 32 ) & 0xFFFFFF; // positions 32 -> 55
289  int AMC_ID = (dataWord >> 56 ) & 0xF; // positions 56 -> 59
290  int control = (dataWord >> 60 ) & 0xF; // positions 59 -> 63
291  int wheel = twinMuxWheel;
292 
293  if( ( AMC_ID < 1 ) or ( AMC_ID > 12 ) ) {
294  edm::LogWarning("TwinMux_unpacker") << "%%%%%% AMC_ID OUT OF RANGE \n"
295  << " TM7fedId " << TM7fedId
296  << " AMC_ID " << AMC_ID;
297  break;
298  }
299 
300  int sector = twinMuxAmcSec[AMC_ID-1];
301 
302  if( ( sector < 1 ) or ( sector > 12 ) ) {
303  if( sector != 15 ) edm::LogWarning("TwinMux_unpacker") << "%%%%%% VALID AMC_ID POINTS TO SECTOR OUT OF RANGE \n"
304  << " TM7fedId " << TM7fedId
305  << " AMC_ID " << AMC_ID
306  << " wheel " << wheel
307  << " sector " << sector;
308  break;
309  }
310 
311  if ( debug_ ) logfile << '[' << ++lcounter << "]\t"
312  << std::hex << dataWord << std::dec << "\t|\t"
313  << "AMC_ID " << AMC_ID << '\t'
314  << "control " << control << '\t'
315  << "event " << event << '\t'
316  << "bxCounter " << bxCounter << '\t'
317  << "dataLenght " << dataLenght << '\n';
318 
319  ++DTTM7iterator; // User word empty /// ==>> increment 2
320  if( DTTM7iterator == DTTM7itend ) {
321  edm::LogInfo("TwinMux_unpacker") << "TRAILING WORD AS A PAYLOAD END in FED "
322  << std::hex << TM7fedId
323  << std::hex << dataWord
324  << std::dec<< " [it pos "
325  << int(DTTM7iterator - DTTM7itend) << " ]";
326  break;
327  }
328 
329  dataWord = (*DTTM7iterator);
330  int boardID = (dataWord & 0xFFFF); // positions 0 -> 15
331  int orbit = (dataWord >> 16 ) & 0xFFFF; // positions 15 -> 32
332 
333  if ( DTTM7iterator == DTTM7itend ) {
334  edm::LogWarning("TwinMux_unpacker") << "%%%%%% AMC_ID " << AMC_ID
335  << " control " << control
336  << " event " << event
337  << " bxCounter " << bxCounter
338  << " size " << dataLenght
339  << " orbit " << orbit
340  << " board " << boardID
341  << " AMCsizes " << AMCsizes[AMC_ID]
342  << " it pos " << int(DTTM7iterator - DTTM7itend);
343  break;
344  }
345 
346  if (debug_ ) logfile << '[' << ++lcounter << "]\t"
347  << std::hex << dataWord
348  << std::dec << "\t|\t"
349  << " orbit " << orbit
350  << " board " << boardID << '\n';
351 
352  int AMCsize = AMCsizes[AMC_ID] - 1;
353  int bxID = 99;
354  int bc0 = -99;
355  int bxNr = -99;
356 
358  for ( int tm7eventsize = 2; tm7eventsize < AMCsize; ++tm7eventsize ) {
359 
360  ++DTTM7iterator;
361  if ( DTTM7iterator == DTTM7itend ) {
362 
363  edm::LogWarning("TwinMux_unpacker") << "UNEXPECTED END OF PAYLOAD INSIDE CHAMBER DESCRIPTION"
364  << " [it pos " << int(DTTM7iterator - DTTM7itend) << " ]" ;
365  break;
366 
367  }
368 
369  long dataWordSub = (*DTTM7iterator);
370  int selector = ( dataWordSub >> 60 ) & 0xF; // positions 60 -> 63
371 
372  if ( selector == 0x4 ) { //TSC word
373 
374  bxID = ( dataWordSub >> 48 ) & 0xFFF; // positions 48 -> 60
375  bc0 = ( dataWordSub >> 22 ) & 0x1; // positions 22 -> 23
376  bxNr = normBx(bxID, bxCounter);
377 
378  if ( debug_ ) logfile << '[' << ++lcounter << "]\t" << std::hex
379  << dataWordSub << std::dec
380  << "\t TSC WORD\t"
381  << "bxID " << bxID << '\t'
382  << "bc0 " << bc0 << '\n';
383 
384  }//TSC WORD
385 
386  else if ( selector == 0x1 ) { //MB1/2 word
387 
388  int mb2_phi = ( dataWordSub & 0xFFF); // positions 0 -> 11
389  int mb2_phib = ( dataWordSub >> 12 ) & 0x3FF; // positions 12 -> 21
390  int mb2_qual = ( dataWordSub >> 22 ) & 0x7; // positions 22 -> 24
391  int mb2_ts2tag = ( dataWordSub >> 28 ) & 0x1; // positions 28
392  /*** NOT UNPACKED
393  int mb2_parity = ( dataWordSub >> 29) & 0x1; // positions 29
394  ***/
395 
396  int mb1_phi = ( dataWordSub >> 30 ) & 0xFFF; // positions 30 -> 41
397  int mb1_phib = ( dataWordSub >> 42 ) & 0x3FF; // positions 42 -> 51
398  int mb1_qual = ( dataWordSub >> 52 ) & 0x7; // positions 52 -> 54
399  int mb1_ts2tag = ( dataWordSub >> 58 ) & 0x1; // positions 58
400  /*** NOT UNPACKED
401  int mb1_parity = ( dataWordSub >> 59 ) &0x1; // positions 59
402  ***/
403 
404  int mb1_phi_conv = radAngConversion(mb1_phi);
405  int mb1_phib_conv = benAngConversion(mb1_phib);
406 
407  int mb2_phi_conv = radAngConversion(mb2_phi);
408  int mb2_phib_conv = benAngConversion(mb2_phib);
409 
410  phiSegments.push_back( L1MuDTChambPhDigi( bxNr, wheel, sector-1,
411  1, mb1_phi_conv, mb1_phib_conv,
412  mb1_qual, mb1_ts2tag, bxCounter ) );
413  phiSegments.push_back( L1MuDTChambPhDigi( bxNr, wheel, sector-1,
414  2, mb2_phi_conv, mb2_phib_conv,
415  mb2_qual, mb2_ts2tag, bxCounter ) );
416 
417  if ( debug_ ) logfile << '[' << ++lcounter << "]\t"<< std::hex
418  << dataWordSub << std::dec << "\t|\t"
419  << "mb1_ts2tag " << mb1_ts2tag << '\t'
420  << "mb1_qual " << mb1_qual << '\t'
421  << "mb1_phib " << mb1_phib_conv << '\t'
422  << "mb1_phi " << mb1_phi_conv << '\t'
423  << "mb2_ts2tag " << mb2_ts2tag << '\t'
424  << "mb2_qual " << mb2_qual << '\t'
425  << "mb2_phib " << mb2_phib_conv << '\t'
426  << "mb2_phi " << mb2_phi_conv << '\n';
427  }//MB1/2 word
428 
429  else if ( selector == 0x2 ) {
430 
431  int mb4_phi = ( dataWordSub & 0xFFF); // positions 0 -> 11
432  int mb4_phib = ( dataWordSub >> 12 ) & 0x3FF; // positions 12 -> 21
433  int mb4_qual = ( dataWordSub >> 22 ) & 0x7; // positions 22 -> 24
434  int mb4_ts2tag = ( dataWordSub >> 28 ) & 0x1; // positions 28
435  /*** NOT UNPACKED
436  int mb4_parity = ( dataWordSub >> 29) & 0x1; // positions 29
437  ***/
438 
439  int mb3_phi = ( dataWordSub >> 30 ) & 0xFFF; // positions 30 -> 41
440  int mb3_phib = ( dataWordSub >> 42 ) & 0x3FF; // positions 42 -> 51
441  int mb3_qual = ( dataWordSub >> 52 ) & 0x7; // positions 52 -> 54
442  int mb3_ts2tag = ( dataWordSub >> 58 ) & 0x1; // positions 58
443  /*** NOT UNPACKED
444  int mb3_parity = ( dataWordSub >> 59 ) &0x1; // positions 59
445  ***/
446 
447  int mb3_phi_conv = radAngConversion(mb3_phi);
448  int mb3_phib_conv = benAngConversion(mb3_phib);
449 
450  int mb4_phi_conv = radAngConversion(mb4_phi);
451  int mb4_phib_conv = benAngConversion(mb4_phib);
452 
453  phiSegments.push_back( L1MuDTChambPhDigi( bxNr, wheel, sector-1,
454  3, mb3_phi_conv, mb3_phib_conv,
455  mb3_qual, mb3_ts2tag, bxCounter) );
456  phiSegments.push_back( L1MuDTChambPhDigi( bxNr, wheel, sector-1,
457  4, mb4_phi_conv, mb4_phib_conv,
458  mb4_qual, mb4_ts2tag, bxCounter) );
459 
460  if ( debug_ ) logfile << '[' << ++lcounter << "]\t"<< std::hex
461  << dataWordSub << std::dec << "\t|\t"
462  << "mb3_ts2tag " << mb3_ts2tag << '\t'
463  << "mb3_qual " << mb3_qual << '\t'
464  << "mb3_phib " << mb3_phib_conv << '\t'
465  << "mb3_phi " << mb3_phi_conv << '\t'
466  << "mb4_ts2tag " << mb4_ts2tag << '\t'
467  << "mb4_qual " << mb4_qual << '\t'
468  << "mb4_phib " << mb4_phib_conv << '\t'
469  << "mb4_phi " << mb4_phi_conv << '\n';
470 
471  }//MB3/4 word
472 
473  else if ( selector == 0x3 ) { //etha word
474 
475  int posBTI[7], qualBTI[7];
476 
477  int mb3_eta = ( dataWordSub & 0xFF ); // positions 0 -> 7
478  int mb2_eta = ( dataWordSub >> 16 ) & 0xFF; // positions 16 -> 23
479  int mb1_eta = ( dataWordSub >> 40 ) & 0xFF; // positions 40 -> 47
480 
481  int mb3_eta_HQ = ( dataWordSub >> 8 ) & 0xFF; // positions 8 -> 15
482  int mb2_eta_HQ = ( dataWordSub >> 32 ) & 0xFF; // positions 32 -> 39
483  int mb1_eta_HQ = ( dataWordSub >> 48 ) & 0xFF; // positions 48 -> 55
484 
485  if ( debug_ ) logfile << '[' << ++lcounter << "]\t" << std::hex
486  << dataWordSub << std::dec << "\t|\t"
487  << "mb1_eta " << mb1_eta << '\t'
488  << "mb2_eta " << mb2_eta << '\t'
489  << "mb3_eta " << mb3_eta << '\t'
490  << "mb1_eta_HQ " << mb1_eta_HQ << '\t'
491  << "mb2_eta_HQ " << mb2_eta_HQ << '\t'
492  << "mb3_eta_HQ " << mb3_eta_HQ << '\n';
493 
494  //MB1
495  posBTI[0] = (mb1_eta & 0x01);
496  posBTI[1] = ((mb1_eta & 0x02)>>1);
497  posBTI[2] = ((mb1_eta & 0x04)>>2);
498  posBTI[3] = ((mb1_eta & 0x08)>>3);
499  posBTI[4] = ((mb1_eta & 0x10)>>4);
500  posBTI[5] = ((mb1_eta & 0x20)>>5);
501  posBTI[6] = (((mb1_eta & 0x40)>>6) || ((mb1_eta & 0x80)>>7));
502 
503  qualBTI[0] = (mb1_eta_HQ & 0x01);
504  qualBTI[1] = ((mb1_eta_HQ & 0x02)>>1);
505  qualBTI[2] = ((mb1_eta_HQ & 0x04)>>2);
506  qualBTI[3] = ((mb1_eta_HQ & 0x08)>>3);
507  qualBTI[4] = ((mb1_eta_HQ & 0x10)>>4);
508  qualBTI[5] = ((mb1_eta_HQ & 0x20)>>5);
509  qualBTI[6] = (((mb1_eta_HQ & 0x40)>>6) || ((mb1_eta_HQ & 0x80)>>7));
510 
511  theSegments.push_back( L1MuDTChambThDigi( bxNr, wheel, sector-1, 1, posBTI, qualBTI) );
512 
513  //MB2
514  posBTI[0] = (mb2_eta & 0x01);
515  posBTI[1] = ((mb2_eta & 0x02)>>1);
516  posBTI[2] = ((mb2_eta & 0x04)>>2);
517  posBTI[3] = ((mb2_eta & 0x08)>>3);
518  posBTI[4] = ((mb2_eta & 0x10)>>4);
519  posBTI[5] = ((mb2_eta & 0x20)>>5);
520  posBTI[6] = (((mb2_eta & 0x40)>>6) || ((mb2_eta & 0x80)>>7));
521 
522  qualBTI[0] = (mb2_eta_HQ & 0x01);
523  qualBTI[1] = ((mb2_eta_HQ & 0x02)>>1);
524  qualBTI[2] = ((mb2_eta_HQ & 0x04)>>2);
525  qualBTI[3] = ((mb2_eta_HQ & 0x08)>>3);
526  qualBTI[4] = ((mb2_eta_HQ & 0x10)>>4);
527  qualBTI[5] = ((mb2_eta_HQ & 0x20)>>5);
528  qualBTI[6] = (((mb2_eta_HQ & 0x40)>>6) || ((mb2_eta_HQ & 0x80)>>7));
529 
530  theSegments.push_back( L1MuDTChambThDigi( bxNr, wheel, sector-1, 2, posBTI, qualBTI) );
531 
532  //MB3
533  posBTI[0] = (mb3_eta & 0x01);
534  posBTI[1] = ((mb3_eta & 0x02)>>1);
535  posBTI[2] = ((mb3_eta & 0x04)>>2);
536  posBTI[3] = ((mb3_eta & 0x08)>>3);
537  posBTI[4] = ((mb3_eta & 0x10)>>4);
538  posBTI[5] = ((mb3_eta & 0x20)>>5);
539  posBTI[6] = (((mb3_eta & 0x40)>>6) || ((mb3_eta & 0x80)>>7));
540 
541  qualBTI[0] = (mb3_eta_HQ & 0x01);
542  qualBTI[1] = ((mb3_eta_HQ & 0x02)>>1);
543  qualBTI[2] = ((mb3_eta_HQ & 0x04)>>2);
544  qualBTI[3] = ((mb3_eta_HQ & 0x08)>>3);
545  qualBTI[4] = ((mb3_eta_HQ & 0x10)>>4);
546  qualBTI[5] = ((mb3_eta_HQ & 0x20)>>5);
547  qualBTI[6] = (((mb3_eta_HQ & 0x40)>>6) || ((mb3_eta_HQ & 0x80)>>7));
548 
549  theSegments.push_back( L1MuDTChambThDigi( bxNr, wheel, sector-1, 3, posBTI, qualBTI) );
550 
551  }//etha word
552 
553  else if ( selector == 0xB ) { //MB1/2 output word
554 
555  int mb2_phi = ( dataWordSub & 0xFFF); // positions 0 -> 11
556  int mb2_phib = ( dataWordSub >> 12 ) & 0x3FF; // positions 12 -> 21
557  int mb2_qual = ( dataWordSub >> 22 ) & 0x7; // positions 22 -> 24
558  int mb2_q3 = ( dataWordSub >> 25 ) & 0x1; // positions 25
559  int mb2_q4 = ( dataWordSub >> 26 ) & 0x1; // positions 26
560  int mb2_ts2tag = ( dataWordSub >> 28 ) & 0x1; // positions 28
561  /*** NOT UNPACKED
562  int mb2_parity = ( dataWordSub >> 29) & 0x1; // positions 29
563  ***/
564 
565  int mb1_phi = ( dataWordSub >> 30 ) & 0xFFF; // positions 30 -> 41
566  int mb1_phib = ( dataWordSub >> 42 ) & 0x3FF; // positions 42 -> 51
567  int mb1_qual = ( dataWordSub >> 52 ) & 0x7; // positions 52 -> 54
568  int mb1_q3 = ( dataWordSub >> 55 ) & 0x1; // positions 55
569  int mb1_q4 = ( dataWordSub >> 56 ) & 0x1; // positions 56
570  int mb1_ts2tag = ( dataWordSub >> 58 ) & 0x1; // positions 58
571  /*** NOT UNPACKED
572  int mb1_parity = ( dataWordSub >> 59 ) &0x1; // positions 59
573  ***/
574 
575  int mb1_phi_conv = radAngConversion(mb1_phi);
576  int mb1_phib_conv = benAngConversion(mb1_phib);
577 
578  int mb2_phi_conv = radAngConversion(mb2_phi);
579  int mb2_phib_conv = benAngConversion(mb2_phib);
580 
581  phioutSegments.push_back( L1MuDTChambPhDigi( bxNr, wheel, sector-1,
582  1, mb1_phi_conv, mb1_phib_conv,
583  mb1_qual, mb1_ts2tag, bxCounter, mb1_q3 + 2*mb1_q4 ) );
584  phioutSegments.push_back( L1MuDTChambPhDigi( bxNr, wheel, sector-1,
585  2, mb2_phi_conv, mb2_phib_conv,
586  mb2_qual, mb2_ts2tag, bxCounter, mb2_q3 + 2*mb2_q4 ) );
587 
588  if ( debug_ ) logfile << '[' << ++lcounter << "]\t"<< std::hex
589  << dataWordSub << std::dec << "\t|\t"
590  << "mb1_ts2tag_out " << mb1_ts2tag << '\t'
591  << "mb1_qual_out " << mb1_qual << '\t'
592  << "mb1_q3_out " << mb1_q3 << '\t'
593  << "mb1_q4_out " << mb1_q4 << '\t'
594  << "mb1_phib_out " << mb1_phib_conv << '\t'
595  << "mb1_phi_out " << mb1_phi_conv << '\t'
596  << "mb2_ts2tag_out " << mb2_ts2tag << '\t'
597  << "mb2_qual_out " << mb2_qual << '\t'
598  << "mb2_q3_out " << mb2_q3 << '\t'
599  << "mb2_q4_out " << mb2_q4 << '\t'
600  << "mb2_phib_out " << mb2_phib_conv << '\t'
601  << "mb2_phi_out " << mb2_phi_conv << '\n';
602 
603  }//MB1/2 output word
604 
605 
606  else if ( selector == 0xC ) { //MB3/4 output word
607 
608  int mb4_phi = ( dataWordSub & 0xFFF); // positions 0 -> 11
609  int mb4_phib = ( dataWordSub >> 12 ) & 0x3FF; // positions 12 -> 21
610  int mb4_qual = ( dataWordSub >> 22 ) & 0x7; // positions 22 -> 24
611  int mb4_q3 = ( dataWordSub >> 25 ) & 0x1; // positions 25
612  int mb4_q4 = ( dataWordSub >> 26 ) & 0x1; // positions 26
613  int mb4_ts2tag = ( dataWordSub >> 28 ) & 0x1; // positions 28
614  /*** NOT UNPACKED
615  int mb4_parity = ( dataWordSub >> 29) & 0x1; // positions 29
616  ***/
617 
618  int mb3_phi = ( dataWordSub >> 30 ) & 0xFFF; // positions 30 -> 41
619  int mb3_phib = ( dataWordSub >> 42 ) & 0x3FF; // positions 42 -> 51
620  int mb3_qual = ( dataWordSub >> 52 ) & 0x7; // positions 52 -> 54
621  int mb3_q3 = ( dataWordSub >> 55 ) & 0x1; // positions 55
622  int mb3_q4 = ( dataWordSub >> 56 ) & 0x1; // positions 56
623  int mb3_ts2tag = ( dataWordSub >> 58 ) & 0x1; // positions 58
624  /*** NOT UNPACKED
625  int mb3_parity = ( dataWordSub >> 59 ) &0x1; // positions 59
626  ***/
627 
628  int mb3_phi_conv = radAngConversion(mb3_phi);
629  int mb3_phib_conv = benAngConversion(mb3_phib);
630 
631  int mb4_phi_conv = radAngConversion(mb4_phi);
632  int mb4_phib_conv = benAngConversion(mb4_phib);
633 
634  phioutSegments.push_back( L1MuDTChambPhDigi( bxNr, wheel, sector-1,
635  3, mb3_phi_conv, mb3_phib_conv,
636  mb3_qual, mb3_ts2tag, bxCounter, mb3_q3 + 2*mb3_q4 ) );
637  phioutSegments.push_back( L1MuDTChambPhDigi( bxNr, wheel, sector-1,
638  4, mb4_phi_conv, mb4_phib_conv,
639  mb4_qual, mb4_ts2tag, bxCounter, mb4_q3 + 2*mb4_q4 ) );
640 
641  if ( debug_ ) logfile << '[' << ++lcounter << "]\t"<< std::hex
642  << dataWordSub << std::dec << "\t|\t"
643  << "mb3_ts2tag_out " << mb3_ts2tag << '\t'
644  << "mb3_qual_out " << mb3_qual << '\t'
645  << "mb3_q3_out " << mb3_q3 << '\t'
646  << "mb3_q4_out " << mb3_q4 << '\t'
647  << "mb3_phib_out " << mb3_phib_conv << '\t'
648  << "mb3_phi_out " << mb3_phi_conv << '\t'
649  << "mb4_ts2tag_out " << mb4_ts2tag << '\t'
650  << "mb4_qual_out " << mb4_qual << '\t'
651  << "mb4_q3_out " << mb4_q3 << '\t'
652  << "mb4_q4_out " << mb4_q4 << '\t'
653  << "mb4_phib_out " << mb4_phib_conv << '\t'
654  << "mb4_phi_out " << mb4_phi_conv << '\n';
655 
656  }//MB3/4 output word
657 
658  else if ( selector == 0xD ) { //etha output word
659 
660  if ( debug_ ) logfile << '[' << ++lcounter << "]\t" << std::hex
661  << dataWordSub << std::dec
662  << "\t ETHA OUTPUT WORD\n";
663 
664  }//etha output word
665 
666  else if ( selector == 0x9 || selector == 0xE ) { //RPC word
667 
668  edm::LogInfo("TwinMux_unpacker") << "RPC WORD [" << std::dec << tm7eventsize << "] : "
669  << std::hex << dataWordSub << std::dec
670  << " it pos " << int(DTTM7iterator - DTTM7itend);
671 
672  if ( debug_ ) logfile << '[' << ++lcounter << "]\t" << std::hex
673  << dataWordSub << std::dec
674  << "\t RPC WORD\n";
675 
676  }//RPC word
677 
678  else if ( selector == 0x6 ) { //HO word
679 
680  edm::LogInfo("TwinMux_unpacker") << "HO WORD [" << std::dec << tm7eventsize << "] : "
681  << std::hex << dataWordSub << std::dec
682  << " it pos " << int(DTTM7iterator - DTTM7itend);
683 
684  if ( debug_ ) logfile << '[' << ++lcounter << "]\t" << std::hex
685  << dataWordSub << std::dec
686  << "\t HO WORD\n";
687 
688  }//HO word
689 
690  else if ( selector == 0xF ) { //ERROR word
691 
692  edm::LogInfo("TwinMux_unpacker") << "ERROR WORD [" << std::dec << tm7eventsize << "] : "
693  << std::hex << dataWordSub << std::dec
694  << " it pos " << int(DTTM7iterator - DTTM7itend);
695 
696  if ( debug_ ) logfile << '[' << ++lcounter << "]\t" << std::hex
697  << dataWordSub << std::dec
698  << "\t ERROR WORD\n";
699  }//ERROR word
700 
701  else { //unkown word
702 
703  edm::LogInfo("TwinMux_unpacker") << "UNKNOWN WORD received " << std::hex << dataWordSub
704  << " in FED " << std::hex << TM7fedId;
705 
706  if ( debug_ ) logfile << '[' << ++lcounter << "]\t" << std::hex
707  << dataWordSub << std::dec
708  << "\t UNKNOWN WORD\n";
709  }
710 
711  if( DTTM7iterator == DTTM7itend ) break;
712 
713  } //end of loop over AMCsize
714 
715 
717  ++DTTM7iterator;
718 
719  if( DTTM7iterator == DTTM7itend ) break;
720 
721  } // end for-loop container content
722 
723  return;
724 }
725 
726 
727 
728 void L1TTwinMuxRawToDigi::calcCRC( long word, int & myC ) {
729 
730  int myCRC[16], D[64], C[16];
731 
732  for ( int i = 0; i < 64; ++i ) { D[i] = (word >> i) & 0x1; }
733  for ( int i = 0; i < 16; ++i ) { C[i] = (myC>>i) & 0x1; }
734 
735  myCRC[0] = ( D[63] + D[62] + D[61] + D[60] + D[55] + D[54] +
736  D[53] + D[52] + D[51] + D[50] + D[49] + D[48] +
737  D[47] + D[46] + D[45] + D[43] + D[41] + D[40] +
738  D[39] + D[38] + D[37] + D[36] + D[35] + D[34] +
739  D[33] + D[32] + D[31] + D[30] + D[27] + D[26] +
740  D[25] + D[24] + D[23] + D[22] + D[21] + D[20] +
741  D[19] + D[18] + D[17] + D[16] + D[15] + D[13] +
742  D[12] + D[11] + D[10] + D[9] + D[8] + D[7] +
743  D[6] + D[5] + D[4] + D[3] + D[2] + D[1] +
744  D[0] + C[0] + C[1] + C[2] + C[3] + C[4] +
745  C[5] + C[6] + C[7] + C[12] + C[13] + C[14] +
746  C[15] )%2;
747 
748  myCRC[1] = ( D[63] + D[62] + D[61] + D[56] + D[55] + D[54] +
749  D[53] + D[52] + D[51] + D[50] + D[49] + D[48] +
750  D[47] + D[46] + D[44] + D[42] + D[41] + D[40] +
751  D[39] + D[38] + D[37] + D[36] + D[35] + D[34] +
752  D[33] + D[32] + D[31] + D[28] + D[27] + D[26] +
753  D[25] + D[24] + D[23] + D[22] + D[21] + D[20] +
754  D[19] + D[18] + D[17] + D[16] + D[14] + D[13] +
755  D[12] + D[11] + D[10] + D[9] + D[8] + D[7] +
756  D[6] + D[5] + D[4] + D[3] + D[2] + D[1] +
757  C[0] + C[1] + C[2] + C[3] + C[4] + C[5] +
758  C[6] + C[7] + C[8] + C[13] + C[14] + C[15] )%2;
759 
760  myCRC[2] = ( D[61] + D[60] + D[57] + D[56] + D[46] + D[42] +
761  D[31] + D[30] + D[29] + D[28] + D[16] + D[14] +
762  D[1] + D[0] + C[8] + C[9] + C[12] + C[13] )%2;
763 
764  myCRC[3] = ( D[62] + D[61] + D[58] + D[57] + D[47] + D[43] +
765  D[32] + D[31] + D[30] + D[29] + D[17] + D[15] +
766  D[2] + D[1] + C[9] + C[10] + C[13] + C[14] )%2;
767 
768  myCRC[4] = ( D[63] + D[62] + D[59] + D[58] + D[48] + D[44] +
769  D[33] + D[32] + D[31] + D[30] + D[18] + D[16] +
770  D[3] + D[2] + C[0] + C[10] + C[11] + C[14] +
771  C[15] )%2;
772 
773  myCRC[5] = ( D[63] + D[60] + D[59] + D[49] + D[45] + D[34] +
774  D[33] + D[32] + D[31] + D[19] + D[17] + D[4] +
775  D[3] + C[1] + C[11] + C[12] + C[15] )%2;
776 
777  myCRC[6] = ( D[61] + D[60] + D[50] + D[46] + D[35] + D[34] +
778  D[33] + D[32] + D[20] + D[18] + D[5] + D[4] +
779  C[2] + C[12] + C[13] )%2;
780 
781  myCRC[7] = ( D[62] + D[61] + D[51] + D[47] + D[36] + D[35] +
782  D[34] + D[33] + D[21] + D[19] + D[6] + D[5] +
783  C[3] + C[13] + C[14] )%2;
784 
785  myCRC[8] = ( D[63] + D[62] + D[52] + D[48] + D[37] + D[36] +
786  D[35] + D[34] + D[22] + D[20] + D[7] + D[6] +
787  C[0] + C[4] + C[14] + C[15] )%2;
788 
789  myCRC[9] = ( D[63] + D[53] + D[49] + D[38] + D[37] + D[36] +
790  D[35] + D[23] + D[21] + D[8] + D[7] + C[1] +
791  C[5] + C[15] )%2;
792 
793  myCRC[10] = ( D[54] + D[50] + D[39] + D[38] + D[37] + D[36] +
794  D[24] + D[22] + D[9] + D[8] + C[2] + C[6] )%2;
795 
796  myCRC[11] = ( D[55] + D[51] + D[40] + D[39] + D[38] + D[37] +
797  D[25] + D[23] + D[10] + D[9] + C[3] + C[7] )%2;
798 
799  myCRC[12] = ( D[56] + D[52] + D[41] + D[40] + D[39] + D[38] +
800  D[26] + D[24] + D[11] + D[10] + C[4] + C[8] )%2;
801 
802  myCRC[13] = ( D[57] + D[53] + D[42] + D[41] + D[40] + D[39] +
803  D[27] + D[25] + D[12] + D[11] + C[5] + C[9] )%2;
804 
805  myCRC[14] = ( D[58] + D[54] + D[43] + D[42] + D[41] + D[40] +
806  D[28] + D[26] + D[13] + D[12] + C[6] + C[10] )%2;
807 
808  myCRC[15] = ( D[63] + D[62] + D[61] + D[60] + D[59] + D[54] +
809  D[53] + D[52] + D[51] + D[50] + D[49] + D[48] +
810  D[47] + D[46] + D[45] + D[44] + D[42] + D[40] +
811  D[39] + D[38] + D[37] + D[36] + D[35] + D[34] +
812  D[33] + D[32] + D[31] + D[30] + D[29] + D[26] +
813  D[25] + D[24] + D[23] + D[22] + D[21] + D[20] +
814  D[19] + D[18] + D[17] + D[16] + D[15] + D[14] +
815  D[12] + D[11] + D[10] + D[9] + D[8] + D[7] +
816  D[6] + D[5] + D[4] + D[3] + D[2] + D[1] +
817  D[0] + C[0] + C[1] + C[2] + C[3] + C[4] +
818  C[5] + C[6] + C[11] + C[12] + C[13] + C[14] +
819  C[15] )%2;
820 
821  int tempC = 0x0;
822  for ( int i = 0; i < 16 ; ++i) { tempC = tempC + ( myCRC[i] << i ); }
823  myC = tempC;
824  return;
825 }
826 
827 
828 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
int normBx(int bx_, int bxCnt_)
std::vector< long long int > amcsecmap_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< std::array< short, 12 > > amcsec_
L1TTwinMuxRawToDigi(const edm::ParameterSet &pset)
Constructor.
void processFed(int twinmuxfed, int wheel, std::array< short, 12 > twinMuxAmcSec, edm::Handle< FEDRawDataCollection > data, L1MuDTChambPhContainer::Phi_Container &phi_data, L1MuDTChambThContainer::The_Container &the_data, L1MuDTChambPhContainer::Phi_Container &phi_out_data)
int radAngConversion(int radAng_)
void readline(int &lines, long &dataWord)
bool fillRawData(edm::Event &e, L1MuDTChambPhContainer::Phi_Container &phi_data, L1MuDTChambThContainer::The_Container &the_data, L1MuDTChambPhContainer::Phi_Container &phi_out_data)
Generate and fill FED raw data for a full event.
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
virtual ~L1TTwinMuxRawToDigi()
Destructor.
std::vector< int > feds_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
void produce(edm::Event &e, const edm::EventSetup &c)
Produce digis out of raw data.
std::vector< L1MuDTChambPhDigi > Phi_Container
std::vector< L1MuDTChambThDigi > The_Container
std::vector< int > wheels_
edm::EDGetTokenT< FEDRawDataCollection > Raw_token
edm::InputTag DTTM7InputTag_
int benAngConversion(int benAng_)
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
unsigned char * LineFED_
string fname
main script
void calcCRC(long word, int &myC)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
static unsigned int const shift
volatile std::atomic< bool > shutdown_flag false