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 }
HcalElectronicsMap.h
FEDNumbering.h
FEDNumbering::MAXCASTORFEDID
Definition: FEDNumbering.h:46
CastorRawCollections
Definition: CastorRawCollections.h:16
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
ESHandle.h
CastorRawToDigi::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: CastorRawToDigi.cc:67
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
CastorRawCollections::zdcCont
std::vector< ZDCDataFrame > * zdcCont
Definition: CastorRawCollections.h:21
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
CastorUnpacker::unpack
void unpack(const FEDRawData &raw, const CastorElectronicsMap &emap, CastorRawCollections &conts, HcalUnpackerReport &report, bool silent=false)
For histograms, no begin and end.
Definition: CastorUnpacker.cc:75
CastorRawCollections.h
edm::SortedCollection
Definition: SortedCollection.h:49
CastorRawToDigi::filter_
CastorDataFrameFilter filter_
Definition: CastorRawToDigi.h:50
CastorRawToDigi::ctdcunpacker_
CastorCtdcUnpacker ctdcunpacker_
Definition: CastorRawToDigi.h:49
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::RunBase::run
RunNumber_t run() const
Definition: RunBase.h:40
CastorCtdcUnpacker::unpack
void unpack(const FEDRawData &raw, const CastorElectronicsMap &emap, CastorRawCollections &conts, HcalUnpackerReport &report)
Definition: CastorCtdcUnpacker.cc:25
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
FEDRawData
Definition: FEDRawData.h:19
FileInPath.h
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
CastorRawToDigi::complainEmptyData_
bool complainEmptyData_
Definition: CastorRawToDigi.h:53
edm::SortedCollection::swap
void swap(SortedCollection &other)
Definition: SortedCollection.h:193
CastorUnpacker::setExpectedOrbitMessageTime
void setExpectedOrbitMessageTime(int time)
Definition: CastorUnpacker.h:19
FEDNumbering::MINCASTORFEDID
Definition: FEDNumbering.h:45
HcalDigiCollections.h
CastorRawToDigi::fedUnpackList_
std::vector< int > fedUnpackList_
Definition: CastorRawToDigi.h:51
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
Run.h
edm::ESHandle
Definition: DTSurvey.h:22
CastorRawToDigi::expectedOrbitMessageTime_
int expectedOrbitMessageTime_
Definition: CastorRawToDigi.h:59
CastorRawToDigi::tok_input_
edm::EDGetTokenT< FEDRawDataCollection > tok_input_
Definition: CastorRawToDigi.h:61
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
CastorRawToDigi::usingctdc_
bool usingctdc_
Definition: CastorRawToDigi.h:54
CastorRawToDigi::unpackZDC_
bool unpackZDC_
Definition: CastorRawToDigi.h:56
CastorRawToDigi::dataTag_
edm::InputTag dataTag_
Definition: CastorRawToDigi.h:46
funct::true
true
Definition: Factorize.h:173
edm::ParameterSet
Definition: ParameterSet.h:47
CastorRawToDigi::CastorRawToDigi
CastorRawToDigi(const edm::ParameterSet &ps)
Definition: CastorRawToDigi.cc:16
createfilelist.int
int
Definition: createfilelist.py:10
CastorRawCollections::castorCont
std::vector< CastorDataFrame > * castorCont
Definition: CastorRawCollections.h:20
FEDRawDataCollection.h
CastorRawToDigi::zdcunpacker_
ZdcUnpacker zdcunpacker_
Definition: CastorRawToDigi.h:48
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
CastorRawToDigi::usenominalOrbitMessageTime_
bool usenominalOrbitMessageTime_
Definition: CastorRawToDigi.h:58
edm::EventSetup
Definition: EventSetup.h:57
CastorRawToDigi::unpackTTP_
bool unpackTTP_
Definition: CastorRawToDigi.h:55
ZdcUnpacker::unpack
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
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
edmIntegrityCheck.report
report
Definition: edmIntegrityCheck.py:349
hcalSimParameters_cfi.zdc
zdc
Definition: hcalSimParameters_cfi.py:97
HcalTopology.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
CastorDataFrameFilter::active
bool active() const
whether any filters are on
Definition: CastorDataFrameFilter.cc:51
CastorRawToDigi.h
CastorRawToDigi::unpacker_
CastorUnpacker unpacker_
Definition: CastorRawToDigi.h:47
CastorRawToDigi::~CastorRawToDigi
~CastorRawToDigi() override
Definition: CastorRawToDigi.cc:64
CastorRawCollections::tpCont
std::vector< CastorTriggerPrimitiveDigi > * tpCont
Definition: CastorRawCollections.h:23
CastorRawToDigi::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: CastorRawToDigi.cc:197
CastorElectronicsMap
Definition: CastorElectronicsMap.h:30
CastorDbService::getCastorMapping
const CastorElectronicsMap * getCastorMapping() const
Definition: CastorDbService.cc:183
cms::Exception
Definition: Exception.h:70
CastorRawCollections::ttp
std::vector< HcalTTPDigi > * ttp
Definition: CastorRawCollections.h:24
edm::Event
Definition: Event.h:73
CastorRawToDigi::tok_pSetup_
edm::ESGetToken< CastorDbService, CastorDbRecord > tok_pSetup_
Definition: CastorRawToDigi.h:63
CastorDataFrameFilter::filter
CastorDigiCollection filter(const CastorDigiCollection &incol, HcalUnpackerReport &r)
filter Castor data frames
Definition: CastorDataFrameFilter.cc:40
castorDigitizer_cfi.castor
castor
Definition: castorDigitizer_cfi.py:9
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37