CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Attributes | Private Attributes
TowerBlockFormatter Class Reference

#include <TowerBlockFormatter.h>

Inheritance diagram for TowerBlockFormatter:
BlockFormatter

Public Member Functions

void DigiToRaw (const EBDataFrame &dataframe, FEDRawData &rawdata, const EcalElectronicsMapping *TheMapping)
 
void DigiToRaw (const EEDataFrame &dataframe, FEDRawData &rawdata, const EcalElectronicsMapping *TheMapping)
 
void EndEvent (FEDRawDataCollection *productRawData)
 
std::map< int, std::map< int, int > > * GetFEDorder ()
 
void StartEvent ()
 
 TowerBlockFormatter ()
 
 ~TowerBlockFormatter ()
 
- Public Member Functions inherited from BlockFormatter
 BlockFormatter ()
 
void CleanUp (FEDRawDataCollection *productRawData, std::map< int, std::map< int, int > > *FEDorder)
 
void DigiToRaw (FEDRawDataCollection *productRawData)
 
void print (FEDRawData &rawdata)
 
void PrintSizes (FEDRawDataCollection *productRawData)
 
void SetParam (EcalDigiToRaw *base)
 
 ~BlockFormatter ()
 

Static Public Attributes

static const int kCardsPerTower = 5
 
- Static Public Attributes inherited from BlockFormatter
static const int kCardsPerTower = 5
 

Private Attributes

std::map< int, std::map< int, int > > * FEDmap
 
std::map< int, std::map< int, int > > * FEDorder
 

Additional Inherited Members

- Public Types inherited from BlockFormatter
typedef uint16_t Word16
 
typedef uint64_t Word64
 
- Protected Attributes inherited from BlockFormatter
bool debug_
 
bool doBarrel_
 
bool doEndCap_
 
bool doSR_
 
bool doTCC_
 
bool doTower_
 
int * pbx_
 
int * pcounter_
 
std::vector< int32_t > * plistDCCId_
 
int * plv1_
 
int * porbit_number_
 
int * prunnumber_
 

Detailed Description

Definition at line 22 of file TowerBlockFormatter.h.

Constructor & Destructor Documentation

TowerBlockFormatter::TowerBlockFormatter ( )

Definition at line 15 of file TowerBlockFormatter.cc.

15  {
16 
17 }
TowerBlockFormatter::~TowerBlockFormatter ( )

Definition at line 19 of file TowerBlockFormatter.cc.

19  {
20 
21 }

Member Function Documentation

void TowerBlockFormatter::DigiToRaw ( const EBDataFrame dataframe,
FEDRawData rawdata,
const EcalElectronicsMapping TheMapping 
)

Definition at line 25 of file TowerBlockFormatter.cc.

References gather_cfg::cout, FEDRawData::data(), TauDecayModes::dec, end, Exception, alignCSCRings::ff, spr::find(), mps_fire::i, EBDataFrame::id(), edm::eventsetup::heterocontainer::insert(), createfilelist::int, genParticles_cff::map, FEDNumbering::MINECALFEDID, edm::print(), FEDRawData::resize(), EcalDataFrame::sample(), EcalDataFrame::size(), FEDRawData::size(), EcalElectronicsId::stripId(), EcalElectronicsId::towerId(), groupFilesInBlocks::tt, and EcalElectronicsId::xtalId().

