CMS 3D CMS Logo

SRBlockFormatter.cc
Go to the documentation of this file.
1 #include <memory>
2 
4 
5 using namespace std;
6 
8 
9 void SRBlockFormatter::DigiToRaw(int dccid, int dcc_channel, int flag, FEDRawData& rawdata) {
10  if (debug_)
11  cout << "enter in SRBlockFormatter::DigiToRaw " << endl;
12  if (debug_)
13  print(rawdata);
14 
15  int bx = bx_;
16  int lv1 = lv1_;
17 
18  int Nrows_SRP = 5; // Both for Barrel and EndCap (without the header row)
19  int SRid = (dccid - 1) / 3 + 1;
20 
21  // int Number_SRP_Flags = 68;
22 
23  int SRP_index;
24  int icode = 1000 * dccid + SRid;
25  if (debug_)
26  cout << "size of header_ map is " << header_.size() << endl;
27 
28  std::map<int, int>::const_iterator it_header = header_.find(icode);
29 
30  if (it_header != header_.end()) {
31  SRP_index = rawdata.size() / 8 - Nrows_SRP;
32  if (debug_)
33  cout << "This SRid is already there." << endl;
34  } else {
35  if (debug_)
36  cout << "New SR Block added on Raw data " << endl;
37  header_[icode] = 1;
38  SRP_index = rawdata.size() / 8;
39  rawdata.resize(rawdata.size() + 8 + 8 * Nrows_SRP); // 1 line for SRP header, 5 lines of data
40  unsigned char* ppData = rawdata.data();
41  ppData[8 * SRP_index] = SRid & 0xFF;
42  ppData[8 * SRP_index + 2] = bx & 0xFF;
43  ppData[8 * SRP_index + 3] = (bx & 0xF00) >> 8;
44  ppData[8 * SRP_index + 3] |= 0x80;
45  ppData[8 * SRP_index + 4] = lv1 & 0xFF;
46  ppData[8 * SRP_index + 5] = (lv1 & 0xF00) >> 8;
47  // ppData[8*SRP_index+6] = Number_SRP_Flags;
48  ppData[8 * SRP_index + 6] = 0;
49  ppData[8 * SRP_index + 7] = 0x80;
50  SRP_index++;
51  if (debug_)
52  cout << "Added headers and empty lines : " << endl;
53  if (debug_)
54  print(rawdata);
55 
56  // -- put the B011 and B100 already, since for Endcap there can be empty
57  // -- lines in the TCC and the SRP blocks
58  unsigned char* Data = rawdata.data();
59  for (int iline = SRP_index; iline < SRP_index + Nrows_SRP; iline++) {
60  Data[8 * iline + 7] |= 0x80;
61  Data[8 * iline + 3] |= 0x80;
62  }
63  }
64 
65  unsigned char* pData = rawdata.data();
66 
67  // -- Now the TCC Block :
68 
69  int nflags = pData[8 * (SRP_index - 1) + 6] & 0x7F;
70  nflags++;
71  pData[8 * (SRP_index - 1) + 6] = nflags & 0x7F;
72 
73  int jTT = (dcc_channel - 1);
74  int irow = jTT / 16;
75  int ival = jTT % 4;
76  int kval = (jTT % 16) / 4;
77  SRP_index += irow;
78 
79  if (debug_)
80  cout << "Now add SC to SRBlock " << dec << dcc_channel << " irow ival " << dec << irow << " " << dec << ival
81  << endl;
82  if (debug_)
83  cout << "new data will be added at line " << dec << SRP_index << endl;
84 
85  unsigned char* buff = &pData[8 * SRP_index];
86  Word64* pw = reinterpret_cast<Word64*>(const_cast<unsigned char*>(buff));
87  int nbits = kval * 16 + 3 * ival;
88  Word64 wflag = (Word64)((short int)flag & 0x7) << nbits;
89  *pw |= wflag;
90  Word64 b1 = (Word64)((Word64)0x80 << 56);
91  *pw |= b1;
92  Word64 b2 = (Word64)((Word64)0x80 << 24);
93  *pw |= b2;
94 
95  if (debug_)
96  print(rawdata);
97 }
BlockFormatter::Word64
uint64_t Word64
Definition: BlockFormatter.h:15
gather_cfg.cout
cout
Definition: gather_cfg.py:144
BlockFormatter::Params
Definition: BlockFormatter.h:28
b2
static constexpr float b2
Definition: L1EGammaCrystalsEmulatorProducer.cc:83
BlockFormatter::print
void print(FEDRawData &rawdata)
Definition: BlockFormatter.cc:89
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
SRBlockFormatter::header_
std::map< int, int > header_
Definition: SRBlockFormatter.h:20
FEDRawData
Definition: FEDRawData.h:19
simKBmtfDigis_cfi.bx
bx
Definition: simKBmtfDigis_cfi.py:55
BlockFormatter
Definition: BlockFormatter.h:13
b1
static constexpr float b1
Definition: L1EGammaCrystalsEmulatorProducer.cc:83
BlockFormatter::bx_
int bx_
Definition: BlockFormatter.h:49
BlockFormatter::debug_
const bool debug_
Definition: BlockFormatter.h:53
SRBlockFormatter::SRBlockFormatter
SRBlockFormatter(BlockFormatter::Config const &, BlockFormatter::Params const &)
Definition: SRBlockFormatter.cc:7
BlockFormatter::lv1_
int lv1_
Definition: BlockFormatter.h:50
ntuplemaker.iline
iline
Definition: ntuplemaker.py:186
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
std
Definition: JetResolutionObject.h:76
SRBlockFormatter.h
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
SRBlockFormatter::DigiToRaw
void DigiToRaw(int dccid, int dcc_channel, int flag, FEDRawData &rawdata)
Definition: SRBlockFormatter.cc:9
Config
Definition: Config.py:1
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116