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  : fRawDataLabel(p.get< std::string >("RawDataLabel")),
59  fWarningIssued(false)
60  {
61  this->reconfigure(p);
62  produces<dq::DAQEventSummary>();
63  }
64 
65  //...........................................................................
67 
68 
69  //...........................................................................
70  /// Unpack the raw data
71  /// \param e : ART event
72  /// \param raw : Raw event
75  {
76  try {
78  e.getByLabel(fRawDataLabel, flat_hdl);
79  if (flat_hdl->size()!=1) {
80  if (!fWarningIssued){
81  std::cerr << __FILE__ << ":" << __LINE__
82  << " Must have one and only one flat daq object. Supressing further warnings."
83  << " Found " << flat_hdl->size() << std::endl;
84  fWarningIssued = true;
85  }
86  return false;
87  }
88  raw.readData( (*flat_hdl)[0].getRawBufferPointer() );
89  return true;
90  }
91  catch (...) {
92  if (!fWarningIssued){
93  std::cerr << __FILE__ << ":" << __LINE__
94  << " Bad unpack of flat DAQ data! Supressing further warnings."
95  << std::endl;
96  fWarningIssued = true;
97  }
98  return false;
99  }
100 
101  // Only errors fall through to here.
102  return false;
103  }
104 
105  //...........................................................................
107  {
108  DAQEventUnpack daqUnpack;
109  std::unique_ptr<dq::DAQEventSummary> daqSummary(new dq::DAQEventSummary);
110 
111  // If this is MC, put an empty product and move on
112  if(!e.isRealData()) {
113  e.put(std::move(daqSummary));
114  return;
115  }
116 
117  static daqdataformats::RawEvent raw;
118 
119  bool success = this->UnpackRawDaqData(e, raw);
120 
121  // If the flat daq data didn't unpack properly, put an empty product and move on
122  if (!success) {
123  e.put(std::move(daqSummary));
124  return;
125  }
126 
127  // Unpack, analyze, and summarize the DAQ data
128  daqUnpack.UnpackRawEvent(raw, daqSummary.get());
129 
130  // Grab dropped microblocks (but only if it exists as a product)
131  std::vector<art::Handle< std::vector<rawdata::RawSumDropMB>>> droppedMBs_vec;
132  e.getManyByType(droppedMBs_vec);
133  if (droppedMBs_vec.size() != 0){
135  e.getByLabel(fRawDataLabel, droppedMBs);
136  daqSummary.get()->fNDroppedMicroBlocks = (*droppedMBs)[0].fSumTrig_NumDroppedMicroblocks;
137  }
138 
139  // Grab microslice information from DAQ Header
141  e.getByLabel(fRawDataLabel, daqheader);
142  daqSummary.get()->fNmicroSlices = daqheader->TotalMicroSlices();
143 
144  // Determine number of diblocks in this event
145  daqSummary.get()->fDiblocks.sort();
146  daqSummary.get()->fDiblocks.unique();
147  daqSummary.get()->fNDiblocks = daqSummary.get()->fDiblocks.size();
148 
149  e.put(std::move(daqSummary));
150  }
151 
152 } // end namespace
153 
155 //////////////////////////////////////////////////////////////////////////
bool UnpackRawDaqData(art::Event &e, daqdataformats::RawEvent &raw)
void reconfigure(fhicl::ParameterSet const &p)
const char * p
Definition: xmltok.h:285
OStream cerr
Definition: OStream.cxx:7
bool isRealData() const
Definition: Event.h:83
DEFINE_ART_MODULE(TestTMapFile)
int TotalMicroSlices() const
Definition: DAQHeader.h:27
std::string fRawDataLabel
label of where to find RawData
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
DAQHeaderSummary(fhicl::ParameterSet const &p)
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:446
def success(message)
Definition: log.py:5
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
bool fWarningIssued
Set to true once a warning is issued; throttles warning messages to 1 per job.
Float_t e
Definition: plot.C:35
void UnpackRawEvent(daqdataformats::RawEvent &rawevt, dq::DAQEventSummary *daqsum)
enum BeamMode string