NOvARawInputDriver.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file NOvARawInputSource.cxx
3 /// \brief Source to convert raw binary files to root files
4 ///
5 /// \version $Id: NOvARawInputDriver.cxx,v 1.19 2012-12-01 07:05:47 bckhouse Exp $
6 /// \author brebel@fnal.gov, soderber@fnal.gov, greenc@fnal.gov, paterno@fnal.gov
7 ////////////////////////////////////////////////////////////////////////
8 
9 //NOvA includes
13 #include "NovaTimingUtilities/TimingUtilities.h"
14 #include "RawData/DAQHeader.h"
15 #include "RawData/RawDigit.h"
16 #include "RawData/RawTrigger.h"
17 #include "RawData/FlatDAQData.h"
18 #include "RawData/RawSumDropMB.h"
19 #include "RawData/RawSumDCM.h"
20 #include "SummaryData/RunData.h"
21 #include "NovaDAQConventions/DAQConventions.h"
22 
23 // Framework includes
31 #include "fhiclcpp/ParameterSet.h"
32 
33 
34 namespace daq2raw{
35 
36  //------------------------------------------------------------------------------
37  // Required constructor.
40  art::SourceHelper const &pm)
41  // look to see if the user provided a base file name for the gdml file, if not
42  // pass along an emptry string to default to the behavior previously in NOvAInputDriverBase
43  : NOvAInputDriverBase(pset.get<std::string>("GDMLFileBase",""))
44  , fSourceHelper(pm)
45  , fCurrentFilename()
46  , fCurrentSubRunID(-1, -1) ///< Has to be distinguished from the ones that are acually used
47  , fParser()
48  , fMaxEventSize(pset.get<size_t>("maxEventSizeK", 65536) * 1024)
49  , fFilterCorruptedNanoslices(pset.get<bool>("FilterCorruptedNanoslices"))
50  , fDoFillFlatDAQData(pset.get<bool>("DoFillFlatDAQData"))
51  {
52  // Declare products that *may* be in the event (or run, or subRun)
53  // here. Note the use of "reconstitutes" vs "produces": this is what
54  // allows us to specify module label, process name and (optionally)
55  // instance label for each product.
57  helper.reconstitutes<std::vector<rawdata::RawDigit>, art::InEvent>("daq");
58  helper.reconstitutes<std::vector<rawdata::RawTrigger>, art::InEvent>("daq");
59  helper.reconstitutes<std::vector<rawdata::RawSumDropMB>, art::InEvent>("daq");
60  helper.reconstitutes<std::vector<rawdata::RawSumDCM>, art::InEvent>("daq");
61  if(fDoFillFlatDAQData) helper.reconstitutes<std::vector<rawdata::FlatDAQData>, art::InEvent>("daq");
62  helper.reconstitutes<sumdata::RunData, art::InRun >("daq");
63  // Turn off printf messages in the parser.
64  fParser.setDebug(false);
65  }
66 
67  //------------------------------------------------------------------------------
68  // Required function: close currently-open file.
70  fParser.close(); // Ignore error return
71  }
72 
73  // Required function: open the file, "name" and construct and return a
74  // new FileBlock object. MUST be successful or throw:
75  // art::Exception(art::errors::FileOpenError) or
76  // art::Exception(art::errors::FileReadError) are good candidates.
78  art::FileBlock* &fb) {
80 
81  int fd = fParser.open(fCurrentFilename.c_str());
82  if (fd == -1) { // Failure
84  << "Unable to open file "
85  << name
86  << " due to system error, \""
87  << strerror(errno)
88  << "\"\n";
89  }
90 
91  fb = new art::FileBlock(art::FileFormatVersion(1, "NOvARawInput 2011a"),
93  }
94 
95  // Required function: read and fill Run, SubRun and/or Event as might be
96  // appropriate.
98  art::SubRunPrincipal* const &inSR,
99  art::RunPrincipal* &outR,
100  art::SubRunPrincipal* &outSR,
101  art::EventPrincipal* &outE)
102  {
103  ////////////////////////////////////
104  // Unpack the data.
105 
106  // NOTE: As of OnlineUnpack.cxx r1.9, the histogram pointers required
107  // in the constructor are *not* filled. In the event that one *does*
108  // want this kind of information, the data to be histogrammed should
109  // be put into event products (not necessarily written out to file)
110  // and turned into histograms by a downstream analyzer. This will
111  // enable easy management of different histograms for diferent runs,
112  // subruns, etc, etc and trivial control of whether histograns are
113  // actually wanted or not.
114  daq2raw::OnlineUnpack up(nullptr, nullptr, nullptr, &fCurrentFilename);
116 
117  /// Define data structures, which will be filled by OnlineUnpack::ProcessRawEvent
118  std::unique_ptr<std::vector<rawdata::RawDigit> > digits(new std::vector<rawdata::RawDigit>);
119  rawdata::RawTrigger raw_trigger;
120  rawdata::RawSumDropMB raw_sumDropMB;
121  rawdata::RawSumDCM raw_sumDCM;
122  rawdata::FlatDAQData flat_daq_data;
123  rawdata::DAQHeader daq_header;
124 
125  /// Fill the data structures for this event.
126  if (!up.ProcessRawEvent(fParser, digits.get(), &raw_trigger, &raw_sumDropMB, &raw_sumDCM, &flat_daq_data, &daq_header)) return false;
127 
128  // Get the actual timestamp here - use the current time as the
129  // default, maybe the default should really be a ridiculous value
130  struct timespec ts;
131 
134 
135  // art::Timestamp has the seconds since the beginning of the epoch
136  // in the upper 32 bits and the fractional seconds in the lower 32
137  // bits.
138  art::Timestamp tstamp = (ts.tv_sec << 32) | ts.tv_nsec;
139 
140  ////////////////////////////////////
141  // Assemble new principals as required.
142  art::SubRunID newID(up.getRunNumber(), up.getSubrunNumber());
143  if (inR == nullptr || fCurrentSubRunID.runID() != newID.runID()) { // New Run fragment
144  outR = fSourceHelper.makeRunPrincipal(up.getRunNumber(), tstamp);
145 
146  // get the base form of the geometry file for the current detector
147  //\todo at some point we should query a database to get this, especially
148  //\todo when we have instances of only part of a detector working
149  std::string detFileBase = getDetectorGDML(up.getDetId());
150  std::unique_ptr<sumdata::RunData> rundata(new sumdata::RunData(novadaq::cnv::DetId(up.getDetId()), detFileBase, geo::GeometryBase::ExtractGDML(detFileBase+".gdml", false)));
151  art::put_product_in_principal(std::move(rundata),
152  *outR,
153  "daq"); // Module label
154  }
155  if (inSR == nullptr || fCurrentSubRunID != newID) { // New SubRun fragment
157  up.getSubrunNumber(),
158  tstamp);
159  fCurrentSubRunID = newID;
160  }
162  up.getSubrunNumber(),
163  up.getEventNumber(),
164  tstamp);
165 
166  ////////////////////////////////////
167  // Add the event products to the event:
168 
169  // Digitized data:
170  art::put_product_in_principal(std::move(digits), *outE, "daq");
171 
172  // Trigger data:
173  std::unique_ptr<std::vector<rawdata::RawTrigger> > rtcol(new std::vector<rawdata::RawTrigger>);
174  rtcol->push_back(raw_trigger); // Read one, product is a vector.
175  art::put_product_in_principal(std::move(rtcol),
176  *outE,
177  "daq"); // Module label
178 
179  // RawSumDropMB data:
180  std::unique_ptr<std::vector<rawdata::RawSumDropMB> > rtcol_MB(new std::vector<rawdata::RawSumDropMB>);
181  rtcol_MB->push_back(raw_sumDropMB); // Read one, product is a vector.
182  art::put_product_in_principal(std::move(rtcol_MB),
183  *outE,
184  "daq"); // Module label
185 
186  // RawSumDCM data:
187  std::unique_ptr<std::vector<rawdata::RawSumDCM> > rtcol_DCM(new std::vector<rawdata::RawSumDCM>);
188  rtcol_DCM->push_back(raw_sumDCM); // Read one, product is a vector.
189  art::put_product_in_principal(std::move(rtcol_DCM),
190  *outE,
191  "daq"); // Module label
192 
193  // DAQ header:
194  std::unique_ptr<rawdata::DAQHeader > daqcol(new rawdata::DAQHeader(daq_header));
195  art::put_product_in_principal(std::move(daqcol),
196  *outE,
197  "daq"); // Module label
198 
199  /// Put FlatDAQData object
200  if(fDoFillFlatDAQData) {
201  std::unique_ptr<std::vector<rawdata::FlatDAQData> > flatcol(new std::vector<rawdata::FlatDAQData>);
202  flatcol->push_back(flat_daq_data); // Read one, product is a vector.
203  art::put_product_in_principal(std::move(flatcol),
204  *outE,
205  "daq"); // Module label
206  }
207 
208  return true;
209  }
210 
211 }// end of namespace
void readFile(std::string const &name, art::FileBlock *&fb)
void setDebug(bool f)
Close any currently open file.
Definition: RawFileParser.h:65
int open(const char *filename)
General initialization and reinitialization.
std::string getDetectorGDML(const int detid) const
const XML_Char * name
Definition: expat.h:151
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::shared_ptr< History > &&history) const
std::enable_if_t< P::branch_type==InEvent||P::branch_type==InResults > put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
uint32_t getSubrunNumber() const
Definition: OnlineUnpack.h:80
rawfileparser::RawFileParser fParser
Online raw file parsing utility.
bool fFilterCorruptedNanoslices
Do we need to filter out Corrupted NanoSlices?
Definition: OnlineUnpack.h:96
bool convertNovaTimeToUnixTime(uint64_t const &inputNovaTime, struct timespec &outputUnixTime)
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
RunID const & runID() const
Definition: SubRunID.h:77
art::SourceHelper const & fSourceHelper
Class to help with {Run, SubRun, Event}Principal construction.
std::string fCurrentFilename
Hang on to the current filename.
Encapsulate the geometry of one entire detector (near, far, ndos)
int close()
Open a file for parsing.
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
art::SubRunID fCurrentSubRunID
Keep track of the current subRun details.
A module to produce rawdata::RawDigits from NOvADDT DAQHits.
bool fDoFillFlatDAQData
Do we need to fill FlatDAQData object?
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
bool readNext(art::RunPrincipal *const &inR, art::SubRunPrincipal *const &inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
unsigned long long fTriggerTimingMarker_TimeStart
Definition: RawTrigger.h:38
bool fFilterCorruptedNanoslices
Filter the corrupted nanaslices in the unpacking?
std::string ExtractGDML() const
Extract contents from fGDMLFile and return as a string.
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
int getDetId() const
Definition: OnlineUnpack.h:82
NOvARawInputDriver(fhicl::ParameterSet const &pset, art::ProductRegistryHelper &help, art::SourceHelper const &pm)
uint32_t getRunNumber() const
Definition: OnlineUnpack.h:79
bool ProcessRawEvent(void *rawevent_buffer, std::vector< rawdata::RawDigit > *, rawdata::RawTrigger *, rawdata::RawSumDropMB *, rawdata::RawSumDCM *, rawdata::FlatDAQData *, rawdata::DAQHeader *)
Unpack the RawEvent.
unsigned long long getEventNumber() const
Definition: OnlineUnpack.h:81
int errno
Definition: errno.cpp:12