HighLAND
InputConverter.cxx
1 #include "InputConverter.hxx"
2 
3 //*****************************************************************************
4 InputConverter::InputConverter(const std::string& name){
5 //*****************************************************************************
6  fChain = NULL;
7  _treeName = name;
8  _currentFileIndex=0;
9  _currentFileName ="";
10 }
11 
12 //*****************************************************************************
13 Long64_t InputConverter::LoadTree(Long64_t entry){
14 //*****************************************************************************
15 
16  // Set the environment to read one entry
17  if (!fChain) return -5;
18  Long64_t centry = fChain->LoadTree(entry);
19  if (centry < 0) return centry;
20  if (!fChain->InheritsFrom(TChain::Class())) return centry;
21  TChain *chain = (TChain*)fChain;
22  if (chain->GetTreeNumber() != fCurrent) {
23  fCurrent = chain->GetTreeNumber();
24  // Notify();
25  }
26  return centry;
27 }
28 
29 //*****************************************************************************
31 //*****************************************************************************
32 
33  _nentries = GetChain()->GetEntries();
34 
35  return _nentries;
36 }
37 
38 
39 //*****************************************************************************
40 Int_t InputConverter::GetNEvents(Int_t entries){
41 //*****************************************************************************
42 
43  if (entries==-1) return GetEntries();
44  else return entries;
45 }
46 
47 //****************************************************************************
48 bool InputConverter::IsCorrectType(const std::string& inputString){
49 //****************************************************************************
50 
51  bool correct = true;
52 
53  TFile *f = TFile::Open(inputString.c_str());
54  f->cd();
55  if (!f->Get(_treeName.c_str())) correct = false;
56  f->Close();
57  if (correct)
58  std::cout << " - Converter '" << _name << "' looking for tree '" << _treeName << "' --> Yes" << std::endl;
59  else
60  std::cout << " - Converter '" << _name << "' looking for tree '" << _treeName << "' --> No" << std::endl;
61 
62 
63  return correct;
64 }
65 
InputConverter(const std::string &name)
Constrctor provided a name.
std::string _name
The name of the converter.
int _nentries
The number of entries in the chain. To be set by the implementation.
std::string _treeName
The name of the tree to convert.
virtual Int_t GetNEvents(Int_t entries=-1)
Return the total number of events for a given number of entries in the tree.
virtual Long64_t LoadTree(Long64_t entry)
Handle loading the correct entry from fChain.
Int_t fCurrent
current Tree number in a TChain
virtual bool IsCorrectType(const std::string &inputString)
Whether the implementation can handle the specified file.
TChain * GetChain(const std::string &name="")
virtual Long64_t GetEntries()
Return the total number of entries in the chain.
TChain * fChain
The main TChain used to read events from the input file.