]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEERBase/TTreeStream.h
ATO-98 - default streamer TFile::Open , const char * option="update"
[u/mrichter/AliRoot.git] / STEER / STEERBase / TTreeStream.h
1 #ifndef TTREESTREAM_H
2 #define TTREESTREAM_H
3 ///////////////////////////////////////////////////////////////////////////////
4 //                                                                           //
5 //  TTreeSRedirector                                                              //                      
6
7 #include "TObject.h"
8 #include "TString.h"
9 #include "TTree.h"
10 #include "TDirectory.h"
11 #include "TFile.h"
12 class TObjArray;
13 class TTree;
14 class TDataType;
15
16 class TTreeDataElement: public TNamed {
17   friend class TTreeStream;
18  public:
19   TTreeDataElement(Char_t type);
20   TTreeDataElement(TDataType* type);
21   TTreeDataElement(TClass* cl);
22   void   SetPointer(void* pointer) {fPointer=pointer;} 
23   Char_t GetType() const {return fType;}
24  protected:
25
26   TTreeDataElement(const TTreeDataElement & tde);
27   TTreeDataElement & operator=(const TTreeDataElement & tde);
28
29   Char_t  fType;     // type of data element
30   TDataType *fDType; //data type pointer 
31   TClass    *fClass; //data type pointer
32   void * fPointer;  // pointer to element
33   ClassDef(TTreeDataElement,2)
34 };
35
36 class TTreeStream: public TNamed {
37   friend class TTreeSRedirector;
38 public:
39   TTreeStream(const char *treename, TTree* externalTree=NULL);
40   ~TTreeStream();
41   void Close();
42   static void Test();
43   Int_t CheckIn(Char_t type, void *pointer);  
44   //Int_t CheckIn(const char *type, void *pointer);
45   Int_t CheckIn(TObject *o);
46   void BuildTree();
47   void Fill();
48   Double_t GetSize(){ return fTree->GetZipBytes();}
49   TTreeStream& Endl();
50   //
51   TTreeStream  &operator<<(Bool_t   &b){CheckIn('B',&b);return *this;}
52   TTreeStream  &operator<<(Char_t   &c){CheckIn('B',&c);return *this;}
53   TTreeStream  &operator<<(UChar_t  &c){CheckIn('b',&c);return *this;}
54   TTreeStream  &operator<<(Short_t  &h){CheckIn('S',&h);return *this;}
55   TTreeStream  &operator<<(UShort_t &h){CheckIn('s',&h);return *this;}
56   TTreeStream  &operator<<(Int_t    &i){CheckIn('I',&i);return *this;}
57   TTreeStream  &operator<<(UInt_t   &i){CheckIn('i',&i);return *this;}
58   TTreeStream  &operator<<(Long_t   &l){CheckIn('L',&l);return *this;}
59   TTreeStream  &operator<<(ULong_t  &l){CheckIn('l',&l);return *this;}
60   TTreeStream  &operator<<(Long64_t &l){CheckIn('L',&l);return *this;}
61   TTreeStream  &operator<<(ULong64_t &l){CheckIn('l',&l);return *this;}
62   TTreeStream  &operator<<(Float_t   &f){CheckIn('F',&f);return *this;}
63   TTreeStream  &operator<<(Double_t  &d){CheckIn('D',&d);return *this;}
64   TTreeStream  &operator<<(TObject*o){CheckIn(o);return *this;} 
65   TTreeStream  &operator<<(const Char_t *name);
66   TTree * GetTree() const { return fTree;}
67  protected:
68   //
69
70   TTreeStream(const TTreeStream & ts);
71   TTreeStream & operator=(const TTreeStream & ts);
72
73   TObjArray *fElements; //array of elements
74   TObjArray *fBranches; //pointers to branches
75   TTree *fTree;         //data storage
76   Int_t fCurrentIndex;  //index of current element
77   Int_t fId;            //identifier of layout
78   TString fNextName;    //name for next entry
79   Int_t   fNextNameCounter; //next name counter
80   Int_t   fStatus;      //status of the layout
81   ClassDef(TTreeStream,1)
82 };
83
84
85
86 class TTreeSRedirector: public TObject { 
87 public:
88   TTreeSRedirector(const char *fname="", const char * option="update");
89   virtual ~TTreeSRedirector();
90   void Close();
91   static void Test();
92   static void Test2();
93   static void UnitTestSparse(Double_t scale, Int_t testEntries);
94   static void UnitTest(Int_t testEntries=5000);
95   void StoreObject(TObject* object);
96   TFile * GetFile() {return fDirectory->GetFile();}
97   TDirectory * GetDirectory() {return fDirectory;}
98   virtual   TTreeStream  &operator<<(Int_t id);
99   virtual   TTreeStream  &operator<<(const char *name);
100   void      SetDirectory(TDirectory *sfile); 
101   void      SetFile(TFile *sfile) {SetDirectory(sfile);} 
102   void SetExternalTree(const char* name, TTree* externalTree);
103  
104 private:
105
106   TTreeSRedirector(const TTreeSRedirector & tsr);
107   TTreeSRedirector & operator=(const TTreeSRedirector & tsr);
108
109   TDirectory* fDirectory;        //file
110   Bool_t      fDirectoryOwner;   //do we own the directory?
111   TObjArray *fDataLayouts;   //array of data layouts
112   ClassDef(TTreeSRedirector,2) 
113 };
114
115
116
117
118 #endif