CbmRoot
Loading...
Searching...
No Matches
CbmSourceRecoTimeslice.cxx
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
11
12#include "CbmTimeSlice.h"
13#include "CbmTsEventHeader.h"
14
15#include <FairRootManager.h>
16#include <FairRun.h>
17
18// ---------------------------------------------------------------------------------------------------------------------
19//
21
22
23// ---------------------------------------------------------------------------------------------------------------------
24//
26{
27 LOG(info) << "Source: closing after " << fNumTs << " timeslices";
29}
30
31
32// ---------------------------------------------------------------------------------------------------------------------
33//
35{
36 using namespace cbm::algo;
37
38 // Create input archive
39 fArchive = std::make_unique<cbm::algo::RecoResultsInputArchive>(fInputFileName);
40 LOG(info) << "Source: Reading from input archive " << fInputFileName;
41 auto desc = fArchive->descriptor();
42 LOG(info) << " - Time created: " << desc.time_created();
43 LOG(info) << " - Host name : " << desc.hostname();
44 LOG(info) << " - User name : " << desc.username();
45
46 auto* ioman = FairRootManager::Instance();
47 if (!ioman) {
48 LOG(fatal) << "CbmSourceRecoTimeslice::Init(): FairRootManager is not defined";
49 return kFALSE;
50 }
51
52 if (!(fTsEventHeader = dynamic_cast<CbmTsEventHeader*>(FairRun::Instance()->GetEventHeader()))) {
53 LOG(fatal) << "CbmSourceRecoTimeslice::Init() no CbmTsEventHeader was added to the run. Without it, we can not "
54 "store the UTC of the "
55 "Timeslices correctly. Hence, this causes a fatal. Please add it in the steering macro to the Run.";
56 return kFALSE;
57 }
58
59 // TimeSlice. branch initialization
60 if (ioman->GetObject("TimeSlice.")) {
61 LOG(fatal) << "Source: Branch TimeSlice. already exists!";
62 return kFALSE;
63 }
64 else {
65 // NOTE: the max time of timeslice is 1.28e8, taken from CbmRecoUnpack.cxx
66 fTimeslice = new CbmTimeSlice(0., 1.28e8 + 1.28e6);
67 ioman->Register("TimeSlice.", "DAQ", fTimeslice, kTRUE);
68 }
69
70 auto RegisterVector = [&](auto*& vec, const char* name) -> bool {
71 if (ioman->GetObject(name)) {
72 LOG(fatal) << "Source: branch " << name << " already exists!";
73 return false;
74 }
75 ioman->RegisterAny(name, vec, kTRUE);
76 LOG(info) << "Source: registered branch " << name << " at " << vec;
77
78 return true;
79 };
80
81 // TODO: replace individual vectors with reco-timeslice objects
83 if (!RegisterVector(fBmonHits, "OnlineBmonHit")) {
84 return kFALSE;
85 }
86
88 if (!RegisterVector(fStsHits, "OnlineStsHit")) {
89 return kFALSE;
90 }
91
93 if (!RegisterVector(fTrdHits, "OnlineTrdHit")) {
94 return kFALSE;
95 }
96
98 if (!RegisterVector(fTofHits, "OnlineTofHit")) {
99 return kFALSE;
100 }
101
103 if (!RegisterVector(fTracks, "OnlineTrack")) {
104 return kFALSE;
105 }
106
108 if (!RegisterVector(fTrackStsHitIndices, "OnlineTrackStsHitIndex")) {
109 return kFALSE;
110 }
111
113 if (!RegisterVector(fTrackTrdHitIndices, "OnlineTrackTrdHitIndex")) {
114 return kFALSE;
115 }
116
118 if (!RegisterVector(fTrackTofHitIndices, "OnlineTrackTofHitIndex")) {
119 return kFALSE;
120 }
121
122 return kTRUE;
123}
124
125
126// ---------------------------------------------------------------------------------------------------------------------
127//
129{
130 // Get next timeslice data from archive. Stop run if end of archive is reached.
131 auto results = fArchive->get();
132 if (fArchive->eos()) {
133 LOG(info) << "Source: End of input archive; terminating run";
134 return 1;
135 }
136
137 // Move event data from input archive to ROOT tree
138 if (!results) {
139 LOG(error) << "Source: Failed to read RecoResults from archive";
140 return 1;
141 }
142
143 LOG(info) << "Source: reading TS " << fNumTs << ", index " << results->TsIndex() << ", start " //
144 << results->TsStartTime() << ", contains\n" //
145 << " Hits: BMON=" << results->BmonHits().NElements() << ", STS=" << results->StsHits().NElements() //
146 << ", TRD=" << results->TrdHits().NElements() << ", TOF=" << results->TofHits().NElements() //
147 << "\n Tracks: " << results->Tracks().size();
148
149 fTsEventHeader->SetTsIndex(results->TsIndex());
150 fTsEventHeader->SetTsStartTime(results->TsStartTime());
151 fTimeslice->SetStartTime(results->TsStartTime());
152
153 *fBmonHits = std::move(results->BmonHits());
154 *fStsHits = std::move(results->StsHits());
155 *fTrdHits = std::move(results->TrdHits());
156 *fTofHits = std::move(results->TofHits());
157 *fTracks = std::move(results->Tracks());
158 *fTrackStsHitIndices = std::move(results->TrackStsHitIndices());
159 *fTrackTrdHitIndices = std::move(results->TrackTrdHitIndices());
160 *fTrackTofHitIndices = std::move(results->TrackTofHitIndices());
161
162 ++fNumTs;
163
164 return 0;
165}
166
167
168// ---------------------------------------------------------------------------------------------------------------------
169//
171{
172 fBmonHits->Clear();
173 fStsHits->Clear();
174 fTrdHits->Clear();
175 fTofHits->Clear();
176 fTracks->clear();
177 fTrackStsHitIndices->clear();
178 fTrackTrdHitIndices->clear();
179 fTrackTofHitIndices->clear();
180}
181
182
ClassImp(CbmSourceRecoTimeslice)
A source class for reading reconstruction results from the online processing.
int Int_t
bool Bool_t
Source class for reading reconstruction results from the online processing.
virtual Bool_t Init()
Initializes the source.
cbm::algo::StorableRecoResults::TrackHitIndexContainer_t * fTrackTofHitIndices
CbmTimeSlice * fTimeslice
Timeslice header (NOTE: legacy, will be deprecated soon)
cbm::PartitionedVector< cbm::algo::bmon::Hit > * fBmonHits
virtual void Close()
Closes the source in the end of the run.
std::string fInputFileName
Input file name.
cbm::algo::StorableRecoResults::TrackHitIndexContainer_t * fTrackTrdHitIndices
size_t fNumTs
Timeslice counter.
cbm::PartitionedVector< cbm::algo::trd::Hit > * fTrdHits
cbm::algo::StorableRecoResults::TrackHitIndexContainer_t * fTrackStsHitIndices
cbm::algo::ca::Vector< cbm::algo::ca::Track > * fTracks
CbmTsEventHeader * fTsEventHeader
Timeslice event header.
cbm::PartitionedVector< cbm::algo::tof::Hit > * fTofHits
CbmSourceRecoTimeslice(const char *filename="")
Constructor.
std::unique_ptr< cbm::algo::RecoResultsInputArchive > fArchive
Input archive.
virtual Int_t ReadEvent(UInt_t=0)
Reads one timeslice from file.
void ClearOutputVectors()
Clears the output vectors.
cbm::PartitionedVector< cbm::algo::sts::Hit > * fStsHits
Bookkeeping of time-slice content.
A vector that is partitioned into multiple subvectors.
ca::Vector< std::vector< std::pair< uint32_t, uint32_t > > > TrackHitIndexContainer_t