ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAMBranchInfo.h
Revision: 1.4
Committed: Mon Jul 13 19:20:24 2009 UTC (15 years, 9 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, HEAD
Branch point for: Mit_025c_branch
Changes since 1.3: +20 -10 lines
Log Message:
Cleanup

File Contents

# Content
1 //
2 // $Id: TAMBranchInfo.h,v 1.3 2009/01/20 12:21:48 loizides Exp $
3 //
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
44 // pointer to the branch object
45 BranchPtr_t(BranchAddr_t* ptr) : fPtr(ptr) {}
46 virtual ~BranchPtr_t() { (*fPtr) = 0; }
47 virtual const type_info& GetType() const=0;
48 };
49
50 template <typename T>
51 struct TAMTypedBrPtr : BranchPtr_t {
52 TAMTypedBrPtr(BranchAddr_t* ptr) : BranchPtr_t(ptr) {}
53 virtual ~TAMTypedBrPtr() {}
54 virtual const type_info& GetType() const { return typeid(T); }
55 };
56
57 Bool_t fIsLoaded; //if branch is loaded
58 // for current event
59 TAMVirtualBranchLoader *fLoader; //our data (tree) loader
60 vector<BranchPtr_t*> fUsrAddresses; //list of pointers to each
61 // mod's ptr to branch object
62
63 TAMBranchInfo(const Char_t* branchName=0);
64 virtual ~TAMBranchInfo();
65
66 template <typename T> Bool_t AddPtr(T*& address);
67 Int_t GetEntry(Long64_t entry);
68 TAMVirtualBranchLoader *GetLoader() const { return fLoader; }
69 const type_info& GetType() const;
70 void Init();
71 Bool_t IsLoaded() const { return fIsLoaded; }
72 using TObject::Notify;
73 Bool_t Notify(TTree* tree);
74 void SetUsrAddrs();
75 void SetLoader(TAMVirtualBranchLoader *loader)
76 { fLoader = loader; }
77 void ZeroUsrAddrs();
78
79 ClassDef(TAMBranchInfo,0) // General per branch information
80 };
81
82
83 //______________________________________________________________________________
84 template <typename T>
85 inline Bool_t TAMBranchInfo::AddPtr(T*& address)
86 {
87 // Add a user pointer for this branch.
88
89 // Must do an explicit cast to BranchAddr_t*
90 BranchAddr_t* adr = reinterpret_cast<BranchAddr_t*>(&address);
91 fUsrAddresses.push_back(new TAMTypedBrPtr<T>(adr));
92 return kTRUE;
93 }
94
95 //______________________________________________________________________________
96 inline const type_info &TAMBranchInfo::GetType() const
97 {
98 // Return type of user address.
99
100 return fUsrAddresses.empty() ? typeid(void) : fUsrAddresses[0]->GetType();
101 }
102
103 #endif //ROOT_TAMBranchInfo