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