34 int rdsize = rawdata.
size() / 8;
38 int DCCid = TheMapping -> DCCid(ebdetid);
42 int nsamples = dataframe.
size();
47 "TowerBlockFormatter::DigiToRaw : Invalid iFE " << iFE << endl;
50 map<int, map<int,int> >::iterator fen = FEDorder ->
find(FEDid);
51 map<int, map<int,int> >::iterator fed = FEDmap ->
find(FEDid);
53 if (fen == FEDorder ->
end()) {
54 if (debug_)
cout <<
"New FED in TowerBlockFormatter " <<
dec << FEDid <<
" 0x" << hex << FEDid << endl;
56 pair<map<int, map<int,int> >::iterator,
bool> t1 = FEDorder ->
insert(map<
int, map<int,int> >::
value_type(FEDid,FEorder));
58 pair<map<int, map<int,int> >::iterator,
bool>
t2 = FEDmap ->
insert(map<
int, map<int,int> >::
value_type(FEDid,FEmap));
63 map<int, int>& FEorder = (*fen).second;
64 map<int, int>& FEmap = (*fed).second;
66 map<int,int>::iterator fe = FEorder.find(iFE);
69 if (fe != FEorder.end()) {
70 FE_order = (*fe).second;
71 map<int,int>::iterator
ff = FEmap.find(FE_order);
72 if (ff == FEmap.end())
cout <<
"Error with maps... " << endl;
73 FE_index = (*ff).second;
74 if (debug_)
cout <<
"FE already there, FE_index = " <<
dec << FE_index <<
" FEorder " << FE_order << endl;
77 if (debug_)
cout <<
"New FE in TowerBlockFormatter FE " <<
dec << iFE <<
" 0x" << hex << iFE <<
" in FED id " <<
dec << FEDid << endl;
79 int number_FEs = FEorder.size() -1;
80 FE_order = number_FEs+1;
82 if (! t2.second)
cout <<
" FE insertion failed...";
85 FE_index = (*fe).second;
86 if (debug_)
cout <<
"Build the Tower Block header for FE id " << iFE <<
" start at line " << rdsize << endl;
87 if (debug_)
cout <<
"This is the Fe number (order) " << number_FEs+1 << endl;
88 rawdata.
resize( 8*rdsize + 8);
89 unsigned char* pData = rawdata.
data();
90 pData[8*FE_index] = iFE & 0xFF;
91 pData[8*FE_index+1] = (nsamples & 0x7F);
92 pData[8*FE_index+2] = bx & 0xFF;
93 pData[8*FE_index+3] = (bx >>8) & 0x0F;
94 pData[8*FE_index+3] |= 0xa0;
95 pData[8*FE_index+4] = lv1 & 0xFF;
96 pData[8*FE_index+5] = (lv1 >>8) & 0x0F;
97 pData[8*FE_index+6] = 1;
98 pData[8*FE_index+7] = 0xc0;
99 if (debug_)
print(rawdata);
107 int ichannel = elid.
xtalId();
109 if (debug_)
cout <<
"Now add crystal : strip channel " <<
dec << istrip <<
" " << ichannel << endl;
112 unsigned char* pData = rawdata.
data();
114 vector<unsigned char> vv(&pData[0],&pData[rawdata.
size()]);
117 int n_add = 2 + 2*nsamples;
118 if (n_add % 8 != 0) n_add = n_add/8 +1;
121 if (debug_)
cout <<
"will add " << n_add <<
" lines of 64 bits at line " << (FE_index+1) << endl;
123 unsigned char* ppData = rawdata.
data();
125 vector<unsigned char>::iterator iter = vv.begin() + 8*(FE_index+1);
127 vector<unsigned char> toadd(n_add*8);
131 toadd[0] = (istrip & 0x7) + ((ichannel & 0x7)<<4);
132 toadd[1] = (tzs & 0x1) <<12;
134 for (
int isample=0; isample < (n_add*8-2)/2; isample++) {
135 if (isample < nsamples) {
136 uint16_t word = (dataframe.
sample(isample)).raw();
137 toadd[2 + isample*2] = word & 0x00FF;
138 toadd[2 + isample*2 +1] = (word & 0xFF00)>>8;
141 toadd[2 + isample*2] = 0;
142 toadd[2 + isample*2 +1] = 0;
144 if (isample % 2 == 0) toadd[2 + isample*2 +1] |= 0xc0;
147 vv.insert(iter,toadd.begin(),toadd.end());
151 for (
int i=0;
i < (int)vv.size();
i++) {
156 cout <<
"pData for this FED is now " << endl;
161 for (
int i=FE_order+1;
i < (int)FEorder.size();
i++) {
163 if (debug_)
cout <<
"FEmap updated for fe number " <<
dec <<
i << endl;
164 if (debug_)
cout <<
" FEmap[" <<
i <<
"] = " << FEmap[
i] << endl;
168 int blocklength = ppData[8*FE_index+6]
169 + ((ppData[8*FE_index+7] & 0x1)<<8);
170 blocklength += n_add;
171 ppData[8*FE_index+6] = blocklength & 0xFF;
172 ppData[8*FE_index+7] |= (blocklength & 0x100)>>8;
186 if (debug_)
cout <<
"enter in TowerBlockFormatter::EndEvent. First reorder the FE's. " << endl;
188 for (
int idcc=1; idcc <= 54; idcc++) {
196 FEDRawData& fedData = productRawData -> FEDData(FEDid);
197 if (fedData.
size() <= 16)
continue;
199 if (debug_)
cout <<
"This is FEDid = " << FEDid << endl;
201 unsigned char * pData = fedData.
data();
205 int length = fedData.
size() / 8;
206 int iDAQ_header(-1), iDCC_header(-1), iTCCBlock_header(-1),
207 iSRBlock_header(-1), iTowerBlock_header(-1), iDAQ_trailer(-1);
209 for (
int i=length-1;
i > -1;
i--) {
210 if ( ( (words[
i] >> 60) & 0xF) == 0x5 ) iDAQ_header=
i;
211 if ( ( (words[
i] >> 62) & 0x3) == 0x0 ) iDCC_header=
i;
212 if ( ( (words[
i] >> 61) & 0x7) == 0x3 ) iTCCBlock_header=
i;
213 if ( ( (words[
i] >> 61) & 0x7) == 0x4 ) iSRBlock_header=
i;
214 if ( ( (words[
i] >> 62) & 0x3) == 0x3 ) iTowerBlock_header=
i;
215 if ( ( (words[
i] >> 60) & 0xF) == 0xA ) iDAQ_trailer=
i;
218 if (iTowerBlock_header < 0) iTowerBlock_header = iDAQ_trailer;
219 if (iSRBlock_header < 0) iSRBlock_header = iTowerBlock_header;
220 if (iTCCBlock_header < 0) iTCCBlock_header = iSRBlock_header;
223 cout <<
"iDAQ_header = " << iDAQ_header << endl;
224 cout <<
" iDCC_header = " << iDCC_header << endl;
225 cout <<
" iTCCBlock_header = " << iTCCBlock_header << endl;
226 cout <<
" iSRBlock_header = " << iSRBlock_header << endl;
227 cout <<
" iTowerBlock_header = " << iTowerBlock_header << endl;
228 cout <<
" iDAQ_trailer = " << iDAQ_trailer << endl;
231 std::map<int, int> FrontEnd;
232 std::map<int, std::vector<Word64> > Map_xtal_data;
234 int iTowerBlock_header_keep = iTowerBlock_header;
236 while (iTowerBlock_header < iDAQ_trailer) {
237 int fe = words[iTowerBlock_header] & 0xFF;
238 int nlines = (words[iTowerBlock_header] >> 48) & 0x1FF;
239 if (debug_)
cout <<
"This is FE number " << fe <<
"needs nlines = " << nlines << endl;
240 FrontEnd[fe] = nlines;
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();
253 it != FrontEnd.end(); it++) {
254 int fe = it ->
first;
256 cout <<
"FE line " << fe <<
" " << l << endl;
260 iTowerBlock_header = iTowerBlock_header_keep;
261 for (std::map<int, int>::const_iterator it=FrontEnd.begin();
262 it != FrontEnd.end(); it++) {
263 int fe = it ->
first;
264 int nlines = it ->
second;
265 if (debug_)
cout <<
"iTowerBlock_header = " << iTowerBlock_header << endl;
266 vector<Word64> xtal_data = Map_xtal_data[fe];
267 for (
int j=0;
j < nlines;
j++) {
268 words[iTowerBlock_header+
j] = xtal_data[
j];
269 if (debug_)
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;
282 if (debug_)
cout <<
"now reorder the xtals within the FEs" << endl;
284 iTowerBlock_header = iTowerBlock_header_keep;
286 for (std::map<int, int>::const_iterator it=FrontEnd.begin();
287 it != FrontEnd.end(); it++) {
289 int fe = it ->
first;
290 if (fe > 68)
cout <<
"Problem... fe = " << fe <<
" in FEDid = " << FEDid << endl;
291 if (debug_)
cout <<
" This is for FE = " << fe << endl;
292 int nlines = it ->
second;
293 int timesamples = pData[8*iTowerBlock_header+1] & 0x7F;
294 int n4=timesamples-3;
296 if ( n4 % 4 != 0) n_lines4 ++;
297 if (n_lines4<0) n_lines4=0;
298 int Nxtal_max = (nlines-1)/(1+n_lines4);
301 map< int, map<int, vector<Word64> > > Strip_Map;
303 while (Nxtal < Nxtal_max) {
305 int i_xtal = iTowerBlock_header+1 + Nxtal*(1+n_lines4);
306 int strip = words[i_xtal] & 0x7;
307 int xtal = ( words[i_xtal] >>4) & 0x7;
309 map< int, map<int, vector<Word64> > >::iterator iit = Strip_Map.find(strip);
311 map<int, vector<Word64> > NewMap;
312 map<int, vector<Word64> > Xtal_Map;
314 if (iit == Strip_Map.end()) {
321 std::vector<Word64> xtal_data;
322 for (
int j=0;
j < n_lines4 +1;
j++) {
324 xtal_data.push_back(ww);
326 Xtal_Map[xtal] = xtal_data;
327 Strip_Map[strip] = Xtal_Map;
335 for (map<
int, map<
int, vector<Word64> > >::const_iterator jt = Strip_Map.begin();
336 jt != Strip_Map.end(); jt++) {
338 int strip = jt ->
first;
339 if (debug_)
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();
343 kt != Xtal_Map.end(); kt++) {
344 int xtal = kt ->
first;
345 if (debug_)
cout <<
" this is xtal number " << xtal << endl;
346 vector<Word64> xtal_data = kt ->
second;
348 int mlines = (int)xtal_data.size();
349 if (debug_)
cout <<
" mlines = " << mlines << endl;
350 for (
int j=0;
j < mlines;
j++) {
351 int line = iTowerBlock_header+1+idx+
j;
352 if (line >= iDAQ_trailer)
cout <<
"smth wrong... line " << line <<
" trailer " << iDAQ_trailer << endl;
353 words[
line] = xtal_data[
j] ;
354 if (debug_)
cout <<
" updated line " << iTowerBlock_header+idx+j << endl;
365 iTowerBlock_header += nlines;
369 if (debug_)
cout <<
" DONE FOR FED " << FEDid << endl;
371 Map_xtal_data.clear();
395 FEDmap =
new map<int, map<int,int> >;
396 FEDorder =
new map<int, map<int,int> >;
416 int rdsize = rawdata.
size() / 8;
420 int DCCid = elid.
dccId();
424 if (debug_)
cout <<
"enter in TowerBlockFormatter::DigiToRaw DCCid FEDid iFE " <<
425 dec << DCCid <<
" " << FEDid <<
" " << iFE << endl;
427 int nsamples = dataframe.
size();
429 if (iFE <= 0 || iFE > 68) {
430 cout <<
"invalid iFE for EndCap DCCid iFE " << DCCid <<
" " << iFE << endl;
435 map<int, map<int,int> >::iterator fen = FEDorder ->
find(FEDid);
436 map<int, map<int,int> >::iterator fed = FEDmap ->
find(FEDid);
438 if (fen == FEDorder ->
end()) {
439 if (debug_)
cout <<
"New FED in TowerBlockFormatter " <<
dec << FEDid <<
" 0x" << hex << FEDid << endl;
440 map<int,int> FEorder;
441 pair<map<int, map<int,int> >::iterator,
bool> t1 = FEDorder ->
insert(map<
int, map<int,int> >::
value_type(FEDid,FEorder));
443 pair<map<int, map<int,int> >::iterator,
bool>
t2 = FEDmap ->
insert(map<
int, map<int,int> >::
value_type(FEDid,FEmap));
448 map<int, int>& FEorder = (*fen).second;
449 map<int, int>& FEmap = (*fed).second;
451 map<int,int>::iterator fe = FEorder.find(iFE);
454 if (fe != FEorder.end()) {
455 FE_order = (*fe).second;
456 map<int,int>::iterator
ff = FEmap.find(FE_order);
457 if (ff == FEmap.end())
cout <<
"Error with maps... " << endl;
458 FE_index = (*ff).second;
459 if (debug_)
cout <<
"FE already there, FE_index = " <<
dec << FE_index <<
" FEorder " << FE_order << endl;
462 if (debug_)
cout <<
"New FE in TowerBlockFormatter FE " <<
dec << iFE <<
" 0x" << hex << iFE <<
" in FED id " <<
dec << FEDid << endl;
464 int number_FEs = FEorder.size() -1;
465 FE_order = number_FEs+1;
467 if (! t2.second)
cout <<
" FE insertion failed...";
470 FE_index = (*fe).second;
471 if (debug_)
cout <<
"Build the Tower Block header for FE id " << iFE <<
" start at line " << rdsize << endl;
472 if (debug_)
cout <<
"This is the Fe number (order) " << number_FEs+1 << endl;
473 rawdata.
resize( 8*rdsize + 8);
474 unsigned char* pData = rawdata.
data();
476 pData[8*FE_index] = iFE & 0xFF;
477 pData[8*FE_index+1] = (nsamples & 0x7F);
478 pData[8*FE_index+2] = bx & 0xFF;
479 pData[8*FE_index+3] = (bx >>8) & 0x0F;
480 pData[8*FE_index+3] |= 0xa0;
481 pData[8*FE_index+4] = lv1 & 0xFF;
482 pData[8*FE_index+5] = (lv1 >>8) & 0x0F;
483 pData[8*FE_index+6] = 1;
484 pData[8*FE_index+7] = 0xc0;
485 if (debug_)
print(rawdata);
493 int ichannel = elid.
xtalId();
495 if (debug_)
cout <<
"Now add crystal strip channel " <<
dec << istrip <<
" " << ichannel << endl;
497 unsigned char* pData = rawdata.
data();
499 vector<unsigned char> vv(&pData[0],&pData[rawdata.
size()]);
502 int n_add = 2 + 2*nsamples;
503 if (n_add % 8 != 0) n_add = n_add/8 +1;
506 if (debug_)
cout <<
"nsamples = " <<
dec << nsamples << endl;
507 if (debug_)
cout <<
"will add " << n_add <<
" lines of 64 bits at line " << (FE_index+1) << endl;
509 unsigned char* ppData = rawdata.
data();
511 vector<unsigned char>::iterator iter = vv.begin() + 8*(FE_index+1);
513 vector<unsigned char> toadd(n_add*8);
517 toadd[0] = (istrip & 0x7) + ((ichannel & 0x7)<<4);
518 toadd[1] = (tzs & 0x1) <<12;
520 for (
int isample=0; isample < (n_add*8-2)/2; isample++) {
521 if (isample < nsamples) {
522 uint16_t word = (dataframe.
sample(isample)).raw();
523 toadd[2 + isample*2] = word & 0x00FF;
524 toadd[2 + isample*2 +1] = (word & 0xFF00)>>8;
527 toadd[2 + isample*2] = 0;
528 toadd[2 + isample*2 +1] = 0;
530 if (isample % 2 == 0) toadd[2 + isample*2 +1] |= 0xc0;
533 vv.insert(iter,toadd.begin(),toadd.end());
537 for (
int i=0;
i < (int)vv.size();
i++) {
542 cout <<
"pData for this FED is now " << endl;
547 for (
int i=FE_order+1;
i < (int)FEorder.size();
i++) {
549 if (debug_)
cout <<
"FEmap updated for fe number " <<
dec <<
i << endl;
550 if (debug_)
cout <<
" FEmap[" <<
i <<
"] = " << FEmap[
i] << endl;
554 int blocklength = ppData[8*FE_index+6]
555 + ((ppData[8*FE_index+7] & 0x1)<<8);
556 blocklength += n_add;
557 ppData[8*FE_index+6] = blocklength & 0xFF;
558 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
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)
Container::value_type value_type
auto const T2 &decltype(t1.eta()) t2
void resize(size_t newsize)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.