@@ -74,7 +74,6 @@ class sbndaq::SBNDXARAPUCADecoder : public art::EDProducer {
7474 void produce (art::Event& e) override ;
7575
7676private:
77-
7877 constexpr static uint64_t NANOSEC_IN_SEC = 1'000'000'000 ; /* *< Number of nanoseconds in one second. */
7978 constexpr static uint64_t MICROSEC_IN_NANOSEC = 1'000 ; /* *< Number of nanoseconds in one microsecond. */
8079 constexpr static double NANOSEC_TO_MICROSEC = 1E-3 ; /* *< Conversion factor from nanoseconds to microseconds. */
@@ -91,6 +90,7 @@ class sbndaq::SBNDXARAPUCADecoder : public art::EDProducer {
9190 constexpr static uint16_t PTB_TIMING = 1 ; /* *< Timing reference frame: HLT (High Level Trigger) timestamp from the PTB (Penn Trigger Board). */
9291 constexpr static uint16_t CAEN_ONLY_TIMING = 2 ; /* *< Timing reference frame: CAEN-only. */
9392
93+ constexpr static uint16_t TTT_DEFAULT = 0 ; /* *< Default integer value for the nominal TTT. */
9494 constexpr static uint16_t HLT_NOT_FOUND = 999 ; /* *< Random value to indicate no HL trigger found. */
9595 constexpr static uint16_t HLT_TOO_FAR = 1000 ; /* *< Random value to indicate HL trigger found but too far from the raw timestamp. */
9696
@@ -140,6 +140,7 @@ class sbndaq::SBNDXARAPUCADecoder : public art::EDProducer {
140140 void shift_time (const artdaq::Fragment& fragment, uint64_t TTT_ticks, int64_t TTT_end_ns, uint64_t timestamp, uint32_t num_samples_per_wvfm, double & ini_wvfm_timestamp, double & end_wvfm_timestamp);
141141 void decode_waveforms (const artdaq::Fragment& fragment, std::vector<std::vector<uint16_t >>& wvfms, size_t header_size, uint32_t num_channels, uint32_t num_samples_per_wvfm, uint32_t num_words_per_wvfms, uint32_t num_samples_per_group);
142142
143+ void dump_waveforms (std::vector <raw::OpDetWaveform> & prod_wvfms, const std::vector<std::vector<uint16_t >>& wvfms, std::vector<size_t > & fragment_indices, size_t board_index, uint32_t num_channels, double ini_wvfm_timestamp, double end_wvfm_timestamp);
143144 void save_prod_wvfm (size_t board_idx, size_t ch, double ini_wvfm_timestamp, const std::vector <std::vector <uint16_t > > & wvfms, std::vector <raw::OpDetWaveform> & prod_wvfms);
144145 void save_debug_wvfm (size_t board_idx, size_t fragment_idx, int ch, double ini_wvfm_timestamp, double end_wvfm_timestamp, const std::vector <std::vector <uint16_t > > & wvfms);
145146
@@ -621,7 +622,8 @@ void sbndaq::SBNDXARAPUCADecoder::decode_fragment(uint64_t timestamp, std::vecto
621622 // bool is_nominal_length = false;
622623 // bool is_within_nominal_length = false;
623624 // bool is_first = false;
624-
625+ // int32_t nominal_TTT = TTT_DEFAULT;
626+
625627 // =============== Accesses Event metadata and Event header for this fragment =============== //
626628
627629 CAENV1740Fragment caen_fragment (fragment);
@@ -663,6 +665,8 @@ void sbndaq::SBNDXARAPUCADecoder::decode_fragment(uint64_t timestamp, std::vecto
663665 std::cout << " \t Number of samples per group (this fragment): " << num_samples_per_group << std::endl;
664666 }
665667
668+ std::vector <std::vector <uint16_t > > wvfms (num_channels, std::vector<uint16_t >(num_samples_per_wvfm, 0 ));
669+
666670 // =============== Extracts timing information for this fragment =============== //
667671
668672 uint32_t TTT_ticks = header.triggerTime ();
@@ -673,81 +677,41 @@ void sbndaq::SBNDXARAPUCADecoder::decode_fragment(uint64_t timestamp, std::vecto
673677 std::cout << " \t\t TTT header.triggerTimeRollOver(): " << header.triggerTimeRollOver () << std::endl;
674678 }
675679
676- // // =============== Start decoding the waveforms =============== //
677- std::vector <std::vector <uint16_t > > wvfms (num_channels, std::vector<uint16_t >(num_samples_per_wvfm, 0 ));
680+ // =============== Start decoding the waveforms =============== //
681+ // std::vector <std::vector <uint16_t> > fragment_wvfms (num_channels, std::vector<uint16_t>(num_samples_per_wvfm, 0));
678682 decode_waveforms (fragment, wvfms, header_size, num_channels, num_samples_per_wvfm, num_words_per_wvfms, num_samples_per_group);
679- // if (fverbose) std::cout << " > SBNDXARAPUCADecoder::decode_fragment: binary decoding of the waveforms starting... " << std::endl;
680- //
681- // std::vector <std::vector <uint16_t> > wvfms(num_channels, std::vector<uint16_t>(num_samples_per_wvfm, 0));
682- //
683- // // Absolute sample number [0, TOTAL_NUM_SAMPLES] where TOTAL_NUM_SAMPLES is the total number of samples stored for an event.
684- // uint32_t S = 0;
685- // // Buffer variables.
686- // uint64_t buffer = 0;
687- // uint32_t bits_in_buffer = 0;
688- //
689- // // Data pointer to the beggining of the waveforms stores in the event.
690- // const uint32_t* data_ptr = reinterpret_cast<const uint32_t*>(fragment.dataBeginBytes() + sizeof(CAENV1740EventHeader));
691- // // Accesses each word, stores it in the buffer and then the samples are extracted from the buffer.
692- // for (size_t j = 0; j < num_words_per_wvfms; j++) {
693- // uint64_t word = read_word(data_ptr);
694- //
695- // // Adds the new word to the buffer and increments the number of bits stored in it.
696- // if (fdebug_buffer) std::cout << buffer << "[word: " << word << "]" << std::endl;
697- // buffer |= word << bits_in_buffer;
698- // bits_in_buffer += BITS_PER_WORD; // bytes * 8 bits/byte
699- // if (fdebug_buffer) std::cout << " +" << buffer << " [bits in buffer: "<< bits_in_buffer << "]" << std::endl;
700- //
701- // // Obtains 12-bit sequences from the buffer and assigns each sample to the channel and channel sample it belongs to.
702- // while (bits_in_buffer >= BITS_PER_SAMPLE) {
703- // // Computes board channel, channel sample and group channel and assigns the sample to those indices.
704- // uint32_t g = (S / num_samples_per_group); // Group index.
705- // uint32_t c = ((S / NUM_CONSECUTIVE_SAMPLES) % NUM_CHANNELS_PER_GROUP) + g * NUM_GROUPS; // Channel index.
706- // uint32_t s = (S % NUM_CONSECUTIVE_SAMPLES) + ((S / NUM_SAMPLES_PER_ROUND) * NUM_CONSECUTIVE_SAMPLES) % num_samples_per_wvfm; // Sample/channel index.
707- // uint16_t sample = get_sample(buffer, BITS_PER_SAMPLE - 1, 0);
708- // wvfms[c][s] = sample;
709- // if (fdebug_waveforms) std::cout << "\tSample: " << sample << "\tg: " << g << "\tch: " << c << "\ts:" << s << "\tS: " << S << std::endl;
710- //
711- // // Updates the buffer status removing the read bits and decreasing the number of bits stored in it.
712- // buffer >>= BITS_PER_SAMPLE;
713- // bits_in_buffer -= BITS_PER_SAMPLE;
714- // if (fdebug_buffer) std::cout << " -" << buffer << " [bits in buffer: "<< bits_in_buffer << "]" << std::endl;
715- //
716- // // Increments the absolute sample step.
717- // S++;
718- // }
719- // }
720683
721684 // =============== Shifts timing to the selected timing reference frame =============== //
722685 double ini_wvfm_timestamp = 0 ;
723686 double end_wvfm_timestamp = 0 ;
724687 shift_time (fragment, TTT_ticks, TTT_end_ns, timestamp, num_samples_per_wvfm, ini_wvfm_timestamp, end_wvfm_timestamp);
725688
726- // The decoded waveforms are dumped into two products:
727- // - A xarapucadecoder-art.root file with the OpDetWaveforms as the product of this producer for further analysis.
728- // - A decoder_hist.root file gathering a waveform histograms.
729- if (fverbose) std::cout << " > SBNDXARAPUCADecoder::decode_fragment: binary decoding complete, dumping products..." << std::endl;
730-
731- uint32_t num_debug_wvfms;
732-
733- if (fstore_debug_waveforms == -1 ) {
734- num_debug_wvfms = num_channels;
735- } else {
736- num_debug_wvfms = std::min<size_t >(num_channels, fstore_debug_waveforms);
737- }
738-
739- uint32_t ch;
740-
741- for (ch = 0 ; ch < num_debug_wvfms; ch++) {
742- save_prod_wvfm (board_idx, ch, ini_wvfm_timestamp, wvfms, prod_wvfms);
743- save_debug_wvfm (board_idx, fragment_indices[board_idx], ch, ini_wvfm_timestamp, end_wvfm_timestamp, wvfms);
744- }
745-
746- for (;ch < num_channels; ch++) {
747- save_prod_wvfm (board_idx, ch, ini_wvfm_timestamp, wvfms, prod_wvfms);
748- }
749-
750- fragment_indices[board_idx]++;
689+ dump_waveforms (prod_wvfms, wvfms, fragment_indices, board_idx, num_channels, ini_wvfm_timestamp, end_wvfm_timestamp);
690+ // // The decoded waveforms are dumped into two products:
691+ // // - A xarapucadecoder-art.root file with the OpDetWaveforms as the product of this producer for further analysis.
692+ // // - A decoder_hist.root file gathering a waveform histograms.
693+ // if (fverbose) std::cout << " > SBNDXARAPUCADecoder::decode_fragment: binary decoding complete, dumping products..." << std::endl;
694+ //
695+ // uint32_t num_debug_wvfms;
696+ //
697+ // if (fstore_debug_waveforms == -1) {
698+ // num_debug_wvfms = num_channels;
699+ // } else {
700+ // num_debug_wvfms = std::min<size_t>(num_channels, fstore_debug_waveforms);
701+ // }
702+ //
703+ // uint32_t ch;
704+ //
705+ // for (ch = 0; ch < num_debug_wvfms; ch++) {
706+ // save_prod_wvfm(board_idx, ch, ini_wvfm_timestamp, wvfms, prod_wvfms);
707+ // save_debug_wvfm(board_idx, fragment_indices[board_idx], ch, ini_wvfm_timestamp, end_wvfm_timestamp, wvfms);
708+ // }
709+ //
710+ // for (;ch < num_channels; ch++) {
711+ // save_prod_wvfm(board_idx, ch, ini_wvfm_timestamp, wvfms, prod_wvfms);
712+ // }
713+ //
714+ // fragment_indices[board_idx]++;
751715 }
752716}
753717
@@ -898,8 +862,6 @@ void sbndaq::SBNDXARAPUCADecoder::decode_waveforms(const artdaq::Fragment& fragm
898862 // =============== Start decoding the waveforms =============== //
899863 if (fverbose) std::cout << " > SBNDXARAPUCADecoder::decode_fragment: binary decoding of the waveforms starting... " << std::endl;
900864
901- // std::vector <std::vector <uint16_t> > wvfms(num_channels, std::vector<uint16_t>(num_samples_per_wvfm, 0));
902-
903865 // Absolute sample number [0, TOTAL_NUM_SAMPLES] where TOTAL_NUM_SAMPLES is the total number of samples stored for an event.
904866 uint32_t S = 0 ;
905867 // Buffer variables.
@@ -939,6 +901,35 @@ void sbndaq::SBNDXARAPUCADecoder::decode_waveforms(const artdaq::Fragment& fragm
939901 }
940902}
941903
904+ void sbndaq::SBNDXARAPUCADecoder::dump_waveforms (std::vector <raw::OpDetWaveform> & prod_wvfms, const std::vector<std::vector<uint16_t >>& wvfms, std::vector<size_t > & fragment_indices, size_t board_idx, uint32_t num_channels, double ini_wvfm_timestamp, double end_wvfm_timestamp) {
905+
906+ // The decoded waveforms are dumped into two products:
907+ // - A xarapucadecoder-art.root file with the OpDetWaveforms as the product of this producer for further analysis.
908+ // - A decoder_hist.root file gathering a waveform histograms.
909+ if (fverbose) std::cout << " > SBNDXARAPUCADecoder::decode_fragment: binary decoding complete, dumping products..." << std::endl;
910+
911+ uint32_t num_debug_wvfms;
912+
913+ if (fstore_debug_waveforms == -1 ) {
914+ num_debug_wvfms = num_channels;
915+ } else {
916+ num_debug_wvfms = std::min<size_t >(num_channels, fstore_debug_waveforms);
917+ }
918+
919+ uint32_t ch;
920+
921+ for (ch = 0 ; ch < num_debug_wvfms; ch++) {
922+ save_prod_wvfm (board_idx, ch, ini_wvfm_timestamp, wvfms, prod_wvfms);
923+ save_debug_wvfm (board_idx, fragment_indices[board_idx], ch, ini_wvfm_timestamp, end_wvfm_timestamp, wvfms);
924+ }
925+
926+ for (;ch < num_channels; ch++) {
927+ save_prod_wvfm (board_idx, ch, ini_wvfm_timestamp, wvfms, prod_wvfms);
928+ }
929+
930+ fragment_indices[board_idx]++;
931+ }
932+
942933/* *
943934 * @brief Extract a sample from a 64-bit buffer using the specified bit positions.
944935 *
0 commit comments