ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAMBranchInfo.h
Revision: 1.2
Committed: Thu Dec 4 13:50:56 2008 UTC (16 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -1 lines
Log Message:
Have TAModule::ls

File Contents

# User Rev Content
1 loizides 1.1 //
2 loizides 1.2 // $Id: TAMBranchInfo.h,v 1.1 2008/05/27 19:13:21 loizides Exp $
3 loizides 1.1 //
4    
5     #ifndef ROOT_TAMBranchInfo
6     #define ROOT_TAMBranchInfo
7    
8    
9     #include <vector>
10     using std::vector;
11    
12    
13     #include <typeinfo>
14    
15    
16     #ifndef ROOT_TNamed
17     #include "TNamed.h"
18     #endif
19     #ifndef ROOT_TError
20     #include "TError.h"
21     #endif
22    
23    
24     class TTree;
25     class TAMVirtualBranchLoader;
26    
27    
28     typedef void* BranchAddr_t;
29    
30     struct TAMBranchInfo : TNamed {
31     // Stores the name and pointers to requested branches.
32     // Inherits from TObject to allow storage in a THashTable
33    
34     struct BranchPtr_t {
35     // In ROOT v4.0.8 (and prior) rootcint had trouble with a vector<void**>,
36     // so instead we make a small struct to store the void** and use
37     // a vector of the structs.
38     //
39     // Also serves as an abstract base class for the type-storing class
40     // this allows the minimum number of functions & classes to be
41     // templated.
42    
43     BranchAddr_t *fPtr; // pointer to the TAModule's pointer to the branch object
44     BranchPtr_t(BranchAddr_t* ptr) : fPtr(ptr) {}
45     virtual ~BranchPtr_t() { (*fPtr) = 0; }
46     virtual const type_info& GetType() const=0;
47     };
48    
49     template <typename T>
50     struct TAMTypedBrPtr : BranchPtr_t {
51     TAMTypedBrPtr(BranchAddr_t* ptr) : BranchPtr_t(ptr) {}
52     virtual ~TAMTypedBrPtr() {}
53     virtual const type_info& GetType() const { return typeid(T); }
54     };
55    
56     Bool_t fIsLoaded; //=true if the branch is loaded for current event
57     TAMVirtualBranchLoader *fLoader; //our data (tree) loader
58     vector<BranchPtr_t*> fUsrAddresses; //list of pointers to each TAModule's pointer to branch object
59    
60     TAMBranchInfo(const Char_t* branchName=0);
61     virtual ~TAMBranchInfo();
62    
63     template <typename T> Bool_t AddPtr(T*& address);
64     Int_t GetEntry(Long64_t entry);
65     TAMVirtualBranchLoader *GetLoader() const { return fLoader; }
66     const type_info& GetType() const { return fUsrAddresses.empty() ?
67     typeid(void) : fUsrAddresses[0]->GetType(); }
68     void Init();
69     Bool_t IsLoaded() const { return fIsLoaded; }
70     using TObject::Notify;
71     Bool_t Notify(TTree* tree);
72     void SetUsrAddrs();
73     void SetLoader(TAMVirtualBranchLoader *loader) { fLoader = loader; }
74     void ZeroUsrAddrs();
75    
76     ClassDef(TAMBranchInfo,0) // General per branch information
77     };
78    
79    
80     //______________________________________________________________________________
81     template <typename T>
82     inline Bool_t TAMBranchInfo::AddPtr(T*& address)
83     {
84     // Add a user pointer for this branch.
85    
86     // Must do an explicit cast to BranchAddr_t*
87     BranchAddr_t* adr = reinterpret_cast<BranchAddr_t*>(&address);
88     fUsrAddresses.push_back(new TAMTypedBrPtr<T>(adr));
89 loizides 1.2
90 loizides 1.1 return kTRUE;
91     }
92    
93    
94     #endif //ROOT_TAMBranchInfo