CMS 3D CMS Logo

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