CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TCCBlockFormatter.cc
Go to the documentation of this file.
1 #include <memory>
2 
4 
6 
8 
10 
11 
12 using namespace std;
13 
14 
16 
17  AllTPsamples_ = false;
18 }
19 
21 
22 }
23 
25  FEDRawData& rawdata, const EcalElectronicsMapping* TheMapping)
26 {
27 
28  if (debug_) cout << "enter in TCCBlockFormatter::DigiToRaw " << endl;
29 
30  int HEADER_SIZE = 8 * 9;
31  int bx = *pbx_;
32  int lv1 = *plv1_;
33 
34 
35  const EcalTrigTowerDetId& detid = trigprim.id();
36 
37  if ( (detid.subDet() == EcalBarrel) && (! doBarrel_) ) return;
38  if ( (detid.subDet() == EcalEndcap) && (! doEndCap_) ) return;
39 
40  int iDCC = TheMapping -> DCCid(detid);
41  int TCCid = TheMapping -> TCCid(detid);
42 
43 
44  if (TCCid < EcalElectronicsMapping::MIN_TCCID || TCCid > EcalElectronicsMapping::MAX_TCCID)
45  cout << "Wrong TCCid in TCCBlockFormatter::DigiToRaw " << endl;
46  bool IsEndCap = ( (EcalElectronicsId::MIN_DCCID_EEM <= iDCC && iDCC <= EcalElectronicsId::MAX_DCCID_EEM) ||
48 
49  int FEDid = FEDNumbering::MINECALFEDID + iDCC;
50 
51  // note: row is a 64 bit word
52  int NTT_max = 68; // Barrel case
53  int Nrows_TCC = 17; // Barrel case (without the header row)
54  int NTCC = 1; // Barrel case; number of TCC blocks
55  int itcc_block = 1; // Barrel case
56 
57  if (IsEndCap) {
58  Nrows_TCC = 8; // one row is a 64 bit word
59  NTCC = 4; // 4 TTC in EndCap case. Use some custom numbering since
60  int pair = TCCid % 2; // the TCCid is written to the RawData.
61  int inner = ( detid.ietaAbs() >= 22) ? 1 : 0;
62  itcc_block = 2 * pair + inner + 1;
63  if (inner == 1) NTT_max = 28;
64  else NTT_max = 16;
65  }
66 
67 
68  int nsamples = trigprim.size();
69  if (! AllTPsamples_) nsamples = 1;
70 
71  int iTT = TheMapping -> iTT(detid); // number of tp inside a fed
72  if (debug_) cout << "This is a TrigTower iDCC iTT iTCCBlock TCCid " << dec <<
73  iDCC << " " << iTT << " " << itcc_block << " " << TCCid << endl;
74  if (debug_) cout << "ieta iphi " << dec << detid.ieta() << " " << detid.iphi() << endl;
75  if (iTT <= 0 || iTT > NTT_max) {
76  cout << "invalid iTT " << iTT << endl;
77  return;
78  }
79 
80  int FE_index;
81 
82  // rawdata points to the block which will be built for TCC data
83  if ((int)rawdata.size() != HEADER_SIZE) {
84  FE_index = rawdata.size() / 8 - NTCC*(Nrows_TCC+1); // as far as raw data have been generated
85  FE_index ++; // infer position in TCC block
86  if (debug_) cout << "TCCid already there. FE_index = " << FE_index << endl;
87  }
88  else {
89  if (debug_) cout << "New TTCid added on Raw data, TTCid = " << dec << TCCid << " 0x" << hex << TCCid << endl;
90  FE_index = rawdata.size() / 8; // size in unites of 64 bits word
91  int fe_index = FE_index;
92  for (int iblock=0; iblock < NTCC; iblock++) { // do this once per fed in EB, four times in EE
93  rawdata.resize (rawdata.size() + 8);
94  unsigned char* ppData = rawdata.data(); // use this to navigate and create the binary
95  ppData[8*fe_index] = TCCid & 0xFF; // fed_index increases in units of bytes
96  ppData[8*fe_index+2] = bx & 0xFF; // bx takes bits 0-11: 0-7+8-11
97  ppData[8*fe_index+3] = (bx & 0xF00)>>8;
98  ppData[8*fe_index+3] |= 0x60;
99  ppData[8*fe_index+4] = lv1 & 0xFF; // same game done for lv1, which takes bits 0-11: 0-7+8-11
100  ppData[8*fe_index+5] = (lv1 & 0xF00)>>8; // lv1
101  ppData[8*fe_index+6] = NTT_max;
102  ppData[8*fe_index+6] |= ((nsamples & 0x1)<<7); // nsamples: number time samples
103  ppData[8*fe_index+7] = ((nsamples & 0xE)>>1);
104  ppData[8*fe_index+7] |= 0x60;
105  if (iblock == 0) FE_index ++;
106  fe_index += Nrows_TCC+1;
107  rawdata.resize (rawdata.size() + 8*Nrows_TCC); // 17 lines of TPG data in EB, 8 in EE
108  }
109  if (debug_) cout << "Added headers and empty lines : " << endl;
110  if (debug_) print(rawdata);
111 
112  // -- put the B011 already, since for Endcap there can be empty
113  // -- lines in the TCC and the SRP blocks
114  unsigned char* ppData = rawdata.data();
115  for (int iline=FE_index-1; iline < FE_index + (Nrows_TCC+1)*NTCC -1 ; iline++) {
116  ppData[8*iline + 7] |= 0x60;
117  ppData[8*iline + 3] |= 0x60;
118  }
119  }
120 
121  unsigned char* pData = rawdata.data();
122 
123  // -- Now the TCC Block :
124 
125  int jTT = (iTT-1); // jTT is the TP number insided a block;
126  int irow = jTT/4 + (itcc_block-1)*(Nrows_TCC+1); // you fit 4 TP's per row; move forward if you're not in the first block;
127  int ival = jTT % 4; // for each block you have to skip, move of (Nrows_TCC +1) - 1 is for the TCC header
128 
129  // RTC required TP's tp follow global phi also in EB+, thus swap them inside the single TCC
130  // here you could swap ival -> 3-ival to swap phi insied EB+ supermodules
131  if(NUMB_SM_EB_PLU_MIN <= iDCC && iDCC <= NUMB_SM_EB_PLU_MAX)
132  {ival = 3-ival;}
133 
134  FE_index += irow; // ival is location inside a TP row; varies between 0-3
135 
136  if (debug_) cout << "Now add tower " << dec << iTT << " irow ival " << dec << irow << " " << dec << ival << endl;
137  if (debug_) cout << "new data will be added at line " << dec << FE_index << endl;
138 
139  int fg = trigprim.fineGrain();
140  int et = trigprim.compressedEt();
141  int ttflag = trigprim.ttFlag();
142 
143  if (debug_ && (ttflag != 0)) {
144  cout << "in TCCBlock : this tower has a non zero flag" << endl;
145  cout << "Fedid iTT flag " << dec << FEDid << " " << iTT << " " << "0x" << hex << ttflag << endl;
146  }
147  pData[8*FE_index + ival*2] = et & 0xFF; // ival is location inside a TP row; varies between 0-3; tp goes in bits 0-7
148  pData[8*FE_index + ival*2+1] = (ttflag<<1) + (fg&0x1); // fg follows in bit 8; ttfg is in bits 9-11
149  if (IsEndCap) {
150  // re-write the TCCid and N_Tower_Max :
151  int ibase = 8*(FE_index - (int)(jTT/4) -1);
152  pData[ibase] = TCCid & 0xFF;
153  pData[ibase+6] = NTT_max;
154  pData[ibase+6] |= ((nsamples & 0x1)<<7);
155  pData[ibase+7] |= ((nsamples & 0xE)>>1);
156  }
157  if (debug_) cout << "pData[8*FE_index + ival*2+1] = " << hex << (int)pData[8*FE_index + ival*2+1] << endl;
158  if (debug_) cout << "ttflag ttflag<<1 " << hex << ttflag << " " << hex << (ttflag<<1) << endl;
159  if (debug_) cout << "fg&0x1 " << hex << (fg&0x1) << endl;
160  if (debug_) cout << "sum " << hex << ( (ttflag<<1) + (fg&0x1) ) << endl;
161  if (ival %2 == 1) pData[8*FE_index + ival*2+1] |= 0x60;
162  if (debug_) cout << "ttflag et fgbit " << hex << ttflag << " " << hex << et << " " << hex << fg << endl;
163  if (debug_) print(rawdata);
164 
165 
166 }
167 
168 
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
int ieta() const
get the tower ieta
int compressedEt() const
get the encoded/compressed Et of interesting sample
int ietaAbs() const
get the absolute value of the tower ieta
void resize(size_t newsize)
Definition: FEDRawData.cc:32
void DigiToRaw(const EcalTriggerPrimitiveDigi &trigprim, FEDRawData &rawdata, const EcalElectronicsMapping *TheMapping)
static const int MAX_DCCID_EEM
int iphi() const
get the tower iphi
const EcalTrigTowerDetId & id() const
EcalSubdetector subDet() const
get the subDetector associated to the Trigger Tower
static const int MAX_DCCID_EEP
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
bool fineGrain() const
get the fine-grain bit of interesting sample
tuple cout
Definition: gather_cfg.py:145
dictionary rawdata
Definition: lumiPlot.py:393
int ttFlag() const
get the Trigger tower Flag of interesting sample
static const int MIN_DCCID_EEM
static const int MIN_DCCID_EEP