CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RawDataTask.cc
Go to the documentation of this file.
1 #include "../interface/RawDataTask.h"
2 
4 
7 
9 
10 namespace ecaldqm {
11 
13  DQWorkerTask(_params, _paths, "RawDataTask"),
14  hltTaskMode_(0),
15  hltTaskFolder_(""),
16  run_(0),
17  l1A_(0),
18  orbit_(0),
19  bx_(0),
20  triggerType_(0),
21  feL1Offset_(0)
22  {
24  (0x1 << kLumiSection) |
25  (0x1 << kSource) |
26  (0x1 << kEcalRawData);
27 
28  dependencies_.push_back(std::pair<Collections, Collections>(kEcalRawData, kSource));
29 
30  edm::ParameterSet const& commonParams(_params.getUntrackedParameterSet("Common"));
31 
32  hltTaskMode_ = commonParams.getUntrackedParameter<int>("hltTaskMode");
33  hltTaskFolder_ = commonParams.getUntrackedParameter<std::string>("hltTaskFolder");
34 
35  if(hltTaskMode_ != 0 && hltTaskFolder_.size() == 0)
36  throw cms::Exception("InvalidConfiguration") << "HLTTask mode needs a folder name";
37 
38  if(hltTaskMode_ != 0){
39  std::map<std::string, std::string> replacements;
40  replacements["hlttask"] = hltTaskFolder_;
41 
42  MEs_[kFEDEntries]->name(replacements);
43  MEs_[kFEDFatal]->name(replacements);
44  }
45  }
46 
48  {
49  }
50 
51  void
53  {
55 
56  if(hltTaskMode_ != 1){
57  std::string eventTypes[nEventTypes];
58  eventTypes[0] = "UNKNOWN";
59  // From DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h; should move to reflex
60  eventTypes[EcalDCCHeaderBlock::COSMIC + 1] = "COSMIC";
61  eventTypes[EcalDCCHeaderBlock::BEAMH4 + 1] = "BEAMH4";
62  eventTypes[EcalDCCHeaderBlock::BEAMH2 + 1] = "BEAMH2";
63  eventTypes[EcalDCCHeaderBlock::MTCC + 1] = "MTCC";
64  eventTypes[EcalDCCHeaderBlock::LASER_STD + 1] = "LASER_STD";
65  eventTypes[EcalDCCHeaderBlock::LASER_POWER_SCAN + 1] = "LASER_POWER_SCAN";
66  eventTypes[EcalDCCHeaderBlock::LASER_DELAY_SCAN + 1] = "LASER_DELAY_SCAN";
67  eventTypes[EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM + 1] = "TESTPULSE_SCAN_MEM";
68  eventTypes[EcalDCCHeaderBlock::TESTPULSE_MGPA + 1] = "TESTPULSE_MGPA";
69  eventTypes[EcalDCCHeaderBlock::PEDESTAL_STD + 1] = "PEDESTAL_STD";
70  eventTypes[EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN + 1] = "PEDESTAL_OFFSET_SCAN";
71  eventTypes[EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN + 1] = "PEDESTAL_25NS_SCAN";
72  eventTypes[EcalDCCHeaderBlock::LED_STD + 1] = "LED_STD";
73  eventTypes[EcalDCCHeaderBlock::PHYSICS_GLOBAL + 1] = "PHYSICS_GLOBAL";
74  eventTypes[EcalDCCHeaderBlock::COSMICS_GLOBAL + 1] = "COSMICS_GLOBAL";
75  eventTypes[EcalDCCHeaderBlock::HALO_GLOBAL + 1] = "HALO_GLOBAL";
76  eventTypes[EcalDCCHeaderBlock::LASER_GAP + 1] = "LASER_GAP";
77  eventTypes[EcalDCCHeaderBlock::TESTPULSE_GAP + 1] = "TESTPULSE_GAP";
78  eventTypes[EcalDCCHeaderBlock::PEDESTAL_GAP + 1] = "PEDESTAL_GAP";
79  eventTypes[EcalDCCHeaderBlock::LED_GAP + 1] = "LED_GAP";
80  eventTypes[EcalDCCHeaderBlock::PHYSICS_LOCAL + 1] = "PHYSICS_LOCAL";
81  eventTypes[EcalDCCHeaderBlock::COSMICS_LOCAL + 1] = "COSMICS_LOCAL";
82  eventTypes[EcalDCCHeaderBlock::HALO_LOCAL + 1] = "HALO_LOCAL";
83  eventTypes[EcalDCCHeaderBlock::CALIB_LOCAL + 1] = "CALIB_LOCAL";
84 
85  std::string statuses[nFEFlags];
86  statuses[Enabled] = "ENABLED";
87  statuses[Disabled] = "DISABLED";
88  statuses[Timeout] = "TIMEOUT";
89  statuses[HeaderError] = "HEADERERROR";
90  statuses[ChannelId] = "CHANNELID";
91  statuses[LinkError] = "LINKERROR";
92  statuses[BlockSize] = "BLOCKSIZE";
93  statuses[Suppressed] = "SUPPRESSED";
94  statuses[FIFOFull] = "FIFOFULL";
95  statuses[L1ADesync] = "L1ADESYNC";
96  statuses[BXDesync] = "BXDESYNC";
97  statuses[L1ABXDesync] = "L1ABXDESYNC";
98  statuses[FIFOFullL1ADesync] = "FIFOFULLL1ADESYNC";
99  statuses[HParity] = "HPARITY";
100  statuses[VParity] = "VPARITY";
101  statuses[ForcedZS] = "FORCEDZS";
102 
103  for(unsigned iME(kEventTypePreCalib); iME < kFEByLumi; iME++)
104  MEs_[iME]->book();
105 
106  for(int i(1); i <= nEventTypes; i++){
107  MEs_[kEventTypePreCalib]->setBinLabel(0, i, eventTypes[i - 1], 1);
108  MEs_[kEventTypeCalib]->setBinLabel(0, i, eventTypes[i - 1], 1);
109  MEs_[kEventTypePostCalib]->setBinLabel(0, i, eventTypes[i - 1], 1);
110  }
111 
112  for(int i(1); i <= nFEFlags; i++)
113  MEs_[kFEStatus]->setBinLabel(-1, i, statuses[i - 1], 2);
114  }
115 
116  if(hltTaskMode_ != 0){
117  MEs_[kFEDEntries]->book();
118  MEs_[kFEDFatal]->book();
119  }
120  }
121 
122  void
124  {
125  if(MEs_[kDesyncByLumi]->isActive()) MEs_[kDesyncByLumi]->reset();
126  if(MEs_[kFEByLumi]->isActive()) MEs_[kFEByLumi]->reset();
127  }
128 
129  void
131  {
132  run_ = _evt.run();
133  orbit_ = _evt.orbitNumber() & 0xffffff;
134  bx_ = _evt.bunchCrossing() & 0xfff;
135  triggerType_ = _evt.experimentType() & 0xf;
136  l1A_ = 0;
137  feL1Offset_ = _evt.isRealData() ? 1 : 0;
138  }
139 
140  void
142  {
143  // Get GT L1 info
144  const FEDRawData &gtFED(_fedRaw.FEDData(812));
145  if(gtFED.size() > sizeof(uint64_t)){ // FED header is one 64 bit word
146  uint32_t *halfHeader((uint32_t *)gtFED.data());
147  l1A_ = *(halfHeader + 1) & 0xffffff;
148  }
149 
150  for(unsigned iFED(601); iFED <= 654; iFED++){
151  const FEDRawData& fedData(_fedRaw.FEDData(iFED));
152  unsigned length(fedData.size() / sizeof(uint64_t));
153  if(length > 1){ // FED header is one 64 bit word
154  if(MEs_[kFEDEntries]->isActive()) MEs_[kFEDEntries]->fill(iFED - 600);
155 
156  const uint64_t* pData(reinterpret_cast<const uint64_t*>(fedData.data()));
157  bool crcError((pData[length - 1] >> 2) & 0x1);
158 
159  if(crcError && MEs_[kFEDFatal]->isActive()) MEs_[kFEDFatal]->fill(iFED - 600);
160  if(crcError && MEs_[kCRC]->isActive()) MEs_[kCRC]->fill(iFED - 600);
161  }
162  }
163  }
164 
165  void
167  {
168  using namespace std;
169 
170  if(hltTaskMode_ == 1) return;
171 
172  if(!l1A_){
173  // majority vote on L1A.. is there no better implementation?
174  map<int, int> l1aCounts;
175  for(EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr){
176  l1aCounts[dcchItr->getLV1()]++;
177  }
178  int maxVote(0);
179  for(map<int, int>::iterator l1aItr(l1aCounts.begin()); l1aItr != l1aCounts.end(); ++l1aItr){
180  if(l1aItr->second > maxVote){
181  maxVote = l1aItr->second;
182  l1A_ = l1aItr->first;
183  }
184  }
185  }
186 
187  for(EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr){
188  unsigned dccId(dcchItr->id());
189 
190  int dccL1A(dcchItr->getLV1());
191  short dccL1AShort(dccL1A & 0xfff);
192  int dccBX(dcchItr->getBX());
193 
194  if(dcchItr->getRunNumber() != run_) MEs_[kRunNumber]->fill(dccId);
195  if(dcchItr->getOrbit() != orbit_) MEs_[kOrbit]->fill(dccId);
196  if(dcchItr->getBasicTriggerType() != triggerType_) MEs_[kTriggerType]->fill(dccId);
197  if(dccL1A != l1A_) MEs_[kL1ADCC]->fill(dccId);
198  if(dccBX != bx_) MEs_[kBXDCC]->fill(dccId);
199 
200  const vector<short> &feStatus(dcchItr->getFEStatus());
201  const vector<short> &feBxs(dcchItr->getFEBxs());
202  const vector<short> &feL1s(dcchItr->getFELv1());
203 
204  bool feDesync(false);
205  bool statusError(false);
206 
207  for(unsigned iFE(0); iFE < feStatus.size(); iFE++){
208  if(!ccuExists(dccId, iFE + 1)) continue;
209 
210  short status(feStatus[iFE]);
211 
212  if(status != BXDesync && status != L1ABXDesync){ // BX desync not detected in the DCC
213  if(feBxs[iFE] != dccBX && feBxs[iFE] != -1 && dccBX != -1){
214  MEs_[kBXFE]->fill(dccId);
215  feDesync = true;
216  }
217  }
218 
219  if(status != L1ADesync && status != L1ABXDesync){
220  if(feL1s[iFE] + feL1Offset_ != dccL1AShort && feL1s[iFE] != -1 && dccL1AShort != 0){
221  MEs_[kL1AFE]->fill(dccId);
222  feDesync = true;
223  }
224  }
225 
226  if(iFE >= 68) continue;
227 
228  DetId id(getElectronicsMap()->dccTowerConstituents(dccId, iFE + 1).at(0));
229  MEs_[kFEStatus]->fill(id, status + 0.5);
230 
231  switch(status){
232  case Timeout:
233  case HeaderError:
234  case ChannelId:
235  case LinkError:
236  case BlockSize:
237  case L1ADesync:
238  case BXDesync:
239  case L1ABXDesync:
240  case HParity:
241  case VParity:
242  statusError = true;
243  break;
244  default:
245  continue;
246  }
247  }
248 
249  if(feDesync) MEs_[kDesyncByLumi]->fill(dccId);
250  if(feDesync) MEs_[kDesyncTotal]->fill(dccId);
251  if(statusError) MEs_[kFEByLumi]->fill(dccId);
252 
253  const vector<short> &tccBx(dcchItr->getTCCBx());
254  const vector<short> &tccL1(dcchItr->getTCCLv1());
255 
256  if(tccBx.size() == 4){ // EB uses tccBx[0]; EE uses all
257  if(dccId <= kEEmHigh + 1 || dccId >= kEEpLow + 1){
258  for(int iTCC(0); iTCC < 4; iTCC++){
259 
260  if(tccBx[iTCC] != dccBX && tccBx[iTCC] != -1 && dccBX != -1)
261  MEs_[kBXTCC]->fill(dccId);
262 
263  if(tccL1[iTCC] != dccL1AShort && tccL1[iTCC] != -1 && dccL1AShort != 0)
264  MEs_[kL1ATCC]->fill(dccId);
265 
266  }
267  }else{
268 
269  if(tccBx[0] != dccBX && tccBx[0] != -1 && dccBX != -1)
270  MEs_[kBXTCC]->fill(dccId);
271 
272  if(tccL1[0] != dccL1AShort && tccL1[0] != -1 && dccL1AShort != 0)
273  MEs_[kL1ATCC]->fill(dccId);
274 
275  }
276  }
277 
278  short srpBx(dcchItr->getSRPBx());
279  short srpL1(dcchItr->getSRPLv1());
280 
281  if(srpBx != dccBX && srpBx != -1 && dccBX != -1)
282  MEs_[kBXSRP]->fill(dccId);
283 
284  if(srpL1 != dccL1AShort && srpL1 != -1 && dccL1AShort != 0)
285  MEs_[kL1ASRP]->fill(dccId);
286 
287  const int calibBX(3490);
288 
289  short runType(dcchItr->getRunType() + 1);
290  if(runType < 0 || runType > 22) runType = 0;
291  if(dccBX < calibBX) MEs_[kEventTypePreCalib]->fill(dccId, runType + 0.5, 1. / 54.);
292  else if(dccBX == calibBX) MEs_[kEventTypeCalib]->fill(dccId, runType + 0.5, 1. / 54.);
293  else MEs_[kEventTypePostCalib]->fill(dccId, runType + 0.5, 1. / 54.);
294 
295  }
296  }
297 
298  /*static*/
299  void
300  RawDataTask::setMEData(std::vector<MEData>& _data)
301  {
302  BinService::AxisSpecs eventTypeAxis;
303  eventTypeAxis.nbins = nEventTypes;
304  eventTypeAxis.low = 0.;
305  eventTypeAxis.high = nEventTypes;
306 
307  BinService::AxisSpecs feStatusAxis;
308  feStatusAxis.nbins = nFEFlags;
309  feStatusAxis.low = 0.;
310  feStatusAxis.high = nFEFlags;
311 
312  _data[kEventTypePreCalib] = MEData("EventTypePreCalib", BinService::kEcal, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &eventTypeAxis);
313  _data[kEventTypeCalib] = MEData("EventTypeCalib", BinService::kEcal, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &eventTypeAxis);
314  _data[kEventTypePostCalib] = MEData("EventTypePostCalib", BinService::kEcal, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &eventTypeAxis);
333  }
334 
336 }
int i
Definition: DBlmapReader.cc:9
std::vector< std::pair< Collections, Collections > > dependencies_
Definition: DQWorkerTask.h:31
const EcalElectronicsMapping * getElectronicsMap()
string fill
Definition: lumiContext.py:319
std::vector< T >::const_iterator const_iterator
int bunchCrossing() const
Definition: EventBase.h:62
void runOnRawData(const EcalRawDataCollection &, Collections)
Definition: RawDataTask.cc:166
unsigned dccId(const DetId &)
bool ccuExists(unsigned, unsigned)
bool isRealData() const
Definition: EventBase.h:60
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
ParameterSet const & getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
std::string hltTaskFolder_
Definition: RawDataTask.h:60
RawDataTask(const edm::ParameterSet &, const edm::ParameterSet &)
Definition: RawDataTask.cc:12
RunNumber_t run() const
Definition: Event.h:76
static void setMEData(std::vector< MEData > &)
Definition: RawDataTask.cc:300
int orbitNumber() const
Definition: EventBase.h:63
const_iterator end() const
Definition: DetId.h:20
virtual void bookMEs()
Definition: DQWorker.cc:48
std::vector< MESet * > MEs_
Definition: DQWorker.h:56
unsigned long long uint64_t
Definition: Time.h:15
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
Definition: RawDataTask.cc:123
edm::EventAuxiliary::ExperimentType experimentType() const
Definition: EventBase.h:61
void beginEvent(const edm::Event &, const edm::EventSetup &)
Definition: RawDataTask.cc:130
DEFINE_ECALDQM_WORKER(CertificationClient)
tuple status
Definition: ntuplemaker.py:245
void runOnSource(const FEDRawDataCollection &, Collections)
Definition: RawDataTask.cc:141
const_iterator begin() const
list at
Definition: asciidump.py:428