test
CMS 3D CMS Logo

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