CMS 3D CMS Logo

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