CMS 3D CMS Logo

CastorRawToDigi.cc
Go to the documentation of this file.
7 #include <fstream>
9 #include <iostream>
14 using namespace std;
15 
17  : dataTag_(conf.getParameter<edm::InputTag>("InputLabel")),
18  unpacker_(conf.getParameter<int>("CastorFirstFED"),
19  conf.getParameter<int>("firstSample"),
20  conf.getParameter<int>("lastSample")),
21  zdcunpacker_(conf.getParameter<int>("CastorFirstFED"),
22  conf.getParameter<int>("firstSample"),
23  conf.getParameter<int>("lastSample")),
24  ctdcunpacker_(conf.getParameter<int>("CastorFirstFED"),
25  conf.getParameter<int>("firstSample"),
26  conf.getParameter<int>("lastSample")),
27  filter_(
28  conf.getParameter<bool>("FilterDataQuality"), conf.getParameter<bool>("FilterDataQuality"), false, 0, 0, -1),
29  fedUnpackList_(conf.getUntrackedParameter<std::vector<int> >("FEDs", std::vector<int>())),
30  firstFED_(conf.getParameter<int>("CastorFirstFED")),
31  complainEmptyData_(conf.getUntrackedParameter<bool>("ComplainEmptyData", false)),
32  usingctdc_(conf.getParameter<bool>("CastorCtdc")),
33  unpackTTP_(conf.getParameter<bool>("UnpackTTP")),
34  unpackZDC_(conf.getParameter<bool>("UnpackZDC")),
35  silent_(conf.getUntrackedParameter<bool>("silent", true)),
36  usenominalOrbitMessageTime_(conf.getParameter<bool>("UseNominalOrbitMessageTime")),
37  expectedOrbitMessageTime_(conf.getParameter<int>("ExpectedOrbitMessageTime"))
38 
39 {
40  if (fedUnpackList_.empty()) {
42  fedUnpackList_.push_back(i);
43  }
44 
46  std::ostringstream ss;
47  for (unsigned int i = 0; i < fedUnpackList_.size(); i++)
48  ss << fedUnpackList_[i] << " ";
49  edm::LogInfo("CASTOR") << "CastorRawToDigi will unpack FEDs ( " << ss.str() << ")";
50 
51  // products produced...
52  produces<CastorDigiCollection>();
53  produces<ZDCDigiCollection>();
54  produces<CastorTrigPrimDigiCollection>();
55  produces<HcalUnpackerReport>();
56  if (unpackTTP_)
57  produces<HcalTTPDigiCollection>();
58 
59  tok_input_ = consumes<FEDRawDataCollection>(dataTag_);
60  tok_pSetup_ = esConsumes<CastorDbService, CastorDbRecord>();
61 }
62 
63 // Virtual destructor needed.
65 
66 // Functions that gets called by framework every event
68  // Step A: Get Inputs
70  e.getByToken(tok_input_, rawraw);
71  // get the mapping
73  const CastorElectronicsMap* readoutMap = pSetup->getCastorMapping();
74 
75  // Step B: Create empty output : three vectors for three classes...
76  std::vector<CastorDataFrame> castor;
77  std::vector<ZDCDataFrame> zdc;
78  std::vector<HcalTTPDigi> ttp;
79  std::vector<CastorTriggerPrimitiveDigi> htp;
80 
81  auto report = std::make_unique<HcalUnpackerReport>();
82 
84  colls.castorCont = &castor;
85  colls.zdcCont = &zdc;
86  if (unpackTTP_)
87  colls.ttp = &ttp;
88  colls.tpCont = &htp;
89 
90  // Step C: unpack all requested FEDs
91  const FEDRawData& fed722 = rawraw->FEDData(722);
92  const int fed722size = fed722.size();
93  const FEDRawData& fed693 = rawraw->FEDData(693);
94  const int fed693size = fed693.size();
95  for (std::vector<int>::const_iterator i = fedUnpackList_.begin(); i != fedUnpackList_.end(); i++) {
96  const FEDRawData& fed = rawraw->FEDData(*i);
97  //std::cout<<"Fed number "<<*i<<"is being worked on"<<std::endl;
98  if (*i == 693 && fed693size == 0 && fed722size != 0)
99  continue;
100  if (*i == 722 && fed722size == 0 && fed693size != 0)
101  continue;
102 
103  if (*i != 693 && *i != 722) {
104  if (fed.size() == 0) {
105  if (complainEmptyData_) {
106  edm::LogWarning("EmptyData") << "No data for FED " << *i;
107  report->addError(*i);
108  }
109  } else if (fed.size() < 8 * 3) {
110  edm::LogWarning("EmptyData") << "Tiny data " << fed.size() << " for FED " << *i;
111  report->addError(*i);
112  } else {
113  try {
114  if (usingctdc_) {
115  ctdcunpacker_.unpack(fed, *readoutMap, colls, *report);
116  } else {
117  unpacker_.unpack(fed, *readoutMap, colls, *report);
118  }
119  report->addUnpacked(*i);
120  } catch (cms::Exception& e) {
121  edm::LogWarning("Unpacking error") << e.what();
122  report->addError(*i);
123  } catch (...) {
124  edm::LogWarning("Unpacking exception");
125  report->addError(*i);
126  }
127  }
128  }
129 
130  if (*i == 693 && unpackZDC_) {
131  if (fed.size() == 0) {
132  if (complainEmptyData_) {
133  edm::LogWarning("EmptyData") << "No data for FED " << *i;
134  report->addError(*i);
135  }
136  }
137  if (fed.size() != 0) {
138  zdcunpacker_.unpack(fed, *readoutMap, colls, *report);
139  report->addUnpacked(*i);
140  }
141  }
142 
143  if (*i == 722 && unpackZDC_) {
144  if (fed.size() == 0) {
145  if (complainEmptyData_) {
146  edm::LogWarning("EmptyData") << "No data for FED " << *i;
147  report->addError(*i);
148  }
149  }
150  if (fed.size() != 0) {
151  zdcunpacker_.unpack(fed, *readoutMap, colls, *report);
152  report->addUnpacked(*i);
153  }
154  }
155 
156  } //end of loop over feds
157 
158  // Step B: encapsulate vectors in actual collections
159  auto castor_prod = std::make_unique<CastorDigiCollection>();
160  auto htp_prod = std::make_unique<CastorTrigPrimDigiCollection>();
161 
162  castor_prod->swap_contents(castor);
163  htp_prod->swap_contents(htp);
164 
165  // Step C2: filter FEDs, if required
166  if (filter_.active()) {
167  CastorDigiCollection filtered_castor = filter_.filter(*castor_prod, *report);
168 
169  castor_prod->swap(filtered_castor);
170  }
171 
172  // Step D: Put outputs into event
173  // just until the sorting is proven
174  castor_prod->sort();
175  htp_prod->sort();
176 
177  if (unpackZDC_) {
178  auto zdc_prod = std::make_unique<ZDCDigiCollection>();
179  zdc_prod->swap_contents(zdc);
180 
181  zdc_prod->sort();
182  e.put(std::move(zdc_prod));
183  }
184 
185  e.put(std::move(castor_prod));
186  e.put(std::move(htp_prod));
187 
188  if (unpackTTP_) {
189  auto prod = std::make_unique<HcalTTPDigiCollection>();
190  prod->swap_contents(ttp);
191 
192  prod->sort();
193  e.put(std::move(prod));
194  }
195  e.put(std::move(report));
196 }
197 void CastorRawToDigi::beginRun(edm::Run const& irun, edm::EventSetup const& es) {
199  if (irun.run() > 132640) {
201  } else if (irun.run() > 132174) {
203  } else if (irun.run() > 124371) {
205  } else if (irun.run() > 123984) {
207  } else if (irun.run() > 123584) {
209  } else {
211  }
213  }
214 }
CastorDataFrameFilter filter_
ZdcUnpacker zdcunpacker_
CastorDigiCollection filter(const CastorDigiCollection &incol, HcalUnpackerReport &r)
filter Castor data frames
CastorUnpacker unpacker_
void swap(SortedCollection &other)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
CastorCtdcUnpacker ctdcunpacker_
edm::ESGetToken< CastorDbService, CastorDbRecord > tok_pSetup_
std::vector< int > fedUnpackList_
void beginRun(edm::Run const &, edm::EventSetup const &) override
edm::InputTag dataTag_
void unpack(const FEDRawData &raw, const CastorElectronicsMap &emap, CastorRawCollections &conts, HcalUnpackerReport &report, bool silent=false)
For histograms, no begin and end.
edm::EDGetTokenT< FEDRawDataCollection > tok_input_
bool active() const
whether any filters are on
RunNumber_t run() const
Definition: RunBase.h:40
void unpack(const FEDRawData &raw, const CastorElectronicsMap &emap, CastorRawCollections &conts, HcalUnpackerReport &report)
void setExpectedOrbitMessageTime(int time)
CastorRawToDigi(const edm::ParameterSet &ps)
std::vector< CastorDataFrame > * castorCont
const CastorElectronicsMap * getCastorMapping() const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Log< level::Info, false > LogInfo
void unpack(const FEDRawData &raw, const CastorElectronicsMap &emap, CastorRawCollections &conts, HcalUnpackerReport &report, bool silent=false)
For histograms, no begin and end.
Definition: ZdcUnpacker.cc:108
bool usenominalOrbitMessageTime_
HLT enums.
~CastorRawToDigi() override
void produce(edm::Event &e, const edm::EventSetup &c) override
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45