CbmRoot
Loading...
Searching...
No Matches
CbmTaskEventsCloneInToOut.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5
7
8#include "CbmDefs.h"
9#include "CbmEvent.h"
10
11#include <FairFileSource.h>
12#include <FairRootManager.h>
13#include <Logger.h>
14
15#include <TClonesArray.h>
16#include <TStopwatch.h>
17
18#include <algorithm>
19#include <cassert>
20#include <iomanip>
21
22
23using namespace std;
24
25
26// ----- Constructor -----------------------------------------------------
27CbmTaskEventsCloneInToOut::CbmTaskEventsCloneInToOut() : FairTask("EventsCloneInToOut") {}
28// ---------------------------------------------------------------------------
29
30
31// ----- Destructor ------------------------------------------------------
33// ---------------------------------------------------------------------------
34
35
36// ----- Execution -------------------------------------------------------
38{
39 // --- Timer and counters
40 TStopwatch timer;
41 timer.Start();
42
43 // --- No action if no CbmEvents branch is present
44 if (!fRecoEventsIn) return;
45
46 fRecoEventsOut->Delete(); // Bad way to do it according to ROOT docs, but memory leak otherwise
47
48 // --- Copy all entries in input TClonesArray to output one
49 // => Event loop
50 for (Int_t eventNr = 0; eventNr < fRecoEventsIn->GetEntriesFast(); ++eventNr) {
51 const CbmEvent* pEventIn = dynamic_cast<const CbmEvent*>((*fRecoEventsIn)[eventNr]);
52 if (pEventIn) {
54 new ((*fRecoEventsOut)[eventNr]) CbmEvent(*pEventIn);
55 }
56 else {
57 LOG(fatal) << GetName() << ": Failed to get input event " << eventNr << " in TS " << fNumTs;
58 }
59 }
60
61 if (fRecoEventsIn->GetEntriesFast() != fRecoEventsOut->GetEntriesFast()) {
62 LOG(fatal) << GetName() << ": Input size not matching output one: " << fRecoEventsIn->GetEntriesFast() << " VS "
63 << fRecoEventsOut->GetEntriesFast() << " in TS " << fNumTs;
64 }
65
66 // --- Timeslice log
67 timer.Stop();
68 stringstream logOut;
69 logOut << setw(20) << left << GetName() << " [";
70 logOut << fixed << setw(8) << setprecision(1) << right << timer.RealTime() * 1000. << " ms] ";
71 logOut << "TS " << fNumTs << ", events In " << fRecoEventsIn->GetEntriesFast() << ", events Out "
72 << fRecoEventsOut->GetEntriesFast();
73 LOG(info) << logOut.str();
74
75 // --- Run statistics
76 fNumTs++;
77 fTimeTot += timer.RealTime();
78 fNumEvents += fRecoEventsOut->GetEntriesFast();
79}
80// ----------------------------------------------------------------------------
81
82
83// ----- End-of-timeslice action ------------------------------------------
85{
86 LOG(info) << "=====================================";
87 LOG(info) << GetName() << ": Run summary";
88 LOG(info) << "Timeslices : " << fNumTs;
89 LOG(info) << "Events : " << fNumEvents;
90 LOG(info) << "Time / TS : " << fixed << setprecision(2) << 1000. * fTimeTot / double(fNumTs) << " ms";
91 LOG(info) << "=====================================";
92 fRecoEventsOut->Delete();
93}
94// ----------------------------------------------------------------------------
95
96
97// ----- Initialisation ---------------------------------------------------
99{
100
101 LOG(info) << "==================================================";
102 LOG(info) << GetName() << ": Initialising ";
103
104 // --- Get FairRootManager instance
105 FairRootManager* frm = FairRootManager::Instance();
106 if (nullptr == frm) {
107 LOG(error) << GetName() << ": Failed to get FairRootManager! Aborting...";
108 return kFATAL;
109 }
110
111 // --- Try to get input vector (CbmDigiEvent)
112 fpFileIn = dynamic_cast<FairFileSource*>(frm->GetSource());
113 if (nullptr == fpFileIn) {
114 LOG(error) << GetName() << ": Failed to get Fair file interface object! Aborting...";
115 return kFATAL;
116 }
117
118 TTree* pTree = fpFileIn->GetInTree();
119 if (pTree->GetBranch("CbmEvent")) {
120 fRecoEventsIn = new TClonesArray("CbmEvent", 100);
121 pTree->SetBranchAddress("CbmEvent", &fRecoEventsIn);
122 pTree->SetBranchStatus("CbmEvent", 1);
123
124 LOG(info) << GetName() << ": Found branch CbmEvent in input";
125
126 // --- Event
127 fRecoEventsOut = new TClonesArray("CbmEvent", 1);
128 frm->Register("CbmEvent", "Reco events", fRecoEventsOut, kTRUE);
129 LOG(info) << GetName() << ": created branch CbmEvent in output";
130 }
131 else {
132 LOG(error) << GetName() << ": No CbmEvent branch found in file! Aborting...";
133 return kFATAL;
134 }
135
136 LOG(info) << "==================================================";
137
138 return kSUCCESS;
139}
140// ----------------------------------------------------------------------------
141
ClassImp(CbmConverterManager)
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
Task class for clone CbmEvent objects from the Input to the output to allow their update,...
size_t fNumTs
Number of processed timeslices.
virtual void Finish()
Finish timeslice.
virtual ~CbmTaskEventsCloneInToOut()
Destructor.
size_t fNumEvents
Number of events.
virtual void Exec(Option_t *opt)
Task execution.
virtual InitStatus Init()
Task initialisation.
Hash for CbmL1LinkKey.