Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
40 class TEntryListFromFile: public TEntryList
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 
60  TEntryListFromFile();
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