34 int rdsize = rawdata.
size() / 8;
40 int DCCid = TheMapping -> DCCid(ebdetid);
44 int nsamples = dataframe.
size();
49 "TowerBlockFormatter::DigiToRaw : Invalid iFE " << iFE << endl;
52 map<int, map<int,int> >::iterator fen = FEDorder ->
find(FEDid);
53 map<int, map<int,int> >::iterator fed = FEDmap ->
find(FEDid);
55 if (fen == FEDorder ->
end()) {
56 if (debug_)
cout <<
"New FED in TowerBlockFormatter " << dec << FEDid <<
" 0x" << hex << FEDid << endl;
58 pair<map<int, map<int,int> >::iterator,
bool> t1 = FEDorder ->
insert(
map<
int, map<int,int> >::
value_type(FEDid,FEorder));
60 pair<map<int, map<int,int> >::iterator,
bool> t2 = FEDmap ->
insert(
map<
int, map<int,int> >::
value_type(FEDid,FEmap));
65 map<int, int>& FEorder = (*fen).second;
66 map<int, int>& FEmap = (*fed).second;
68 map<int,int>::iterator fe = FEorder.find(iFE);
71 if (fe != FEorder.end()) {
72 FE_order = (*fe).second;
73 map<int,int>::iterator
ff = FEmap.find(FE_order);
74 if (ff == FEmap.end())
cout <<
"Error with maps... " << endl;
75 FE_index = (*ff).second;
76 if (debug_)
cout <<
"FE already there, FE_index = " << dec << FE_index <<
" FEorder " << FE_order << endl;
79 if (debug_)
cout <<
"New FE in TowerBlockFormatter FE " << dec << iFE <<
" 0x" << hex << iFE <<
" in FED id " << dec << FEDid << endl;
82 int number_FEs = FEorder.size() -1;
83 FE_order = number_FEs+1;
85 if (! t2.second)
cout <<
" FE insertion failed...";
88 FE_index = (*fe).second;
89 if (debug_)
cout <<
"Build the Tower Block header for FE id " << iFE <<
" start at line " << rdsize << endl;
90 if (debug_)
cout <<
"This is the Fe number (order) " << number_FEs+1 << endl;
91 rawdata.
resize( 8*rdsize + 8);
92 unsigned char* pData = rawdata.
data();
93 pData[8*FE_index] = iFE & 0xFF;
94 pData[8*FE_index+1] = (nsamples & 0x7F);
95 pData[8*FE_index+2] = bx & 0xFF;
96 pData[8*FE_index+3] = (bx >>8) & 0x0F;
97 pData[8*FE_index+3] |= 0xa0;
98 pData[8*FE_index+4] = lv1 & 0xFF;
99 pData[8*FE_index+5] = (lv1 >>8) & 0x0F;
100 pData[8*FE_index+6] = 1;
101 pData[8*FE_index+7] = 0xc0;
102 if (debug_)
print(rawdata);
110 int ichannel = elid.
xtalId();
112 if (debug_)
cout <<
"Now add crystal : strip channel " << dec << istrip <<
" " << ichannel << endl;
115 unsigned char* pData = rawdata.
data();
117 vector<unsigned char> vv(&pData[0],&pData[rawdata.
size()]);
120 int n_add = 2 + 2*nsamples;
121 if (n_add % 8 != 0) n_add = n_add/8 +1;
124 if (debug_)
cout <<
"will add " << n_add <<
" lines of 64 bits at line " << (FE_index+1) << endl;
126 unsigned char* ppData = rawdata.
data();
128 vector<unsigned char>::iterator iter = vv.begin() + 8*(FE_index+1);
130 vector<unsigned char> toadd(n_add*8);
134 toadd[0] = (istrip & 0x7) + ((ichannel & 0x7)<<4);
135 toadd[1] = (tzs & 0x1) <<12;
137 for (
int isample=0; isample < (n_add*8-2)/2; isample++) {
138 if (isample < nsamples) {
139 uint16_t word = (dataframe.
sample(isample)).raw();
140 toadd[2 + isample*2] = word & 0x00FF;
141 toadd[2 + isample*2 +1] = (word & 0xFF00)>>8;
144 toadd[2 + isample*2] = 0;
145 toadd[2 + isample*2 +1] = 0;
147 if (isample % 2 == 0) toadd[2 + isample*2 +1] |= 0xc0;
150 vv.insert(iter,toadd.begin(),toadd.end());
154 for (
int i=0;
i < (int)vv.size();
i++) {
159 cout <<
"pData for this FED is now " << endl;
164 for (
int i=FE_order+1;
i < (int)FEorder.size();
i++) {
166 if (debug_)
cout <<
"FEmap updated for fe number " << dec <<
i << endl;
167 if (debug_)
cout <<
" FEmap[" <<
i <<
"] = " << FEmap[
i] << endl;
171 int blocklength = ppData[8*FE_index+6]
172 + ((ppData[8*FE_index+7] & 0x1)<<8);
173 blocklength += n_add;
174 ppData[8*FE_index+6] = blocklength & 0xFF;
175 ppData[8*FE_index+7] |= (blocklength & 0x100)>>8;
189 if (debug_)
cout <<
"enter in TowerBlockFormatter::EndEvent. First reorder the FE's. " << endl;
191 for (
int idcc=1; idcc <= 54; idcc++) {
199 FEDRawData& fedData = productRawData -> FEDData(FEDid);
200 if (fedData.
size() <= 16)
continue;
202 if (debug_)
cout <<
"This is FEDid = " << FEDid << endl;
204 unsigned char * pData = fedData.
data();
208 int length = fedData.
size() / 8;
209 int iDAQ_header(-1), iDCC_header(-1), iTCCBlock_header(-1),
210 iSRBlock_header(-1), iTowerBlock_header(-1), iDAQ_trailer(-1);
212 for (
int i=length-1;
i > -1;
i--) {
213 if ( ( (words[
i] >> 60) & 0xF) == 0x5 ) iDAQ_header=
i;
214 if ( ( (words[
i] >> 62) & 0x3) == 0x0 ) iDCC_header=
i;
215 if ( ( (words[
i] >> 61) & 0x7) == 0x3 ) iTCCBlock_header=
i;
216 if ( ( (words[
i] >> 61) & 0x7) == 0x4 ) iSRBlock_header=
i;
217 if ( ( (words[
i] >> 62) & 0x3) == 0x3 ) iTowerBlock_header=
i;
218 if ( ( (words[
i] >> 60) & 0xF) == 0xA ) iDAQ_trailer=
i;
221 if (iTowerBlock_header < 0) iTowerBlock_header = iDAQ_trailer;
222 if (iSRBlock_header < 0) iSRBlock_header = iTowerBlock_header;
223 if (iTCCBlock_header < 0) iTCCBlock_header = iSRBlock_header;
226 cout <<
"iDAQ_header = " << iDAQ_header << endl;
227 cout <<
" iDCC_header = " << iDCC_header << endl;
228 cout <<
" iTCCBlock_header = " << iTCCBlock_header << endl;
229 cout <<
" iSRBlock_header = " << iSRBlock_header << endl;
230 cout <<
" iTowerBlock_header = " << iTowerBlock_header << endl;
231 cout <<
" iDAQ_trailer = " << iDAQ_trailer << endl;
234 std::map<int, int> FrontEnd;
235 std::map<int, std::vector<Word64> > Map_xtal_data;
237 int iTowerBlock_header_keep = iTowerBlock_header;
239 while (iTowerBlock_header < iDAQ_trailer) {
240 int fe = words[iTowerBlock_header] & 0xFF;
241 int nlines = (words[iTowerBlock_header] >> 48) & 0x1FF;
242 if (debug_)
cout <<
"This is FE number " << fe <<
"needs nlines = " << nlines << endl;
244 std::vector<Word64> xtal_data;
246 Word64 ww = words[iTowerBlock_header+
j];
247 xtal_data.push_back(ww);
249 Map_xtal_data[fe] = xtal_data;
250 iTowerBlock_header +=
nlines;
254 cout <<
"vector of FrontEnd : " << FrontEnd.size() << endl;
255 for (std::map<int, int>::const_iterator it=FrontEnd.begin();
256 it != FrontEnd.end(); it++) {
257 int fe = it ->
first;
259 cout <<
"FE line " << fe <<
" " << l << endl;
263 iTowerBlock_header = iTowerBlock_header_keep;
264 for (std::map<int, int>::const_iterator it=FrontEnd.begin();
265 it != FrontEnd.end(); it++) {
266 int fe = it ->
first;
268 if (debug_)
cout <<
"iTowerBlock_header = " << iTowerBlock_header << endl;
269 vector<Word64> xtal_data = Map_xtal_data[fe];
271 words[iTowerBlock_header+
j] = xtal_data[
j];
272 if (debug_)
cout <<
"update line " << iTowerBlock_header+
j << endl;
275 int jFE = pData[8*(iTowerBlock_header)];
276 cout <<
"Front End on RD : " << jFE << endl;
278 iTowerBlock_header +=
nlines;
285 if (debug_)
cout <<
"now reorder the xtals within the FEs" << endl;
287 iTowerBlock_header = iTowerBlock_header_keep;
289 for (std::map<int, int>::const_iterator it=FrontEnd.begin();
290 it != FrontEnd.end(); it++) {
292 int fe = it ->
first;
293 if (fe > 68)
cout <<
"Problem... fe = " << fe <<
" in FEDid = " << FEDid << endl;
294 if (debug_)
cout <<
" This is for FE = " << fe << endl;
296 int timesamples = pData[8*iTowerBlock_header+1] & 0x7F;
297 int n4=timesamples-3;
299 if ( n4 % 4 != 0) n_lines4 ++;
300 if (n_lines4<0) n_lines4=0;
301 int Nxtal_max = (nlines-1)/(1+n_lines4);
304 map< int, map<int, vector<Word64> > > Strip_Map;
306 while (Nxtal < Nxtal_max) {
308 int i_xtal = iTowerBlock_header+1 + Nxtal*(1+n_lines4);
309 int strip = words[i_xtal] & 0x7;
310 int xtal = ( words[i_xtal] >>4) & 0x7;
312 map< int, map<int, vector<Word64> > >::iterator iit = Strip_Map.find(strip);
314 map<int, vector<Word64> > NewMap;
315 map<int, vector<Word64> > Xtal_Map;
317 if (iit == Strip_Map.end()) {
324 std::vector<Word64> xtal_data;
325 for (
int j=0;
j < n_lines4 +1;
j++) {
327 xtal_data.push_back(ww);
329 Xtal_Map[xtal] = xtal_data;
330 Strip_Map[
strip] = Xtal_Map;
338 for (
map<
int,
map<
int, vector<Word64> > >::const_iterator jt = Strip_Map.begin();
339 jt != Strip_Map.end(); jt++) {
342 if (debug_)
cout <<
" this is strip number " << strip << endl;
343 map<int, vector<Word64> > Xtal_Map = jt ->
second;
345 for (
map<
int, vector<Word64> >::const_iterator kt = Xtal_Map.begin();
346 kt != Xtal_Map.end(); kt++) {
347 int xtal = kt ->
first;
348 if (debug_)
cout <<
" this is xtal number " << xtal << endl;
349 vector<Word64> xtal_data = kt ->
second;
351 int mlines = (int)xtal_data.size();
352 if (debug_)
cout <<
" mlines = " << mlines << endl;
353 for (
int j=0;
j < mlines;
j++) {
354 int line = iTowerBlock_header+1+idx+
j;
355 if (line >= iDAQ_trailer)
cout <<
"smth wrong... line " << line <<
" trailer " << iDAQ_trailer << endl;
356 words[
line] = xtal_data[
j] ;
357 if (debug_)
cout <<
" updated line " << iTowerBlock_header+idx+j << endl;
368 iTowerBlock_header +=
nlines;
372 if (debug_)
cout <<
" DONE FOR FED " << FEDid << endl;
374 Map_xtal_data.clear();
398 FEDmap =
new map<int, map<int,int> >;
399 FEDorder =
new map<int, map<int,int> >;
419 int rdsize = rawdata.
size() / 8;
426 int DCCid = elid.
dccId();
430 if (debug_)
cout <<
"enter in TowerBlockFormatter::DigiToRaw DCCid FEDid iFE " <<
431 dec << DCCid <<
" " << FEDid <<
" " << iFE << endl;
433 int nsamples = dataframe.
size();
435 if (iFE <= 0 || iFE > 68) {
436 cout <<
"invalid iFE for EndCap DCCid iFE " << DCCid <<
" " << iFE << endl;
441 map<int, map<int,int> >::iterator fen = FEDorder ->
find(FEDid);
442 map<int, map<int,int> >::iterator fed = FEDmap ->
find(FEDid);
444 if (fen == FEDorder ->
end()) {
445 if (debug_)
cout <<
"New FED in TowerBlockFormatter " << dec << FEDid <<
" 0x" << hex << FEDid << endl;
446 map<int,int> FEorder;
447 pair<map<int, map<int,int> >::iterator,
bool> t1 = FEDorder ->
insert(
map<
int, map<int,int> >::
value_type(FEDid,FEorder));
449 pair<map<int, map<int,int> >::iterator,
bool> t2 = FEDmap ->
insert(
map<
int, map<int,int> >::
value_type(FEDid,FEmap));
454 map<int, int>& FEorder = (*fen).second;
455 map<int, int>& FEmap = (*fed).second;
457 map<int,int>::iterator fe = FEorder.find(iFE);
460 if (fe != FEorder.end()) {
461 FE_order = (*fe).second;
462 map<int,int>::iterator
ff = FEmap.find(FE_order);
463 if (ff == FEmap.end())
cout <<
"Error with maps... " << endl;
464 FE_index = (*ff).second;
465 if (debug_)
cout <<
"FE already there, FE_index = " << dec << FE_index <<
" FEorder " << FE_order << endl;
468 if (debug_)
cout <<
"New FE in TowerBlockFormatter FE " << dec << iFE <<
" 0x" << hex << iFE <<
" in FED id " << dec << FEDid << endl;
471 int number_FEs = FEorder.size() -1;
472 FE_order = number_FEs+1;
474 if (! t2.second)
cout <<
" FE insertion failed...";
477 FE_index = (*fe).second;
478 if (debug_)
cout <<
"Build the Tower Block header for FE id " << iFE <<
" start at line " << rdsize << endl;
479 if (debug_)
cout <<
"This is the Fe number (order) " << number_FEs+1 << endl;
480 rawdata.
resize( 8*rdsize + 8);
481 unsigned char* pData = rawdata.
data();
483 pData[8*FE_index] = iFE & 0xFF;
484 pData[8*FE_index+1] = (nsamples & 0x7F);
485 pData[8*FE_index+2] = bx & 0xFF;
486 pData[8*FE_index+3] = (bx >>8) & 0x0F;
487 pData[8*FE_index+3] |= 0xa0;
488 pData[8*FE_index+4] = lv1 & 0xFF;
489 pData[8*FE_index+5] = (lv1 >>8) & 0x0F;
490 pData[8*FE_index+6] = 1;
491 pData[8*FE_index+7] = 0xc0;
492 if (debug_)
print(rawdata);
500 int ichannel = elid.
xtalId();
502 if (debug_)
cout <<
"Now add crystal strip channel " << dec << istrip <<
" " << ichannel << endl;
504 unsigned char* pData = rawdata.
data();
506 vector<unsigned char> vv(&pData[0],&pData[rawdata.
size()]);
509 int n_add = 2 + 2*nsamples;
510 if (n_add % 8 != 0) n_add = n_add/8 +1;
513 if (debug_)
cout <<
"nsamples = " << dec << nsamples << endl;
514 if (debug_)
cout <<
"will add " << n_add <<
" lines of 64 bits at line " << (FE_index+1) << endl;
516 unsigned char* ppData = rawdata.
data();
518 vector<unsigned char>::iterator iter = vv.begin() + 8*(FE_index+1);
520 vector<unsigned char> toadd(n_add*8);
524 toadd[0] = (istrip & 0x7) + ((ichannel & 0x7)<<4);
525 toadd[1] = (tzs & 0x1) <<12;
527 for (
int isample=0; isample < (n_add*8-2)/2; isample++) {
528 if (isample < nsamples) {
529 uint16_t word = (dataframe.
sample(isample)).raw();
530 toadd[2 + isample*2] = word & 0x00FF;
531 toadd[2 + isample*2 +1] = (word & 0xFF00)>>8;
534 toadd[2 + isample*2] = 0;
535 toadd[2 + isample*2 +1] = 0;
537 if (isample % 2 == 0) toadd[2 + isample*2 +1] |= 0xc0;
540 vv.insert(iter,toadd.begin(),toadd.end());
544 for (
int i=0;
i < (int)vv.size();
i++) {
549 cout <<
"pData for this FED is now " << endl;
554 for (
int i=FE_order+1;
i < (int)FEorder.size();
i++) {
556 if (debug_)
cout <<
"FEmap updated for fe number " << dec <<
i << endl;
557 if (debug_)
cout <<
" FEmap[" <<
i <<
"] = " << FEmap[
i] << endl;
561 int blocklength = ppData[8*FE_index+6]
562 + ((ppData[8*FE_index+7] & 0x1)<<8);
563 blocklength += n_add;
564 ppData[8*FE_index+6] = blocklength & 0xFF;
565 ppData[8*FE_index+7] |= (blocklength & 0x100)>>8;
int xtalId() const
get the channel id
int stripId() const
get the tower id
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
EcalMGPASample sample(int i) const
int towerId() const
get the tower id
Container::value_type value_type
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
size_t size() const
Lenght of the data buffer in bytes.
U second(std::pair< T, U > const &p)
void resize(size_t newsize)
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
bool insert(Storage &, ItemType *, const IdTag &)