18 #include "detdataformats/wib/WIBFrame.hpp" 24 : fForceOpen(p.
get<
bool>(
"ForceOpen", false)),
25 fFileInfoLabel(p.
get<
std::
string>(
"FileInfoLabel",
"daq")),
26 fMaxChan(p.
get<
int>(
"MaxChan",1000000)),
27 fDefaultCrate(p.
get<unsigned
int>(
"DefaultCrate", 3)),
28 fDebugLevel(p.
get<
int>(
"DebugLevel",0))
35 std::vector<raw::RawDigit> &raw_digits,
36 std::vector<raw::RDTimeStamp> &rd_timestamps,
37 std::vector<raw::RDStatus> &rdstatuses) {
43 std::vector<raw::RawDigit> &raw_digits,
44 std::vector<raw::RDTimeStamp> &rd_timestamps,
45 std::vector<raw::RDStatus> &rdstatuses,
46 std::vector<int> &apalist)
50 const std::string & toplevel_groupname = infoHandle->GetEventGroupName();
52 hid_t file_id = infoHandle->GetHDF5FileHandle();
56 std::cout <<
"HDColdboxDataInterface : " <<
"HDF5 FileName: " << file_name <<
std::endl;
57 std::cout <<
"HDColdboxDataInterface :" <<
"Top-Level Group Name: " << toplevel_groupname <<
std::endl;
64 fHDFFile = H5Fopen(file_name.data(), H5F_ACC_RDONLY, H5P_DEFAULT);
76 std::cout <<
"HDColdboxDataInterface : " <<
"Retrieving Data for " << apalist.size() <<
" APAs " <<
std::endl;
82 for (
const int & i : apalist)
87 std::cout <<
"HDColdboxDataInterface :" <<
"apano: " << i <<
std::endl;
94 rdstatuses.emplace_back(
false,
false, 0);
104 std::vector<raw::RawDigit> &raw_digits,
105 std::vector<raw::RDTimeStamp> &rd_timestamps,
106 std::vector<raw::RDStatus> &rdstatuses,
107 std::vector<int> &apalist)
116 int apano,
unsigned int maxchan)
119 using dunedaq::detdataformats::wib::WIBFrame;
120 using dunedaq::detdataformats::wib::WIBHeader;
124 std::deque<std::string> det_types
127 for (
const auto & det : det_types)
129 if (det !=
"TPC")
continue;
132 std::cout <<
"HDColdboxDataInterface :" <<
"Detector type: " << det <<
std::endl;
135 std::deque<std::string> apaNames
140 std::cout <<
"HDColdboxDataInterface :" <<
"Size of apaNames: " << apaNames.size() <<
std::endl;
141 std::cout <<
"HDColdboxDataInterface :" <<
"apaNames[apano]: " << apaNames[apano-1] <<
std::endl;
147 for (
const auto &
t : linkNames)
149 hid_t dataset = H5Dopen(linkGroup,
t.data(), H5P_DEFAULT);
150 hsize_t ds_size = H5Dget_storage_size(dataset);
151 if (ds_size <=
sizeof(FragmentHeader))
continue;
153 std::vector<char> ds_data(ds_size);
154 H5Dread(dataset, H5T_STD_I8LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, ds_data.data());
158 Fragment frag(&ds_data[0], Fragment::BufferAdoptionMode::kReadOnlyMode);
159 size_t n_frames = (ds_size -
sizeof(FragmentHeader))/
sizeof(WIBFrame);
162 std::cout <<
"HDColdboxDataInterface :" <<
"n_frames : " << n_frames <<
std::endl;
164 std::vector<raw::RawDigit::ADCvector_t> adc_vectors(256);
165 unsigned int slot = 0, fiber = 0;
167 for (
size_t i = 0; i < n_frames; ++i)
169 auto frame =
reinterpret_cast<WIBFrame*
>(
static_cast<uint8_t*
>(frag.get_data()) + i*
sizeof(WIBFrame));
172 std::cout <<
"HDColdboxDataInterface :" <<
"frame : " << frame <<
std::endl;
174 for (
size_t j = 0; j < adc_vectors.size(); ++j)
176 adc_vectors[j].push_back(frame->get_channel(j));
181 slot = frame->get_wib_header()->slot_no;
182 fiber = frame->get_wib_header()->fiber_no;
187 std::cout <<
"HDColdboxDataInterface :" <<
"slot, fiber: " << slot <<
", " << fiber <<
std::endl;
189 for (
size_t iChan = 0; iChan < 256; ++iChan)
194 std::cout <<
"HDColdboxDataInterface : " <<
"Channel: " << iChan <<
" N ticks: " << v_adc.size() <<
" Timestamp: " << frag.get_trigger_timestamp() <<
std::endl;
199 unsigned int fiberloc = 0;
211 MF_LOG_WARNING(
"_process_FELIX_AUX:") <<
" Fiber number " << (
int) fiber <<
" is expected to be 1 or 2 -- revisit logic";
215 unsigned int chloc = iChan;
226 std::cout <<
"HDColdboxDataInterface : " <<
"iChan : " << iChan <<
std::endl;
227 std::cout <<
"HDColdboxDataInterface : " <<
"offline_chan : " << offline_chan <<
std::endl;
229 if (offline_chan < 0)
continue;
230 if (offline_chan > maxchan)
continue;
232 timestamps.push_back(rd_ts);
234 float median = 0., sigma = 0.;
238 raw_digits.push_back(rd);
251 size_t asiz = v_adc.size();
260 imed = TMath::Median(asiz,v_adc.data()) + 0.01;
262 sigma = TMath::RMS(asiz,v_adc.data());
268 for (
size_t i = 0; i < asiz; ++i) {
269 if (v_adc.at(i) < imed) s1++;
270 if (v_adc.at(i) == imed) sm++;
273 float mcorr = (-0.5 + (0.5*(
float) asiz - (
float) s1)/ ((
float) sm) );
Collection of charge vs time digitized from a single readout channel.
int retrieveDataForSpecifiedAPAs(art::Event &evt, std::vector< raw::RawDigit > &raw_digits, std::vector< raw::RDTimeStamp > &rd_timestamps, std::vector< raw::RDStatus > &rdstatuses, std::vector< int > &apalist)
Handle< PROD > getHandle(SelectorBase const &) const
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
std::vector< raw::RawDigit > RawDigits
HDColdboxDataInterface(fhicl::ParameterSet const &ps)
unsigned int fDefaultCrate
unsigned int GetOfflineNumberFromDetectorElements(unsigned int crate, unsigned int slot, unsigned int fiber, unsigned int fembchannel, FelixOrRCE frswitch)
void getMedianSigma(const raw::RawDigit::ADCvector_t &v_adc, float &median, float &sigma)
std::vector< raw::RDTimeStamp > RDTimeStamps
std::list< std::string > getMidLevelGroupNames(hid_t grp)
int retrieveData(art::Event &evt, std::string inputlabel, std::vector< raw::RawDigit > &raw_digits, std::vector< raw::RDTimeStamp > &rd_timestamps, std::vector< raw::RDStatus > &rdstatuses)
std::string fFileInfoLabel
void getFragmentsForEvent(hid_t the_group, RawDigits &raw_digits, RDTimeStamps ×tamps, int apano, unsigned int maxchan)
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
auto const & get(AssnsNode< L, R, D > const &r)
#define MF_LOG_WARNING(category)
int retrieveDataAPAListWithLabels(art::Event &evt, std::string inputlabel, std::vector< raw::RawDigit > &raw_digits, std::vector< raw::RDTimeStamp > &rd_timestamps, std::vector< raw::RDStatus > &rdstatuses, std::vector< int > &apalist)
hid_t getGroupFromPath(HDFFileInfoPtr &hdfFileInfoPtr, const std::string &path)
double median(sqlite3 *db, std::string const &table_name, std::string const &column_name)
QTextStream & endl(QTextStream &s)