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 }
FEDNumbering.h
EcalElectronicsMapping
Definition: EcalElectronicsMapping.h:28
EcalTriggerPrimitiveDigi::size
int size() const
Definition: EcalTriggerPrimitiveDigi.h:30
FEDNumbering::MINECALFEDID
Definition: FEDNumbering.h:43
EcalTrigTowerDetId::iphi
int iphi() const
get the tower iphi
Definition: EcalTrigTowerDetId.h:52
NUMB_SM_EB_PLU_MIN
Definition: DCCRawDataDefinitions.h:56
EcalTrigTowerDetId::ietaAbs
int ietaAbs() const
get the absolute value of the tower ieta
Definition: EcalTrigTowerDetId.h:36
EcalElectronicsMapping::iTT
int iTT(const EcalTrigTowerDetId &id) const
returns the index of a Trigger Tower within its TCC.
Definition: EcalElectronicsMapping.cc:102
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalDetIdCollections.h
TCCBlockFormatter.h
BlockFormatter::Params
Definition: BlockFormatter.h:28
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
BlockFormatter::print
void print(FEDRawData &rawdata)
Definition: BlockFormatter.cc:89
EcalTriggerPrimitiveDigi::ttFlag
int ttFlag() const
get the Trigger tower Flag of interesting sample
Definition: EcalTriggerPrimitiveDigi.cc:36
EcalBarrel
Definition: EcalSubdetector.h:10
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
TCCBlockFormatter::TCCBlockFormatter
TCCBlockFormatter(BlockFormatter::Config const &, BlockFormatter::Params const &)
Definition: TCCBlockFormatter.cc:13
FEDRawData
Definition: FEDRawData.h:19
simKBmtfDigis_cfi.bx
bx
Definition: simKBmtfDigis_cfi.py:55
BlockFormatter
Definition: BlockFormatter.h:13
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
BlockFormatter::bx_
int bx_
Definition: BlockFormatter.h:49
SurfaceOrientation::inner
Definition: Surface.h:19
BlockFormatter::doBarrel_
const bool doBarrel_
Definition: BlockFormatter.h:55
BlockFormatter::debug_
const bool debug_
Definition: BlockFormatter.h:53
EcalEndcap
Definition: EcalSubdetector.h:10
NUMB_SM_EB_PLU_MAX
Definition: DCCRawDataDefinitions.h:57
BlockFormatter::doEndCap_
const bool doEndCap_
Definition: BlockFormatter.h:56
createfilelist.int
int
Definition: createfilelist.py:10
BlockFormatter::lv1_
int lv1_
Definition: BlockFormatter.h:50
ntuplemaker.iline
iline
Definition: ntuplemaker.py:186
EcalElectronicsId::MAX_DCCID_EEM
static const int MAX_DCCID_EEM
Definition: EcalElectronicsId.h:63
EcalElectronicsMapping::DCCid
int DCCid(const EBDetId &id) const
returns the DCC of an EBDetId
Definition: EcalElectronicsMapping.cc:70
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
TCCBlockFormatter::AllTPsamples_
bool AllTPsamples_
Definition: TCCBlockFormatter.h:29
EcalTrigTowerDetId::subDet
EcalSubdetector subDet() const
get the subDetector associated to the Trigger Tower
Definition: EcalTrigTowerDetId.h:33
EcalTrigTowerDetId::ieta
int ieta() const
get the tower ieta
Definition: EcalTrigTowerDetId.h:44
TCCBlockFormatter::DigiToRaw
void DigiToRaw(const EcalTriggerPrimitiveDigi &trigprim, FEDRawData &rawdata, const EcalElectronicsMapping *TheMapping)
Definition: TCCBlockFormatter.cc:17
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
EcalElectronicsMapping::TCCid
int TCCid(const EBDetId &id) const
returns the TCCid of an EBDetId
Definition: EcalElectronicsMapping.cc:86
std
Definition: JetResolutionObject.h:76
EcalTriggerPrimitiveDigi::id
const EcalTrigTowerDetId & id() const
Definition: EcalTriggerPrimitiveDigi.h:29
EcalTriggerPrimitiveDigi
Definition: EcalTriggerPrimitiveDigi.h:16
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
DCCRawDataDefinitions.h
EcalTriggerPrimitiveDigi::compressedEt
int compressedEt() const
get the encoded/compressed Et of interesting sample
Definition: EcalTriggerPrimitiveDigi.cc:19
EcalElectronicsId::MAX_DCCID_EEP
static const int MAX_DCCID_EEP
Definition: EcalElectronicsId.h:69
EcalTriggerPrimitiveDigi::fineGrain
bool fineGrain() const
get the fine-grain bit of interesting sample
Definition: EcalTriggerPrimitiveDigi.cc:28
EcalElectronicsMapping::MAX_TCCID
static const int MAX_TCCID
Definition: EcalElectronicsMapping.h:169
EcalElectronicsId::MIN_DCCID_EEM
static const int MIN_DCCID_EEM
Definition: EcalElectronicsId.h:62
Config
Definition: Config.py:1
EcalElectronicsId::MIN_DCCID_EEP
static const int MIN_DCCID_EEP
Definition: EcalElectronicsId.h:68
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143