DAQHeaderSummary_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 /// \file DAQHeaderSummary_module.cc
3 /// \brief Producer module to extract DAQ header variables relevant to
4 /// data quality
5 /// \date December 2015
6 /// \author Justin Vasel <jvasel@indiana.edu>
7 /// Mark Messier <messier@indiana.edu>
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 // ART
15 
16 // NOvA Online
17 #include "DAQDataFormats/RawEvent.h"
18 #include "DAQDataFormats/RawTrigger.h"
19 #include "DAQDataFormats/RawTriggerMask.h"
20 #include "DAQDataFormats/RawDataBlock.h"
21 #include "DAQDataFormats/RawMicroBlock.h"
22 #include "DAQDataFormats/RawMicroSlice.h"
23 #include "DAQDataFormats/RawNanoSlice.h"
24 
25 // NOvA Offline
26 #include "RawData/FlatDAQData.h"
27 #include "RawData/DAQHeader.h"
28 #include "RawData/RawDigit.h"
29 #include "RawData/RawSumDropMB.h"
32 
33 namespace dq {
34  class DAQHeaderSummary;
35 }
36 
37 
39  public:
40  explicit DAQHeaderSummary(fhicl::ParameterSet const &p);
41 
42  void reconfigure(fhicl::ParameterSet const &p);
45 
46  void produce(art::Event & e);
47 
48  private:
49  std::string fRawDataLabel; ///< label of where to find RawData
50  bool fWarningIssued; ///< Set to true once a warning is issued; throttles warning messages to 1 per job.
51 
52 };
53 
54 namespace dq {
55 
56  //...........................................................................
58  : EDProducer(p)
59  , fRawDataLabel(p.get< std::string >("RawDataLabel")),
60  fWarningIssued(false)
61  {
62  this->reconfigure(p);
63  produces<dq::DAQEventSummary>();
64  }
65 
66  //...........................................................................
68 
69 
70  //...........................................................................
71  /// Unpack the raw data
72  /// \param e : ART event
73  /// \param raw : Raw event
76  {
77  try {
79  e.getByLabel(fRawDataLabel, flat_hdl);
80  if (flat_hdl->size()!=1) {
81  if (!fWarningIssued){
82  std::cerr << __FILE__ << ":" << __LINE__
83  << " Must have one and only one flat daq object. Supressing further warnings."
84  << " Found " << flat_hdl->size() << std::endl;
85  fWarningIssued = true;
86  }
87  return false;
88  }
89  raw.readData( (*flat_hdl)[0].getRawBufferPointer() );
90  return true;
91  }
92  catch (...) {
93  if (!fWarningIssued){
94  std::cerr << __FILE__ << ":" << __LINE__
95  << " Bad unpack of flat DAQ data! Supressing further warnings."
96  << std::endl;
97  fWarningIssued = true;
98  }
99  return false;
100  }
101 
102  // Only errors fall through to here.
103  return false;
104  }
105 
106  //...........................................................................
108  {
109  DAQEventUnpack daqUnpack;
110  std::unique_ptr<dq::DAQEventSummary> daqSummary(new dq::DAQEventSummary);
111 
112  // If this is MC, put an empty product and move on
113  if(!e.isRealData()) {
114  e.put(std::move(daqSummary));
115  return;
116  }
117 
118  static daqdataformats::RawEvent raw;
119 
120  bool success = this->UnpackRawDaqData(e, raw);
121 
122  // If the flat daq data didn't unpack properly, put an empty product and move on
123  if (!success) {
124  e.put(std::move(daqSummary));
125  return;
126  }
127 
128  // Unpack, analyze, and summarize the DAQ data
129  daqUnpack.UnpackRawEvent(raw, daqSummary.get());
130 
131  // Grab dropped microblocks (but only if it exists as a product)
132  std::vector<art::Handle< std::vector<rawdata::RawSumDropMB>>> droppedMBs_vec;
133  e.getManyByType(droppedMBs_vec);
134  if (droppedMBs_vec.size() != 0){
136  e.getByLabel(fRawDataLabel, droppedMBs);
137  daqSummary.get()->fNDroppedMicroBlocks = (*droppedMBs)[0].fSumTrig_NumDroppedMicroblocks;
138  }
139 
140  // Grab microslice information from DAQ Header
142  e.getByLabel(fRawDataLabel, daqheader);
143  daqSummary.get()->fNmicroSlices = daqheader->TotalMicroSlices();
144 
145  // Determine number of diblocks in this event
146  daqSummary.get()->fDiblocks.sort();
147  daqSummary.get()->fDiblocks.unique();
148  daqSummary.get()->fNDiblocks = daqSummary.get()->fDiblocks.size();
149 
150  e.put(std::move(daqSummary));
151  }
152 
153 } // end namespace
154 
156 //////////////////////////////////////////////////////////////////////////
bool UnpackRawDaqData(art::Event &e, daqdataformats::RawEvent &raw)
void reconfigure(fhicl::ParameterSet const &p)
const char * p
Definition: xmltok.h:285
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
OStream cerr
Definition: OStream.cxx:7
DEFINE_ART_MODULE(TestTMapFile)
int TotalMicroSlices() const
Definition: DAQHeader.h:27
std::string fRawDataLabel
label of where to find RawData
DAQHeaderSummary(fhicl::ParameterSet const &p)
bool isRealData() const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:558
def success(message)
Definition: log.py:5
bool fWarningIssued
Set to true once a warning is issued; throttles warning messages to 1 per job.
Float_t e
Definition: plot.C:35
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
void UnpackRawEvent(daqdataformats::RawEvent &rawevt, dq::DAQEventSummary *daqsum)
enum BeamMode string