28 {
29 
30  int bx = *pbx_;
31  int lv1 = *plv1_ - 1;
32 
33 
34  int rdsize = rawdata.size() / 8; // size in Word64
35 
36  const EBDetId& ebdetid = dataframe.id();
37 
38  int DCCid = TheMapping -> DCCid(ebdetid);
39  int FEDid = FEDNumbering::MINECALFEDID + DCCid ;
40 
41 
42  int nsamples = dataframe.size();
43  // -- FE number
44  const EcalElectronicsId& elid = TheMapping -> getElectronicsId(ebdetid);
45  int iFE = elid.towerId();
46  if (iFE <= 0 || iFE > 68) throw cms::Exception("InvalidFEid") <<
47  "TowerBlockFormatter::DigiToRaw : Invalid iFE " << iFE << endl;
48 
49 
50  map<int, map<int,int> >::iterator fen = FEDorder -> find(FEDid);
51  map<int, map<int,int> >::iterator fed = FEDmap -> find(FEDid);
52 
53  if (fen == FEDorder -> end()) {
54  if (debug_) cout << "New FED in TowerBlockFormatter " << dec << FEDid << " 0x" << hex << FEDid << endl;
55  map<int,int> FEorder;
56  pair<map<int, map<int,int> >::iterator, bool> t1 = FEDorder -> insert(map<int, map<int,int> >::value_type(FEDid,FEorder));
57  map<int,int> FEmap;
58  pair<map<int, map<int,int> >::iterator, bool> t2 = FEDmap -> insert(map<int, map<int,int> >::value_type(FEDid,FEmap));
59  fen = t1.first;
60  fed = t2.first;
61  }
62 
63  map<int, int>& FEorder = (*fen).second;
64  map<int, int>& FEmap = (*fed).second;
65 
66  map<int,int>::iterator fe = FEorder.find(iFE);
67  int FE_order;
68  int FE_index;
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;
75  }
76  else {
77  if (debug_) cout << "New FE in TowerBlockFormatter FE " << dec << iFE << " 0x" << hex << iFE << " in FED id " << dec << FEDid << endl;
78  int inser = rdsize;
79  int number_FEs = FEorder.size() -1;
80  FE_order = number_FEs+1;
81  pair<map<int,int>::iterator, bool> t2 = FEorder.insert(map<int,int>::value_type(iFE,FE_order));
82  if (! t2.second) cout << " FE insertion failed...";
83  pair<map<int,int>::iterator, bool> tt = FEmap.insert(map<int,int>::value_type(FE_order,inser));
84  fe = tt.first;
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);
100 
101  }
102 
103 
104  // -- Crystal number inside the SM :
105 
106  int istrip = elid.stripId();
107  int ichannel = elid.xtalId();
108 
109  if (debug_) cout << "Now add crystal : strip channel " << dec << istrip << " " << ichannel << endl;
110 
111 
112  unsigned char* pData = rawdata.data();
113 
114  vector<unsigned char> vv(&pData[0],&pData[rawdata.size()]);
115 
116 
117  int n_add = 2 + 2*nsamples; // 2 bytes per sample, plus 2 bytes before sample 0
118  if (n_add % 8 != 0) n_add = n_add/8 +1;
119  else
120  n_add = n_add/8;
121  if (debug_) cout << "will add " << n_add << " lines of 64 bits at line " << (FE_index+1) << endl;
122  rawdata.resize( rawdata.size() + 8*n_add );
123  unsigned char* ppData = rawdata.data();
124 
125  vector<unsigned char>::iterator iter = vv.begin() + 8*(FE_index+1);
126 
127  vector<unsigned char> toadd(n_add*8);
128 
129 
130  int tzs=0;
131  toadd[0] = (istrip & 0x7) + ((ichannel & 0x7)<<4);
132  toadd[1] = (tzs & 0x1) <<12;
133 
134  for (int isample=0; isample < (n_add*8-2)/2; isample++) {
135  if (isample < nsamples) {
136  uint16_t word = (dataframe.sample(isample)).raw(); // 16 bits word corresponding to this sample
137  toadd[2 + isample*2] = word & 0x00FF;
138  toadd[2 + isample*2 +1] = (word & 0xFF00)>>8;
139  }
140  else {
141  toadd[2 + isample*2] = 0;
142  toadd[2 + isample*2 +1] = 0;
143  }
144  if (isample % 2 == 0) toadd[2 + isample*2 +1] |= 0xc0; // need to add the B11 header...
145  }
146 
147  vv.insert(iter,toadd.begin(),toadd.end());
148 
149 
150  // update the pData for this FED :
151  for (int i=0; i < (int)vv.size(); i++) {
152  ppData[i] = vv[i];
153  }
154 
155  if (debug_) {
156  cout << "pData for this FED is now " << endl;
157  print(rawdata);
158  }
159 
160  // and update the FEmap for this FED :
161  for (int i=FE_order+1; i < (int)FEorder.size(); i++) {
162  FEmap[i] += n_add;
163  if (debug_) cout << "FEmap updated for fe number " << dec << i << endl;
164  if (debug_) cout << " FEmap[" << i << "] = " << FEmap[i] << endl;
165  }
166 
167  // update the block length
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;
173 
174 
175 
176 }
key_type id() const
Definition: EBDataFrame.h:31
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::map< int, std::map< int, int > > * FEDmap
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
int towerId() const
get the tower id
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
int size() const
Definition: EcalDataFrame.h:26
void print(FEDRawData &rawdata)
void resize(size_t newsize)
Definition: FEDRawData.cc:32
std::map< int, std::map< int, int > > * FEDorder
#define end
Definition: vmac.h:39
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void TowerBlockFormatter::DigiToRaw ( const EEDataFrame dataframe,
FEDRawData rawdata,
const EcalElectronicsMapping TheMapping 
)

