ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAMSelector.h
Revision: 1.10
Committed: Tue Feb 17 21:54:17 2009 UTC (16 years, 2 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.9: +11 -23 lines
Log Message:
Implemented much cleaner optimized auto loading of branches from refs

File Contents

# User Rev Content
1 loizides 1.1 //
2 bendavid 1.10 // $Id: TAMSelector.h,v 1.9 2009/02/17 14:21:42 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.1 TTree *fTree; //!the tree or chain
55     THashTable fBranchTable; //!table of requested branches
56     THashTable fEventObjs; //!table of objects available to any module while the current event is processed
57     TAModule *fAModules; //!the top-most TAModule. nothing but a container for more modules
58     Long64_t fCurEvt; //!the current event
59     TList *fOwnInput; //!keep pointer to own input list in case it was created by us
60     Bool_t fAnalysisAborted; //!true if the analysis should be aborted
61     Bool_t fModAborted; //!true if one or more modules(s) have been aborted
62     Bool_t fEventAborted; //!true if the current event should be aborted
63     Bool_t fActNotify; //!true if notify is active (avoiding recursive calls of Notify())
64 loizides 1.4 UInt_t fObjCounter; //!keep object counter for resetting it in the process loop
65     UInt_t fObjCounterRun; //!keep object counter for resetting it in the process loop when end of run is reached
66 loizides 1.1 UInt_t fVerbosity; //true if one wants to print debug info
67 bendavid 1.10 Bool_t fDoProxy; //true if TAMSelector should be proxy for Ref branch autoloads
68     Bool_t fDoObjTableCleaning; //true if TAMSelector should clean Object Tables of process id's
69     Bool_t fObjTablesClean; //bool to track whether object tables of process id's are currently clean
70 loizides 1.1 TList fLoaders; //list of data loaders
71 bendavid 1.10 Long64_t fCurEntry; //cache of current entry for TBranchRef
72     Bool_t fBrRead[1024]; //flag which TBranchRef branch was read
73     static TAMSelector *fEvtSelector; //static pointer to event loop selector
74 loizides 1.1
75     void AddNewOutputLists();
76 bendavid 1.9 void CleanObjTable(TProcessID *pid, UInt_t lastKeptUID) const;
77 loizides 1.1 void ClearAllLoaders();
78     void CopyModsFromInput();
79     Bool_t FindLoader(TAMBranchInfo* brInfo);
80 loizides 1.7 void LoadBranch(TAMBranchInfo* brInfo);
81 loizides 1.1 void TakeModsFromInput();
82     void TakeLoadersFromInput();
83     void ZeroAllBranches();
84 loizides 1.4
85 loizides 1.1
86     public:
87     TAMSelector();
88     virtual ~TAMSelector();
89    
90 bendavid 1.10 static TAMSelector *GetEvtSelector() { return fEvtSelector; }
91    
92 loizides 1.1 void AbortAnalysis();
93     void AbortEvent();
94     void AbortModule(TAModule* mod);
95     virtual void AddInput(TAModule* mod);
96     void AddLoader(TAMVirtualLoader *loader) { fLoaders.AddLast(loader); }
97     virtual Bool_t AddObjThisEvt(TObject* obj);
98     virtual Bool_t AddObjThisEvt(TObject* obj, const char *name);
99     void Begin(TTree* tree);
100 loizides 1.2 virtual Bool_t BeginRun() { return kFALSE; }
101     virtual Bool_t EndRun() { return kFALSE; }
102 loizides 1.1 TAMOutput *FindModOutput(const TAModule* mod);
103     virtual TObject *FindObjThisEvt(const Char_t* name) const;
104     virtual TObject *FindPublicObj(const Char_t* name) const;
105     Long64_t GetCurEvt() const { return fCurEvt; }
106 loizides 1.3 const TFile *GetCurrentFile() const;
107     TFile *GetCurrentFile();
108 loizides 1.1 const TAMOutput *GetModOutput() const;
109     TAMOutput *GetModOutput();
110 bendavid 1.10 TObject *GetObjectWithID(UInt_t uid, TProcessID *pid);
111 loizides 1.3 const TAModule *GetTopModule() const { return fAModules; }
112 loizides 1.4 const TTree *GetTree() const { return fTree; }
113     TTree *GetTree() { return fTree; }
114 loizides 1.1 UInt_t GetVerbosity() const { return fVerbosity; }
115     void Init(TTree* tree);
116     Bool_t IsAModAborted() const { return fModAborted; }
117     Bool_t IsEventAborted() const { return fEventAborted; }
118     Bool_t IsAnalysisAborted() const { return fAnalysisAborted; }
119     void LoadBranch(const Char_t* bname);
120     Bool_t Notify();
121     Bool_t Process(Int_t entry) { return Process(static_cast<Long64_t>(entry)); }
122     Bool_t Process(Long64_t entry);
123     virtual Bool_t PublishObj(TObject* obj);
124     template <typename T>
125     void ReqBranch(const Char_t* bname, T*& address);
126     virtual TObject *RemoveObjThisEvt(const Char_t* name);
127     virtual TObject *RetractObj(const Char_t* name);
128 loizides 1.4 void SetDoProxy(Bool_t b) { fDoProxy = b; }
129 bendavid 1.10 void SetDoObjTableCleaning(Bool_t b) { fDoObjTableCleaning = b; }
130 loizides 1.1 void SetVerbosity(UInt_t vb) { fVerbosity = vb; }
131     void SlaveBegin(TTree* tree);
132     void SlaveTerminate();
133     void Terminate();
134     Int_t Version() const { return 1; }
135    
136 loizides 1.4 ClassDef(TAMSelector,8)
137 loizides 1.1 };
138    
139    
140     //______________________________________________________________________________
141     template <typename T>
142     inline void TAMSelector::ReqBranch(const Char_t* bname, T*& address)
143     {
144     // Tells the selector that a branch with the given name may be
145     // used by an TAModule and that the the module will access the branch
146     // using the pointer 'address'.
147    
148 loizides 1.4 TAMBranchInfo* brInfo =
149     dynamic_cast<TAMBranchInfo*>( fBranchTable.FindObject(bname) );
150 loizides 1.1
151     if (brInfo==0) {
152     brInfo = new TAMBranchInfo(bname);
153     fBranchTable.Add(brInfo);
154     }
155    
156 loizides 1.8 if (!brInfo->AddPtr(address))
157     AbortAnalysis();
158 loizides 1.1 }
159    
160 loizides 1.4
161 loizides 1.1 #endif //ROOT_TAMSelector