21 #include "art_root_io/TFileService.h" 75 void unpack14(
const uint32_t *packed, uint16_t *unpacked);
94 for (
size_t ifile=0; ifile<
fInputFiles.size(); ++ifile)
112 bool discard_data =
false;
114 uint32_t framebuf[117];
115 uint16_t databuf[128];
116 uint64_t timestampstart=0;
117 uint64_t timestamp=0;
127 for (
size_t ifile=0; ifile < nfiles; ++ ifile)
136 "Attempt to read off the end of file " <<
fInputFiles.at(ifile);
138 timestamp= framebuf[3];
140 timestamp += framebuf[2];
150 std::vector<std::vector<uint32_t>> fbcache(nfiles);
151 std::vector<uint64_t> tscache;
152 uint64_t latest_timestamp=0;
156 for (
size_t ifile=0; ifile<nfiles; ++ifile)
158 fbcache.at(ifile).resize(117);
164 "Attempt to read off the end of file " <<
fInputFiles.at(ifile);
166 timestamp= fbcache.at(ifile)[3];
168 timestamp += fbcache.at(ifile)[2];
169 tscache.push_back(timestamp);
170 if (timestamp > latest_timestamp)
172 latest_timestamp = timestamp;
178 for (
size_t ifile=0; ifile<nfiles; ++ifile)
180 while (tscache.at(ifile) + 16 < latest_timestamp)
187 "Attempt to read off the end of file " <<
fInputFiles.at(ifile);
189 timestamp= fbcache.at(ifile)[3];
191 timestamp += fbcache.at(ifile)[2];
192 tscache.at(ifile) = timestamp;
196 for (
size_t ifile=0; ifile < nfiles; ++ ifile)
201 std::vector<raw::RawDigit::ADCvector_t> adcvv(256);
202 for (
size_t itick=0; itick<
fNSamples; ++itick)
206 for (
size_t i=0; i<117; ++i)
208 framebuf[i] = fbcache.at(ifile).at(i);
218 "Attempt to read off the end of file " <<
fInputFiles.at(ifile);
221 int curslot = (framebuf[0] & 0x7000) >> 12;
222 int curfiber = (framebuf[0] & 0x8000) >> 15;
228 "Slot mismatch in file: " << curslot <<
" " << slot;
230 if (curfiber != fiber)
233 "Fiber mismatch in file: " << curfiber <<
" " << fiber;
242 uint64_t timestamp= framebuf[3];
244 timestamp += framebuf[2];
249 timestampstart = timestamp;
255 for (
size_t ichan=0; ichan<128; ++ichan)
257 adcvv.at(ichan).push_back(databuf[ichan]);
259 unpack14(&(framebuf[4+56]),databuf);
260 for (
size_t ichan=0; ichan<128; ++ichan)
262 adcvv.at(ichan+128).push_back(databuf[ichan]);
266 for (
size_t ichan=0; ichan<256; ++ichan)
274 unsigned int fiberloc = 0;
284 unsigned int chloc = ichan;
296 auto slotloc2 = slot;
297 auto fiberloc2 = fiberloc;
299 if (slot == 0 && fiberloc == 4)
304 if (slot == 1 && fiberloc == 4)
309 if (slot == 1 && fiberloc == 3)
314 if (slot == 0 && fiberloc == 3)
322 if ( slotloc2 == 1 && fiberloc2 == 1 )
327 if ( slotloc2 == 2 && fiberloc2 == 1 )
343 raw::RawDigit raw_digit(offlineChannel, uncompressed_nticks, adcvv.at(ichan), cflag);
345 raw_digits.push_back(raw_digit);
348 rd_timestamps.push_back(rdtimestamp);
351 auto const rawdigitptr = rdpm(raw_digits.size()-1);
352 auto const rdtimestampptr = tspm(rd_timestamps.size()-1);
353 rd_ts_assocs.
addSingle(rawdigitptr,rdtimestampptr);
364 statuses.emplace_back(
true,
false,1);
373 unsigned int statword=0;
374 statuses.emplace_back(
false,
false,statword);
388 size_t asiz = v_adc.size();
399 median = TMath::Median(asiz,v_adc.data());
400 sigma = TMath::RMS(asiz,v_adc.data());
407 for (
size_t i = 0; i < 128; i++) {
408 const size_t low_bit = i*14;
409 const size_t low_word = low_bit / 32;
410 const size_t high_bit = (i+1)*14-1;
411 const size_t high_word = high_bit / 32;
414 if (low_word == high_word) {
415 unpacked[i] = (packed[low_word] >> (low_bit%32)) & 0x3FFF;
417 size_t high_off = high_word*32-low_bit;
419 unpacked[i] = (packed[low_word] >> (low_bit%32)) & (0x3FFF >> (14-high_off));
420 unpacked[i] |= (packed[high_word] << high_off) & ((0x3FFF << high_off) & 0x3FFF);
std::vector< raw::RDStatus > RDStatuses
enum raw::_compress Compress_t
Collection of charge vs time digitized from a single readout channel.
art::PtrMaker< raw::RawDigit > RDPmkr
EDProducer(fhicl::ParameterSet const &pset)
void unpack14(const uint32_t *packed, uint16_t *unpacked)
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
std::vector< raw::RDTimeStamp > RDTimeStamps
std::vector< raw::RawDigit > RawDigits
art::PtrMaker< raw::RDTimeStamp > TSPmkr
void produce(art::Event &e) override
unsigned int GetOfflineNumberFromDetectorElements(unsigned int crate, unsigned int slot, unsigned int fiber, unsigned int fembchannel, FelixOrRCE frswitch)
#define DEFINE_ART_MODULE(klass)
T get(std::string const &key) const
art::Assns< raw::RawDigit, raw::RDTimeStamp > RDTsAssocs
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
IcebergFELIXBufferDecoderMarch2021(fhicl::ParameterSet const &p)
void computeMedianSigma(raw::RawDigit::ADCvector_t &v_adc, float &median, float &sigma)
std::vector< FILE * > fInputFilePointers
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
std::vector< std::string > fInputFiles
ULong64_t fDesiredStartTimestamp
cet::coded_exception< error, detail::translate > exception
double median(sqlite3 *db, std::string const &table_name, std::string const &column_name)
IcebergFELIXBufferDecoderMarch2021 & operator=(IcebergFELIXBufferDecoderMarch2021 const &)=delete