Definition at line 403 of file TowerBlockFormatter.cc.

References gather_cfg::cout, FEDRawData::data(), EcalElectronicsId::dccId(), TauDecayModes::dec, end, alignCSCRings::ff, spr::find(), mps_fire::i, EEDataFrame::id(), edm::eventsetup::heterocontainer::insert(), createfilelist::int, genParticles_cff::map, FEDNumbering::MINECALFEDID, edm::print(), FEDRawData::resize(), EcalDataFrame::sample(), EcalDataFrame::size(), FEDRawData::size(), EcalElectronicsId::stripId(), EcalElectronicsId::towerId(), groupFilesInBlocks::tt, and EcalElectronicsId::xtalId().

408 {
409 
410  // debug_ = false;
411 
412  int bx = *pbx_;
413  int lv1 = *plv1_;
414 
415 
416  int rdsize = rawdata.size() / 8; // size in Word64
417 
418  const EEDetId& eedetid = dataframe.id();
419  EcalElectronicsId elid = TheMapping -> getElectronicsId(eedetid);
420  int DCCid = elid.dccId();
421  int FEDid = FEDNumbering::MINECALFEDID + DCCid ;
422  int iFE = elid.towerId();
423 
424  if (debug_) cout << "enter in TowerBlockFormatter::DigiToRaw DCCid FEDid iFE " <<
425  dec << DCCid << " " << FEDid << " " << iFE << endl;
426 
427  int nsamples = dataframe.size();
428 
429  if (iFE <= 0 || iFE > 68) {
430  cout << "invalid iFE for EndCap DCCid iFE " << DCCid << " " << iFE << endl;
431  return;
432  }
433 
434 
435  map<int, map<int,int> >::iterator fen = FEDorder -> find(FEDid);
436  map<int, map<int,int> >::iterator fed = FEDmap -> find(FEDid);
437 
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));
442  map<int,int> FEmap;
443  pair<map<int, map<int,int> >::iterator, bool> t2 = FEDmap -> insert(map<int, map<int,int> >::value_type(FEDid,FEmap));
444  fen = t1.first;
445  fed = t2.first;
446  }
447 
448  map<int, int>& FEorder = (*fen).second;
449  map<int, int>& FEmap = (*fed).second;
450 
451  map<int,int>::iterator fe = FEorder.find(iFE);
452  int FE_order;
453  int FE_index;
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;
460  }
461  else {
462  if (debug_) cout << "New FE in TowerBlockFormatter FE " << dec << iFE << " 0x" << hex << iFE << " in FED id " << dec << FEDid << endl;
463  int inser = rdsize;
464  int number_FEs = FEorder.size() -1;
465  FE_order = number_FEs+1;
466  pair<map<int,int>::iterator, bool> t2 = FEorder.insert(map<int,int>::value_type(iFE,FE_order));
467  if (! t2.second) cout << " FE insertion failed...";
468  pair<map<int,int>::iterator, bool> tt = FEmap.insert(map<int,int>::value_type(FE_order,inser));
469  fe = tt.first;
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();
475 
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);
486 
487  }
488 
489 
490 
491  // -- Crystal number inside the SM :
492  int istrip = elid.stripId();
493  int ichannel = elid.xtalId();
494 
495  if (debug_) cout << "Now add crystal strip channel " << dec << istrip << " " << ichannel << endl;
496 
497  unsigned char* pData = rawdata.data();
498 
499  vector<unsigned char> vv(&pData[0],&pData[rawdata.size()]);
500 
501 
502  int n_add = 2 + 2*nsamples; // 2 bytes per sample, plus 2 bytes before sample 0
503  if (n_add % 8 != 0) n_add = n_add/8 +1;
504  else
505  n_add = n_add/8;
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;
508  rawdata.resize( rawdata.size() + 8*n_add );
509  unsigned char* ppData = rawdata.data();
510 
511  vector<unsigned char>::iterator iter = vv.begin() + 8*(FE_index+1);
512 
513  vector<unsigned char> toadd(n_add*8);
514 
515 
516  int tzs=0;
517  toadd[0] = (istrip & 0x7) + ((ichannel & 0x7)<<4);
518  toadd[1] = (tzs & 0x1) <<12;
519 
520  for (int isample=0; isample < (n_add*8-2)/2; isample++) {
521  if (isample < nsamples) {
522  uint16_t word = (dataframe.sample(isample)).raw(); // 16 bits word corresponding to this sample
523  toadd[2 + isample*2] = word & 0x00FF;
524  toadd[2 + isample*2 +1] = (word & 0xFF00)>>8;
525  }
526  else {
527  toadd[2 + isample*2] = 0;
528  toadd[2 + isample*2 +1] = 0;
529  }
530  if (isample % 2 == 0) toadd[2 + isample*2 +1] |= 0xc0; // need to add the B11 header...
531  }
532 
533  vv.insert(iter,toadd.begin(),toadd.end());
534 
535 
536  // update the pData for this FED :
537  for (int i=0; i < (int)vv.size(); i++) {
538  ppData[i] = vv[i];
539  }
540 
541  if (debug_) {
542  cout << "pData for this FED is now " << endl;
543  print(rawdata);
544  }
545 
546  // and update the FEmap for this FED :
547  for (int i=FE_order+1; i < (int)FEorder.size(); i++) {
548  FEmap[i] += n_add;
549  if (debug_) cout << "FEmap updated for fe number " << dec << i << endl;
550  if (debug_) cout << " FEmap[" << i << "] = " << FEmap[i] << endl;
551  }
552 
553  // update the block length
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;
559 
560 
561 }
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::map< int, std::map< int, int > > * FEDmap
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
int towerId() const
get the tower id
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
int size() const
Definition: EcalDataFrame.h:26
void print(FEDRawData &rawdata)
void resize(size_t newsize)
Definition: FEDRawData.cc:32
std::map< int, std::map< int, int > > * FEDorder
#define end
Definition: vmac.h:39
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
key_type id() const
Definition: EEDataFrame.h:28
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void TowerBlockFormatter::EndEvent ( FEDRawDataCollection productRawData)

