20 #include "FairMQLogger.h"
21 #include "FairMQProgOptions.h"
23 #include "FairFileSource.h"
24 #include "FairRootManager.h"
25 #include "FairRunAna.h"
27 #include "TClonesArray.h"
42 using std::runtime_error::runtime_error;
48 fFileName = fConfig->GetValue<
string>(
"filename");
49 fMaxEvents = fConfig->GetValue<uint64_t>(
"max-events");
52 LOG(info) <<
"Filename: " << fFileName;
53 LOG(info) <<
"MaxEvents: " << fMaxEvents;
57 fChan.CheckChannels(
this);
58 fComponentsToSend = fChan.GetComponentsToSend();
59 fChannelsToSend = fChan.GetChannelsToSend();
61 for (
auto const& value : fComponentsToSend) {
63 throw InitTaskError(
"Sending same data to more than one output channel "
64 "not implemented yet.");
72 FairRunAna* ana =
new FairRunAna();
73 ana->SetContainerStatic();
74 FairRootManager* rootman = FairRootManager::Instance();
76 if (0 != fFileName.size()) {
77 LOG(info) <<
"Open the ROOT input file " << fFileName;
79 FILE* inputFile = fopen(fFileName.c_str(),
"r");
80 if (!inputFile) {
throw InitTaskError(
"Input file doesn't exist."); }
82 FairFileSource* source =
new FairFileSource(fFileName);
83 if (!source) {
throw InitTaskError(
"Could not open input file."); }
84 rootman->SetSource(source);
85 rootman->InitSource();
88 for (
unsigned i = 0;
i < fComponentsToSend.size();
i++) {
91 == fComponentsToSend.at(
93 std::vector<std::string> channel_name = fChannelsToSend.at(
i);
94 LOG(info) << channel_name.at(0);
95 ConnectChannelIfNeeded(
i, channel_name.at(0),
"MvdPoint", rootman);
96 ConnectChannelIfNeeded(
i, channel_name.at(0),
"StsPoint", rootman);
97 ConnectChannelIfNeeded(
i, channel_name.at(0),
"RichPoint", rootman);
98 ConnectChannelIfNeeded(
i, channel_name.at(0),
"MuchPoint", rootman);
99 ConnectChannelIfNeeded(
i, channel_name.at(0),
"TrdPoint", rootman);
100 ConnectChannelIfNeeded(
i, channel_name.at(0),
"TofPoint", rootman);
102 ConnectChannelIfNeeded(
i, channel_name.at(0),
"PsdPoint", rootman);
104 fArrays.at(
i) =
nullptr;
111 Int_t MaxAllowed = FairRootManager::Instance()->CheckMaxEventNo(fMaxEvents);
112 if (MaxAllowed != -1) {
113 if (fMaxEvents == 0) {
114 fMaxEvents = MaxAllowed;
116 if (
static_cast<Int_t
>(fMaxEvents) > MaxAllowed) {
117 LOG(warn) <<
"-------------------Warning---------------------------";
118 LOG(warn) <<
" File has less events than requested!!";
119 LOG(warn) <<
" File contains : " << MaxAllowed <<
" Events";
120 LOG(warn) <<
" Requested number of events = " << fMaxEvents
122 LOG(warn) <<
" The number of events is set to " << MaxAllowed
124 LOG(warn) <<
"-----------------------------------------------------";
125 fMaxEvents = MaxAllowed;
128 LOG(info) <<
"After checking, the run will run from event 0 "
129 <<
" to " << fMaxEvents <<
".";
131 LOG(info) <<
"continue running without stop";
135 fTime = std::chrono::steady_clock::now();
137 LOG(error) << e.what();
143 std::string channel_name,
144 std::string branchname,
145 FairRootManager* rootman) {
146 if (0 == channel_name.compare(branchname)) {
147 LOG(info) <<
"Found expected data type " << branchname;
149 static_cast<TClonesArray*
>(rootman->GetObject(branchname.c_str()));
151 LOG(info) <<
"Consuming device connected but no " << branchname
152 <<
" array in input file!";
153 fComponentsToSend.at(chan_number) =
156 fArrays.at(chan_number) = arr;
163 Int_t readEventReturn = FairRootManager::Instance()->ReadEvent(fEventCounter);
166 if (readEventReturn != 0) {
167 LOG(warn) <<
"FairRootManager::Instance()->ReadEvent(" << fEventCounter
168 <<
") returned " << readEventReturn
169 <<
". Breaking the event loop";
174 for (
unsigned i = 0;
i < fComponentsToSend.size();
i++) {
177 == fComponentsToSend.at(
180 if (0 == fChannelsToSend.at(
i).at(0).compare(
"MvdPoint")) {
181 result = ConvertAndSend<CbmMvdPoint>(fArrays.at(
i),
i);
183 if (0 == fChannelsToSend.at(
i).at(0).compare(
"StsPoint")) {
184 result = ConvertAndSend<CbmStsPoint>(fArrays.at(
i),
i);
186 if (0 == fChannelsToSend.at(
i).at(0).compare(
"RichPoint")) {
187 result = ConvertAndSend<CbmRichPoint>(fArrays.at(
i),
i);
189 if (0 == fChannelsToSend.at(
i).at(0).compare(
"MuchPoint")) {
190 result = ConvertAndSend<CbmMuchPoint>(fArrays.at(
i),
i);
192 if (0 == fChannelsToSend.at(
i).at(0).compare(
"TrdPoint")) {
193 result = ConvertAndSend<CbmTrdPoint>(fArrays.at(
i),
i);
195 if (0 == fChannelsToSend.at(
i).at(0).compare(
"TofPoint")) {
196 result = ConvertAndSend<CbmTofPoint>(fArrays.at(
i),
i);
203 if (0 == fChannelsToSend.at(
i).at(0).compare(
"PsdPoint")) {
204 result = ConvertAndSend<CbmPsdPoint>(fArrays.at(
i),
i);
208 LOG(error) <<
"Problem sending data";
214 if (fEventCounter % 10000 == 0)
215 LOG(info) <<
"Analyse Event " << fEventCounter;
220 if (fEventCounter < fMaxEvents) {
231 std::chrono::duration<double> run_time =
232 std::chrono::steady_clock::now() - fTime;
234 LOG(info) <<
"Runtime: " << run_time.count();
235 LOG(info) <<
"No more input data";