Project
Loading...
Searching...
No Matches
RootChain.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
15#include <TString.h>
16#include <fairlogger/Logger.h>
17#include <fstream>
18
19using namespace o2::utils;
20
21std::unique_ptr<TChain> RootChain::load(const std::string trName, const std::string inpFile)
22{
23 // create chain from the single root file or list of files
24 std::unique_ptr<TChain> chain;
25 if (trName.empty() || inpFile.empty()) {
26 LOG(error) << "Tree name or input file is not provided";
27 return chain;
28 }
29 chain = std::make_unique<TChain>(trName.data());
30 addFile(chain.get(), inpFile);
31 LOG(info) << "Created chain " << chain->GetName() << " with " << chain->GetEntries()
32 << " from " << inpFile;
33 return chain;
34}
35
36void RootChain::addFile(TChain* ch, const std::string inp)
37{
38 // add root file or files from the list extracted from the inp text file
39 TString inpS = inp.data();
40 if (inpS.EndsWith(".root")) {
41 LOG(info) << "Adding " << inp;
42 ch->AddFile(inp.data());
43 } else {
44 std::ifstream inpF(inpS.Data());
45 if (!inpF.good()) {
46 LOG(error) << "Failed to open input file " << inp << " as a text one";
47 return;
48 }
49 //
50 inpS.ReadLine(inpF);
51 while (!inpS.IsNull()) {
52 inpS = inpS.Strip(TString::kBoth, ' ');
53 if (inpS.BeginsWith("//") || inpS.BeginsWith("#")) {
54 inpS.ReadLine(inpF);
55 continue;
56 }
57 inpS = inpS.Strip(TString::kBoth, ',');
58 inpS = inpS.Strip(TString::kBoth, '"');
59 addFile(ch, inpS.Data());
60 inpS.ReadLine(inpF);
61 }
62 }
63}
GPUChain * chain
static void addFile(TChain *ch, const std::string inp)
Definition RootChain.cxx:36
static std::unique_ptr< TChain > load(const std::string trName, const std::string inpFile)
Definition RootChain.cxx:21
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"