CMS 3D CMS Logo

ESFEDIntegrityTask.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 
10 
13 
20 
21 using namespace cms;
22 using namespace edm;
23 using namespace std;
24 
26 
27  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
28  fedDirName_ = ps.getUntrackedParameter<string>("FEDDirName", "FEDIntegrity");
29  debug_ = ps.getUntrackedParameter<bool>("debug", false);
30 
31  dccCollections_ = consumes<ESRawDataCollection>(ps.getParameter<InputTag>("ESDCCCollections"));
32  FEDRawDataCollection_ = consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("FEDRawDataCollection"));
33 
34  meESFedsEntries_ = nullptr;
35  meESFedsFatal_ = nullptr;
36  meESFedsNonFatal_ = nullptr;
37 
38  ievt_ = 0;
39 
40 }
41 
42 void
44 {
45  char histo[200];
46 
47  iBooker.setCurrentFolder(prefixME_ + "/" + fedDirName_);
48 
49  sprintf(histo, "FEDEntries");
50  meESFedsEntries_ = iBooker.book1D(histo, histo, 56, 520, 576);
51 
52  sprintf(histo, "FEDFatal");
53  meESFedsFatal_ = iBooker.book1D(histo, histo, 56, 520, 576);
54 
55  sprintf(histo, "FEDNonFatal");
56  meESFedsNonFatal_ = iBooker.book1D(histo, histo, 56, 520, 576);
57 }
58 
60 
61  LogInfo("ESFEDIntegrityTask") << "analyzed " << ievt_ << " events";
62 
63 }
64 
66 
67  ievt_++;
68 
69  int gt_L1A = 0;
70  // int gt_OrbitNumber = 0, gt_BX = 0;
71  int esDCC_L1A_MostFreqCounts = 0;
72  int esDCC_BX_MostFreqCounts = 0;
73  int esDCC_OrbitNumber_MostFreqCounts = 0;
74  int gtFedDataSize = 0;
75 
77  Handle<FEDRawDataCollection> allFedRawData;
78 
79  if ( e.getByToken(FEDRawDataCollection_, allFedRawData) ) {
80 
81  // ES FEDs
82  for (int esFED=520; esFED<=575; ++esFED) {
83 
84  const FEDRawData& fedData = allFedRawData->FEDData(esFED);
85  int length = fedData.size()/sizeof(uint64_t);
86 
87  if ( length > 0 )
88  if ( meESFedsEntries_ ) meESFedsEntries_->Fill(esFED);
89  }
90 
91  // GT FED data
92  const FEDRawData& gtFedData = allFedRawData->FEDData(812);
93 
94  gtFedDataSize = gtFedData.size()/sizeof(uint64_t);
95 
96  if ( gtFedDataSize > 0 ) {
97 
98  FEDHeader header(gtFedData.data());
99 
100  gt_L1A = header.lvl1ID();
101  //gt_OrbitNumber = e.orbitNumber();
102  //gt_BX = e.bunchCrossing();
103  } else {
104 
105  map<int, int> esDCC_L1A_FreqMap;
106  map<int, int> esDCC_BX_FreqMap;
107  map<int, int> esDCC_OrbitNumber_FreqMap;
108 
109  if ( e.getByToken(dccCollections_, dccs) ) {
110 
111  for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
112  ESDCCHeaderBlock esdcc = (*dccItr);
113 
114  esDCC_L1A_FreqMap[esdcc.getLV1()]++;
115  esDCC_BX_FreqMap[esdcc.getBX()]++;
116  esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()]++;
117 
118  if (esDCC_L1A_FreqMap[esdcc.getLV1()] > esDCC_L1A_MostFreqCounts) {
119  esDCC_L1A_MostFreqCounts = esDCC_L1A_FreqMap[esdcc.getLV1()];
120  gt_L1A = esdcc.getLV1();
121  }
122 
123  if (esDCC_BX_FreqMap[esdcc.getBX()] > esDCC_BX_MostFreqCounts) {
124  esDCC_BX_MostFreqCounts = esDCC_BX_FreqMap[esdcc.getBX()];
125  //gt_BX = esdcc.getBX();
126  }
127 
128  if (esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()] > esDCC_OrbitNumber_MostFreqCounts) {
129  esDCC_OrbitNumber_MostFreqCounts = esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()];
130  //gt_OrbitNumber = esdcc.getOrbitNumber();
131  }
132 
133  }
134  } else {
135  LogWarning("ESFEDIntegrityTask") << "dccCollections not available";
136  }
137 
138  }
139 
140  } else {
141  LogWarning("ESFEDIntegrityTask") << "FEDRawDataCollection not available";
142  }
143 
144  vector<int> fiberStatus;
145  if ( e.getByToken(dccCollections_, dccs) ) {
146  for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
147  ESDCCHeaderBlock dcc = (*dccItr);
148 
149  if (dcc.getDCCErrors() > 0) {
150 
151  if ( meESFedsFatal_ ) meESFedsFatal_->Fill(dcc.fedId());
152 
153  } else {
154  if (debug_) cout<<dcc.fedId()<<" "<<dcc.getOptoRX0()<<" "<<dcc.getOptoRX1()<<" "<<dcc.getOptoRX2()<<endl;
155  fiberStatus = dcc.getFEChannelStatus();
156 
157  if (dcc.getOptoRX0() == 128) {
158  meESFedsNonFatal_->Fill(dcc.fedId(), 1./3.);
159  } else if (dcc.getOptoRX0() == 129) {
160  for (unsigned int i=0; i<12; ++i) {
161  if (fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
162  if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Fill(dcc.fedId(), 1./12.);
163  }
164  }
165  if (dcc.getOptoRX1() == 128) {
166  meESFedsNonFatal_->Fill(dcc.fedId(), 1./3.);
167  } else if (dcc.getOptoRX1() == 129) {
168  for (unsigned int i=12; i<24; ++i) {
169  if (fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
170  if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Fill(dcc.fedId(), 1./12.);
171  }
172  }
173  if (dcc.getOptoRX2() == 128) {
174  meESFedsNonFatal_->Fill(dcc.fedId(), 1./3.);
175  } else if (dcc.getOptoRX2() == 129){
176  for (unsigned int i=24; i<36; ++i) {
177  if (fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
178  if ( meESFedsNonFatal_ ) meESFedsNonFatal_->Fill(dcc.fedId(), 1./12.);
179  }
180  }
181  }
182 
183  if (dcc.getLV1() != gt_L1A) meESFedsNonFatal_->Fill(dcc.fedId());
184  //if (dcc.getBX() != gt_BX) meESFedsNonFatal_->Fill(dcc.fedId());
185  //if (dcc.getOrbitNumber() != gt_OrbitNumber) meESFedsNonFatal_->Fill(dcc.fedId());
186  }
187  }
188 
189  //for (ESLocalRawDataCollection::const_iterator kItr = kchips->begin(); kItr != kchips->end(); ++kItr) {
190 
191  //ESKCHIPBlock kchip = (*kItr);
192 
193  //Int_t nErr = 0;
194  //if (kchip.getFlag1() > 0) nErr++;
195  //if (kchip.getFlag2() > 0) nErr++;
196  //if (kchip.getBC() != kchip.getOptoBC()) nErr++;
197  //if (kchip.getEC() != kchip.getOptoEC()) nErr++;
198  //if (nErr>0) meESFedsNonFatal_->Fill(dcc.fedId());
199  //}
200 
201 }
202 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int getLV1() const
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< ESDCCHeaderBlock >::const_iterator const_iterator
int getOptoRX0() const
int getOptoRX1() const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
const std::vector< int > & getFEChannelStatus() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
int getBX() const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
ESFEDIntegrityTask(const edm::ParameterSet &ps)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
int getOrbitNumber() const
Namespace of DDCMS conversion namespace.
const_iterator end() const
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
unsigned long long uint64_t
Definition: Time.h:15
HLT enums.
int getDCCErrors() const
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
const int fedId() const
int getOptoRX2() const
const_iterator begin() const
Definition: Run.h:44