ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAMSelector.h
Revision: 1.11
Committed: Mon Mar 2 12:34:51 2009 UTC (16 years, 2 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009c, Mit_009b, Mit_009a, Mit_009, Mit_008, Mit_008pre2, Mit_008pre1
Changes since 1.10: +37 -21 lines
Log Message:
BranchProxy that combines previous AutoLoad class with recent changes in TAMSelector.

File Contents

# User Rev Content
1 loizides 1.1 //
2 loizides 1.11 // $Id: TAMSelector.h,v 1.10 2009/02/17 21:54:17 bendavid Exp $
3 loizides 1.1 //
4    
5     #ifndef ROOT_TAMSelector
6     #define ROOT_TAMSelector
7    
8     // keep this for compatibility
9     #define TAM_TAMSelector
10    
11    
12     #ifndef ROOT_TSelector
13     #include "TSelector.h"
14     #endif
15     #ifndef ROOT_THashTable
16     #include "THashTable.h"
17     #endif
18     #ifndef ROOT_List
19     #include "TList.h"
20     #endif
21     #ifndef ROOT_TAMBranchInfo
22     #include "TAMBranchInfo.h"
23     #endif
24     #ifndef ROOT_TAMVirtualLoader
25     #include "TAMVirtualLoader.h"
26     #endif
27     #ifndef ROOT_Riostream
28     #include <Riostream.h>
29     #endif
30    
31    
32     class TBranch;
33     class TTree;
34     class TFile;
35     class TAModule;
36     class TAMOutput;
37 loizides 1.4 class TBranchRef;
38 loizides 1.1
39     class TAMSelector : public TSelector {
40 loizides 1.2 protected:
41 loizides 1.1
42     struct TAMEvtObj : TNamed {
43     // Class for storing event objects:
44     // It assumes ownership of the object.
45     // It is needed to force the THashTable to call Hash on a TNamed
46     // to allow lookup using the hash value given the object's name
47     // (as opposed to its pointer value, as is done for TObject's).
48 loizides 1.4 TObject* fObj; //the object
49 loizides 1.1 TAMEvtObj(TObject* obj) : TNamed(obj->GetName(),0), fObj(obj) {}
50     TAMEvtObj(TObject* obj, const char *name) : TNamed(name,0), fObj(obj) {}
51     virtual ~TAMEvtObj() { if (fObj!=0) delete fObj; }
52     };
53 loizides 1.4
54 loizides 1.11 class BranchProxy : public TObject {
55     // Class that acts as a proxy between the TRefTable, TAM and TBranchRef.
56     // If SetDoProxy(kTRUE) is called TRef branch auto-loading will be done via
57     // TAM loaders.
58     public:
59     BranchProxy(TAMSelector *sel, Bool_t e=kFALSE);
60     virtual ~BranchProxy();
61     void Disable();
62     void Enable();
63     TObject *GetObjectWithID(UInt_t uid, TProcessID *pid);
64     Bool_t Notify();
65    
66     protected:
67     Bool_t Load(UInt_t uid, TProcessID *pid, TBranchRef *br, TRefTable *table);
68    
69     TAMSelector *fSel; //ptr to TAMSelector (we are a friend)
70     TRefTable *fOrig; //ptr to original TRefTable filled by I/O (owner is TBranchRef)
71     TRefTable *fFake; //ptr to our fake TRefTable of which we are owner
72     Long64_t fCurEntry; //cache of current entry
73     Bool_t fBrRead[1024]; //flag which TBranchRef branch was read
74     };
75    
76 loizides 1.1 TTree *fTree; //!the tree or chain
77     THashTable fBranchTable; //!table of requested branches
78     THashTable fEventObjs; //!table of objects available to any module while the current event is processed
79     TAModule *fAModules; //!the top-most TAModule. nothing but a container for more modules
80     Long64_t fCurEvt; //!the current event
81     TList *fOwnInput; //!keep pointer to own input list in case it was created by us
82     Bool_t fAnalysisAborted; //!true if the analysis should be aborted
83     Bool_t fModAborted; //!true if one or more modules(s) have been aborted
84     Bool_t fEventAborted; //!true if the current event should be aborted
85     Bool_t fActNotify; //!true if notify is active (avoiding recursive calls of Notify())
86 loizides 1.4 UInt_t fObjCounter; //!keep object counter for resetting it in the process loop
87     UInt_t fObjCounterRun; //!keep object counter for resetting it in the process loop when end of run is reached
88 loizides 1.1 UInt_t fVerbosity; //true if one wants to print debug info
89 loizides 1.11 BranchProxy fProxy; //proxy for reference resolving branch loading via TAM
90     Bool_t fDoProxy; //true if TAMSelector should be proxy for TRef branch autoloads
91     Bool_t fDoObjTabClean; //true if TAMSelector should clean the object tables of process id's
92     Bool_t fObjTabClean; //bool to track whether object tables of process id's are currently clean
93 loizides 1.1 TList fLoaders; //list of data loaders
94    
95     void AddNewOutputLists();
96 bendavid 1.9 void CleanObjTable(TProcessID *pid, UInt_t lastKeptUID) const;
97 loizides 1.1 void ClearAllLoaders();
98     void CopyModsFromInput();
99     Bool_t FindLoader(TAMBranchInfo* brInfo);
100 loizides 1.7 void LoadBranch(TAMBranchInfo* brInfo);
101 loizides 1.1 void TakeModsFromInput();
102     void TakeLoadersFromInput();
103     void ZeroAllBranches();
104    
105     public:
106     TAMSelector();
107     virtual ~TAMSelector();
108    
109     void AbortAnalysis();
110     void AbortEvent();
111     void AbortModule(TAModule* mod);
112     virtual void AddInput(TAModule* mod);
113     void AddLoader(TAMVirtualLoader *loader) { fLoaders.AddLast(loader); }
114     virtual Bool_t AddObjThisEvt(TObject* obj);
115     virtual Bool_t AddObjThisEvt(TObject* obj, const char *name);
116     void Begin(TTree* tree);
117 loizides 1.2 virtual Bool_t BeginRun() { return kFALSE; }
118     virtual Bool_t EndRun() { return kFALSE; }
119 loizides 1.1 TAMOutput *FindModOutput(const TAModule* mod);
120     virtual TObject *FindObjThisEvt(const Char_t* name) const;
121     virtual TObject *FindPublicObj(const Char_t* name) const;
122     Long64_t GetCurEvt() const { return fCurEvt; }
123 loizides 1.3 const TFile *GetCurrentFile() const;
124     TFile *GetCurrentFile();
125 loizides 1.1 const TAMOutput *GetModOutput() const;
126     TAMOutput *GetModOutput();
127 bendavid 1.10 TObject *GetObjectWithID(UInt_t uid, TProcessID *pid);
128 loizides 1.11 const TAModule *GetTopModule() const { return fAModules; }
129     const TTree *GetTree() const { return fTree; }
130     Bool_t GetObjTabClean() const { return fObjTabClean; }
131     TTree *GetTree() { return fTree; }
132     UInt_t GetVerbosity() const { return fVerbosity; }
133 loizides 1.1 void Init(TTree* tree);
134 loizides 1.11 Bool_t IsAModAborted() const { return fModAborted; }
135     Bool_t IsEventAborted() const { return fEventAborted; }
136 loizides 1.1 Bool_t IsAnalysisAborted() const { return fAnalysisAborted; }
137     void LoadBranch(const Char_t* bname);
138     Bool_t Notify();
139     Bool_t Process(Int_t entry) { return Process(static_cast<Long64_t>(entry)); }
140     Bool_t Process(Long64_t entry);
141     virtual Bool_t PublishObj(TObject* obj);
142     template <typename T>
143     void ReqBranch(const Char_t* bname, T*& address);
144     virtual TObject *RemoveObjThisEvt(const Char_t* name);
145     virtual TObject *RetractObj(const Char_t* name);
146 loizides 1.11 void SetDoProxy(Bool_t b) { fDoProxy = b; }
147     void SetDoObjTabClean(Bool_t b) { fDoObjTabClean = b; }
148     void SetVerbosity(UInt_t vb) { fVerbosity = vb; }
149 loizides 1.1 void SlaveBegin(TTree* tree);
150     void SlaveTerminate();
151     void Terminate();
152     Int_t Version() const { return 1; }
153    
154 loizides 1.4 ClassDef(TAMSelector,8)
155 loizides 1.1 };
156    
157    
158     //______________________________________________________________________________
159     template <typename T>
160     inline void TAMSelector::ReqBranch(const Char_t* bname, T*& address)
161     {
162     // Tells the selector that a branch with the given name may be
163     // used by an TAModule and that the the module will access the branch
164     // using the pointer 'address'.
165    
166 loizides 1.4 TAMBranchInfo* brInfo =
167     dynamic_cast<TAMBranchInfo*>( fBranchTable.FindObject(bname) );
168 loizides 1.1
169     if (brInfo==0) {
170     brInfo = new TAMBranchInfo(bname);
171     fBranchTable.Add(brInfo);
172     }
173    
174 loizides 1.8 if (!brInfo->AddPtr(address))
175     AbortAnalysis();
176 loizides 1.1 }
177     #endif //ROOT_TAMSelector