CMS 3D CMS Logo

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