Definition at line 180 of file TowerBlockFormatter.cc.

References hitfit::clear(), gather_cfg::cout, FEDRawData::data(), plotBeamSpotDB::first, mps_fire::i, training_settings::idx, createfilelist::int, checklumidiff::l, geometryCSVtoXML::line, genParticles_cff::map, FEDNumbering::MINECALFEDID, edm::second(), FEDRawData::size(), and digitizers_cfi::strip.

180  {
181 
182 // -- Need to reorder the FE's in teh TowerBlock. They come in the right
183 // order when reading the unsuppressed digis, but ganz durcheinander
184 // when reading the SelectiveReadout_Suppressed digis.
185 
186  if (debug_) cout << "enter in TowerBlockFormatter::EndEvent. First reorder the FE's. " << endl;
187 
188  for (int idcc=1; idcc <= 54; idcc++) {
189 
190  // debug_ = (idcc == 34);
191 
192  //if (idcc != 34) continue;
193 
194  int FEDid = FEDNumbering::MINECALFEDID + idcc;
195  // cout << "Process FED " << FEDid << endl;
196  FEDRawData& fedData = productRawData -> FEDData(FEDid);
197  if (fedData.size() <= 16) continue;
198 
199  if (debug_) cout << "This is FEDid = " << FEDid << endl;
200 
201  unsigned char * pData = fedData.data();
202  // Word64* words = reinterpret_cast<Word64*>(const_cast<unsigned char*>(pData));
203  Word64* words = reinterpret_cast<Word64*>(pData);
204 
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);
208 
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;
216  }
217 
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;
221 
222  if (debug_) {
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;
229  }
230 
231  std::map<int, int> FrontEnd;
232  std::map<int, std::vector<Word64> > Map_xtal_data;
233 
234  int iTowerBlock_header_keep = iTowerBlock_header;
235 
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);
245  }
246  Map_xtal_data[fe] = xtal_data;
247  iTowerBlock_header += nlines;
248  }
249 
250  if (debug_) {
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;
255  int l = it -> second;
256  cout << "FE line " << fe << " " << l << endl;
257  }
258  }
259 
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;
270  }
271  if (debug_) {
272  int jFE = pData[8*(iTowerBlock_header)];
273  cout << "Front End on RD : " << jFE << endl;
274  }
275  iTowerBlock_header += nlines;
276  }
277 
278  // -- now the FEs are ordered. STill need to order the xtals within FEs;
279  // need : xtal 1,2,3,4, 5 in strip 1, xtal 1,2,3,4,5 in strip 2 etc..
280  // with possibly missing ones.
281 
282  if (debug_) cout << "now reorder the xtals within the FEs" << endl;
283 
284  iTowerBlock_header = iTowerBlock_header_keep;
285 
286  for (std::map<int, int>::const_iterator it=FrontEnd.begin();
287  it != FrontEnd.end(); it++) {
288 
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;
295  int n_lines4 = n4/4;
296  if ( n4 % 4 != 0) n_lines4 ++;
297  if (n_lines4<0) n_lines4=0;
298  int Nxtal_max = (nlines-1)/(1+n_lines4);
299  int Nxtal = 0;
300 
301  map< int, map<int, vector<Word64> > > Strip_Map;
302 
303  while (Nxtal < Nxtal_max) {
304 
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;
308 
309  map< int, map<int, vector<Word64> > >::iterator iit = Strip_Map.find(strip);
310 
311  map<int, vector<Word64> > NewMap;
312  map<int, vector<Word64> > Xtal_Map;
313 
314  if (iit == Strip_Map.end()) { // new strip
315  Xtal_Map = NewMap;
316  }
317  else {
318  Xtal_Map = iit -> second;
319  }
320 
321  std::vector<Word64> xtal_data;
322  for (int j=0; j < n_lines4 +1; j++) {
323  Word64 ww = words[i_xtal +j];
324  xtal_data.push_back(ww);
325  }
326  Xtal_Map[xtal] = xtal_data;
327  Strip_Map[strip] = Xtal_Map;
328 
329  Nxtal ++;
330  }
331 
332  // now, update the xtals for this FE :
333 
334  int idx = 0;
335  for (map< int, map<int, vector<Word64> > >::const_iterator jt = Strip_Map.begin();
336  jt != Strip_Map.end(); jt++) {
337 
338  int strip = jt -> first;
339  if (debug_) cout << " this is strip number " << strip << endl;
340  map<int, vector<Word64> > Xtal_Map = jt -> second;
341 
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;
347 
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;
355  }
356  idx += mlines;
357 
358  } // end loop on xtals
359  Xtal_Map.clear();
360 
361  } // end loop on strips
362 
363  Strip_Map.clear();
364 
365  iTowerBlock_header += nlines;
366  } // end loop on FEs
367 
368 
369  if (debug_) cout << " DONE FOR FED " << FEDid << endl;
370  FrontEnd.clear();
371  Map_xtal_data.clear();
372 
373  } // end loop on DCC
374 
375  // cout << " finished reorder, now clean up " << endl;
376 
377 // -- clean up
378 
379  // FEDmap -> empty();
380  // FEDorder -> empty();
381  FEDmap -> clear();
382  FEDorder -> clear();
383  delete FEDmap;
384  delete FEDorder;
385  FEDmap = nullptr;
386  FEDorder = nullptr;
387 
388  debug_ = false;
389 
390  // cout << "end of EndEvent " << endl;
391 }
std::map< int, std::map< int, int > > * FEDmap
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
U second(std::pair< T, U > const &p)
std::map< int, std::map< int, int > > * FEDorder
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
uint64_t Word64
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::map<int, std::map<int,int> >* TowerBlockFormatter::GetFEDorder ( )
inline

Definition at line 33 of file TowerBlockFormatter.h.

References FEDorder.

33 {return FEDorder; }
std::map< int, std::map< int, int > > * FEDorder
void TowerBlockFormatter::StartEvent ( )

Definition at line 393 of file TowerBlockFormatter.cc.

393  {
394 
395  FEDmap = new map<int, map<int,int> >;
396  FEDorder = new map<int, map<int,int> >;
397 
398 }
std::map< int, std::map< int, int > > * FEDmap
std::map< int, std::map< int, int > > * FEDorder

Member Data Documentation

std::map<int, std::map<int,int> >* TowerBlockFormatter::FEDmap
private

Definition at line 36 of file TowerBlockFormatter.h.

std::map<int, std::map<int,int> >* TowerBlockFormatter::FEDorder
private

Definition at line 37 of file TowerBlockFormatter.h.

Referenced by GetFEDorder().

const int TowerBlockFormatter::kCardsPerTower = 5
static

Definition at line 27 of file TowerBlockFormatter.h.