HDF5RawInput_source.cc
Go to the documentation of this file.
7 
9  fhicl::ParameterSet const & ps,
11  art::SourceHelper const & sh)
12  : pretend_module_name(ps.get<std::string>("raw_data_label", "daq")),
13  fLogLevel(ps.get<int>("LogLevel", 0)),
14  pmaker(sh) {
17 }
18 
20  std::string const & filename, art::FileBlock*& fb) {
24  MF_LOG_INFO("HDF5")
25  << "HDF5 opened HDF file with run number " <<
26  hdf_file_->runNumber << " and " <<
27  unprocessedEventList_.size() << " events";
28  for (const auto & e : unprocessedEventList_)
29  MF_LOG_INFO("HDF5") << e;
30 
31  fb = new art::FileBlock(art::FileFormatVersion(1, "RawEvent2011"),
32  filename);
33 }
34 
36  art::SubRunPrincipal const* const inSR,
37  art::RunPrincipal*& outR,
38  art::SubRunPrincipal*& outSR,
39  art::EventPrincipal*& outE)
40 {
41  using namespace dune::HDF5Utils;
42 
43  // Establish default 'results'
44  outR = 0;
45  outSR = 0;
46  outE = 0;
47 
48  if (unprocessedEventList_.empty()) {return false;}
49  std::string nextEventGroupName = unprocessedEventList_.front();
50  unprocessedEventList_.pop_front();
51 
52  size_t run_id = 999; //runNumber can be 0,
53  //but this seems like an issue
54  //with art
55 
56  //Accessing run number
57  hid_t the_group = getGroupFromPath (hdf_file_->filePtr, nextEventGroupName);
58  HeaderInfo header_info;
59  std::string det_type = "TriggerRecordHeader";
60 
61  getHeaderInfo(the_group, det_type, header_info);
62  if (fLogLevel > 0) {
63  std::cout << " Magic word: 0x" << std::hex << header_info.magicWord <<
65  std::cout << " Version: " << std::dec << header_info.version <<
67  std::cout << " Trig Num: " << std::dec << header_info.trigNum <<
69  std::cout << " Trig Timestamp: " << std::dec <<
70  header_info.trigTimestamp << std::dec << std::endl;
71  std::cout << " No. of requested components: " << std::dec <<
72  header_info.nReq << std::dec << std::endl;
73  std::cout << " Run Number: " << std::dec << header_info.runNum <<
74  std::endl;
75  std::cout << " Error bits: " << std::dec << header_info.errBits <<
76  std::endl;
77  std::cout << " Trigger type: " << std::dec << header_info.triggerType <<
78  std::endl;
79  }
80  MF_LOG_INFO("HDF5") << "header_info.trigTimestamp :" << header_info.trigTimestamp << std::endl;
81 
82  // trigTimeStamp is NOT time but Clock-tick since the epoch.
83  uint64_t trigTimeStamp = header_info.trigTimestamp;
84 
85  uint64_t getTrigTime = formatTrigTimeStamp (trigTimeStamp);
86  // std::cout << "getTrigTime :" << getTrigTime << std::endl;
87 
88  art::Timestamp artTrigStamp (getTrigTime);
89  // std::cout << "artTrigStamp :" << artTrigStamp.value() << std::endl;
90 
91  run_id = header_info.runNum;
92  std::unique_ptr<raw::RDTimeStamp> rd_timestamp(
93  new raw::RDTimeStamp(header_info.trigTimestamp));
94 
95  // make new run if inR is 0 or if the run has changed
96  if (inR == 0 || inR->run() != run_id) {
97  outR = pmaker.makeRunPrincipal(run_id,artTrigStamp);
98  }
99 
100  // make new subrun if inSR is 0 or if the subrun has changed
101  art::SubRunID subrun_check(run_id, 1);
102  if (inSR == 0 || subrun_check != inSR->subRunID()) {
103  outSR = pmaker.makeSubRunPrincipal(run_id, 1, artTrigStamp);
104  }
105 
106  //Where to get event number?
107  //For now -- parse from input record
108  std::string event_str = nextEventGroupName;
109  std::string trig = "TriggerRecord";
110  auto pos = event_str.begin() + event_str.find(trig);
111  event_str.erase(pos, pos + trig.size());
112  int event = std::stoi(event_str);
113  outE = pmaker.makeEventPrincipal(run_id, 1, event, artTrigStamp);
114  //std::cout << "Event Time Stamp :" << event.time() << std::endl;
115 
116  std::unique_ptr<raw::DUNEHDF5FileInfo> the_info(
117  new raw::DUNEHDF5FileInfo(hdf_file_->fileName, hdf_file_->filePtr,
118  0, nextEventGroupName));
119 
121  "");
123  "trigger");
124 
125  return true;
126 }
127 
128 //typedef for shorthand
129 namespace dune {
131 }
132 
133 
RunNumber_t run() const
Definition: Principal.cc:1070
std::string string
Definition: nybbler.cc:12
bool readNext(art::RunPrincipal const *const inR, art::SubRunPrincipal const *const inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
std::deque< std::string > unprocessedEventList_
Definition: HDF5RawInput.h:49
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
HDF5RawInputDetail(fhicl::ParameterSet const &ps, art::ProductRegistryHelper &rh, art::SourceHelper const &sh)
STL namespace.
art::SourceHelper const & pmaker
Definition: HDF5RawInput.h:52
QTextStream & hex(QTextStream &s)
string filename
Definition: train.py:213
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
Definition: SourceHelper.cc:92
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
std::deque< std::string > getTopLevelGroupNames(HDFFileInfoPtr &hdfFileInfoPtr)
Definition: HDF5Utils.cc:36
const double e
def move(depos, offset)
Definition: depos.py:107
SubRunID subRunID() const
Definition: Principal.cc:1058
static constexpr double ps
Definition: Units.h:99
#define MF_LOG_INFO(category)
std::string pretend_module_name
Definition: HDF5RawInput.h:50
QTextStream & dec(QTextStream &s)
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={})
void getHeaderInfo(hid_t the_group, const std::string &det_type, HeaderInfo &info)
Definition: HDF5Utils.cc:96
uint64_t formatTrigTimeStamp(uint64_t trigTimeStamp)
Definition: HDF5Utils.cc:58
HDFFileInfoPtr openFile(const std::string &fileName)
Definition: HDF5Utils.cc:12
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
#define DEFINE_ART_INPUT_SOURCE(klass)
void readFile(std::string const &filename, art::FileBlock *&fb)
hid_t getGroupFromPath(HDFFileInfoPtr &hdfFileInfoPtr, const std::string &path)
std::unique_ptr< dune::HDF5Utils::HDFFileInfo > hdf_file_
Definition: HDF5RawInput.h:45
QTextStream & endl(QTextStream &s)
Event finding and building.