File indexing completed on 2025-01-18 10:17:19
0001
0002
0003
0004
0005 #include "RootProcessor.h"
0006 #include "ADCSample.h"
0007
0008
0009
0010
0011 RootProcessor::RootProcessor() = default;
0012
0013
0014
0015
0016 RootProcessor::~RootProcessor() {
0017
0018 outFile->Close();
0019 }
0020
0021
0022
0023
0024 void RootProcessor::Init() {
0025
0026
0027
0028 outFileName = new TString("outFile.root");
0029 outFile = new TFile(*outFileName, "RECREATE");
0030 outFile->cd();
0031 std::cout << "RootProcessor::Init -> Output ROOT file " << *outFileName << " created" << std::endl;
0032
0033 eventTree = new TTree("ET", "Streaming Detector Event Data Tree");
0034 sampleTree = new TTree("ST", "Streaming Detector Sample Data Tree");
0035 nentries = 0;
0036 eventTree->Branch("event", &event);
0037
0038 adc_samples_chans = new TBranch* [numChans];
0039 tdc_samples_chans = new TBranch* [numChans];
0040
0041 for (uint ichan = 0; ichan < numChans; ichan++) {
0042 adc_samples_chans[ichan] = sampleTree->Branch(Form("adcSamplesChan_%d", ichan + 1), &adcSample);
0043 tdc_samples_chans[ichan] = sampleTree->Branch(Form("tdcSamplesChan_%d", ichan + 1), &tdcSample);
0044 }
0045
0046 outFile->Write();
0047 outFile->Flush();
0048 outFile->cd();
0049 }
0050
0051
0052
0053
0054 void RootProcessor::Process(const std::shared_ptr<const JEvent>& aEvent) {
0055
0056
0057 auto eventData = aEvent->Get<ADCSample>();
0058
0059 lock_guard<mutex> lck(fillMutex);
0060
0061 for (auto sample : eventData) {
0062
0063
0064
0065 chan = sample->channel_id + 1;
0066 event = static_cast <uint> (aEvent->GetEventNumber());
0067 adcSample = sample->adc_value;
0068 tdcSample = (sample->sample_id + 1) + numSamples*(event - 1);
0069 adc_samples_chans[chan-1]->Fill();
0070 tdc_samples_chans[chan-1]->Fill();
0071 }
0072
0073
0074 eventTree->Fill();
0075 nentries += eventData.size()/numChans;
0076 sampleTree->SetEntries(nentries);
0077
0078
0079 if (aEvent->GetEventNumber() % 10 == 0) {
0080 outFile->Write();
0081 outFile->Flush();
0082 outFile->cd();
0083 }
0084 }
0085
0086
0087
0088
0089 void RootProcessor::Finish() {
0090
0091 outFile->Write();
0092
0093
0094 }