CbmRoot
Loading...
Searching...
No Matches
CbmSourceTs.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese[committer] */
4
5#include "CbmSourceTs.h"
6
7#include <TimesliceAutoSource.hpp>
8
9#include <FairSource.h>
10#include <Logger.h>
11
12
13using fles::Timeslice;
14using std::string;
15using std::vector;
16
17
18// ----- Constructor ------------------------------------------------------
19CbmSourceTs::CbmSourceTs(const char* fileName) { AddInputFile(fileName); }
20// ----------------------------------------------------------------------------
21
22// ----- Constructor ------------------------------------------------------
23CbmSourceTs::CbmSourceTs(vector<string> fileNames) : fFileNames(fileNames) {}
24// ----------------------------------------------------------------------------
25
26
27// ----- Add an input file ------------------------------------------------
28size_t CbmSourceTs::AddInputFile(const char* fileName)
29{
30 string sFile(fileName);
31 if (sFile.size()) fFileNames.push_back(sFile);
32 return fFileNames.size();
33}
34// ----------------------------------------------------------------------------
35
36
37// ----- Close -----------------------------------------------------------
39// ----------------------------------------------------------------------------
40
41
42// ----- Initialisation ---------------------------------------------------
44{
45 LOG(info) << "SourceTs: Creating TimesliceSource with " << fFileNames.size() << " input files.";
46 fFlesSource = new fles::TimesliceAutoSource(fFileNames);
47 return kTRUE;
48}
49// ----------------------------------------------------------------------------
50
51
52// ----- Read one time slice from archive ---------------------------------
53Int_t CbmSourceTs::ReadEvent(UInt_t tsIndex)
54{
55 // Timeslices can only be read sequentially.
56 // It appears that the first call to this method from FairRunOnline is in the
57 // init stage. In order not to always lose the first timeslice, a call to
58 // TimesliceSource::get is avoided in the first call.
59 if (fNumCalls == 0) {
60 LOG(info) << "SourceTs: Init call to ReadEvent";
61 fNumCalls++;
62 }
63 else if (tsIndex > 0 && tsIndex < fNumCalls - 1) {
64 LOG(error) << "SourceTs: Out-of-sequence reading of timeslices not supported.";
65 return 1;
66 }
67 else {
68 do {
69 fFlesTs = nullptr;
70 fFlesTs = fFlesSource->get();
71 if (!fFlesTs) {
72 LOG(info) << "SourceTs: End of archive reached; stopping run.";
73 return 1;
74 }
75 if (tsIndex == fNumCalls - 1) {
76 LOG(info) << "SourceTs: Reading time slice " << GetNumTs() << " (index " << fFlesTs->index()
77 << ") at t = " << fFlesTs->start_time() << " ns";
78 }
79 else {
80 LOG(info) << "SourceTs: Skipping time slice " << GetNumTs() << " (index " << fFlesTs->index()
81 << ") at t = " << fFlesTs->start_time() << " ns";
82 LOG(info) << "(TS is still fetched from disk, this may take some time)";
83 }
84 fNumCalls++;
85 } while (tsIndex >= fNumCalls - 1);
86 }
87 return 0;
88}
89// ----------------------------------------------------------------------------
90
91
ClassImp(CbmConverterManager)
Source class for reading from archived time slice data.
Definition CbmSourceTs.h:26
virtual Bool_t Init()
Initialisation.
virtual void Close()
Demanded by base class.
size_t fNumCalls
CbmSourceTs(const char *fileName="")
Constructor.
size_t AddInputFile(const char *fileName)
Add an input file.
std::unique_ptr< fles::Timeslice > fFlesTs
fles::TimesliceSource * fFlesSource
std::vector< std::string > fFileNames
virtual Int_t ReadEvent(UInt_t=0)
Read one time slice from file.
size_t GetNumTs() const
Number of processed timeslices.
Definition CbmSourceTs.h:72