CbmRoot
Loading...
Searching...
No Matches
CbmSourceDigiEvents.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese[committer] */
4
6
7#include <FairRootManager.h>
8#include <Logger.h>
9
10#include <utility>
11
12
13// ----- Constructor ------------------------------------------------------
14CbmSourceDigiEvents::CbmSourceDigiEvents(const char* fileName) : fInputFileName(fileName) {}
15// ----------------------------------------------------------------------------
16
17
18// ----- Close ------------------------------------------------------------
20{
21 LOG(info) << "Source: Closing after " << fNumTs << "timeslices with " << fNumEvents << "events.";
22}
23// ----------------------------------------------------------------------------
24
25
26// ----- Initialisation ---------------------------------------------------
28{
29
30 // Create input archive
31 fArchive = std::make_unique<cbm::algo::RecoResultsInputArchive>(fInputFileName);
32 LOG(info) << "Source: Reading from input archive " << fInputFileName;
33 auto desc = fArchive->descriptor();
34 LOG(info) << " - Time created: " << desc.time_created();
35 LOG(info) << " - Host name : " << desc.hostname();
36 LOG(info) << " - User name : " << desc.username();
37
38 // Create and register the DigiEvent tree branch
39 FairRootManager* ioman = FairRootManager::Instance();
40 assert(ioman);
41 if (ioman->GetObject("DigiEvent")) {
42 LOG(fatal) << "Source: Branch DigiEvent already exists!";
43 return kFALSE;
44 }
45 fEvents = new std::vector<CbmDigiEvent>();
46 ioman->RegisterAny("DigiEvent", fEvents, true);
47 LOG(info) << "Source: Registered branch DigiEvent at " << fEvents;
48
49 return kTRUE;
50}
51// ----------------------------------------------------------------------------
52
53
54// ----- Read one time slice from archive ---------------------------------
56{
57
58 // Clear output event vector
59 fEvents->clear();
60
61 // Get next timeslice data from archive. Stop run if end of archive is reached.
62 auto results = fArchive->get();
63 if (fArchive->eos()) {
64 LOG(info) << "Source: End of input archive; terminating run";
65 return 1;
66 }
67
68 // Move event data from input archive to ROOT tree
69 if (results == nullptr) {
70 LOG(error) << "Source: Failed to read RecoResults from archive";
71 return 1;
72 }
73 size_t numEvents = results->DigiEvents().size();
74 LOG(info);
75 LOG(info) << "Source: Reading TS " << fNumTs << ", index " << results->TsIndex() << ", start "
76 << results->TsStartTime() << ", events " << numEvents;
77 std::move(results->DigiEvents().begin(), results->DigiEvents().end(), std::back_inserter(*fEvents));
78 assert(fEvents->size() == numEvents);
79
80 // Update counters
81 fNumTs++;
82 fNumEvents += numEvents;
83
84 return 0;
85}
86// ----------------------------------------------------------------------------
87
88
ClassImp(CbmConverterManager)
Source class for reading from files resulting from online processing (containing DigiEvents)
virtual void Close()
Close source after end of run.
CbmSourceDigiEvents(const char *fileName="")
Constructor.
virtual Bool_t Init()
Initialisation.
std::unique_ptr< cbm::algo::RecoResultsInputArchive > fArchive
Int_t ReadEvent(UInt_t=0)
Read one time slice from file.
std::vector< CbmDigiEvent > * fEvents