23 for (
size_t ifile=0; ifile<
fInputFiles.size(); ++ifile)
35 std::vector<raw::RawDigit> &raw_digits,
36 std::vector<raw::RDTimeStamp> &rd_timestamps,
37 std::vector<raw::RDStatus> &rdstatuses)
42 uint32_t framebuf[117];
43 uint16_t databuf[128];
44 uint64_t timestampstart=0;
48 rd_timestamps.clear();
59 for (
size_t ifile=0; ifile < nfiles; ++ ifile)
68 for (
size_t jfile = 0; jfile < nfiles; ++jfile)
75 timestamp= framebuf[3];
77 timestamp += framebuf[2];
86 std::vector<std::vector<uint32_t>> fbcache(nfiles);
87 std::vector<uint64_t> tscache;
88 uint64_t latest_timestamp=0;
92 for (
size_t ifile=0; ifile<nfiles; ++ifile)
94 fbcache.at(ifile).resize(117);
100 for (
size_t jfile = 0; jfile < nfiles; ++jfile)
107 timestamp= fbcache.at(ifile)[3];
109 timestamp += fbcache.at(ifile)[2];
110 tscache.push_back(timestamp);
111 if (timestamp > latest_timestamp)
113 latest_timestamp = timestamp;
119 for (
size_t ifile=0; ifile<nfiles; ++ifile)
121 while (tscache.at(ifile) + 16 < latest_timestamp)
128 for (
size_t jfile = 0; jfile < nfiles; ++jfile)
135 timestamp= fbcache.at(ifile)[3];
137 timestamp += fbcache.at(ifile)[2];
138 tscache.at(ifile) = timestamp;
144 for (
size_t ifile=0; ifile < nfiles; ++ ifile)
150 std::vector<raw::RawDigit::ADCvector_t> adcvv(256);
151 for (
size_t itick=0; itick<
fNSamples; ++itick)
155 for (
size_t i=0; i<117; ++i)
157 framebuf[i] = fbcache.at(ifile).at(i);
166 for (
size_t jfile = 0; jfile < nfiles; ++jfile)
175 int curslot = (framebuf[0] & 0x7000) >> 12;
176 int curfiber = (framebuf[0] & 0x8000) >> 15;
182 "Slot mismatch in file: " << curslot <<
" " << slot;
184 if (curfiber != fiber)
187 "Fiber mismatch in file: " << curfiber <<
" " << fiber;
196 timestamp= framebuf[3];
198 timestamp += framebuf[2];
203 timestampstart = timestamp;
209 for (
size_t ichan=0; ichan<128; ++ichan)
211 adcvv.at(ichan).push_back(databuf[ichan]);
213 unpack14(&(framebuf[4+56]),databuf);
214 for (
size_t ichan=0; ichan<128; ++ichan)
216 adcvv.at(ichan+128).push_back(databuf[ichan]);
220 for (
size_t ichan=0; ichan<256; ++ichan)
228 unsigned int fiberloc = 0;
238 unsigned int chloc = ichan;
250 auto slotloc2 = slot;
251 auto fiberloc2 = fiberloc;
253 if (slot == 0 && fiberloc == 4)
258 if (slot == 1 && fiberloc == 4)
263 if (slot == 1 && fiberloc == 3)
268 if (slot == 0 && fiberloc == 3)
276 if ( slotloc2 == 1 && fiberloc2 == 1 )
281 if ( slotloc2 == 2 && fiberloc2 == 1 )
289 size_t uncompressed_nticks = adcvv.at(0).size();
297 raw::RawDigit raw_digit(offlineChannel, uncompressed_nticks, adcvv.at(ichan), cflag);
299 raw_digits.push_back(raw_digit);
302 rd_timestamps.push_back(rdtimestamp);
307 unsigned int statword = 0;
308 rdstatuses.emplace_back(
false,
false,statword);
316 std::vector<raw::RawDigit> &raw_digits,
317 std::vector<raw::RDTimeStamp> &rd_timestamps,
318 std::vector<raw::RDStatus> &rdstatuses,
319 std::vector<int> &apalist)
322 return retrieveData(evt,
" ",raw_digits,rd_timestamps,rdstatuses);
330 std::vector<raw::RawDigit> &raw_digits,
331 std::vector<raw::RDTimeStamp> &rd_timestamps,
332 std::vector<raw::RDStatus> &rdstatuses,
333 std::vector<int> &apalist)
335 return retrieveData(evt,inputLabel,raw_digits,rd_timestamps,rdstatuses);
345 size_t asiz = v_adc.size();
356 imed = TMath::Median(asiz,v_adc.data()) + 0.01;
358 sigma = TMath::RMS(asiz,v_adc.data());
364 for (
size_t i=0; i<asiz; ++i)
366 if (v_adc[i] < imed) s1++;
367 if (v_adc[i] == imed) sm++;
371 float mcorr = (-0.5 + (0.5*(
float) asiz - (
float) s1)/ ((
float) sm) );
379 for (
size_t i = 0; i < 128; i++) {
380 const size_t low_bit = i*14;
381 const size_t low_word = low_bit / 32;
382 const size_t high_bit = (i+1)*14-1;
383 const size_t high_word = high_bit / 32;
386 if (low_word == high_word) {
387 unpacked[i] = (packed[low_word] >> (low_bit%32)) & 0x3FFF;
389 size_t high_off = high_word*32-low_bit;
391 unpacked[i] = (packed[low_word] >> (low_bit%32)) & (0x3FFF >> (14-high_off));
392 unpacked[i] |= (packed[high_word] << high_off) & ((0x3FFF << high_off) & 0x3FFF);
enum raw::_compress Compress_t
Collection of charge vs time digitized from a single readout channel.
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::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
ULong64_t fDesiredStartTimestamp
IcebergDataInterfaceFELIXBufferMarch2021(fhicl::ParameterSet const &ps)
std::vector< std::string > fInputFiles
unsigned int GetOfflineNumberFromDetectorElements(unsigned int crate, unsigned int slot, unsigned int fiber, unsigned int fembchannel, FelixOrRCE frswitch)
T get(std::string const &key) const
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)
std::vector< FILE * > fInputFilePointers
void unpack14(const uint32_t *packed, uint16_t *unpacked)
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
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)
void computeMedianSigma(raw::RawDigit::ADCvector_t &v_adc, float &median, float &sigma)
cet::coded_exception< error, detail::translate > exception
double median(sqlite3 *db, std::string const &table_name, std::string const &column_name)