CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESRawDataTask.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 
9 
12 
18 
23 
25 
26 using namespace cms;
27 using namespace edm;
28 using namespace std;
29 
31 
32  init_ = false;
33 
34  dqmStore_ = Service<DQMStore>().operator->();
35 
36  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
37  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
38  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
39 
40  FEDRawDataCollection_ = consumes<FEDRawDataCollection>(ps.getParameter<InputTag>("FEDRawDataCollection"));
41  dccCollections_ = consumes<ESRawDataCollection>(ps.getParameter<InputTag>("ESDCCCollections"));
42 
43 }
44 
46 }
47 
49 
50  ievt_ = 0;
51 
52  if ( dqmStore_ ) {
53  dqmStore_->setCurrentFolder(prefixME_ + "/ESRawDataTask");
54  dqmStore_->rmdir(prefixME_ + "/ESRawDataTask");
55  }
56 
57 }
58 
59 void ESRawDataTask::beginRun(const Run& r, const EventSetup& c) {
60 
61  if ( ! mergeRuns_ ) this->reset();
62 
63 }
64 
65 void ESRawDataTask::endRun(const Run& r, const EventSetup& c) {
66 
67 }
68 
70 
71 }
72 
74 
75  init_ = true;
76 
77  char histo[200];
78 
79  if (dqmStore_) {
80  dqmStore_->setCurrentFolder(prefixME_ + "/ESRawDataTask");
81 
82  //sprintf(histo, "ES run number errors");
83  //meRunNumberErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
84  //meRunNumberErrors_->setAxisTitle("ES FED", 1);
85  //meRunNumberErrors_->setAxisTitle("Num of Events", 2);
86 
87  sprintf(histo, "ES L1A DCC errors");
88  meL1ADCCErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
89  meL1ADCCErrors_->setAxisTitle("ES FED", 1);
90  meL1ADCCErrors_->setAxisTitle("Num of Events", 2);
91 
92  sprintf(histo, "ES BX DCC errors");
93  meBXDCCErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
94  meBXDCCErrors_->setAxisTitle("ES FED", 1);
95  meBXDCCErrors_->setAxisTitle("Num of Events", 2);
96 
97  sprintf(histo, "ES Orbit Number DCC errors");
98  meOrbitNumberDCCErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
99  meOrbitNumberDCCErrors_->setAxisTitle("ES FED", 1);
100  meOrbitNumberDCCErrors_->setAxisTitle("Num of Events", 2);
101 
102  sprintf(histo, "Difference between ES and GT L1A");
103  meL1ADiff_ = dqmStore_->book1D(histo, histo, 201, -100.5, 100.5);
104  meL1ADiff_->setAxisTitle("ES - GT L1A", 1);
105  meL1ADiff_->setAxisTitle("Num of Events", 2);
106 
107  sprintf(histo, "Difference between ES and GT BX");
108  meBXDiff_ = dqmStore_->book1D(histo, histo, 201, -100.5, 100.5);
109  meBXDiff_->setAxisTitle("ES - GT BX", 1);
110  meBXDiff_->setAxisTitle("Num of Events", 2);
111 
112  sprintf(histo, "Difference between ES and GT Orbit Number");
113  meOrbitNumberDiff_ = dqmStore_->book1D(histo, histo, 201, -100.5, 100.5);
114  meOrbitNumberDiff_->setAxisTitle("ES - GT orbit number", 1);
115  meOrbitNumberDiff_->setAxisTitle("Num of Events", 2);
116  }
117 
118 }
119 
121 
122  if ( ! init_ ) return;
123 
124  if ( dqmStore_ ) {
125  //if ( meRunNumberErrors_ ) dqmStore_->removeElement( meRunNumberErrors_->getName() );
126  //meRunNumberErrors_ = 0;
127 
128  if ( meL1ADCCErrors_ ) dqmStore_->removeElement( meL1ADCCErrors_->getName() );
129  meL1ADCCErrors_ = 0;
130 
131  if ( meBXDCCErrors_ ) dqmStore_->removeElement( meBXDCCErrors_->getName() );
132  meBXDCCErrors_ = 0;
133 
134  if ( meOrbitNumberDCCErrors_ ) dqmStore_->removeElement( meOrbitNumberDCCErrors_->getName() );
135  meOrbitNumberDCCErrors_ = 0;
136 
137  if ( meL1ADiff_ ) dqmStore_->removeElement( meL1ADiff_->getName() );
138  meL1ADiff_ = 0;
139 
140  if ( meBXDiff_ ) dqmStore_->removeElement( meBXDiff_->getName() );
141  meBXDiff_ = 0;
142 
143  if ( meOrbitNumberDiff_ ) dqmStore_->removeElement( meOrbitNumberDiff_->getName() );
144  meOrbitNumberDiff_ = 0;
145  }
146 
147  init_ = false;
148 
149 }
150 
152 
153  LogInfo("ESRawDataTask") << "analyzed " << ievt_ << " events";
154 
155  if ( enableCleanup_ ) this->cleanup();
156 
157 }
158 
160 
161  if ( ! init_ ) this->setup();
162 
163  ievt_++;
164  runNum_ = e.id().run();
165 
166  int gt_L1A = 0, gt_OrbitNumber = 0, gt_BX = 0;
167  int esDCC_L1A_MostFreqCounts = 0;
168  int esDCC_BX_MostFreqCounts = 0;
169  int esDCC_OrbitNumber_MostFreqCounts = 0;
170 
172  Handle<FEDRawDataCollection> allFedRawData;
173 
174  int gtFedDataSize = 0;
175 
176  if ( e.getByToken(FEDRawDataCollection_, allFedRawData) ) {
177 
178  // GT FED data
179  const FEDRawData& gtFedData = allFedRawData->FEDData(812);
180 
181  gtFedDataSize = gtFedData.size()/sizeof(uint64_t);
182 
183  if ( gtFedDataSize > 0 ) {
184 
185  FEDHeader header(gtFedData.data());
186 
187  gt_L1A = header.lvl1ID();
188  gt_OrbitNumber = e.orbitNumber();
189  gt_BX = e.bunchCrossing();
190  } else {
191 
192  map<int, int> esDCC_L1A_FreqMap;
193  map<int, int> esDCC_BX_FreqMap;
194  map<int, int> esDCC_OrbitNumber_FreqMap;
195 
196  if ( e.getByToken(dccCollections_, dccs) ) {
197  for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
198  ESDCCHeaderBlock esdcc = (*dccItr);
199 
200  esDCC_L1A_FreqMap[esdcc.getLV1()]++;
201  esDCC_BX_FreqMap[esdcc.getBX()]++;
202  esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()]++;
203 
204  if (esDCC_L1A_FreqMap[esdcc.getLV1()] > esDCC_L1A_MostFreqCounts) {
205  esDCC_L1A_MostFreqCounts = esDCC_L1A_FreqMap[esdcc.getLV1()];
206  gt_L1A = esdcc.getLV1();
207  }
208 
209  if (esDCC_BX_FreqMap[esdcc.getBX()] > esDCC_BX_MostFreqCounts) {
210  esDCC_BX_MostFreqCounts = esDCC_BX_FreqMap[esdcc.getBX()];
211  gt_BX = esdcc.getBX();
212  }
213 
214  if (esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()] > esDCC_OrbitNumber_MostFreqCounts) {
215  esDCC_OrbitNumber_MostFreqCounts = esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()];
216  gt_OrbitNumber = esdcc.getOrbitNumber();
217  }
218 
219  }
220  } else {
221  LogWarning("ESRawDataTask") << "dccCollections not available";
222  }
223 
224  }
225  } else {
226  LogWarning("ESRawDataTask") << "FEDRawDataCollection not available";
227  }
228 
229  // DCC
230  vector<int> fiberStatus;
231  if ( e.getByToken(dccCollections_, dccs) ) {
232 
233  for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
234  ESDCCHeaderBlock dcc = (*dccItr);
235 
236  //if (dcc.getRunNumber() != runNum_) {
237  //meRunNumberErrors_->Fill(dcc.fedId());
238  //cout<<"Run # err : "<<dcc.getRunNumber()<<" "<<runNum_<<endl;
239  //}
240 
241  if (dcc.getLV1() != gt_L1A) {
242  meL1ADCCErrors_->Fill(dcc.fedId());
243  //cout<<"L1A err : "<<dcc.getLV1()<<" "<<gt_L1A<<endl;
244  Float_t l1a_diff = dcc.getLV1() - gt_L1A;
245  if (l1a_diff > 100) l1a_diff = 100;
246  else if (l1a_diff < -100) l1a_diff = -100;
247  meL1ADiff_->Fill(l1a_diff);
248  }
249 
250  if (dcc.getBX() != gt_BX) {
251  meBXDCCErrors_->Fill(dcc.fedId());
252  //cout<<"BX err : "<<dcc.getBX()<<" "<<gt_BX<<endl;
253  Float_t bx_diff = dcc.getBX() - gt_BX;
254  if (bx_diff > 100) bx_diff = 100;
255  else if (bx_diff < -100) bx_diff = -100;
256  meBXDiff_->Fill(bx_diff);
257  }
258  if (dcc.getOrbitNumber() != gt_OrbitNumber) {
259  meOrbitNumberDCCErrors_->Fill(dcc.fedId());
260  //cout<<"Orbit err : "<<dcc.getOrbitNumber()<<" "<<gt_OrbitNumber<<endl;
261  Float_t orbitnumber_diff = dcc.getOrbitNumber() - gt_OrbitNumber;
262  if (orbitnumber_diff > 100) orbitnumber_diff = 100;
263  else if (orbitnumber_diff < -100) orbitnumber_diff = -100;
264  meOrbitNumberDiff_->Fill(orbitnumber_diff);
265  }
266  }
267  }
268 
269 }
270 
RunNumber_t run() const
Definition: EventID.h:42
virtual ~ESRawDataTask()
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int getLV1() const
void cleanup(void)
Cleanup.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< ESDCCHeaderBlock >::const_iterator const_iterator
static void cleanup(const Factory::MakerMap::value_type &v)
Definition: Factory.cc:12
int bunchCrossing() const
Definition: EventBase.h:62
void setup(void)
Setup.
void beginJob(void)
BeginJob.
ESRawDataTask(const edm::ParameterSet &ps)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
int getBX() const
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
int getOrbitNumber() const
int orbitNumber() const
Definition: EventBase.h:63
DEFINE_FWK_MODULE(CaloMETProducer)
void endJob(void)
EndJob.
unsigned long long uint64_t
Definition: Time.h:15
edm::EventID id() const
Definition: EventBase.h:56
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
const int fedId() const
int lvl1ID()
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:20
void reset(void)
Reset.
void reset(double vett[256])
Definition: TPedValues.cc:11
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:41