test
CMS 3D CMS Logo

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