Public Member Functions | Public Attributes | List of all members
dune::PdspHDFFileReader Struct Reference

The PdspHDFFileReader is a class which implements the methods needed by art::Source. More...

#include <PdspHDFFileReader.hh>

Public Member Functions

 PdspHDFFileReader (PdspHDFFileReader const &)=delete
 Copy Constructor is deleted. More...
 
PdspHDFFileReaderoperator= (PdspHDFFileReader const &)=delete
 Copy Assignment operator is deleted. More...
 
 PdspHDFFileReader (fhicl::ParameterSet const &ps, art::ProductRegistryHelper &help, art::SourceHelper const &pm)
 PdspHDFFileReader Constructor. More...
 
virtual ~PdspHDFFileReader ()
 PdspHDFFileReader destructor. More...
 
void closeCurrentFile ()
 Emulate closing a file. No-Op. More...
 
void readFile (std::string const &, art::FileBlock *&fb)
 Emulate opening a file. More...
 
bool readNext (art::RunPrincipal *const &inR, art::SubRunPrincipal *const &inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
 Dequeue a RawEvent and declare its Fragment contents to art, creating Run, SubRun, and EventPrincipal objects as necessary. More...
 

Public Attributes

art::SourceHelper const & pmaker
 An art::SourceHelper instance. More...
 
std::string pretend_module_name
 The module name to store data under. More...
 
size_t bytesRead
 running total of number of bytes received More...
 
unsigned readNext_calls_
 The number of times readNext has been called. More...
 
std::unique_ptr< dune::HDFFileReader::HDFFileInfohdf_file_
 
std::list< std::stringunprocessedEventList_
 

Detailed Description

The PdspHDFFileReader is a class which implements the methods needed by art::Source.

Definition at line 35 of file PdspHDFFileReader.hh.

Constructor & Destructor Documentation

dune::PdspHDFFileReader::PdspHDFFileReader ( PdspHDFFileReader const &  )
delete

Copy Constructor is deleted.

dune::PdspHDFFileReader::PdspHDFFileReader ( fhicl::ParameterSet const &  ps,
art::ProductRegistryHelper help,
art::SourceHelper const &  pm 
)
inline

PdspHDFFileReader Constructor.

Parameters
psParameterSet used for configuring PdspHDFFileReader
helpart::ProductRegistryHelper which is used to inform art about different Fragment types
pmart::SourceHelper used to initalize the SourceHelper member
* PdspHDFFileReader accepts the following Parameters:
* "raw_data_label" (Default: "daq"): The label to use for all raw data
* "shared_memory_key" (Default: 0xBEE7): The key for the shared memory segment
* 

Definition at line 68 of file PdspHDFFileReader.hh.

71  : pmaker(pm)
72  , pretend_module_name(ps.get<std::string>("raw_data_label", "daq"))
73  , bytesRead(0)
74  , readNext_calls_(0)
75  {
76  TLOG_INFO("PdspHDFFileReader") << "PdspHDFFileReader initializing with ParameterSet: " << ps.to_string();
77 
78  std::set<std::string> instance_names = {"FELIX", "PHOTON"};
79  for (const auto& set_iter : instance_names)
80  {
82  }
85 
86  TLOG_INFO("PdspHDFFileReader") << "PdspHDFFileReader opened HDF file with run number " << hdf_file_->runNumber
87  << " and " << unprocessedEventList_.size() << " events";
88  }
HDFFileInfoPtr openFile(const std::string &fileName)
std::string string
Definition: nybbler.cc:12
std::string pretend_module_name
The module name to store data under.
std::list< std::string > getTopLevelGroupNames(HDFFileInfoPtr &hdfFileInfoPtr)
art::SourceHelper const & pmaker
An art::SourceHelper instance.
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
std::list< std::string > unprocessedEventList_
size_t bytesRead
running total of number of bytes received
static constexpr double ps
Definition: Units.h:99
std::unique_ptr< dune::HDFFileReader::HDFFileInfo > hdf_file_
unsigned readNext_calls_
The number of times readNext has been called.
std::vector< Fragment > Fragments
Definition: HDF5Utils.h:57
virtual dune::PdspHDFFileReader::~PdspHDFFileReader ( )
inlinevirtual

PdspHDFFileReader destructor.

Definition at line 93 of file PdspHDFFileReader.hh.

94  {
96  }
def move(depos, offset)
Definition: depos.py:107
std::unique_ptr< dune::HDFFileReader::HDFFileInfo > hdf_file_
void closeFile(HDFFileInfoPtr hdfFileInfoPtr)

Member Function Documentation

void dune::PdspHDFFileReader::closeCurrentFile ( )
inline

Emulate closing a file. No-Op.

Definition at line 101 of file PdspHDFFileReader.hh.

101 {}
PdspHDFFileReader& dune::PdspHDFFileReader::operator= ( PdspHDFFileReader const &  )
delete

Copy Assignment operator is deleted.

Returns
PdspHDFFileReader copy
void dune::PdspHDFFileReader::readFile ( std::string const &  ,
art::FileBlock *&  fb 
)
inline

Emulate opening a file.

Parameters
[out]fbart::FileBlock object

Definition at line 107 of file PdspHDFFileReader.hh.

108  {
109  TLOG_ARB(5, "PdspHDFFileReader") << "readFile enter/start";
110  fb = new art::FileBlock(art::FileFormatVersion(1, "RawEvent2011"), "nothing");
111  }
bool dune::PdspHDFFileReader::readNext ( art::RunPrincipal *const &  inR,
art::SubRunPrincipal *const &  inSR,
art::RunPrincipal *&  outR,
art::SubRunPrincipal *&  outSR,
art::EventPrincipal *&  outE 
)
inline

Dequeue a RawEvent and declare its Fragment contents to art, creating Run, SubRun, and EventPrincipal objects as necessary.

Parameters
[in]inRInput art::RunPrincipal
[in]inSRInput art::SubRunPrincipal
[out]outROutput art::RunPrincipal
[out]outSROutput art::SubRunPrincipal
[out]outEOutput art::EventPrincipal
Returns
Whether an event was returned

Definition at line 123 of file PdspHDFFileReader.hh.

125  {
126  TLOG_DEBUG("PdspHDFFileReader") << "readNext BEGIN";
127  ++readNext_calls_;
128 
129  // Establish default 'results'
130  outR = 0;
131  outSR = 0;
132  outE = 0;
133 
134  if (unprocessedEventList_.empty()) {return false;}
135 
136  std::string nextEventGroupName = unprocessedEventList_.front();
137  unprocessedEventList_.pop_front();
138 
140 
143 
144  if (fragmentMap.size() == 0)
145  {
146  TLOG_ERROR("PdspHDFFileReader") << "No data received, either because of a problem or end of file. Returning false (should exit art)";
147  return false;
148  }
149 
150  artdaq::detail::RawEventHeader evtHeader(hdf_file_->runNumber, 1, readNext_calls_, readNext_calls_, 0);
151 
152  for (auto& subDetName_fragmentList_pair : fragmentMap)
153  {
154  for (auto& frag : *subDetName_fragmentList_pair.second)
155  {
156  TLOG_DEBUG("PdspHDFFileReader") << subDetName_fragmentList_pair.first << " Fragment, " << " type "
157  << ((int) frag.type()) << ", timestamp " << frag.timestamp()
158  << ", sequence_id " << frag.sequenceID()
159  << " fragment_id " << frag.fragmentID();
160  evtHeader.event_id = frag.sequenceID();
161  evtHeader.sequence_id = frag.sequenceID();
162  evtHeader.timestamp = frag.timestamp();
163  }
164  }
165 
166  art::Timestamp currentTime = 0;
167  timespec hi_res_time;
168  int retcode = clock_gettime(CLOCK_REALTIME, &hi_res_time);
169  TLOG_ARB(15, "PdspHDFFileReader") << "hi_res_time tv_sec = " << hi_res_time.tv_sec
170  << " tv_nsec = " << hi_res_time.tv_nsec << " (retcode = " << retcode << ")";
171  if (retcode == 0)
172  {
173  currentTime = ((hi_res_time.tv_sec & 0xffffffff) << 32) | (hi_res_time.tv_nsec & 0xffffffff);
174  }
175  else
176  {
177  TLOG_ERROR("PdspHDFFileReader")
178  << "Unable to fetch a high-resolution time with clock_gettime for art::Event Timestamp. "
179  << "The art::Event Timestamp will be zero for event " << evtHeader.event_id;
180  }
181 
182  // make new run if inR is 0 or if the run has changed
183  if (inR == 0 || inR->run() != evtHeader.run_id)
184  {
185  outR = pmaker.makeRunPrincipal(evtHeader.run_id, currentTime);
186  }
187 
188  // make new subrun if inSR is 0 or if the subrun has changed
189  art::SubRunID subrun_check(evtHeader.run_id, evtHeader.subrun_id);
190  if (inSR == 0 || subrun_check != inSR->subRunID())
191  {
192  outSR = pmaker.makeSubRunPrincipal(evtHeader.run_id, evtHeader.subrun_id, currentTime);
193  }
194 
195  outE = pmaker.makeEventPrincipal(evtHeader.run_id, evtHeader.subrun_id, evtHeader.event_id, currentTime);
196 
197  for (auto& subDetName_fragmentList_pair : fragmentMap)
198  {
199  put_product_in_principal(std::move(subDetName_fragmentList_pair.second), *outE, pretend_module_name,
200  subDetName_fragmentList_pair.first);
201  }
202 
203 
204 #if 0
205  else
206  {
207  TLOG_TRACE("PdspHDFFileReader") << "EventHeader has Run " << evtHeader.run_id << ", SubRun " << evtHeader.subrun_id << ", Event " << evtHeader.event_id << ", SeqID " << evtHeader.sequence_id << ", IsComplete " << evtHeader.is_complete;
208  }
209 
210 
211  for (auto& fragmentTypePair : eventMap)
212  {
213  auto type_code = fragmentTypePair.first;
214  TLOG_TRACE("PdspHDFFileReader") << "Before GetFragmentsByType call, type is " << (int)type_code;
215  TLOG_TRACE("PdspHDFFileReader") << "After GetFragmentsByType call, number of fragments is " << fragmentTypePair.second->size();
216 
217  std::unordered_map<std::string, std::unique_ptr<artdaq::Fragments>> derived_fragments;
218  for (auto& frag : *fragmentTypePair.second)
219  {
220  bytesRead += frag.sizeBytes();
221 
222  // std::pair<bool, std::string> instance_name_result = translator->GetInstanceNameForFragment(frag);
223  std::string label = instance_name_result.second;
224  if (!instance_name_result.first)
225  {
226  TLOG_WARNING("PdspHDFFileReader")
227  << "UnknownFragmentType: The product instance name mapping for fragment type \"" << ((int)type_code)
228  << "\" is not known. Fragments of this "
229  << "type will be stored in the event with an instance name of \"" << label << "\".";
230  }
231  if (!derived_fragments.count(label))
232  {
233  derived_fragments[label] = std::make_unique<Fragments>();
234  }
235  auto fragSize = frag.size();
236  TLOG_TRACE("PdspHDFFileReader") << "Moving Fragment with size " << fragSize << " from type map (type=" << type_code << ") to derived map label=" << label;
237  derived_fragments[label]->emplace_back(std::move(frag));
238  }
239  TLOG_TRACE("PdspHDFFileReader") << "Placing derived fragments in outE";
240  for (auto& type : derived_fragments)
241  {
243  }
244  }
245 #endif
246  TLOG_TRACE("PdspHDFFileReader") << "After putting fragments in event";
247  TLOG_ARB(10, "PdspHDFFileReader") << "readNext: bytesRead=" << bytesRead;;
248 
249  TLOG_TRACE("PdspHDFFileReader") << "Returning from readNext";
250  return true;
251  }
HDFFileInfoPtr reopenFile(HDFFileInfoPtr oldHdfFileInfoPtr)
RunNumber_t run() const
Definition: Principal.cc:1070
std::string string
Definition: nybbler.cc:12
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
std::string pretend_module_name
The module name to store data under.
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
Definition: SourceHelper.cc:92
art::SourceHelper const & pmaker
An art::SourceHelper instance.
def move(depos, offset)
Definition: depos.py:107
SubRunID subRunID() const
Definition: Principal.cc:1058
std::list< std::string > unprocessedEventList_
size_t bytesRead
running total of number of bytes received
FragmentListsByType getFragmentsForEvent(HDFFileInfoPtr &hdfFileInfoPtr, const std::string &topLevelGroupName)
std::unique_ptr< dune::HDFFileReader::HDFFileInfo > hdf_file_
std::enable_if_t<!detail::range_sets_supported(P::branch_type)> put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
std::map< std::string, std::unique_ptr< artdaq::Fragments > > FragmentListsByType
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
unsigned readNext_calls_
The number of times readNext has been called.

Member Data Documentation

size_t dune::PdspHDFFileReader::bytesRead

running total of number of bytes received

Definition at line 50 of file PdspHDFFileReader.hh.

std::unique_ptr<dune::HDFFileReader::HDFFileInfo> dune::PdspHDFFileReader::hdf_file_

Definition at line 53 of file PdspHDFFileReader.hh.

art::SourceHelper const& dune::PdspHDFFileReader::pmaker

An art::SourceHelper instance.

Definition at line 48 of file PdspHDFFileReader.hh.

std::string dune::PdspHDFFileReader::pretend_module_name

The module name to store data under.

Definition at line 49 of file PdspHDFFileReader.hh.

unsigned dune::PdspHDFFileReader::readNext_calls_

The number of times readNext has been called.

Definition at line 51 of file PdspHDFFileReader.hh.

std::list<std::string> dune::PdspHDFFileReader::unprocessedEventList_

Definition at line 54 of file PdspHDFFileReader.hh.


The documentation for this struct was generated from the following file: