22 int rdsize = rawdata.
size() / 8;
26 int DCCid = TheMapping->
DCCid(ebdetid);
29 int nsamples = dataframe.
size();
33 if (iFE <= 0 || iFE > 68)
34 throw cms::Exception(
"InvalidFEid") <<
"TowerBlockFormatter::DigiToRaw : Invalid iFE " << iFE << endl;
36 map<int, map<int, int> >::iterator fen =
FEDorder.find(FEDid);
37 map<int, map<int, int> >::iterator fed =
FEDmap.find(FEDid);
41 cout <<
"New FED in TowerBlockFormatter " <<
dec << FEDid <<
" 0x" << hex << FEDid << endl;
42 map<int, int> FEorder;
43 pair<map<int, map<int, int> >::iterator,
bool>
t1 =
46 pair<map<int, map<int, int> >::iterator,
bool>
t2 =
52 map<int, int>& FEorder = (*fen).second;
53 map<int, int>& FEmap = (*fed).second;
55 map<int, int>::iterator fe = FEorder.find(iFE);
58 if (fe != FEorder.end()) {
59 FE_order = (*fe).second;
60 map<int, int>::iterator
ff = FEmap.find(FE_order);
61 if (
ff == FEmap.end())
62 cout <<
"Error with maps... " << endl;
63 FE_index = (*ff).second;
65 cout <<
"FE already there, FE_index = " <<
dec << FE_index <<
" FEorder " << FE_order << endl;
68 cout <<
"New FE in TowerBlockFormatter FE " <<
dec << iFE <<
" 0x" << hex << iFE <<
" in FED id " <<
dec << FEDid
71 int number_FEs = FEorder.size() - 1;
72 FE_order = number_FEs + 1;
75 cout <<
" FE insertion failed...";
78 FE_index = (*fe).second;
80 cout <<
"Build the Tower Block header for FE id " << iFE <<
" start at line " << rdsize << endl;
82 cout <<
"This is the Fe number (order) " << number_FEs + 1 << endl;
83 rawdata.
resize(8 * rdsize + 8);
84 unsigned char* pData = rawdata.
data();
85 pData[8 * FE_index] = iFE & 0xFF;
86 pData[8 * FE_index + 1] = (nsamples & 0x7F);
87 pData[8 * FE_index + 2] =
bx & 0xFF;
88 pData[8 * FE_index + 3] = (
bx >> 8) & 0x0F;
89 pData[8 * FE_index + 3] |= 0xa0;
90 pData[8 * FE_index + 4] = lv1 & 0xFF;
91 pData[8 * FE_index + 5] = (lv1 >> 8) & 0x0F;
92 pData[8 * FE_index + 6] = 1;
93 pData[8 * FE_index + 7] = 0xc0;
101 int ichannel = elid.
xtalId();
104 cout <<
"Now add crystal : strip channel " <<
dec << istrip <<
" " << ichannel << endl;
106 unsigned char* pData = rawdata.
data();
108 vector<unsigned char> vv(&pData[0], &pData[rawdata.
size()]);
110 int n_add = 2 + 2 * nsamples;
112 n_add = n_add / 8 + 1;
116 cout <<
"will add " << n_add <<
" lines of 64 bits at line " << (FE_index + 1) << endl;
118 unsigned char* ppData = rawdata.
data();
120 vector<unsigned char>::iterator iter = vv.begin() + 8 * (FE_index + 1);
122 vector<unsigned char> toadd(n_add * 8);
125 toadd[0] = (istrip & 0x7) + ((ichannel & 0x7) << 4);
126 toadd[1] = (tzs & 0x1) << 12;
128 for (
int isample = 0; isample < (n_add * 8 - 2) / 2; isample++) {
129 if (isample < nsamples) {
130 uint16_t
word = (dataframe.
sample(isample)).raw();
131 toadd[2 + isample * 2] =
word & 0x00FF;
132 toadd[2 + isample * 2 + 1] = (
word & 0xFF00) >> 8;
134 toadd[2 + isample * 2] = 0;
135 toadd[2 + isample * 2 + 1] = 0;
137 if (isample % 2 == 0)
138 toadd[2 + isample * 2 + 1] |= 0xc0;
141 vv.insert(iter, toadd.begin(), toadd.end());
144 for (
int i = 0;
i < (
int)vv.size();
i++) {
149 cout <<
"pData for this FED is now " << endl;
154 for (
int i = FE_order + 1;
i < (
int)FEorder.size();
i++) {
157 cout <<
"FEmap updated for fe number " <<
dec <<
i << endl;
159 cout <<
" FEmap[" <<
i <<
"] = " << FEmap[
i] << endl;
163 int blocklength = ppData[8 * FE_index + 6] + ((ppData[8 * FE_index + 7] & 0x1) << 8);
164 blocklength += n_add;
165 ppData[8 * FE_index + 6] = blocklength & 0xFF;
166 ppData[8 * FE_index + 7] |= (blocklength & 0x100) >> 8;
175 cout <<
"enter in TowerBlockFormatter::EndEvent. First reorder the FE's. " << endl;
177 for (
int idcc = 1; idcc <= 54; idcc++) {
185 if (fedData.
size() <= 16)
189 cout <<
"This is FEDid = " << FEDid << endl;
191 unsigned char* pData = fedData.
data();
193 Word64* words = reinterpret_cast<Word64*>(pData);
195 int length = fedData.
size() / 8;
196 int iDAQ_header(-1), iDCC_header(-1), iTCCBlock_header(-1), iSRBlock_header(-1), iTowerBlock_header(-1),
199 for (
int i = length - 1;
i > -1;
i--) {
200 if (((words[
i] >> 60) & 0xF) == 0x5)
202 if (((words[
i] >> 62) & 0x3) == 0x0)
204 if (((words[
i] >> 61) & 0x7) == 0x3)
205 iTCCBlock_header =
i;
206 if (((words[
i] >> 61) & 0x7) == 0x4)
208 if (((words[
i] >> 62) & 0x3) == 0x3)
209 iTowerBlock_header =
i;
210 if (((words[
i] >> 60) & 0xF) == 0xA)
214 if (iTowerBlock_header < 0)
215 iTowerBlock_header = iDAQ_trailer;
216 if (iSRBlock_header < 0)
217 iSRBlock_header = iTowerBlock_header;
218 if (iTCCBlock_header < 0)
219 iTCCBlock_header = iSRBlock_header;
222 cout <<
"iDAQ_header = " << iDAQ_header << endl;
223 cout <<
" iDCC_header = " << iDCC_header << endl;
224 cout <<
" iTCCBlock_header = " << iTCCBlock_header << endl;
225 cout <<
" iSRBlock_header = " << iSRBlock_header << endl;
226 cout <<
" iTowerBlock_header = " << iTowerBlock_header << endl;
227 cout <<
" iDAQ_trailer = " << iDAQ_trailer << endl;
231 std::map<int, std::vector<Word64> > Map_xtal_data;
233 int iTowerBlock_header_keep = iTowerBlock_header;
235 while (iTowerBlock_header < iDAQ_trailer) {
236 int fe = words[iTowerBlock_header] & 0xFF;
237 int nlines = (words[iTowerBlock_header] >> 48) & 0x1FF;
239 cout <<
"This is FE number " << fe <<
"needs nlines = " << nlines << endl;
241 std::vector<Word64> xtal_data;
242 for (
int j = 0;
j < nlines;
j++) {
243 Word64 ww = words[iTowerBlock_header +
j];
244 xtal_data.push_back(ww);
246 Map_xtal_data[fe] = xtal_data;
247 iTowerBlock_header += nlines;
251 cout <<
"vector of FrontEnd : " <<
FrontEnd.size() << endl;
252 for (std::map<int, int>::const_iterator it =
FrontEnd.begin(); it !=
FrontEnd.end(); it++) {
255 cout <<
"FE line " << fe <<
" " <<
l << endl;
259 iTowerBlock_header = iTowerBlock_header_keep;
260 for (std::map<int, int>::const_iterator it =
FrontEnd.begin(); it !=
FrontEnd.end(); it++) {
262 int nlines = it->second;
264 cout <<
"iTowerBlock_header = " << iTowerBlock_header << endl;
265 vector<Word64> xtal_data = Map_xtal_data[fe];
266 for (
int j = 0;
j < nlines;
j++) {
267 words[iTowerBlock_header +
j] = xtal_data[
j];
269 cout <<
"update line " << iTowerBlock_header +
j << endl;
272 int jFE = pData[8 * (iTowerBlock_header)];
273 cout <<
"Front End on RD : " << jFE << endl;
275 iTowerBlock_header += nlines;
283 cout <<
"now reorder the xtals within the FEs" << endl;
285 iTowerBlock_header = iTowerBlock_header_keep;
287 for (std::map<int, int>::const_iterator it =
FrontEnd.begin(); it !=
FrontEnd.end(); it++) {
290 cout <<
"Problem... fe = " << fe <<
" in FEDid = " << FEDid << endl;
292 cout <<
" This is for FE = " << fe << endl;
293 int nlines = it->second;
294 int timesamples = pData[8 * iTowerBlock_header + 1] & 0x7F;
295 int n4 = timesamples - 3;
296 int n_lines4 = n4 / 4;
301 int Nxtal_max = (nlines - 1) / (1 + n_lines4);
304 map<int, map<int, vector<Word64> > > Strip_Map;
306 while (Nxtal < Nxtal_max) {
307 int i_xtal = iTowerBlock_header + 1 + Nxtal * (1 + n_lines4);
308 int strip = words[i_xtal] & 0x7;
309 int xtal = (words[i_xtal] >> 4) & 0x7;
311 map<int, map<int, vector<Word64> > >::iterator iit = Strip_Map.find(
strip);
313 map<int, vector<Word64> > NewMap;
314 map<int, vector<Word64> > Xtal_Map;
316 if (iit == Strip_Map.end()) {
319 Xtal_Map = iit->second;
322 std::vector<Word64> xtal_data;
323 for (
int j = 0;
j < n_lines4 + 1;
j++) {
325 xtal_data.push_back(ww);
327 Xtal_Map[xtal] = xtal_data;
328 Strip_Map[
strip] = Xtal_Map;
336 for (
map<
int,
map<
int, vector<Word64> > >::const_iterator jt = Strip_Map.begin(); jt != Strip_Map.end(); jt++) {
337 int strip = jt->first;
339 cout <<
" this is strip number " <<
strip << endl;
340 map<int, vector<Word64> > Xtal_Map = jt->second;
342 for (
map<
int, vector<Word64> >::const_iterator kt = Xtal_Map.begin(); kt != Xtal_Map.end(); kt++) {
343 int xtal = kt->first;
345 cout <<
" this is xtal number " << xtal << endl;
346 vector<Word64> xtal_data = kt->second;
348 int mlines = (
int)xtal_data.size();
350 cout <<
" mlines = " << mlines << endl;
351 for (
int j = 0;
j < mlines;
j++) {
352 int line = iTowerBlock_header + 1 +
idx +
j;
353 if (
line >= iDAQ_trailer)
354 cout <<
"smth wrong... line " <<
line <<
" trailer " << iDAQ_trailer << endl;
355 words[
line] = xtal_data[
j];
357 cout <<
" updated line " << iTowerBlock_header +
idx +
j << endl;
368 iTowerBlock_header += nlines;
372 cout <<
" DONE FOR FED " << FEDid << endl;
374 Map_xtal_data.clear();
401 int rdsize = rawdata.
size() / 8;
405 int DCCid = elid.
dccId();
410 cout <<
"enter in TowerBlockFormatter::DigiToRaw DCCid FEDid iFE " <<
dec << DCCid <<
" " << FEDid <<
" " << iFE
413 int nsamples = dataframe.
size();
415 if (iFE <= 0 || iFE > 68) {
416 cout <<
"invalid iFE for EndCap DCCid iFE " << DCCid <<
" " << iFE << endl;
420 map<int, map<int, int> >::iterator fen =
FEDorder.find(FEDid);
421 map<int, map<int, int> >::iterator fed =
FEDmap.find(FEDid);
425 cout <<
"New FED in TowerBlockFormatter " <<
dec << FEDid <<
" 0x" << hex << FEDid << endl;
426 map<int, int> FEorder;
427 pair<map<int, map<int, int> >::iterator,
bool>
t1 =
430 pair<map<int, map<int, int> >::iterator,
bool>
t2 =
436 map<int, int>& FEorder = (*fen).second;
437 map<int, int>& FEmap = (*fed).second;
439 map<int, int>::iterator fe = FEorder.find(iFE);
442 if (fe != FEorder.end()) {
443 FE_order = (*fe).second;
444 map<int, int>::iterator
ff = FEmap.find(FE_order);
445 if (
ff == FEmap.end())
446 cout <<
"Error with maps... " << endl;
447 FE_index = (*ff).second;
449 cout <<
"FE already there, FE_index = " <<
dec << FE_index <<
" FEorder " << FE_order << endl;
452 cout <<
"New FE in TowerBlockFormatter FE " <<
dec << iFE <<
" 0x" << hex << iFE <<
" in FED id " <<
dec << FEDid
455 int number_FEs = FEorder.size() - 1;
456 FE_order = number_FEs + 1;
459 cout <<
" FE insertion failed...";
462 FE_index = (*fe).second;
464 cout <<
"Build the Tower Block header for FE id " << iFE <<
" start at line " << rdsize << endl;
466 cout <<
"This is the Fe number (order) " << number_FEs + 1 << endl;
467 rawdata.
resize(8 * rdsize + 8);
468 unsigned char* pData = rawdata.
data();
470 pData[8 * FE_index] = iFE & 0xFF;
471 pData[8 * FE_index + 1] = (nsamples & 0x7F);
472 pData[8 * FE_index + 2] =
bx & 0xFF;
473 pData[8 * FE_index + 3] = (
bx >> 8) & 0x0F;
474 pData[8 * FE_index + 3] |= 0xa0;
475 pData[8 * FE_index + 4] = lv1 & 0xFF;
476 pData[8 * FE_index + 5] = (lv1 >> 8) & 0x0F;
477 pData[8 * FE_index + 6] = 1;
478 pData[8 * FE_index + 7] = 0xc0;
485 int ichannel = elid.
xtalId();
488 cout <<
"Now add crystal strip channel " <<
dec << istrip <<
" " << ichannel << endl;
490 unsigned char* pData = rawdata.
data();
492 vector<unsigned char> vv(&pData[0], &pData[rawdata.
size()]);
494 int n_add = 2 + 2 * nsamples;
496 n_add = n_add / 8 + 1;
500 cout <<
"nsamples = " <<
dec << nsamples << endl;
502 cout <<
"will add " << n_add <<
" lines of 64 bits at line " << (FE_index + 1) << endl;
504 unsigned char* ppData = rawdata.
data();
506 vector<unsigned char>::iterator iter = vv.begin() + 8 * (FE_index + 1);
508 vector<unsigned char> toadd(n_add * 8);
511 toadd[0] = (istrip & 0x7) + ((ichannel & 0x7) << 4);
512 toadd[1] = (tzs & 0x1) << 12;
514 for (
int isample = 0; isample < (n_add * 8 - 2) / 2; isample++) {
515 if (isample < nsamples) {
516 uint16_t
word = (dataframe.
sample(isample)).raw();
517 toadd[2 + isample * 2] =
word & 0x00FF;
518 toadd[2 + isample * 2 + 1] = (
word & 0xFF00) >> 8;
520 toadd[2 + isample * 2] = 0;
521 toadd[2 + isample * 2 + 1] = 0;
523 if (isample % 2 == 0)
524 toadd[2 + isample * 2 + 1] |= 0xc0;
527 vv.insert(iter, toadd.begin(), toadd.end());
530 for (
int i = 0;
i < (
int)vv.size();
i++) {
535 cout <<
"pData for this FED is now " << endl;
540 for (
int i = FE_order + 1;
i < (
int)FEorder.size();
i++) {
543 cout <<
"FEmap updated for fe number " <<
dec <<
i << endl;
545 cout <<
" FEmap[" <<
i <<
"] = " << FEmap[
i] << endl;
549 int blocklength = ppData[8 * FE_index + 6] + ((ppData[8 * FE_index + 7] & 0x1) << 8);
550 blocklength += n_add;
551 ppData[8 * FE_index + 6] = blocklength & 0xFF;
552 ppData[8 * FE_index + 7] |= (blocklength & 0x100) >> 8;