CbmRoot
Loading...
Searching...
No Matches
CbmSourceTsArchive.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: Jan de Cuveland, Volker Friese[committer], Pierre-Alain Loizeau */
4
6
7#include <TimesliceAutoSource.hpp>
8
9#include <FairSource.h>
10#include <Logger.h>
11
12
13using fles::Timeslice;
14using std::string;
15using std::unique_ptr;
16
17
18// ----- Constructor ------------------------------------------------------
19CbmSourceTsArchive::CbmSourceTsArchive(const char* fileName) { AddInputFile(fileName); }
20// ----------------------------------------------------------------------------
21
22// ----- Constructor ------------------------------------------------------
23CbmSourceTsArchive::CbmSourceTsArchive(std::vector<std::string> fileNames) : fFileNames(fileNames) {}
24// ----------------------------------------------------------------------------
25
26
27// ----- Add an input file ------------------------------------------------
28size_t CbmSourceTsArchive::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 LOG(info) << "SourceTsArchive::Close() Let's hear some famous last words: ";
42}
43// ----------------------------------------------------------------------------
44
45
46// ----- Initialisation ---------------------------------------------------
48{
49 if (1 == fFileNames.size()) {
50 LOG(info) << "SourceTsArchive::Init() calling string constructor with ";
51 LOG(info) << fFileNames[0];
52 fTsSource = new fles::TimesliceAutoSource(fFileNames[0]);
53 }
54 else {
55 LOG(info) << "SourceTsArchive::Init() calling vector constructor with size ";
56 LOG(info) << fFileNames.size();
57 fTsSource = new fles::TimesliceAutoSource(fFileNames);
58 }
59
60 // Initialise unpacker
61 fUnpack.Init();
62 LOG(info) << "Source: Init done";
63 return kTRUE;
64}
65// ----------------------------------------------------------------------------
66
67
68// ----- Read one time slice from archive ---------------------------------
70{
71
72 unique_ptr<Timeslice> ts;
73 ts = fTsSource->get();
74
75 if (!ts) {
76 LOG(info) << "SourceTsArchive: End of archive reached; stopping run.";
77 return 1;
78 }
79 if (fDoDebugPrints || 0 == fTsCounter % 100) {
80 LOG(info) << "SourceTsArchive: Reading time slice " << fTsCounter << " (index " << ts->index() << ")";
81 }
82
83 fUnpack.Unpack(std::move(ts));
84
85
86 fTsCounter++;
87 return 0;
88}
89// ----------------------------------------------------------------------------
90
91
ClassImp(CbmConverterManager)
void Finish()
Actions at the end of the run.
void Unpack(std::unique_ptr< fles::Timeslice > ts)
Trigger the unpacking procedure.
Bool_t Init()
Initialisation.
Source class for reading from archived time slice data.
bool fDoDebugPrints
Flag if extended debug output is to be printed or not.
size_t AddInputFile(const char *fileName)
Add an input file.
fles::TimesliceSource * fTsSource
Int_t ReadEvent(UInt_t=0)
Read one time slice from file.
std::vector< std::string > fFileNames
CbmSourceTsArchive(const char *fileName="")
Constructor.
virtual void Close()
Close source after end of run.
virtual Bool_t Init()
Initialisation.