File indexing completed on 2025-01-18 10:17:18
0001
0002
0003
0004
0005 #include "DecodeDASSource.h"
0006 #include "ADCSample.h"
0007
0008 #include <iostream>
0009 #include <vector>
0010
0011
0012
0013
0014 DecodeDASSource::DecodeDASSource(std::string source_name, JApplication* app) : JEventSource(source_name, app) {
0015 SetCallbackStyle(CallbackStyle::ExpertMode);
0016 }
0017
0018 DecodeDASSource::~DecodeDASSource() {
0019 }
0020
0021 void DecodeDASSource::Open() {
0022
0023
0024 ifs.open(GetResourceName());
0025 if (!ifs) throw JException("Unable to open '%s'", GetResourceName().c_str());
0026
0027 }
0028
0029 void DecodeDASSource::Close() {
0030
0031 std::cout << "Closing " << GetResourceName() << std::endl;
0032 ifs.close();
0033 }
0034
0035 JEventSource::Result DecodeDASSource::Emit(JEvent& event) {
0036
0037 size_t MAX_CHANNELS = 80;
0038 size_t MAX_SAMPLES = 1024;
0039
0040
0041 if (ifs.is_open()) {
0042 if (!ifs.eof()) {
0043
0044
0045 std::vector<ADCSample*> hits;
0046 for (uint16_t sample = 0; sample < MAX_SAMPLES && !ifs.eof(); ++sample) {
0047 for (uint16_t channel = 0; channel < MAX_CHANNELS; ++channel) {
0048 auto hit = new ADCSample;
0049 hit->sample_id = sample;
0050 hit->channel_id = channel;
0051 ifs >> hit->adc_value;
0052 hits.push_back(hit);
0053 }
0054 }
0055
0056 event.Insert(hits);
0057 event.SetEventNumber(current_event_nr++);
0058 return Result::Success;
0059 }
0060
0061 std::cout << "Reached end of file/stream " << GetResourceName() << std::endl;
0062 }
0063 return Result::FailureFinished;
0064
0065 }
0066
0067