NovaDDTRawInputDriver.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file NovaDDTRawInputDriver.cxx
3 /// \brief Source to convert raw binary files to DDT root files
4 ///
5 /// \author janzirn@fnal.gov
6 ////////////////////////////////////////////////////////////////////////
7 
8 //NOvA includes
10 #include "DDTCore/OnlineUnpack.h"
13 
14 #include "NovaTimingUtilities/TimingUtilities.h"
15 #include "NovaDAQConventions/DAQConventions.h"
16 
17 // Framework includes
25 #include "fhiclcpp/ParameterSet.h"
26 
27 
28 namespace novaddt{
29 
30  //------------------------------------------------------------------------------
31  // Required constructor.
34  art::SourceHelper const &pm)
35  : fSourceHelper(pm)
36  , fCurrentFilename()
37  , fCurrentSubRunID(-1, -1) ///< Has to be distinguished from the ones that are acually used
38  , fParser()
39  , fMaxEventSize(pset.get<size_t>("maxEventSizeK", 65536) * 1024)
40  , fFilterCorruptedNanoslices(pset.get<bool>("FilterCorruptedNanoslices"))
41  {
42  // Declare products that *may* be in the event (or run, or subRun)
43  // here. Note the use of "reconstitutes" vs "produces": this is what
44  // allows us to specify module label, process name and (optionally)
45  // instance label for each product.
47  helper.reconstitutes<std::vector<novaddt::DAQHit>, art::InEvent>("DDTdaq");
48  // Turn off printf messages in the parser.
49  fParser.setDebug(false);
50  }
51 
52  //------------------------------------------------------------------------------
53  // Required function: close currently-open file.
55  fParser.close(); // Ignore error return
56  }
57 
58  // Required function: open the file, "name" and construct and return a
59  // new FileBlock object. MUST be successful or throw:
60  // art::Exception(art::errors::FileOpenError) or
61  // art::Exception(art::errors::FileReadError) are good candidates.
63  art::FileBlock* &fb) {
65 
66  int fd = fParser.open(fCurrentFilename.c_str());
67  if (fd == -1) { // Failure
69  << "Unable to open file "
70  << name
71  << " due to system error, \""
72  << strerror(errno)
73  << "\"\n";
74  }
75 
76  fb = new art::FileBlock(art::FileFormatVersion(1, "NovaDDTRawInput 2015a"),
78  }
79 
80  // Required function: read and fill Run, SubRun and/or Event as might be
81  // appropriate.
83  art::SubRunPrincipal* const &inSR,
84  art::RunPrincipal* &outR,
85  art::SubRunPrincipal* &outSR,
86  art::EventPrincipal* &outE)
87  {
88  ////////////////////////////////////
89  // Unpack the data.
90 
91  /// Define data structures, which will be filled by OnlineUnpack::ProcessRawEvent
92  std::unique_ptr<std::vector<novaddt::DAQHit> > hits(new std::vector<novaddt::DAQHit>);
93  novaddt::EventHeader evt_header;
94 
97 
98  /// Fill the data structures for this event.
99  if (!up.ProcessRawEvent(fParser, hits.get(), &evt_header)) return false;
100 
101  // TODO
102  // Get the actual timestamp here - use the current time as the
103  // default, maybe the default should really be a ridiculous value
104  // The below code is from daq2raw digit, DDT never implimented a trigger
105  // object, ironic, so we can't read the triggered time
106  // Use dummy timestamp, just like the streamer reader.
107  /*
108  struct timespec ts;
109 
110  novadaq::timeutils::
111  convertNovaTimeToUnixTime(raw_trigger.fTriggerTimingMarker_TimeStart, ts);
112 
113  // art::Timestamp has the seconds since the beginning of the epoch
114  // in the upper 32 bits and the fractional seconds in the lower 32
115  // bits.
116  art::Timestamp tstamp = (ts.tv_sec << 32) | ts.tv_nsec;
117  */
118 
119  art::Timestamp tstamp;
120 
121  ////////////////////////////////////
122  // Assemble new principals as required.
123 
124  art::SubRunID newID(up.getRunNumber(), up.getSubrunNumber());
125 
126  if (inR == nullptr || fCurrentSubRunID.runID() != newID.runID()) { // New Run
127  outR = fSourceHelper.makeRunPrincipal(up.getRunNumber(), tstamp);
128 
129  }
130 
131  if (inR == nullptr || fCurrentSubRunID != newID) { // New SubRun
133  up.getSubrunNumber(),
134  tstamp);
135  fCurrentSubRunID = newID;
136  }
137 
139  up.getSubrunNumber(),
140  up.getEventNumber(),
141  tstamp);
142 
143  ////////////////////////////////////
144  // Add the event products to the event:
145 
146  // Digitized data:
147  art::put_product_in_principal(std::move(hits), *outE, "DDTdaq");
148 
149  // MilliBlock header:
150  std::unique_ptr<novaddt::EventHeader > mbhead(new novaddt::EventHeader(evt_header));
151  art::put_product_in_principal(std::move(mbhead), *outE, "DDTdaq");
152 
153  return true;
154  }
155 
156 }// end of namespace
void setDebug(bool f)
Close any currently open file.
Definition: RawFileParser.h:65
int open(const char *filename)
General initialization and reinitialization.
const XML_Char * name
Definition: expat.h:151
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::shared_ptr< History > &&history) const
rawfileparser::RawFileParser fParser
Online raw file parsing utility.
bool fFilterCorruptedNanoslices
Filter the corrupted nanaslices in the unpacking?
void readFile(std::string const &name, art::FileBlock *&fb)
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 getRunNumber() const
Definition: OnlineUnpack.h:63
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
art::SubRunID fCurrentSubRunID
Keep track of the current subRun details.
RunID const & runID() const
Definition: SubRunID.h:77
uint32_t getSubrunNumber() const
Definition: OnlineUnpack.h:64
void hits()
Definition: readHits.C:15
bool readNext(art::RunPrincipal *const &inR, art::SubRunPrincipal *const &inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
uint64_t getEventNumber() const
Definition: OnlineUnpack.h:65
int close()
Open a file for parsing.
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool ProcessRawEvent(void *rawevent_buffer, std::vector< novaddt::DAQHit > *, novaddt::EventHeader *)
Unpack the RawEvent.
NovaDDTRawInputDriver(fhicl::ParameterSet const &pset, art::ProductRegistryHelper &help, art::SourceHelper const &pm)
bool fFilterCorruptedNanoslices
Do we need to filter out Corrupted NanoSlices?
Definition: OnlineUnpack.h:69
Source to convert raw binary files to DDT root files adapted from daq2rawdigit::NOvARawInputDriver.h.
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
std::string fCurrentFilename
Hang on to the current filename.
art::SourceHelper const & fSourceHelper
Class to help with {Run, SubRun, Event}Principal construction.
int errno
Definition: errno.cpp:12
enum BeamMode string