CMS 3D CMS Logo

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