CMS 3D CMS Logo

RawDataTask.cc
Go to the documentation of this file.
2 
6 
9 
12 
13 namespace ecaldqm {
14 
16  : DQWorkerTask(), runNumber_(0), l1A_(0), orbit_(0), bx_(0), triggerType_(0), feL1Offset_(0) {}
17 
19  _dependencies.push_back(Dependency(kEcalRawData, kSource));
20  }
21 
22  void RawDataTask::beginRun(edm::Run const& _run, edm::EventSetup const&) { runNumber_ = _run.run(); }
23 
24  void RawDataTask::beginEvent(edm::Event const& _evt, edm::EventSetup const&, bool const& ByLumiResetSwitch, bool&) {
25  orbit_ = _evt.orbitNumber() & 0xffffffff;
26 
27  bx_ = _evt.bunchCrossing() & 0xfff;
28  // There's no agreement in CMS on how to label the last/first BX
29  // TCDS calls it always 3564, but some subsystems call it 0.
30  // From testing: bx_ is labeled 0, dccBX and FEBxs[iFE] labeled 3564
31  // Setting bx_ to 0 to match the other two
32  if (bx_ == LumiConstants::numBX) // 3564
33  bx_ = 0;
34 
35  triggerType_ = _evt.experimentType() & 0xf;
36  l1A_ = 0;
37  feL1Offset_ = _evt.isRealData() ? 1 : 0;
38  if (ByLumiResetSwitch) {
39  MEs_.at("DesyncByLumi").reset(GetElectronicsMap());
40  MEs_.at("FEByLumi").reset(GetElectronicsMap());
41  MEs_.at("FEStatusErrMapByLumi").reset(GetElectronicsMap());
42  }
43  }
44 
46  MESet& meCRC(MEs_.at("CRC"));
47 
48  // Get GT L1 info
49  const FEDRawData& gtFED(_fedRaw.FEDData(812));
50  if (gtFED.size() > sizeof(uint64_t)) { // FED header is one 64 bit word
51  const uint32_t* halfHeader = reinterpret_cast<const uint32_t*>(gtFED.data());
52  l1A_ = *(halfHeader + 1) & 0xffffff;
53  }
54 
55  for (int iFED(601); iFED <= 654; iFED++) {
56  const FEDRawData& fedData(_fedRaw.FEDData(iFED));
57  unsigned length(fedData.size() / sizeof(uint64_t));
58  if (length > 1) { // FED header is one 64 bit word
59  const uint64_t* pData(reinterpret_cast<uint64_t const*>(fedData.data()));
60  if ((pData[length - 1] & 0x4) != 0)
61  meCRC.fill(getEcalDQMSetupObjects(), iFED - 600);
62  }
63  }
64  }
65 
67  using namespace std;
68 
69  MESet& meRunNumber(MEs_.at("RunNumber"));
70  MESet& meOrbit(MEs_.at("Orbit"));
71  MESet& meOrbitDiff(MEs_.at("OrbitDiff"));
72  MESet& meTriggerType(MEs_.at("TriggerType"));
73  MESet& meL1ADCC(MEs_.at("L1ADCC"));
74  MESet& meBXDCC(MEs_.at("BXDCC"));
75  MESet& meBXDCCDiff(MEs_.at("BXDCCDiff"));
76  MESet& meBXFE(MEs_.at("BXFE"));
77  MESet& meBXFEDiff(MEs_.at("BXFEDiff"));
78  MESet& meBXFEInvalid(MEs_.at("BXFEInvalid"));
79  MESet& meL1AFE(MEs_.at("L1AFE"));
80  MESet& meFEStatus(MEs_.at("FEStatus"));
81  MESet& meFEStatusErrMapByLumi(MEs_.at("FEStatusErrMapByLumi"));
82  MESet& meFEStatusMEM(MEs_.at("FEStatusMEM"));
83  MESet& meDesyncByLumi(MEs_.at("DesyncByLumi"));
84  MESet& meDesyncTotal(MEs_.at("DesyncTotal"));
85  MESet& meFEByLumi(MEs_.at("FEByLumi"));
86  MESet& meBXTCC(MEs_.at("BXTCC"));
87  MESet& meL1ATCC(MEs_.at("L1ATCC"));
88  MESet& meBXSRP(MEs_.at("BXSRP"));
89  MESet& meL1ASRP(MEs_.at("L1ASRP"));
90  MESet& meTrendNSyncErrors(MEs_.at("L1ATCC"));
91  MESet& meTrendBXTCC(MEs_.at("TrendBXTCC"));
92  MESet& meTrendL1ATCC(MEs_.at("TrendL1ATCC"));
93  MESet& meTrendBXSRP(MEs_.at("TrendBXSRP"));
94  MESet& meTrendL1ASRP(MEs_.at("TrendL1ASRP"));
95  MESet& meEventTypePreCalib(MEs_.at("EventTypePreCalib"));
96  MESet& meEventTypeCalib(MEs_.at("EventTypeCalib"));
97  MESet& meEventTypePostCalib(MEs_.at("EventTypePostCalib"));
98 
99  if (!l1A_) {
100  // majority vote on L1A.. is there no better implementation?
101  map<int, int> l1aCounts;
102  for (EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr) {
103  l1aCounts[dcchItr->getLV1()]++;
104  }
105  int maxVote(0);
106  for (map<int, int>::iterator l1aItr(l1aCounts.begin()); l1aItr != l1aCounts.end(); ++l1aItr) {
107  if (l1aItr->second > maxVote) {
108  maxVote = l1aItr->second;
109  l1A_ = l1aItr->first;
110  }
111  }
112  }
113 
114  for (EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr) {
115  int dccId(dcchItr->id());
116 
117  int dccL1A(dcchItr->getLV1());
118  short dccL1AShort(dccL1A & 0xfff);
119  int dccBX(dcchItr->getBX());
120 
121  meOrbitDiff.fill(getEcalDQMSetupObjects(), dccId, dcchItr->getOrbit() - orbit_);
122  meBXDCCDiff.fill(getEcalDQMSetupObjects(), dccId, dccBX - bx_);
123  if (dccBX == -1)
124  meBXFEInvalid.fill(getEcalDQMSetupObjects(), dccId, 68.5);
125 
126  if (dcchItr->getRunNumber() != int(runNumber_))
127  meRunNumber.fill(getEcalDQMSetupObjects(), dccId);
128  if (dcchItr->getOrbit() != orbit_)
129  meOrbit.fill(getEcalDQMSetupObjects(), dccId);
130  if (dcchItr->getBasicTriggerType() != triggerType_)
131  meTriggerType.fill(getEcalDQMSetupObjects(), dccId);
132  if (dccL1A != l1A_)
133  meL1ADCC.fill(getEcalDQMSetupObjects(), dccId);
134  if (dccBX != bx_)
135  meBXDCC.fill(getEcalDQMSetupObjects(), dccId);
136 
137  const vector<short>& feStatus(dcchItr->getFEStatus());
138  const vector<short>& feBxs(dcchItr->getFEBxs());
139  const vector<short>& feL1s(dcchItr->getFELv1());
140 
141  double feDesync(0.);
142  double statusError(0.);
143 
144  for (unsigned iFE(0); iFE < feStatus.size(); iFE++) {
145  if (!ccuExists(dccId, iFE + 1))
146  continue;
147 
148  short status(feStatus[iFE]);
149 
150  if (feBxs[iFE] != -1 && dccBX != -1) {
151  meBXFEDiff.fill(getEcalDQMSetupObjects(), dccId, feBxs[iFE] - dccBX);
152  }
153  if (feBxs[iFE] == -1)
154  meBXFEInvalid.fill(getEcalDQMSetupObjects(), dccId, iFE + 0.5);
155 
156  if (status != BXDesync && status != L1ABXDesync) { // BX desync not detected in the DCC
157  if (feBxs[iFE] != dccBX && feBxs[iFE] != -1 && dccBX != -1) {
158  meBXFE.fill(getEcalDQMSetupObjects(), dccId, iFE + 0.5);
159  feDesync += 1.;
160  }
161  }
162 
163  if (status != L1ADesync && status != L1ABXDesync) {
164  if (feL1s[iFE] + feL1Offset_ != dccL1AShort && feL1s[iFE] != -1 && dccL1AShort != 0) {
165  meL1AFE.fill(getEcalDQMSetupObjects(), dccId, iFE + 0.5);
166  feDesync += 1.;
167  }
168  }
169 
170  if (iFE >= 68) {
171  // FE Status for MEM boxes (towerIds 69 and 70)
172  // Plot contains two bins per dccId. Integer number
173  // bins correspond to towerId 69 and half integer
174  // number bins correspond to towerId 70.
175  if (iFE + 1 == 69)
176  meFEStatusMEM.fill(getEcalDQMSetupObjects(), dccId + 0.0, status);
177  else if (iFE + 1 == 70)
178  meFEStatusMEM.fill(getEcalDQMSetupObjects(), dccId + 0.5, status);
179  continue;
180  }
181 
182  DetId id(GetElectronicsMap()->dccTowerConstituents(dccId, iFE + 1).at(0));
183  meFEStatus.fill(getEcalDQMSetupObjects(), id, status);
184  // Fill FE Status Error Map with error states only
185  if (status != Enabled && status != Suppressed && status != ForcedFullSupp && status != FIFOFull &&
186  status != ForcedZS)
187  meFEStatusErrMapByLumi.fill(getEcalDQMSetupObjects(), id, status);
188 
189  switch (status) {
190  case Timeout:
191  case HeaderError:
192  case ChannelId:
193  case LinkError:
194  case BlockSize:
195  case L1ADesync:
196  case BXDesync:
197  case L1ABXDesync:
198  case HParity:
199  case VParity:
200  statusError += 1.;
201  break;
202  default:
203  continue;
204  }
205  }
206 
207  if (feDesync > 0.) {
208  meDesyncByLumi.fill(getEcalDQMSetupObjects(), dccId, feDesync);
209  meDesyncTotal.fill(getEcalDQMSetupObjects(), dccId, feDesync);
210  meTrendNSyncErrors.fill(getEcalDQMSetupObjects(), double(timestamp_.iLumi), feDesync);
211  }
212  if (statusError > 0.)
213  meFEByLumi.fill(getEcalDQMSetupObjects(), dccId, statusError);
214 
215  const vector<short>& tccBx(dcchItr->getTCCBx());
216  const vector<short>& tccL1(dcchItr->getTCCLv1());
217 
218  if (tccBx.size() == 4) { // EB uses tccBx[0]; EE uses all
219  if (dccId <= kEEmHigh + 1 || dccId >= kEEpLow + 1) {
220  for (int iTCC(0); iTCC < 4; iTCC++) {
221  if (tccBx[iTCC] != dccBX && tccBx[iTCC] != -1 && dccBX != -1) {
222  meBXTCC.fill(getEcalDQMSetupObjects(), dccId);
223  meTrendBXTCC.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), 1);
224  }
225 
226  if (tccL1[iTCC] != dccL1AShort && tccL1[iTCC] != -1 && dccL1AShort != 0) {
227  meL1ATCC.fill(getEcalDQMSetupObjects(), dccId);
228  meTrendL1ATCC.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), 1);
229  }
230  }
231  } else {
232  if (tccBx[0] != dccBX && tccBx[0] != -1 && dccBX != -1) {
233  meBXTCC.fill(getEcalDQMSetupObjects(), dccId);
234  meTrendBXTCC.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), 1);
235  }
236 
237  if (tccL1[0] != dccL1AShort && tccL1[0] != -1 && dccL1AShort != 0) {
238  meL1ATCC.fill(getEcalDQMSetupObjects(), dccId);
239  meTrendL1ATCC.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), 1);
240  }
241  }
242  }
243 
244  short srpBx(dcchItr->getSRPBx());
245  short srpL1(dcchItr->getSRPLv1());
246 
247  if (srpBx != dccBX && srpBx != -1 && dccBX != -1) {
248  meBXSRP.fill(getEcalDQMSetupObjects(), dccId);
249 
250  if (dccId <= kEEmHigh + 1 || dccId >= kEEpLow + 1) { // EE
251  meTrendBXSRP.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), 1);
252  } else { // EB
253  meTrendBXSRP.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), 1);
254  }
255  }
256 
257  if (srpL1 != dccL1AShort && srpL1 != -1 && dccL1AShort != 0) {
258  meL1ASRP.fill(getEcalDQMSetupObjects(), dccId);
259 
260  if (dccId <= kEEmHigh + 1 || dccId >= kEEpLow + 1) { // EE
261  meTrendL1ASRP.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), 1);
262  } else { // EB
263  meTrendL1ASRP.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), 1);
264  }
265  }
266 
267  const int calibBX(3490);
268 
269  short runType(dcchItr->getRunType() + 1);
270  if (runType < 0 || runType > 22)
271  runType = 0;
272  if (dccBX < calibBX)
273  meEventTypePreCalib.fill(getEcalDQMSetupObjects(), dccId, runType, 1. / 54.);
274  else if (dccBX == calibBX)
275  meEventTypeCalib.fill(getEcalDQMSetupObjects(), dccId, runType, 1. / 54.);
276  else
277  meEventTypePostCalib.fill(getEcalDQMSetupObjects(), dccId, runType, 1. / 54.);
278  }
279  }
280 
282 } // namespace ecaldqm
static const char runNumber_[]
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:168
edm::LuminosityBlockNumber_t iLumi
Definition: DQWorker.h:48
void runOnRawData(EcalRawDataCollection const &)
Definition: RawDataTask.cc:66
MESet & at(const std::string &key)
Definition: MESet.h:401
std::vector< T >::const_iterator const_iterator
static const unsigned int numBX
Definition: LumiConstants.h:8
void beginEvent(edm::Event const &, edm::EventSetup const &, bool const &, bool &) override
Definition: RawDataTask.cc:24
bool ccuExists(unsigned, unsigned)
void addDependencies(DependencySet &) override
Definition: RawDataTask.cc:18
RunNumber_t run() const
Definition: RunBase.h:40
edm::RunNumber_t runNumber_
Definition: RawDataTask.h:30
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: RawDataTask.cc:22
unsigned dccId(DetId const &, EcalElectronicsMapping const *)
void runOnSource(FEDRawDataCollection const &)
Definition: RawDataTask.cc:45
const_iterator begin() const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
const_iterator end() const
int orbitNumber() const
Definition: EventBase.h:69
EcalElectronicsMapping const * GetElectronicsMap()
Definition: DQWorker.cc:150
EcalDQMSetupObjects const getEcalDQMSetupObjects()
Definition: DQWorker.cc:170
Definition: DetId.h:17
Timestamp timestamp_
Definition: DQWorker.h:134
unsigned long long uint64_t
Definition: Time.h:13
int bunchCrossing() const
Definition: EventBase.h:68
MESetCollection MEs_
Definition: DQWorker.h:131
bool isRealData() const
Definition: EventBase.h:66
virtual void reset(EcalElectronicsMapping const *, double=0., double=0., double=0.)
Definition: MESet.cc:98
void push_back(Dependency const &_d)
Definition: DQWorkerTask.h:46
edm::EventAuxiliary::ExperimentType experimentType() const
Definition: EventBase.h:67
Definition: Run.h:45