Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
daq2raw::TestBeamRawInputDriver Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-09-26/DAQ2RawDigit/testbeam/TestBeamRawInputDriver.h"

Inheritance diagram for daq2raw::TestBeamRawInputDriver:
daq2raw::NOvAInputDriverBase

Public Member Functions

 TestBeamRawInputDriver (fhicl::ParameterSet const &pset, art::ProductRegistryHelper &help, art::SourceHelper const &pm)
 
void closeCurrentFile ()
 Close currently-open file. More...
 
void readFile (std::string const &name, art::FileBlock *&fb)
 
bool readNext (art::RunPrincipal *const &inR, art::SubRunPrincipal *const &inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
 
void reconfigure (const fhicl::ParameterSet &pset)
 

Protected Member Functions

std::string getDetectorGDML (const int detid) const
 

Private Member Functions

void readBeamline ()
 read in the beamline files corresponding to the time period of this input file More...
 
LariatFragment * loadSpillFragments (TBranch *fragBranch, unsigned int index)
 load the artdaq spill fragments from the input file More...
 
std::vector< TDUFragment * > loadTDUFragments (TBranch *tduBranch, unsigned int index)
 load the artdaq TDU fragments from the input file More...
 
LariatFragment * getSpillFrag (const SpillWrapper *spillWrapper)
 get the lariat fragment from the artdaq fragments More...
 
BeamlineEventloadBeamlineEvent (unsigned long long tduTime)
 find and load the beamline event which corresponds to a specific TDU timestamp More...
 

Private Attributes

art::InputTag fInputSpillTag
 
art::InputTag fInputTDUTag
 
std::string fConfigName
 
std::string fTriggerName
 
std::string fToFName
 
std::string fWCName
 
std::string fCherenkovName
 
std::string fMuonStackName
 
std::string fPaddleDigitName
 
std::string fWCDigitName
 
std::string fOtherDigitName
 
std::string fSourceName
 
std::unique_ptr< daq2raw::BeamlineUnpackfBeamlineUnpack
 Algorithm to handle unpacking of beamline data. More...
 
std::unique_ptr< BeamlineEventsfBeamlineEvents
 Container to hold all beamline events before matching with detector data. More...
 
std::map< unsigned long long, BeamlineTriggerIndexfBeamlineIndex
 Container to index beamline file, spill, trigger and TDU information. More...
 
art::SourceHelper const & fSourceHelper
 Class to help with {Run, SubRun, Event}Principal construction. More...
 
std::string fCurrentFilename
 Hang on to the current filename. More...
 
art::SubRunID fCurrentSubRunID
 Keep track of the current subRun details. More...
 
rawfileparser::RawFileParser fParser
 Online raw file parsing utility. More...
 
size_t fMaxEventSize
 Will not try to read an event bigger than this. More...
 
bool fFilterCorruptedNanoslices
 Filter the corrupted nanaslices in the unpacking? More...
 
bool fDoFillFlatDAQData
 Do we need to fill FlatDAQData object? More...
 
bool fFilterBeamlineEvents
 Filter bad beamline events. More...
 

Detailed Description

Class to fill the constraints on a template argument to the class, art::Source

Definition at line 117 of file TestBeamRawInputDriver.h.

Constructor & Destructor Documentation

daq2raw::TestBeamRawInputDriver::TestBeamRawInputDriver ( fhicl::ParameterSet const &  pset,
art::ProductRegistryHelper helper,
art::SourceHelper const &  pm 
)

So, how does this work? Good question.

We have two data streams: detector and beamline. Anticipate both beamline and detector files will be data collected over period of ~O(1 hour) (similar to ND), but they will obviously not necessarily overlap. The detector files contain beamline triggers and other (e.g. cosmic) triggers. Beamline triggers will line up with triggers in the beamline files. Other trigger streams are saved in separate output files, so only need to worry about beamline triggers here.

Demonstration (| = trigger):

| || | | | | -------------------------------------— ----— Detector data -----------------— ------------------------— Beamline data | || | | | |

This module is designed to run over a single detector file and assumes the beamline data files which align with this in time are in the working directory. No checks on this are performed nor are any attempts made to look up files in this module.

In order to match and merge the two streams into the same art::Event, the following is performed: – perform an initial scan through the beamline data files to index the file name, spill number and trigger number for each TDU timestamp; – read in the given detector data file and convert to NOvASoft data formatting; – convert the detector data into NOvASoft-formatted offline data products; – for each event, compare TDU timestamp with the timestamps of the beamline events and find corresponding beamline information; – save all the NOvASoft data products within an art::Event.

Definition at line 51 of file TestBeamRawInputDriver.cxx.

References fCherenkovName, fConfigName, fDoFillFlatDAQData, fMuonStackName, fOtherDigitName, fPaddleDigitName, fParser, fSourceName, fToFName, fTriggerName, fWCDigitName, fWCName, art::InEvent, art::InRun, readBeamline(), reconfigure(), art::ProductRegistryHelper::reconstitutes(), and rawfileparser::RawFileParser::setDebug().

53  :
54  NOvAInputDriverBase(pset.get<std::string>("GDMLFileBase","")),
55  fBeamlineUnpack(new BeamlineUnpack(pset.get<fhicl::ParameterSet>("BeamlineUnpack"))),
56  fSourceHelper(pm),
58  fCurrentSubRunID(-1, -1),
59  fParser() {
60 
61  this->reconfigure(pset);
62 
63  fParser.setDebug(false);
64 
65  // Declare everything to be put in the art record
68  helper.reconstitutes<std::vector<rawdata::RawDigit>, art::InEvent>(fSourceName);
69  helper.reconstitutes<std::vector<rawdata::RawTrigger>, art::InEvent>(fSourceName);
70  helper.reconstitutes<std::vector<rawdata::RawSumDropMB>, art::InEvent>(fSourceName);
71  helper.reconstitutes<std::vector<rawdata::RawSumDCM>, art::InEvent>(fSourceName);
73  helper.reconstitutes<std::vector<rawdata::FlatDAQData>, art::InEvent>(fSourceName);
75  helper.reconstitutes<std::vector<rawdata::RawBeamlineTrigger>, art::InEvent>(fSourceName, fTriggerName);
76  helper.reconstitutes<std::vector<rawdata::RawBeamlineDigit>, art::InEvent>(fSourceName, fToFName);
77  helper.reconstitutes<std::vector<rawdata::RawBeamlineWC>, art::InEvent>(fSourceName, fWCName);
78  helper.reconstitutes<std::vector<rawdata::RawBeamlineDigit>, art::InEvent>(fSourceName, fCherenkovName);
79  helper.reconstitutes<std::vector<rawdata::RawBeamlineDigit>, art::InEvent>(fSourceName, fMuonStackName);
80  helper.reconstitutes<std::vector<rawdata::RawBeamlineDigit>, art::InEvent>(fSourceName, fPaddleDigitName);
81  helper.reconstitutes<std::vector<rawdata::RawBeamlineDigit>, art::InEvent>(fSourceName, fWCDigitName);
82  helper.reconstitutes<std::vector<rawdata::RawBeamlineDigit>, art::InEvent>(fSourceName, fOtherDigitName);
83 
84  // Read in all the beamline data
85  this->readBeamline();
86 
87 }
void setDebug(bool f)
Close any currently open file.
Definition: RawFileParser.h:65
bool fDoFillFlatDAQData
Do we need to fill FlatDAQData object?
rawfileparser::RawFileParser fParser
Online raw file parsing utility.
void readBeamline()
read in the beamline files corresponding to the time period of this input file
art::SourceHelper const & fSourceHelper
Class to help with {Run, SubRun, Event}Principal construction.
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
NOvAInputDriverBase(std::string gdmlBase="")
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::unique_ptr< daq2raw::BeamlineUnpack > fBeamlineUnpack
Algorithm to handle unpacking of beamline data.
std::string fCurrentFilename
Hang on to the current filename.
void reconfigure(const fhicl::ParameterSet &pset)
art::SubRunID fCurrentSubRunID
Keep track of the current subRun details.

Member Function Documentation

void daq2raw::TestBeamRawInputDriver::closeCurrentFile ( )

Close currently-open file.

Definition at line 119 of file TestBeamRawInputDriver.cxx.

References rawfileparser::RawFileParser::close(), and fParser.

119  {
120  fParser.close();
121 }
rawfileparser::RawFileParser fParser
Online raw file parsing utility.
int close()
Open a file for parsing.
std::string daq2raw::NOvAInputDriverBase::getDetectorGDML ( const int  detid) const
protectedinherited

Definition at line 22 of file NOvAInputDriverBase.cxx.

References daq2raw::NOvAInputDriverBase::fGDMLBase, novadaq::cnv::kFARDET, novadaq::cnv::kNDOS, novadaq::cnv::kNEARDET, and novadaq::cnv::kTESTBEAM.

Referenced by daq2raw::DAQHit2Raw::beginRun(), daq2raw::NOvARawInputDriver::readNext(), daq2raw::NOvASocketInputDriver::readNext(), and readNext().

22  {
23 
24  // get the base form of the geometry file for the current detector
25  if(!fGDMLBase.empty()) return fGDMLBase;
26 
27  //\todo at some point we should query a database to get this, especially
28  //\todo when we have instances of only part of a detector working
29  std::string detFileBase("");
30  if (detid == novadaq::cnv::kNDOS)
31  detFileBase = "ndos-2x3-4block_nomc-xtru-vacuum";
32  else if (detid == novadaq::cnv::kNEARDET)
33  detFileBase = "neardet-3x3-8block-xtru-vacuum-stagger";
34  else if(detid == novadaq::cnv::kFARDET)
35  detFileBase = "fardet-12x12-28block-xtru-vacuum-stagger-pivoter";
36  else if(detid == novadaq::cnv::kTESTBEAM)
37  detFileBase = "testbeam-2x2-2block-xtru-vacuum-stagger";
38 
39  return detFileBase;
40  }
Far Detector at Ash River, MN.
Prototype Near Detector on the surface at FNAL.
Near Detector in the NuMI cavern.
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
LariatFragment * daq2raw::TestBeamRawInputDriver::getSpillFrag ( const SpillWrapper spillWrapper)
private

get the lariat fragment from the artdaq fragments

Get the lariat fragment from the spill wrapper.

Definition at line 239 of file TestBeamRawInputDriver.cxx.

References daq2raw::SpillWrapper::get(), and daq2raw::SpillWrapper::size().

Referenced by loadSpillFragments().

239  {
240 
241  // get the spill data
242  mf::LogVerbatim("TestBeamRawInputDriver") << "Spill construction complete\n"
243  << "Spill starts at "
244  << static_cast<const void*>(spillWrapper->get())
245  << ", can pass this pointer to the LariatFragment constructor\n"
246  << "Spill appears to be " << spillWrapper->size() << " bytes\n";
247 
248  const uint8_t* spillDataPtr(spillWrapper->get());
249 
250  mf::LogVerbatim("TestBeamRawInputDriver") << "Spill is "
251  << spillWrapper->size()
252  << " bytes, starting at "
253  << static_cast<const void*>(spillDataPtr);
254 
255  // make a lariat fragment
256  LariatFragment* spillFrag = new LariatFragment((char*)spillDataPtr, spillWrapper->size());
257 
258  return spillFrag;
259 
260 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
daq2raw::BeamlineEvent * daq2raw::TestBeamRawInputDriver::loadBeamlineEvent ( unsigned long long  tduTime)
private

find and load the beamline event which corresponds to a specific TDU timestamp

Find and load the beamline event which corresponds to a specific TDU timestamp

Definition at line 322 of file TestBeamRawInputDriver.cxx.

References allTimeWatchdog::endl, art::rootNames::eventTreeName(), fBeamlineIndex, fBeamlineUnpack, daq2raw::BeamlineFileIndex::File, daq2raw::BeamlineEvents::FindEvent(), fInputSpillTag, fInputTDUTag, inFile, loadSpillFragments(), loadTDUFragments(), art::EventAuxiliary::run(), daq2raw::BeamlineSpillIndex::Spill, and daq2raw::BeamlineTriggerIndex::Trigger.

Referenced by readNext().

322  {
323 
324  BeamlineTriggerIndex bl_index;
325 
326  if (fBeamlineIndex.count(tduTime))
327  bl_index = fBeamlineIndex[tduTime];
328  else if (fBeamlineIndex.count(tduTime-1))
329  bl_index = fBeamlineIndex[tduTime-1];
330  else if (fBeamlineIndex.count(tduTime+1))
331  bl_index = fBeamlineIndex[tduTime+1];
332  else if (fBeamlineIndex.count(tduTime+2))
333  bl_index = fBeamlineIndex[tduTime+2];
334  else if (fBeamlineIndex.count(tduTime-2))
335  bl_index = fBeamlineIndex[tduTime-2];
336  else {
337  mf::LogWarning("TestBeamRawInputDriver::loadBeamlineEvent")
338  << "No beamline event with TDU timestamp " << tduTime << " found." << std::endl;
339  return nullptr;
340  }
341 
342  // open the input file and get the branches
343  TFile* inFile = TFile::Open(bl_index.File.c_str(), "READ");
344  TTree* eventTree = reinterpret_cast<TTree*>(inFile->Get(art::rootNames::eventTreeName().c_str()));
345  TBranch* eventAuxBranch = eventTree->GetBranch("EventAuxiliary");
346  TBranch* spillBranch = eventTree->GetBranch(getBranchName<artdaq::Fragments>(fInputSpillTag).data());
347  TBranch* tduBranch = eventTree->GetBranch(getBranchName<artdaq::Fragments>(fInputTDUTag).data());
348 
349  // load the artdaq fragments
350  LariatFragment* spillFrag = loadSpillFragments(spillBranch, bl_index.Spill);
351  std::vector<TDUFragment*> tduFrags = loadTDUFragments(tduBranch, bl_index.Spill);
352 
353  // find run number for unpacking the magnetic field
354  art::EventAuxiliary eventAux;
355  art::EventAuxiliary* eventAuxPtr = &eventAux;
356  eventAuxBranch->SetAddress(&eventAuxPtr);
357  eventAuxBranch->GetEntry(bl_index.Spill);
358  unsigned int beamline_run = eventAux.run();
359 
360  // configure beamline unpack alg?
361 
362  // unpack and retrieve the beamline events
363  fBeamlineUnpack->Unpack(spillFrag, tduFrags, beamline_run, bl_index.File);
364  BeamlineEvents* beamlineEvents = fBeamlineUnpack->GetBeamlineEvents();
365 
366  // find the trigger
367  // Make a new pointer to this on heap so all the other events
368  // can be cleaned up at the end of this function.
369  // It is the responsibility of the eventual user of this data
370  // to clean up when done.
371  BeamlineEvent* beamlineEvent
372  = new BeamlineEvent(*beamlineEvents->FindEvent(bl_index.Trigger));
373 
374  // tidy up
375  inFile->Close();
376  delete spillFrag;
377  for (std::vector<TDUFragment*>::const_iterator tduIt = tduFrags.begin();
378  tduIt != tduFrags.end(); ++tduIt)
379  delete *tduIt;
380  fBeamlineUnpack->EndSpill();
381 
382  mf::LogVerbatim("TestBeamRawInputDriver::loadBeamlineEvent")
383  << "Found matching beamline event from file "
384  << bl_index.File << ", spill "
385  << bl_index.Spill << " and trigger "
386  << bl_index.Trigger << std::endl;
387 
388  return beamlineEvent;
389 
390 }
RunNumber_t run() const
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< TDUFragment * > loadTDUFragments(TBranch *tduBranch, unsigned int index)
load the artdaq TDU fragments from the input file
std::string const & eventTreeName()
const XML_Char const XML_Char * data
Definition: expat.h:268
ifstream inFile
Definition: AnaPlotMaker.h:34
LariatFragment * loadSpillFragments(TBranch *fragBranch, unsigned int index)
load the artdaq spill fragments from the input file
std::map< unsigned long long, BeamlineTriggerIndex > fBeamlineIndex
Container to index beamline file, spill, trigger and TDU information.
std::unique_ptr< daq2raw::BeamlineUnpack > fBeamlineUnpack
Algorithm to handle unpacking of beamline data.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
LariatFragment * daq2raw::TestBeamRawInputDriver::loadSpillFragments ( TBranch *  fragBranch,
unsigned int  index 
)
private

load the artdaq spill fragments from the input file

Load the artdaq fragments.

Definition at line 264 of file TestBeamRawInputDriver.cxx.

References daq2raw::SpillWrapper::add(), allTimeWatchdog::endl, daq2raw::getFragments(), getSpillFrag(), and daq2raw::SpillWrapper::ready().

Referenced by loadBeamlineEvent(), and readBeamline().

265  {
266 
267  SpillWrapper* spillWrapper = new SpillWrapper(1);
268  artdaq::Fragments* fragments = getFragments(fragBranch, index);
269 
270  if ((*fragments).size() > 1)
271  throw cet::exception("TestBeamRawInputDriver")
272  << "artdaq::Fragment SPILL vector contains more than one fragment.";
273 
274  const artdaq::Fragment& fragment = fragments->at(0);
275  spillWrapper->add(fragment);
276 
277  if (!spillWrapper->ready())
278  throw cet::exception("TestBeamRawInputDriver")
279  << "Spill construction failed; spill is incomplete." << std::endl;
280 
281  // load the lariat fragment
282  LariatFragment* spillFrag = getSpillFrag(spillWrapper);
283 
284  delete spillWrapper;
285  return spillFrag;
286 }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
artdaq::Fragments * getFragments(TBranch *br, unsigned entry)
LariatFragment * getSpillFrag(const SpillWrapper *spillWrapper)
get the lariat fragment from the artdaq fragments
std::vector< TDUFragment * > daq2raw::TestBeamRawInputDriver::loadTDUFragments ( TBranch *  tduBranch,
unsigned int  index 
)
private

load the artdaq TDU fragments from the input file

Load the TDU artdaq fragment.

Definition at line 290 of file TestBeamRawInputDriver.cxx.

References elec2geo::block, and daq2raw::getFragments().

Referenced by loadBeamlineEvent(), and readBeamline().

291  {
292 
293  // container of tdu fragments to be read in from the
294  // artdaq branch
295  std::vector<TDUFragment*> tduFrags;
296 
297  artdaq::Fragments* fragments = getFragments(tduBranch, index);
298 
299  if ((*fragments).size() > 1)
300  throw cet::exception("TestBeamRawInputDriver")
301  << "artdaq::Fragment TDU vector contains more than one fragment.";
302 
303  for (artdaq::Fragments::const_iterator fragIt = fragments->begin(); fragIt != fragments->end(); ++fragIt) {
304 
305  artdaq::ContainerFragment cont_frag(*fragIt);
306 
307  for (size_t block = 0; block < cont_frag.block_count(); ++block) {
308  const artdaq::Fragment frag = *cont_frag[block];
309  TDUFragment* tduFrag = new TDUFragment(reinterpret_cast<const char*>(frag.dataBeginBytes()));
310  tduFrags.push_back(tduFrag);
311  }
312 
313  }
314 
315  return tduFrags;
316 
317 }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
artdaq::Fragments * getFragments(TBranch *br, unsigned entry)
block
print "ROW IS " print row
Definition: elec2geo.py:31
void daq2raw::TestBeamRawInputDriver::readBeamline ( )
private

read in the beamline files corresponding to the time period of this input file

Read in all the beamline triggers from the beamline data files. Expect all files relevant for this detector data to have been found and placed in this working directory.

Definition at line 127 of file TestBeamRawInputDriver.cxx.

References dir, e, allTimeWatchdog::endl, art::rootNames::eventTreeName(), fBeamlineEvents, fBeamlineIndex, fBeamlineUnpack, file, ConvertToSnowGlobesInput::file_name, compareCafs::files, daq2raw::BeamlineEvents::FindEvent(), fInputSpillTag, fInputTDUTag, daq2raw::BeamlineEvent::GetTDUTime(), inFile, loadSpillFragments(), loadTDUFragments(), make_pair(), next(), daq2raw::BeamlineEvents::NumEvents(), and g4zmq::pwd().

Referenced by TestBeamRawInputDriver().

127  {
128 
129  fBeamlineEvents.reset(new BeamlineEvents(0));
130 
131  // get files in working directory
132  TString pwd(gSystem->pwd());
133  TSystemDirectory dir(pwd, pwd);
134  TList* files = dir.GetListOfFiles();
135  if (!files)
136  return;
137 
138  // loop over files in working directory
139  TSystemFile* file;
140  TString file_name;
141  TIter next(files);
142  while ((file = (TSystemFile*)next())) {
143 
144  file_name = file->GetName();
145  if (!file_name.BeginsWith("novabeamline_") or !file_name.EndsWith(".root"))
146  continue;
147  mf::LogVerbatim("TestBeamRawInputDriver::readBeamline")
148  << "Reading in beamline file " << file_name << std::endl;
149  BeamlineFileIndex bl_file(file_name.Data());
150 
151  // get artdaq::Fragments branch
152  TFile* inFile = TFile::Open(file_name, "READ");
153  TTree* eventTree = reinterpret_cast<TTree*>(inFile->Get(art::rootNames::eventTreeName().c_str()));
154  TBranch* spillBranch = eventTree->GetBranch(getBranchName<artdaq::Fragments>(fInputSpillTag).data());
155  TBranch* tduBranch = eventTree->GetBranch(getBranchName<artdaq::Fragments>(fInputTDUTag).data());
156 
157  // ensure we have the same number of spills in each component
158  unsigned int numSpillsInFile = 0;
159  if (spillBranch->GetEntries() != tduBranch->GetEntries())
160  throw cet::exception("TestBeamRawInputDriver::readBeamline")
161  << "In file " << file_name << ", "
162  << "number of spills recorded in spill branch (" << spillBranch->GetEntries() << ") "
163  << "does not match number of spills recorded in TDU branch (" << tduBranch->GetEntries() << ")."
164  << std::endl;
165  else {
166  numSpillsInFile = spillBranch->GetEntries();
167  mf::LogVerbatim("TestBeamRawInputDriver::readBeamline")
168  << "Number of spills in file " << file_name << ": "
169  << numSpillsInFile << std::endl;
170  }
171 
172  // loop through spills in the file
173  for (unsigned int spillIt = 0; spillIt < numSpillsInFile; ++spillIt) {
174 
175  BeamlineSpillIndex bl_spill(bl_file, spillIt);
176 
177  // load the artdaq fragments
178  LariatFragment* spillFrag = loadSpillFragments(spillBranch, spillIt);
179  std::vector<TDUFragment*> tduFrags = loadTDUFragments(tduBranch, spillIt);
180 
181  // configure beamline unpack alg?
182 
183  // fill all novasoft data products
184  try {
185  fBeamlineUnpack->Unpack(spillFrag, tduFrags);
186  }
187  catch (cet::exception& e) {
188  mf::LogWarning("TestBeamRawInputDriver::readBeamline")
189  << "Unpacking " << file_name << ", spill " << spillIt << std::endl
190  << e.what() << std::endl
191  << "EXCEPTION CAUGHT: ignoring this spill." << std::endl;
192  continue;
193  }
194 
195  // get the beamline events
196  BeamlineEvents* beamlineEvents = fBeamlineUnpack->GetBeamlineEvents();
197  mf::LogVerbatim("TestBeamRawInputDriver::readBeamline")
198  << "Number of spills in file " << file_name << ", spill " << spillIt << ": "
199  << beamlineEvents->NumEvents() << std::endl;
200 
201  // loop through triggers in this spill
202  for (unsigned int triggerIt = 0; triggerIt < beamlineEvents->NumEvents(); ++triggerIt) {
203 
204  BeamlineTriggerIndex bl_trigger(bl_spill, triggerIt);
205 
206  BeamlineEvent* beamlineEvent = beamlineEvents->FindEvent(triggerIt);
207  fBeamlineIndex.insert(std::make_pair(beamlineEvent->GetTDUTime(), bl_trigger));
208 
209  } // trigger
210 
211  delete spillFrag;
212  for (std::vector<TDUFragment*>::const_iterator tduIt = tduFrags.begin();
213  tduIt != tduFrags.end(); ++tduIt)
214  delete *tduIt;
215  fBeamlineUnpack->EndSpill();
216 
217  } // spill
218 
219  inFile->Close();
220 
221  } // file
222 
223  mf::LogVerbatim("TestBeamRawInputDriver::readBeamline")
224  << "Contents of the beamline index map:" << std::endl;
225  for (std::map<unsigned long long, BeamlineTriggerIndex>::const_iterator blIndexIt = fBeamlineIndex.begin();
226  blIndexIt != fBeamlineIndex.end(); ++blIndexIt)
227  mf::LogVerbatim("TestBeamRawInputDriver::readBeamline")
228  << "NOvA time " << blIndexIt->first
229  << " corresponds to file " << blIndexIt->second.File
230  << ", spill " << blIndexIt->second.Spill
231  << " and trigger " << blIndexIt->second.Trigger << "." << std::endl;
232 
233  return;
234 
235 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< TDUFragment * > loadTDUFragments(TBranch *tduBranch, unsigned int index)
load the artdaq TDU fragments from the input file
std::string const & eventTreeName()
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
def pwd()
Definition: g4zmq.py:47
const XML_Char const XML_Char * data
Definition: expat.h:268
ifstream inFile
Definition: AnaPlotMaker.h:34
LariatFragment * loadSpillFragments(TBranch *fragBranch, unsigned int index)
load the artdaq spill fragments from the input file
std::unique_ptr< BeamlineEvents > fBeamlineEvents
Container to hold all beamline events before matching with detector data.
std::map< unsigned long long, BeamlineTriggerIndex > fBeamlineIndex
Container to index beamline file, spill, trigger and TDU information.
TDirectory * dir
Definition: macro.C:5
std::unique_ptr< daq2raw::BeamlineUnpack > fBeamlineUnpack
Algorithm to handle unpacking of beamline data.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
TFile * file
Definition: cellShifts.C:17
Float_t e
Definition: plot.C:35
void next()
Definition: show_event.C:84
void daq2raw::TestBeamRawInputDriver::readFile ( std::string const &  name,
art::FileBlock *&  fb 
)

Open the file, "name" and construct and return a new FileBlock object. MUST be successful or throw: art::Exception(art::errors::FileOpenError) or art::Exception(art::errors::FileReadError) are good candidates.

Definition at line 397 of file TestBeamRawInputDriver.cxx.

References errno, fCurrentFilename, fd, art::errors::FileOpenError, fParser, and rawfileparser::RawFileParser::open().

398  {
399 
401 
402  int fd = fParser.open(fCurrentFilename.c_str());
403  if (fd == -1) { // Failure
405  << "Unable to open file "
406  << name
407  << " due to system error, \""
408  << strerror(errno)
409  << "\"\n";
410  }
411 
412  fb = new art::FileBlock(art::FileFormatVersion(1, "NOvARawInput 2011a"),
414 }
int open(const char *filename)
General initialization and reinitialization.
const XML_Char * name
Definition: expat.h:151
rawfileparser::RawFileParser fParser
Online raw file parsing utility.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string fCurrentFilename
Hang on to the current filename.
int errno
Definition: errno.cpp:12
bool daq2raw::TestBeamRawInputDriver::readNext ( art::RunPrincipal *const &  inR,
art::SubRunPrincipal *const &  inSR,
art::RunPrincipal *&  outR,
art::SubRunPrincipal *&  outSR,
art::EventPrincipal *&  outE 
)

Read and fill Run, SubRun and/or Event as might be appropriate.

Define data structures, which will be filled by OnlineUnpack::ProcessRawEvent

Fill the data structures for this event.

Put FlatDAQData object

Definition at line 419 of file TestBeamRawInputDriver.cxx.

References novadaq::timeutils::convertNovaTimeToUnixTime(), geo::GeometryBase::ExtractGDML(), fCherenkovName, fConfigName, fCurrentFilename, fCurrentSubRunID, fDoFillFlatDAQData, daq2raw::OnlineUnpack::fFilterCorruptedNanoslices, fFilterCorruptedNanoslices, fMuonStackName, fOtherDigitName, fPaddleDigitName, fParser, fSourceHelper, fSourceName, fToFName, fTriggerName, rawdata::RawTrigger::fTriggerTimingMarker_TimeStart, fWCDigitName, fWCName, daq2raw::BeamlineEvent::GetCherenkov(), daq2raw::BeamlineEvent::GetConfig(), daq2raw::NOvAInputDriverBase::getDetectorGDML(), daq2raw::OnlineUnpack::getDetId(), daq2raw::OnlineUnpack::getEventNumber(), daq2raw::BeamlineEvent::GetMuonStack(), daq2raw::OnlineUnpack::getRunNumber(), daq2raw::OnlineUnpack::getSubrunNumber(), daq2raw::BeamlineEvent::GetToF(), daq2raw::BeamlineEvent::GetTrigger(), daq2raw::BeamlineEvent::GetWC(), loadBeamlineEvent(), art::SourceHelper::makeEventPrincipal(), art::SourceHelper::makeRunPrincipal(), art::SourceHelper::makeSubRunPrincipal(), daq2raw::OnlineUnpack::ProcessRawEvent(), art::put_product_in_principal(), art::SubRunID::runID(), and msf_helper::timespec.

423  {
424 
425  ////////////////////////////////////
426  // Unpack the data.
427 
428  // NOTE: As of OnlineUnpack.cxx r1.9, the histogram pointers required
429  // in the constructor are *not* filled. In the event that one *does*
430  // want this kind of information, the data to be histogrammed should
431  // be put into event products (not necessarily written out to file)
432  // and turned into histograms by a downstream analyzer. This will
433  // enable easy management of different histograms for diferent runs,
434  // subruns, etc, etc and trivial control of whether histograns are
435  // actually wanted or not.
436  daq2raw::OnlineUnpack up(nullptr, nullptr, nullptr, &fCurrentFilename);
437  up.fFilterCorruptedNanoslices = fFilterCorruptedNanoslices;
438 
439  /// Define data structures, which will be filled by OnlineUnpack::ProcessRawEvent
440  std::unique_ptr<std::vector<rawdata::RawDigit> > digits(new std::vector<rawdata::RawDigit>);
441  rawdata::RawTrigger raw_trigger;
442  rawdata::RawSumDropMB raw_sumDropMB;
443  rawdata::RawSumDCM raw_sumDCM;
444  rawdata::FlatDAQData flat_daq_data;
445  rawdata::DAQHeader daq_header;
446 
447  /// Fill the data structures for this event.
448  if (!up.ProcessRawEvent(fParser,
449  digits.get(),
450  &raw_trigger,
451  &raw_sumDropMB,
452  &raw_sumDCM,
453  &flat_daq_data,
454  &daq_header))
455  return false;
456 
457  // Get the actual timestamp here - use the current time as the
458  // default, maybe the default should really be a ridiculous value
459  struct timespec ts;
460 
463 
464  // Find the corresponding beamline event which matches this
465  // detector trigger.
466  BeamlineEvent* beamlineEvent
468  // // Consider leaving this event if there is no corresponding beamline data
469  // if (!beamlineEvent)
470  // return true;
471 
472  // art::Timestamp has the seconds since the beginning of the epoch
473  // in the upper 32 bits and the fractional seconds in the lower 32
474  // bits.
475  art::Timestamp tstamp = (ts.tv_sec << 32) | ts.tv_nsec;
476 
477  ////////////////////////////////////
478  // Assemble new principals as required.
479  art::SubRunID newID(up.getRunNumber(), up.getSubrunNumber());
480  if (inR == nullptr || fCurrentSubRunID.runID() != newID.runID()) { // New Run fragment
481  outR = fSourceHelper.makeRunPrincipal(up.getRunNumber(), tstamp);
482 
483  // get the base form of the geometry file for the current detector
484  //\todo at some point we should query a database to get this, especially
485  //\todo when we have instances of only part of a detector working
486  std::string detFileBase = getDetectorGDML(up.getDetId());
487  std::unique_ptr<sumdata::RunData> rundata
488  (new sumdata::RunData(novadaq::cnv::DetId(up.getDetId()),
489  detFileBase,
490  geo::GeometryBase::ExtractGDML(detFileBase+".gdml", false)));
491  art::put_product_in_principal(std::move(rundata),
492  *outR,
493  fSourceName); // Module label
494  }
495  if (inSR == nullptr || fCurrentSubRunID != newID) { // New SubRun fragment
496  outSR = fSourceHelper.makeSubRunPrincipal(up.getRunNumber(),
497  up.getSubrunNumber(),
498  tstamp);
499  fCurrentSubRunID = newID;
500  }
501  outE = fSourceHelper.makeEventPrincipal(up.getRunNumber(),
502  up.getSubrunNumber(),
503  up.getEventNumber(),
504  tstamp);
505 
506  ////////////////////////////////////
507  // Add the event products to the event:
508 
509  // Digitized data:
510  art::put_product_in_principal(std::move(digits), *outE, fSourceName);
511 
512  // Trigger data:
513  std::unique_ptr<std::vector<rawdata::RawTrigger> > rtcol(new std::vector<rawdata::RawTrigger>);
514  rtcol->push_back(raw_trigger); // Read one, product is a vector.
515  art::put_product_in_principal(std::move(rtcol),
516  *outE,
517  fSourceName);
518 
519  // RawSumDropMB data:
520  std::unique_ptr<std::vector<rawdata::RawSumDropMB> > rtcol_MB(new std::vector<rawdata::RawSumDropMB>);
521  rtcol_MB->push_back(raw_sumDropMB); // Read one, product is a vector.
522  art::put_product_in_principal(std::move(rtcol_MB),
523  *outE,
524  fSourceName);
525 
526  // RawSumDCM data:
527  std::unique_ptr<std::vector<rawdata::RawSumDCM> > rtcol_DCM(new std::vector<rawdata::RawSumDCM>);
528  rtcol_DCM->push_back(raw_sumDCM); // Read one, product is a vector.
529  art::put_product_in_principal(std::move(rtcol_DCM),
530  *outE,
531  fSourceName);
532 
533  // DAQ header:
534  std::unique_ptr<rawdata::DAQHeader > daqcol(new rawdata::DAQHeader(daq_header));
535  art::put_product_in_principal(std::move(daqcol),
536  *outE,
537  fSourceName);
538 
539  /// Put FlatDAQData object
540  if(fDoFillFlatDAQData) {
541  std::unique_ptr<std::vector<rawdata::FlatDAQData> > flatcol(new std::vector<rawdata::FlatDAQData>);
542  flatcol->push_back(flat_daq_data); // Read one, product is a vector.
543  art::put_product_in_principal(std::move(flatcol),
544  *outE,
545  fSourceName);
546  }
547 
548  ////////////////////////////////////
549  // Beamline data products:
550  rawdata::RawBeamlineConfig bl_config;
551  std::vector<rawdata::RawBeamlineTrigger> bl_trigger;
552  std::vector<rawdata::RawBeamlineDigit> bl_tof;
553  std::vector<rawdata::RawBeamlineWC> bl_wc;
554  std::vector<rawdata::RawBeamlineDigit> bl_cherenkov;
555  std::vector<rawdata::RawBeamlineDigit> bl_muonstack;
556  std::vector<rawdata::RawBeamlineDigit> bl_paddledigit;
557  std::vector<rawdata::RawBeamlineDigit> bl_wcdigit;
558  std::vector<rawdata::RawBeamlineDigit> bl_otherdigit;
559 
560  if (beamlineEvent) {
561  bl_config = beamlineEvent->GetConfig();
562  bl_trigger = beamlineEvent->GetTrigger();
563  bl_tof = beamlineEvent->GetToF();
564  bl_wc = beamlineEvent->GetWC();
565  bl_cherenkov = beamlineEvent->GetCherenkov();
566  bl_muonstack = beamlineEvent->GetMuonStack();
567  delete beamlineEvent;
568  }
569 
571  (std::make_unique<rawdata::RawBeamlineConfig>(bl_config), *outE, fSourceName, fConfigName);
573  (std::make_unique<std::vector<rawdata::RawBeamlineTrigger> >(bl_trigger), *outE, fSourceName, fTriggerName);
575  (std::make_unique<std::vector<rawdata::RawBeamlineDigit> >(bl_tof), *outE, fSourceName, fToFName);
577  (std::make_unique<std::vector<rawdata::RawBeamlineWC> >(bl_wc), *outE, fSourceName, fWCName);
579  (std::make_unique<std::vector<rawdata::RawBeamlineDigit> >(bl_cherenkov), *outE, fSourceName, fCherenkovName);
581  (std::make_unique<std::vector<rawdata::RawBeamlineDigit> >(bl_muonstack), *outE, fSourceName, fMuonStackName);
583  (std::make_unique<std::vector<rawdata::RawBeamlineDigit> >(bl_paddledigit), *outE, fSourceName, fPaddleDigitName);
585  (std::make_unique<std::vector<rawdata::RawBeamlineDigit> >(bl_wcdigit), *outE, fSourceName, fWCDigitName);
587  (std::make_unique<std::vector<rawdata::RawBeamlineDigit> >(bl_otherdigit), *outE, fSourceName, fOtherDigitName);
588 
589 
590  return true;
591 }
std::string getDetectorGDML(const int detid) const
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={})
bool fDoFillFlatDAQData
Do we need to fill FlatDAQData object?
rawfileparser::RawFileParser fParser
Online raw file parsing utility.
bool convertNovaTimeToUnixTime(uint64_t const &inputNovaTime, struct timespec &outputUnixTime)
art::SourceHelper const & fSourceHelper
Class to help with {Run, SubRun, Event}Principal construction.
BeamlineEvent * loadBeamlineEvent(unsigned long long tduTime)
find and load the beamline event which corresponds to a specific TDU timestamp
RunID const & runID() const
Definition: SubRunID.h:77
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
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
std::string fCurrentFilename
Hang on to the current filename.
art::SubRunID fCurrentSubRunID
Keep track of the current subRun details.
void daq2raw::TestBeamRawInputDriver::reconfigure ( const fhicl::ParameterSet pset)

Definition at line 90 of file TestBeamRawInputDriver.cxx.

References fCherenkovName, fConfigName, fDoFillFlatDAQData, fFilterBeamlineEvents, fFilterCorruptedNanoslices, fInputSpillTag, fInputTDUTag, fMaxEventSize, fMuonStackName, fOtherDigitName, fPaddleDigitName, fSourceName, fToFName, fTriggerName, fWCDigitName, fWCName, and fhicl::ParameterSet::get().

Referenced by TestBeamRawInputDriver().

90  {
91 
92  // output module label
93  fSourceName = pset.get<std::string>("SourceName");
94 
95  // beamline unpack config
96  fhicl::ParameterSet beamline_config = pset.get<fhicl::ParameterSet>("BeamlineUnpackConfig");
97  fInputSpillTag = beamline_config.get<art::InputTag>("InputSpillTag");
98  fInputTDUTag = beamline_config.get<art::InputTag>("InputTDUTag");
99  fConfigName = beamline_config.get<std::string>("ConfigName");
100  fTriggerName = beamline_config.get<std::string>("TriggerName");
101  fToFName = beamline_config.get<std::string>("ToFName");
102  fWCName = beamline_config.get<std::string>("WCName");
103  fCherenkovName = beamline_config.get<std::string>("CherenkovName");
104  fMuonStackName = beamline_config.get<std::string>("MuonStackName");
105  fPaddleDigitName = beamline_config.get<std::string>("PaddleDigitName");
106  fWCDigitName = beamline_config.get<std::string>("WCDigitName");
107  fOtherDigitName = beamline_config.get<std::string>("OtherDigitName");
108 
109  // running options
110  fMaxEventSize = pset.get<size_t>("maxEventSizeK", 65536) * 1024;
111  fFilterCorruptedNanoslices = pset.get<bool>("FilterCorruptedNanoslices");
112  fDoFillFlatDAQData = pset.get<bool>("DoFillFlatDAQData");
113  fFilterBeamlineEvents = pset.get<bool>("FilterBeamlineEvents");
114 
115 }
bool fDoFillFlatDAQData
Do we need to fill FlatDAQData object?
bool fFilterBeamlineEvents
Filter bad beamline events.
T get(std::string const &key) const
Definition: ParameterSet.h:231
size_t fMaxEventSize
Will not try to read an event bigger than this.
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
bool fFilterCorruptedNanoslices
Filter the corrupted nanaslices in the unpacking?

Member Data Documentation

std::unique_ptr<BeamlineEvents> daq2raw::TestBeamRawInputDriver::fBeamlineEvents
private

Container to hold all beamline events before matching with detector data.

Definition at line 171 of file TestBeamRawInputDriver.h.

Referenced by readBeamline().

std::map<unsigned long long, BeamlineTriggerIndex> daq2raw::TestBeamRawInputDriver::fBeamlineIndex
private

Container to index beamline file, spill, trigger and TDU information.

Definition at line 173 of file TestBeamRawInputDriver.h.

Referenced by loadBeamlineEvent(), and readBeamline().

std::unique_ptr<daq2raw::BeamlineUnpack> daq2raw::TestBeamRawInputDriver::fBeamlineUnpack
private

Algorithm to handle unpacking of beamline data.

Definition at line 170 of file TestBeamRawInputDriver.h.

Referenced by loadBeamlineEvent(), and readBeamline().

std::string daq2raw::TestBeamRawInputDriver::fCherenkovName
private

Definition at line 162 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

std::string daq2raw::TestBeamRawInputDriver::fConfigName
private

Definition at line 158 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

std::string daq2raw::TestBeamRawInputDriver::fCurrentFilename
private

Hang on to the current filename.

Definition at line 176 of file TestBeamRawInputDriver.h.

Referenced by readFile(), and readNext().

art::SubRunID daq2raw::TestBeamRawInputDriver::fCurrentSubRunID
private

Keep track of the current subRun details.

Definition at line 177 of file TestBeamRawInputDriver.h.

Referenced by readNext().

bool daq2raw::TestBeamRawInputDriver::fDoFillFlatDAQData
private

Do we need to fill FlatDAQData object?

Definition at line 181 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

bool daq2raw::TestBeamRawInputDriver::fFilterBeamlineEvents
private

Filter bad beamline events.

Definition at line 182 of file TestBeamRawInputDriver.h.

Referenced by reconfigure().

bool daq2raw::TestBeamRawInputDriver::fFilterCorruptedNanoslices
private

Filter the corrupted nanaslices in the unpacking?

Definition at line 180 of file TestBeamRawInputDriver.h.

Referenced by readNext(), and reconfigure().

art::InputTag daq2raw::TestBeamRawInputDriver::fInputSpillTag
private

Definition at line 156 of file TestBeamRawInputDriver.h.

Referenced by loadBeamlineEvent(), readBeamline(), and reconfigure().

art::InputTag daq2raw::TestBeamRawInputDriver::fInputTDUTag
private

Definition at line 157 of file TestBeamRawInputDriver.h.

Referenced by loadBeamlineEvent(), readBeamline(), and reconfigure().

size_t daq2raw::TestBeamRawInputDriver::fMaxEventSize
private

Will not try to read an event bigger than this.

Definition at line 179 of file TestBeamRawInputDriver.h.

Referenced by reconfigure().

std::string daq2raw::TestBeamRawInputDriver::fMuonStackName
private

Definition at line 163 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

std::string daq2raw::TestBeamRawInputDriver::fOtherDigitName
private

Definition at line 166 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

std::string daq2raw::TestBeamRawInputDriver::fPaddleDigitName
private

Definition at line 164 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

rawfileparser::RawFileParser daq2raw::TestBeamRawInputDriver::fParser
private

Online raw file parsing utility.

Definition at line 178 of file TestBeamRawInputDriver.h.

Referenced by closeCurrentFile(), readFile(), readNext(), and TestBeamRawInputDriver().

art::SourceHelper const& daq2raw::TestBeamRawInputDriver::fSourceHelper
private

Class to help with {Run, SubRun, Event}Principal construction.

Definition at line 175 of file TestBeamRawInputDriver.h.

Referenced by readNext().

std::string daq2raw::TestBeamRawInputDriver::fSourceName
private

Definition at line 168 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

std::string daq2raw::TestBeamRawInputDriver::fToFName
private

Definition at line 160 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

std::string daq2raw::TestBeamRawInputDriver::fTriggerName
private

Definition at line 159 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

std::string daq2raw::TestBeamRawInputDriver::fWCDigitName
private

Definition at line 165 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().

std::string daq2raw::TestBeamRawInputDriver::fWCName
private

Definition at line 161 of file TestBeamRawInputDriver.h.

Referenced by readNext(), reconfigure(), and TestBeamRawInputDriver().


The documentation for this class was generated from the following files: