Functions
VDColdboxDataInterface_tool.cc File Reference
#include "VDColdboxDataInterface.h"
#include <hdf5.h>
#include <iostream>
#include <list>
#include <set>
#include <sstream>
#include <cstring>
#include <string>
#include "TMath.h"
#include "TString.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "dunecore/DuneObj/DUNEHDF5FileInfo.h"
#include "dunecore/HDF5Utils/HDF5Utils.h"
#include "detdataformats/wib/WIBFrame.hpp"
#include "duneprototypes/Coldbox/vd/ChannelMap/VDColdboxChannelMapService.h"

Go to the source code of this file.

Functions

void readFragmentsForEvent (art::Event &evt)
 

Function Documentation

void readFragmentsForEvent ( art::Event evt)

Definition at line 25 of file VDColdboxDataInterface_tool.cc.

26 {
27 
28  using namespace dune::HDF5Utils;
29  auto infoHandle = evt.getHandle <raw::DUNEHDF5FileInfo> ("daq");
30  std::cout << "Got infos? " << infoHandle << std::endl;
31 
32  const std::string & toplevel_groupname = infoHandle->GetEventGroupName();
33  const std::string & file_name = infoHandle->GetFileName();
34  hid_t file_id = infoHandle->GetHDF5FileHandle();
35 
36  std::cout << "Top-Level Group Name: " << toplevel_groupname << std::endl;
37  std::cout << "HDF5 FileName: " << file_name << std::endl;
38 
39  // now look inside those "Top-Level Group Name" for "Detector type".
40  hid_t requestedGroup = getGroupFromPath(file_id, toplevel_groupname);
41 
42  std::deque<std::string> detectorTypeNames = getMidLevelGroupNames(requestedGroup);
43 
44  for (auto& detectorTypeName : detectorTypeNames)
45  {
46  if (detectorTypeName == "TPC" && detectorTypeName != "TriggerRecordHeader")
47  {
48  std::cout << " Detector type: " << detectorTypeName << std::endl;
49  std::string geoPath = toplevel_groupname + "/" + detectorTypeName;
50  hid_t geoGroup = getGroupFromPath(file_id,geoPath);
51  std::deque<std::string> apaNames = getMidLevelGroupNames(geoGroup);
52 
53  // loop over APAs
54  for (auto& apaName : apaNames)
55  {
56  std::string apaGroupPath = geoPath + "/" + apaName;
57  std::cout << " Geo path: " << apaGroupPath << std::endl;
58  hid_t linkGroup = getGroupFromPath(file_id,apaGroupPath);
59  std::deque<std::string> linkNames = getMidLevelGroupNames(linkGroup);
60 
61  // loop over Links
62  for (auto& linkName : linkNames)
63  {
64  std::string dataSetPath = apaGroupPath + "/" + linkName;
65  std::cout << " Data Set Path: " << dataSetPath << std::endl;
66  hid_t datasetid = H5Dopen(linkGroup,linkName.data(),H5P_DEFAULT);
67  hsize_t ds_size = H5Dget_storage_size(datasetid);
68  std::cout << " Data Set Size (bytes): " << ds_size << std::endl;
69 
70  if (ds_size < 80) continue;
71 
72  size_t narray = ds_size / sizeof(char);
73  size_t rdr = ds_size % sizeof(char);
74  if (rdr > 0 || narray == 0) narray++;
75  char *ds_data = new char[narray];
76  herr_t ecode = H5Dread(datasetid, H5T_STD_I8LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, ds_data);
77  int firstbyte = ds_data[0];
78  firstbyte &= 0xFF;
79  int lastbyte = ds_data[narray-1];
80  lastbyte &= 0xFF;
81 
82  std::cout << std::hex << " Retrieved data: ecode: " << ecode << " first byte: " << firstbyte
83  << " last byte: " << lastbyte << std::dec << std::endl;
84 
85 
86  int magic_word = 0;
87  memcpy(&magic_word,&ds_data[0],4);
88  std::cout << " Magic word: 0x" << std::hex << magic_word << std::dec << std::endl;
89 
90  int version = 0;
91  memcpy(&version, &ds_data[4],4);
92  std::cout << " Version: " << std::dec << version << std::dec << std::endl;
93 
94  uint64_t fragsize=0;
95  memcpy(&fragsize, &ds_data[8],8);
96  std::cout << " Frag Size: " << std::dec << fragsize << std::dec << std::endl;
97 
98  uint64_t trignum=0;
99  memcpy(&trignum, &ds_data[16],8);
100  std::cout << " Trig Num: " << std::dec << trignum << std::dec << std::endl;
101 
102  uint64_t trig_timestamp=0;
103  memcpy(&trig_timestamp, &ds_data[24],8);
104  std::cout << " Trig Timestamp: " << std::dec << trig_timestamp << std::dec << std::endl;
105 
106  uint64_t windowbeg=0;
107  memcpy(&windowbeg, &ds_data[32],8);
108  std::cout << " Window Begin: " << std::dec << windowbeg << std::dec << std::endl;
109 
110  uint64_t windowend=0;
111  memcpy(&windowend, &ds_data[40],8);
112  std::cout << " Window End: " << std::dec << windowend << std::dec << std::endl;
113 
114  int runno=0;
115  memcpy(&runno, &ds_data[48], 4);
116  std::cout << " Run Number: " << std::dec << runno << std::endl;
117 
118  int errbits=0;
119  memcpy(&errbits, &ds_data[52], 4);
120  std::cout << " Error bits: " << std::dec << errbits << std::endl;
121 
122  int fragtype=0;
123  memcpy(&fragtype, &ds_data[56], 4);
124  std::cout << " Fragment type: " << std::dec << fragtype << std::endl;
125 
126  int fragpadding=0;
127  memcpy(&fragtype, &ds_data[60], 4);
128  std::cout << " Fragment padding: " << std::dec << fragpadding << std::endl;
129 
130  int geoidversion=0;
131  memcpy(&geoidversion, &ds_data[64], 4);
132  std::cout << " GeoID version: " << std::dec << geoidversion << std::endl;
133 
134  unsigned short geoidtype;
135  memcpy(&geoidtype, &ds_data[70], 1);
136  std::cout << " GeoID type: " << geoidtype << std::endl;
137 
138  unsigned short geoidregion=0;
139  memcpy(&geoidregion, &ds_data[71], 1);
140  std::cout << " GeoID region: " << std::dec << geoidregion << std::endl;
141 
142  int geoidelement=0;
143  memcpy(&geoidelement, &ds_data[72], 4);
144  std::cout << " GeoID element: " << std::dec << geoidelement << std::endl;
145 
146  int geoidpadding=0;
147  memcpy(&geoidpadding, &ds_data[76], 4);
148  std::cout << " GeoID padding: " << std::dec << geoidpadding << std::endl;
149 
150  delete[] ds_data; // free up memory
151 
152  }
153  }
154  }
155  }
156 
157 }
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
std::deque< std::string > getMidLevelGroupNames(hid_t grp)
Definition: HDF5Utils.cc:43
QTextStream & hex(QTextStream &s)
QCString file_name
QTextStream & dec(QTextStream &s)
hid_t getGroupFromPath(hid_t fd, const std::string &path)
Definition: HDF5Utils.cc:91
QTextStream & endl(QTextStream &s)