CMS 3D CMS Logo

BlockFormatter.cc
Go to the documentation of this file.
1 #include <memory>
2 
3 // user include files
4 
5 
9 
10 
11 using namespace std;
12 
14  plistDCCId_{iC.plistDCCId_},
15  counter_{iP.counter_},
16  orbit_number_{iP.orbit_number_},
17  bx_{iP.bx_},
18  lv1_{iP.lv1_},
19  runnumber_{iP.runnumber_},
20  debug_{iC.debug_},
21  doBarrel_{iC.doBarrel_},
22  doEndCap_{iC.doEndCap_},
23  doTCC_{iC.doTCC_},
24  doSR_{iC.doSR_},
25  doTower_{iC.doTower_}
26 {
27 }
28 
30 
31  int run_number = runnumber_;
32  int bx = bx_;
33  int lv1 = lv1_;
34 
35  if (debug_) cout << "in BlockFormatter::DigiToRaw run_number orbit_number bx lv1 " << dec << run_number << " " <<
36  orbit_number_ << " " << bx << " " << lv1 << endl;
37 
38  for (int idcc=1; idcc <= 54; idcc++) {
39  if ( (! doBarrel_) &&
41  if ( (! doEndCap_) &&
42  (idcc <= EcalElectronicsId::MAX_DCCID_EEM || idcc >= EcalElectronicsId::MIN_DCCID_EEP)) continue;
43 
44  int FEDid = FEDNumbering::MINECALFEDID + idcc;
45  FEDRawData& rawdata = productRawData -> FEDData(FEDid);
46  unsigned char * pData;
47  short int DCC_ERRORS = 0;
48 
49  if (rawdata.size() == 0) {
50  rawdata.resize(8);
51  pData = rawdata.data();
52 
53  Word64 word = 0x18 + ((FEDid & 0xFFF)<<8)
54  + ((Word64)((Word64)bx & 0xFFF)<<20)
55  + ((Word64)((Word64)lv1 & 0xFFFFFF)<<32)
56  + (Word64)((Word64)0x51<<56);
57  Word64* pw = reinterpret_cast<Word64*>(const_cast<unsigned char*>(pData));
58  *pw = word; // DAQ header
59 
60  rawdata.resize(rawdata.size() + 8*8); // DCC header
61  pData = rawdata.data();
62  pData[11] = DCC_ERRORS & 0xFF;
63  pData[12] = run_number & 0xFF;
64  pData[13] = (run_number >>8) & 0xFF;
65  pData[14] = (run_number >> 16) & 0xFF;
66  pData[15] = 0x01;
67 
68  for (int i=16; i <= 22; i++) {
69  pData[i] = 0; // to be filled for local data taking or calibration
70  }
71  pData[23] = 0x02;
72  pData[24] = orbit_number_ & 0xFF;
73  pData[25] = (orbit_number_ >>8) & 0xFF;
74  pData[26] = (orbit_number_ >>16) & 0xFF;
75  pData[27] = (orbit_number_ >>24) & 0xFF;
76  int SRenable_ = 1;
77  int SR = SRenable_;
78  int ZS = 0;
79  int TZS = 0;
80  // int SR_CHSTATUS = 0;
81  pData[28] = (SR&0x1) + ((ZS&0x1)<<1) + ((TZS&0x1)<<2);
82  pData[31] = 0x03;
83 
84  for (int i=0; i<=4; i++) {
85  for (int j=0; j<7; j++) {
86  pData[32 +8*i + j] = 0;
87  }
88  pData[32 +8*i + 7] = 0x04;
89  }
90 
91  } // endif rawdatasize == 0
92  } // loop on id
93 
94 }
95 
96 
97 
99  int size = rawdata.size();
100  cout << "Print RawData size " << dec << size << endl;
101  unsigned char* pData = rawdata.data();
102 
103  int n = size/8;
104  for (int i=0; i < n; i++) {
105  for (int j=7; j>=0; j--) {
106  if (8*i+j <= size) cout << hex << (int)pData[8*i+j] << " ";
107  }
108  cout << endl;
109  }
110 }
111 
112 
113 
115  map<int, map<int,int> >* FEDorder ) {
116 
117 
118  for (int id=0; id < 36 + 18; id++) {
119  if ( (! doBarrel_) && (id >= 9 && id <= 44)) continue;
120  if ( (! doEndCap_) && (id <= 8 || id >= 45)) continue;
121 
122  int FEDid = FEDNumbering::MINECALFEDID + id +1;
123  FEDRawData& rawdata = productRawData -> FEDData(FEDid);
124 
125  // ---- if raw need not be made for a given fed, set its size to empty and return
126  if ( find( (*plistDCCId_).begin(), (*plistDCCId_).end(), (id+1) ) == (*plistDCCId_).end() )
127  {
128  rawdata.resize( 0 );
129  continue;
130  }
131 
132  // ---- Add the trailer word
133  int lastline = rawdata.size();
134  rawdata.resize( lastline + 8);
135  unsigned char * pData = rawdata.data();
136  int event_length = (lastline + 8) / 8; // in 64 bits words
137 
138  pData[lastline+7] = 0xa0;
139  // pData[lastline+4] = event_length & 0xFFFFFF;
140  pData[lastline+4] = event_length & 0xFF;
141  pData[lastline+5] = (event_length >> 8) & 0xFF;
142  pData[lastline+6] = (event_length >> 16) & 0xFF;
143  int event_status = 0;
144  pData[lastline+1] = event_status & 0x0F;
145  int tts = 0 <<4;
146  pData[lastline] = tts & 0xF0;
147 
148  // ---- Write the event length in the DCC header
149  // pData[8] = event_length & 0xFFFFFF;
150  pData[8] = event_length & 0xFF;
151  pData[9] = (event_length >> 8) & 0xFF;
152  pData[10] = (event_length >> 16) & 0xFF;
153 
154  // cout << " in BlockFormatter::CleanUp. FEDid = " << FEDid << " event_length*8 " << dec << event_length*8 << endl;
155 
156  map<int, map<int,int> >::iterator fen = FEDorder -> find(FEDid);
157 
158  bool FED_has_data = true;
159  if (fen == FEDorder->end()) FED_has_data = false;
160  if (debug_ && (! FED_has_data)) cout << " FEDid is not in FEDorder ! " << endl;
161  if ( ! FED_has_data) {
162  int ch_status = 7;
163  for (int iFE=1; iFE <= 68; iFE++) {
164  int irow = (iFE-1) / 14;
165  int kval = ( (iFE-1) % 14) / 2;
166  if (iFE % 2 ==1) pData[32 + 8*irow + kval] |= ch_status & 0xFF;
167  else pData[32 + 8*irow + kval] |= ((ch_status <<4) & 0xFF);
168  }
169  }
170 
171  if (FED_has_data) {
172  map<int, int>& FEorder = (*fen).second;
173 
174  for (int iFE=1; iFE <= 68; iFE++) {
175  map<int,int>::iterator fe = FEorder.find(iFE);
176  int ch_status = 0;
177  if (fe == FEorder.end()) // FE not present due to SRP, update CH_status
178  ch_status = 7; // CH_SUPPRESS
179  int irow = (iFE-1) / 14;
180  int kval = ( (iFE-1) % 14) / 2;
181  if (iFE % 2 ==1) pData[32 + 8*irow + kval] |= ch_status & 0xFF;
182  else pData[32 + 8*irow + kval] |= ((ch_status <<4) & 0xFF);
183 
184  }
185  }
186 
187  }
188 }
189 
190 
192 
193 
194  for (int id=0; id < 36 + 18; id++) {
195 
196  // if ( (! doBarrel_) && (id >= 9 && id <= 44)) continue;
197  // if ( (! doEndCap_) && (id <= 8 || id >= 45)) continue;
198 
199 
200  int FEDid = FEDNumbering::MINECALFEDID + id;
201  FEDRawData& rawdata = productRawData -> FEDData(FEDid);
202  if (rawdata.size() > 0)
203  cout << "Size of FED id " << dec << FEDid << " is : " << dec << rawdata.size() << endl;
204 
205  }
206 }
207 
208 
size
Write out results.
void DigiToRaw(FEDRawDataCollection *productRawData)
const bool doBarrel_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void print(FEDRawData &rawdata)
BlockFormatter(Config const &iC, Params const &iP)
void CleanUp(FEDRawDataCollection *productRawData, std::map< int, std::map< int, int > > *FEDorder)
void PrintSizes(FEDRawDataCollection *productRawData)
const bool doTower_
void resize(size_t newsize)
Definition: FEDRawData.cc:32
static const int MAX_DCCID_EBP
static const int MIN_DCCID_EBM
const bool debug_
const bool doSR_
const bool doEndCap_
const std::vector< int32_t > * plistDCCId_
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
const bool doTCC_
Definition: Config.py:1
static const int MIN_DCCID_EEP