CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DCCEventBlock.cc
Go to the documentation of this file.
9 #include <sys/time.h>
10 
11 #include <iomanip>
12 #include <sstream>
13 
14 DCCEventBlock::DCCEventBlock( DCCDataUnpacker * u , EcalElectronicsMapper * m , bool hU, bool srpU, bool tccU, bool feU, bool memU, bool forceToKeepFRdata) :
15  unpacker_(u), mapper_(m), headerUnpacking_(hU), srpUnpacking_(srpU), tccUnpacking_(tccU), feUnpacking_(feU),memUnpacking_(memU), forceToKeepFRdata_(forceToKeepFRdata)
16 {
17 
18  // Build a Mem Unpacker Block
19  memBlock_ = new DCCMemBlock(u,m,this);
20 
21  // setup and initialize ch status vectors
22  for( int feChannel=1; feChannel <= 70; feChannel++) { feChStatus_.push_back(0); hlt_.push_back(1);}
23  for( int tccChannel=1; tccChannel <= 4 ; tccChannel++){ tccChStatus_.push_back(0);}
24 
25  // setup and initialize sync vectors
26  for( int feChannel=1; feChannel <= 70; feChannel++) { feBx_.push_back(-1); feLv1_.push_back(-1); }
27  for( int tccChannel=1; tccChannel <= 4 ; tccChannel++){ tccBx_.push_back(-1); tccLv1_.push_back(-1);}
28  srpBx_=-1;
29  srpLv1_=-1;
30 
31 }
32 
33 
35 
36  // reset sync vectors
37  for( int feChannel=1; feChannel <= 70; feChannel++) { feBx_[feChannel-1]=-1; feLv1_[feChannel-1]=-1; }
38  for( int tccChannel=1; tccChannel <= 4 ; tccChannel++){ tccBx_[tccChannel-1]=-1; tccLv1_[tccChannel-1]=-1;}
39  srpBx_=-1;
40  srpLv1_=-1;
41 
42 
43 }
44 
50 }
51 
52 
53 
56 }
57 
58 
59 
60 unsigned int DCCEventBlock::next_tower_search(const unsigned int current_tower_id)
61 {
62  const uint64_t* const prev_data = data_;
63  const unsigned int prev_dwToEnd = dwToEnd_;
64 
65  // expected LV1, BX, #TS
66  const uint32_t lv1 = ((l1_ - 1) & 0xFFF);
67  const uint32_t bx = (bx_ != 3564) ? bx_ : 0;
68  const uint32_t ts = mapper_->numbXtalTSamples();
69 
70  // construct tower header and mask
71  const uint64_t s_hi = 0xC0000000 + lv1;
72  const uint64_t s_lo = 0xC0000000 + (bx << 16) + (ts << 8);
73 
74  const uint64_t sign = (s_hi << 32) + s_lo;
75  const uint64_t mask = 0xC0001FFFDFFF7F00;
76 
77  // step forward to skip header word of problematic tower
78  data_++;
79  dwToEnd_--;
80 
81  //std::cerr << "header of bad tower = " << current_tower_id << " #" << dwToEnd_ << " 0x" << std::hex << *data_ << std::dec << std::endl;
82  //std::cerr << "mask and sign = 0x" << std::hex << mask << " 0x" << sign << std::dec << std::endl;
83 
84  // navigate through tower data blocks to find tower block header
85  while (dwToEnd_ > 0) {
86  data_++;
87  dwToEnd_--;
88 
89  //std::cerr << current_tower_id << " #" << dwToEnd_ << " 0x" << std::hex << *data_ << " 0x" << (*data_ & mask) << std::dec << std::endl;
90 
91  if ((*data_ & mask) == sign) {
92  const unsigned int next_tower_id = (*data_) & 0xFF;
93 
94  if (next_tower_id <= current_tower_id) continue;
95 
96  //std::cerr << "next tower = " << next_tower_id << std::endl;
97 
98  // step back one word of the next tower header
99  data_--;
100  dwToEnd_++;
101 
102  return next_tower_id;
103  }
104  }
105 
106  // can't find next tower header
107  // restore data pointer
108  data_ = prev_data;
109  dwToEnd_ = prev_dwToEnd;
110  return 1000;
111 }
112 
114 
116 
121 
122 }
123 
124 
125 
126 
128 
129 
130  EcalDCCHeaderBlock theDCCheader;
131 
132  // container for fed_id (601-654 for ECAL)
133  theDCCheader.setFedId(fedId_);
134 
135 
136  // this needs to be migrated to the ECAL mapping package
137 
138  // dccId is number internal to ECAL running 1.. 54.
139  // convention is that dccId = (fed_id - 600)
140  int dccId = mapper_->getActiveSM();
141  // DCCHeaders follow the same convenction
142  theDCCheader.setId(dccId);
143 
144 
145  theDCCheader.setRunNumber(runNumber_);
146  theDCCheader.setBasicTriggerType(triggerType_);
147  theDCCheader.setLV1(l1_);
148  theDCCheader.setBX(bx_);
149  theDCCheader.setOrbit(orbitCounter_);
150  theDCCheader.setErrors(dccErrors_);
151  theDCCheader.setSelectiveReadout(sr_);
152  theDCCheader.setZeroSuppression(zs_);
153  theDCCheader.setTestZeroSuppression(tzs_);
154  theDCCheader.setSrpStatus(srChStatus_);
155  theDCCheader.setTccStatus(tccChStatus_);
156  theDCCheader.setFEStatus(feChStatus_);
157 
158 
159  theDCCheader.setSRPLv1(srpLv1_);
160  theDCCheader.setSRPBx(srpBx_);
161  theDCCheader.setFELv1(feLv1_);
162  theDCCheader.setFEBx(feBx_);
163  theDCCheader.setTCCLv1(tccLv1_);
164  theDCCheader.setTCCBx(tccBx_);
165 
166 
167  EcalDCCHeaderRuntypeDecoder theRuntypeDecoder;
168  unsigned int DCCruntype = runType_;
169  unsigned int DCCdetTriggerType = detailedTriggerType_;
170  theRuntypeDecoder.Decode(triggerType_, DCCdetTriggerType , DCCruntype, &theDCCheader);
171 
172  // Add Header to collection
173  (*dccHeaders_)->push_back(theDCCheader);
174 
175 }
176 
177 void DCCEventBlock::display(std::ostream& o){
178  o<<"\n Unpacked Info for DCC Event Class"
179  <<"\n DW1 ============================="
180  <<"\n Fed Id "<<fedId_
181  <<"\n Bx "<<bx_
182  <<"\n L1 "<<l1_
183  <<"\n Trigger Type "<<triggerType_
184  <<"\n DW2 ============================="
185  <<"\n Length "<<blockLength_
186  <<"\n Dcc errors "<<dccErrors_
187  <<"\n Run number "<<runNumber_
188  <<"\n DW3 ============================="
189  <<"\n SR "<<sr_
190  <<"\n ZS "<<zs_
191  <<"\n TZS "<<tzs_
192  <<"\n SRStatus "<<srChStatus_;
193 
194  std::vector<short>::iterator it;
195  int i(0),k(0);
196  for(it = tccChStatus_.begin(); it!=tccChStatus_.end();it++,i++){
197  o<<"\n TCCStatus#"<<i<<" "<<(*it);
198  }
199 
200  i=0;
201  for(it = feChStatus_.begin();it!=feChStatus_.end();it++ ,i++){
202  if(!(i%14)){ o<<"\n DW"<<(k+3)<<" ============================="; k++; }
203  o<<"\n FEStatus#"<<i<<" "<<(*it);
204  }
205 
206  o<<"\n";
207 }
208 
209 
211  if(towerBlock_){ delete towerBlock_; }
212  if(tccBlock_) { delete tccBlock_; }
213  if(memBlock_) { delete memBlock_; }
214  if(srpBlock_) { delete srpBlock_; }
215 }
216 
217 
218 // -----------------------------------------------------------------------
219 // sync checking
220 
221 bool isSynced(const unsigned int dccBx,
222  const unsigned int bx,
223  const unsigned int dccL1,
224  const unsigned int l1,
225  const BlockType type,
226  const unsigned int fov)
227 {
228  // avoid checking for MC until EcalDigiToRaw bugfixed
229  // and to guarantee backward compatibility on RAW data
230  if ( fov < 1 ) return true;
231  // check the BX sync according the following rule:
232  //
233  // FE Block MEM Block TCC Block SRP Block DCC
234  // ------------------------------------------------------------------
235  // fe_bx == mem_bx == 0 tcc_bx == srp_bx == DCC_bx == 3564
236  // fe_bx == mem_bx == tcc_bx == srp_bx == DCC_bx != 3564
237 
238  const bool bxSynced =
239  ((type == FE_MEM) && (bx == 0) && (dccBx == 3564)) ||
240  ((type == FE_MEM) && (bx == dccBx) && (dccBx != 3564)) ||
241  ((type == TCC_SRP) && (bx == dccBx));
242 
243  // check the L1A sync:
244  //
245  // L1A counter relation is valid modulo 0xFFF:
246  // fe_l1 == mem_l1 == (DCC_l1-1) & 0xFFF
247  // tcc_l1 == srp_l1 == DCC_l1 & 0xFFF
248 
249  const bool l1Synced =
250  ((type == FE_MEM) && (l1 == ((dccL1 - 1) & 0xFFF))) ||
251  ((type == TCC_SRP) && (l1 == ( dccL1 & 0xFFF)));
252 
253  return (bxSynced && l1Synced);
254 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
bool isSynced(const unsigned int dccBx, const unsigned int bx, const unsigned int dccL1, const unsigned int l1, const BlockType type, const unsigned int fov)
void setSelectiveReadout(const bool &selectiveReadout)
DCCEventBlock(DCCDataUnpacker *u, EcalElectronicsMapper *m, bool hU, bool srpU, bool tccU, bool feU, bool memU, bool forceToKeepFRdata)
void enableSyncChecks()
unsigned int runType_
Definition: DCCEventBlock.h:98
EcalElectronicsMapper * mapper_
DCCFEBlock * towerBlock_
DCCSRPBlock * srpBlock_
void setFedId(const int &fedId)
unsigned int dwToEnd_
Definition: DCCEventBlock.h:74
void setBasicTriggerType(const short &triggerType)
void enableFeIdChecks()
std::auto_ptr< EcalRawDataCollection > * dccHeaders_
void setTCCBx(const std::vector< short > &tccBx)
unsigned dccId(const DetId &)
DCCMemBlock * memBlock_
void setSRPBx(const short &srpBx)
unsigned int srChStatus_
Definition: DCCEventBlock.h:87
void setFEStatus(const std::vector< short > &feStatus)
void setRunNumber(const int &run)
unsigned int detailedTriggerType_
Definition: DCCEventBlock.h:99
std::vector< short > hlt_
Definition: DCCEventBlock.h:80
unsigned int blockLength_
Definition: DCCEventBlock.h:95
unsigned int triggerType_
Definition: DCCEventBlock.h:93
const uint64_t * data_
Definition: DCCEventBlock.h:72
void setZeroSuppression(const bool &zeroSuppression)
DCCDataUnpacker * unpacker_
Definition: DCCEventBlock.h:71
virtual void updateCollectors()
Definition: DCCFEBlock.cc:20
unsigned int runNumber_
Definition: DCCEventBlock.h:97
std::vector< short > tccBx_
Definition: DCCEventBlock.h:83
unsigned int sr_
unsigned int l1_
Definition: DCCEventBlock.h:92
std::auto_ptr< EcalRawDataCollection > * dccHeadersCollection()
unsigned int bx()
Definition: DCCEventBlock.h:55
void updateCollectors()
Definition: DCCMemBlock.cc:29
std::vector< short > tccLv1_
Definition: DCCEventBlock.h:83
std::vector< short > feBx_
Definition: DCCEventBlock.h:82
void setTestZeroSuppression(const bool &testZeroSuppression)
unsigned int orbitCounter_
bool Decode(unsigned long TrTy, unsigned long detTrTy, unsigned long runType, EcalDCCHeaderBlock *theHeader)
void setTccStatus(const std::vector< short > &tccStatus)
int k[5][pyjets_maxn]
DCCTCCBlock * tccBlock_
std::vector< short > feChStatus_
Definition: DCCEventBlock.h:78
void setSRPLv1(const short &srpLv1)
unsigned long long uint64_t
Definition: Time.h:15
void setErrors(const int &dccErrors)
void setFEBx(const std::vector< short > &feBx)
void setFELv1(const std::vector< short > &feLv1)
void updateCollectors()
std::vector< short > feLv1_
Definition: DCCEventBlock.h:82
void setSrpStatus(const short &srpStatus)
unsigned int bx_
Definition: DCCEventBlock.h:91
BlockType
void setOrbit(const int &orbit)
void enableFeIdChecks()
Definition: DCCFEBlock.h:32
virtual ~DCCEventBlock()
void setId(const int &dccId)
unsigned int zs_
void addHeaderToCollection()
unsigned int next_tower_search(const unsigned int current_tower_id)
void setLV1(const int &LV1)
void setBX(const int &BX)
unsigned int tzs_
void display(std::ostream &o)
std::vector< short > tccChStatus_
Definition: DCCEventBlock.h:79
void setTCCLv1(const std::vector< short > &tccLv1)
unsigned int fedId_
Definition: DCCEventBlock.h:90
unsigned int dccErrors_
Definition: DCCEventBlock.h:96