Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:19

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #include "RootProcessor.h"
0006 #include "ADCSample.h"
0007 
0008 //---------------------------------
0009 // RootProcessor    (Constructor)
0010 //---------------------------------
0011 RootProcessor::RootProcessor() = default;
0012 
0013 //---------------------------------
0014 // ~RootProcessor    (Destructor)
0015 //---------------------------------
0016 RootProcessor::~RootProcessor() {
0017     // close output root file
0018     outFile->Close();
0019 }
0020 
0021 //------------------
0022 // Init
0023 //------------------
0024 void RootProcessor::Init() {
0025 
0026     // This is called once at program startup.
0027     // define root file
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     // define trees and branches
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     // update the root file
0046     outFile->Write();
0047     outFile->Flush();
0048     outFile->cd();
0049 }
0050 
0051 //------------------
0052 // Process
0053 //------------------
0054 void RootProcessor::Process(const std::shared_ptr<const JEvent>& aEvent) {
0055 
0056     // get adc sample object for each event
0057     auto eventData = aEvent->Get<ADCSample>();
0058     // impose mutex lock
0059     lock_guard<mutex> lck(fillMutex);
0060     // for each adc sample in the current event
0061     for (auto sample : eventData) {
0062         // Insert this sample into the correct location in the ROOT tree.
0063         // This is effectively doing a transpose of the incoming DAS file
0064         // Correctness requires that our samples be ordered by increasing sample_id
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     // fill event tree and set nentries on sample tree
0074     eventTree->Fill();
0075     nentries += eventData.size()/numChans;
0076     sampleTree->SetEntries(nentries);
0077 
0078     // update the root file
0079     if (aEvent->GetEventNumber() % 10 == 0) {
0080         outFile->Write();
0081         outFile->Flush();
0082         outFile->cd();
0083     }
0084 }
0085 
0086 //------------------
0087 // Finish
0088 //------------------
0089 void RootProcessor::Finish() {
0090 
0091     outFile->Write();
0092     // outFile->Write();
0093 
0094 }