Logo ROOT  
Reference Guide
TEntryListFromFile.h
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Anna Kreshuk 17/03/2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TEntryListFromFile
13 #define ROOT_TEntryListFromFile
14 
15 //////////////////////////////////////////////////////////////////////////
16 // TEntryListFromFile
17 //
18 // Manages entry lists from different files, when they are not loaded
19 // in memory at the same time.
20 //
21 // This entry list should only be used when processing a TChain (see
22 // TChain::SetEntryList() function). File naming convention:
23 // - by default, filename_elist.root is used, where filename is the
24 // name of the chain element.
25 // - xxx$xxx.root - $ sign is replaced by the name of the chain element
26 // If the list name is not specified (by passing filename_elist.root/listname to
27 // the TChain::SetEntryList() function, the first object of class TEntryList
28 // in the file is taken.
29 // It is assumed that there are as many lists, as there are chain elements,
30 // and they are in the same order.
31 //
32 // If one of the list files can't be opened, or there is an error reading a list
33 // from the file, this list is skipped and the entry loop continues on the next
34 // list.
35 
36 #include "TEntryList.h"
37 
38 class TFile;
39 
41 {
42 protected:
43  TString fListFileName; ///< from this string names of all files can be found
44  TString fListName; ///< name of the list
45  Int_t fNFiles; ///< total number of files
46  Long64_t *fListOffset; ///<[fNFiles] numbers of entries in ind. lists
47  TFile *fFile; ///< currently open file
48  ///< fCurrent points to the currently open list
49  TObjArray *fFileNames; ///<! points to the fFiles data member of the corresponding chain
50 
51  // Obsolete use TTree::kMaxEntries
52  static constexpr auto kBigNumber = std::numeric_limits<Long64_t>::max();
53 
54 private:
55  TEntryListFromFile(const TEntryListFromFile&); // Not implemented.
56  TEntryListFromFile &operator=(const TEntryListFromFile&); // Not implemented.
57 
58 public:
59 
61  TEntryListFromFile(const char *filename, const char *listname, Int_t nfiles);
62  virtual ~TEntryListFromFile();
63  virtual void Add(const TEntryList * /*elist*/){};
64  virtual Int_t Contains(Long64_t /*entry*/, TTree * /*tree = 0*/) {return 0;};
65  virtual Bool_t Enter(Long64_t /*entry*/, TTree * /*tree = 0*/){return 0;};
66  virtual TEntryList *GetCurrentList() const { return fCurrent; };
67  virtual TEntryList *GetEntryList(const char * /*treename*/, const char * /*filename*/, Option_t * /*opt=""*/) {return 0;};
68 
69  virtual Long64_t GetEntry(Int_t index);
70  virtual Long64_t GetEntryAndTree(Int_t index, Int_t &treenum);
71  virtual Long64_t GetEntries();
72  virtual Long64_t GetEntriesFast() const { return fN; };
73 
74  virtual Long64_t GetN() const { return fN; }
75  virtual const char *GetTreeName() const { return fTreeName.Data(); }
76  virtual const char *GetFileName() const { return fFileName.Data(); }
77  virtual Int_t GetTreeNumber() const { return fTreeNumber; }
78 
79  virtual Int_t LoadList(Int_t listnumber);
80 
81  virtual Int_t Merge(TCollection * /*list*/){ return 0; };
82 
83  virtual Long64_t Next();
84  virtual void OptimizeStorage() {};
85  virtual Bool_t Remove(Long64_t /*entry*/, TTree * /*tree = 0*/){ return 0; };
86 
87  virtual void Print(const Option_t* option = "") const;
88 
89  virtual void SetTree(const TTree * /*tree*/){};
90  virtual void SetTree(const char * /*treename*/, const char * /*filename*/){};
91  virtual void SetFileNames(TObjArray *names) { fFileNames = names; }
92  virtual void SetTreeNumber(Int_t index) { fTreeNumber=index; }
93  virtual void SetNFiles(Int_t nfiles) { fNFiles = nfiles; }
94  virtual void Subtract(const TEntryList * /*elist*/) {};
95 
96  ClassDef(TEntryListFromFile, 1); //Manager for entry lists from different files
97 };
98 #endif
TEntryListFromFile::Merge
virtual Int_t Merge(TCollection *)
Merge this list with the lists from the collection.
Definition: TEntryListFromFile.h:81
TEntryListFromFile
Definition: TEntryListFromFile.h:40
TEntryListFromFile::GetN
virtual Long64_t GetN() const
Definition: TEntryListFromFile.h:74
TObjArray
Definition: TObjArray.h:37
TEntryListFromFile::GetTreeNumber
virtual Int_t GetTreeNumber() const
Definition: TEntryListFromFile.h:77
TString::Data
const char * Data() const
Definition: TString.h:369
TEntryListFromFile::GetFileName
virtual const char * GetFileName() const
Definition: TEntryListFromFile.h:76
TEntryList::fTreeName
TString fTreeName
name of the tree
Definition: TEntryList.h:38
TEntryListFromFile::Next
virtual Long64_t Next()
Returns the next entry in the list.
Definition: TEntryListFromFile.cxx:184
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TTree
Definition: TTree.h:79
TEntryList::fCurrent
TEntryList * fCurrent
! currently filled entry list
Definition: TEntryList.h:32
TEntryListFromFile::fNFiles
Int_t fNFiles
total number of files
Definition: TEntryListFromFile.h:45
Int_t
int Int_t
Definition: RtypesCore.h:45
TEntryListFromFile::GetEntryList
virtual TEntryList * GetEntryList(const char *, const char *, Option_t *)
Return the entry list, corresponding to treename and filename By default, the filename is first tried...
Definition: TEntryListFromFile.h:67
TEntryListFromFile::Remove
virtual Bool_t Remove(Long64_t, TTree *)
Remove entry #entry from the list.
Definition: TEntryListFromFile.h:85
TString
Definition: TString.h:136
TEntryListFromFile::TEntryListFromFile
TEntryListFromFile()
Definition: TEntryListFromFile.cxx:43
TEntryListFromFile::SetNFiles
virtual void SetNFiles(Int_t nfiles)
Definition: TEntryListFromFile.h:93
bool
TEntryListFromFile::GetEntries
virtual Long64_t GetEntries()
Returns the total number of entries in the list.
Definition: TEntryListFromFile.cxx:166
TEntryListFromFile::OptimizeStorage
virtual void OptimizeStorage()
Checks if the array representation is more economical and if so, switches to it.
Definition: TEntryListFromFile.h:84
TEntryListFromFile::SetTreeNumber
virtual void SetTreeNumber(Int_t index)
Definition: TEntryListFromFile.h:92
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TEntryListFromFile::Contains
virtual Int_t Contains(Long64_t, TTree *)
Definition: TEntryListFromFile.h:64
TEntryListFromFile::fFile
TFile * fFile
currently open file fCurrent points to the currently open list
Definition: TEntryListFromFile.h:47
TEntryListFromFile::GetEntriesFast
virtual Long64_t GetEntriesFast() const
Definition: TEntryListFromFile.h:72
TEntryList::fFileName
TString fFileName
name of the file, where the tree is
Definition: TEntryList.h:39
TEntryListFromFile::~TEntryListFromFile
virtual ~TEntryListFromFile()
d-tor
Definition: TEntryListFromFile.cxx:78
TEntryListFromFile::SetTree
virtual void SetTree(const TTree *)
If a list for a tree with such name and filename exists, sets it as the current sublist If not,...
Definition: TEntryListFromFile.h:89
TEntryListFromFile::SetFileNames
virtual void SetFileNames(TObjArray *names)
Definition: TEntryListFromFile.h:91
TEntryListFromFile::Print
virtual void Print(const Option_t *option="") const
Print info about this list.
Definition: TEntryListFromFile.cxx:305
TEntryListFromFile::GetEntryAndTree
virtual Long64_t GetEntryAndTree(Int_t index, Int_t &treenum)
Return the entry corresponding to the index parameter and the number of the tree, where this entry is...
Definition: TEntryListFromFile.cxx:155
TEntryListFromFile::fListFileName
TString fListFileName
from this string names of all files can be found
Definition: TEntryListFromFile.h:43
TFile
Definition: TFile.h:54
TEntryListFromFile::Enter
virtual Bool_t Enter(Long64_t, TTree *)
Add entry #entry to the list.
Definition: TEntryListFromFile.h:65
TEntryList
Definition: TEntryList.h:25
TEntryListFromFile::LoadList
virtual Int_t LoadList(Int_t listnumber)
Loads the list #listnumber This is the only function that can modify fCurrent and fFile data members.
Definition: TEntryListFromFile.cxx:231
TEntryListFromFile::kBigNumber
static constexpr auto kBigNumber
Definition: TEntryListFromFile.h:52
TEntryListFromFile::Add
virtual void Add(const TEntryList *)
Add 2 entry lists.
Definition: TEntryListFromFile.h:63
TEntryListFromFile::Subtract
virtual void Subtract(const TEntryList *)
Remove all the entries of this entry list, that are contained in elist.
Definition: TEntryListFromFile.h:94
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TEntryListFromFile::SetTree
virtual void SetTree(const char *, const char *)
If a list for a tree with such name and filename exists, sets it as the current sublist If not,...
Definition: TEntryListFromFile.h:90
TEntryList.h
TEntryListFromFile::fFileNames
TObjArray * fFileNames
! points to the fFiles data member of the corresponding chain
Definition: TEntryListFromFile.h:49
TEntryListFromFile::operator=
TEntryListFromFile & operator=(const TEntryListFromFile &)
TCollection
Definition: TCollection.h:63
TEntryListFromFile::GetTreeName
virtual const char * GetTreeName() const
Definition: TEntryListFromFile.h:75
TEntryListFromFile::fListName
TString fListName
name of the list
Definition: TEntryListFromFile.h:44
TEntryList::fN
Long64_t fN
number of entries in the list
Definition: TEntryList.h:36
TEntryList::fTreeNumber
Int_t fTreeNumber
! the index of the tree in the chain (used when the entry list is used as input (TTree::SetEntryList(...
Definition: TEntryList.h:41
TEntryListFromFile::GetCurrentList
virtual TEntryList * GetCurrentList() const
Definition: TEntryListFromFile.h:66
TEntryListFromFile::fListOffset
Long64_t * fListOffset
[fNFiles] numbers of entries in ind. lists
Definition: TEntryListFromFile.h:46
TEntryListFromFile::GetEntry
virtual Long64_t GetEntry(Int_t index)
Returns entry #index See also Next() for a faster alternative.
Definition: TEntryListFromFile.cxx:90
int