ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAMSelector.h
Revision: 1.12
Committed: Mon Jul 13 19:20:24 2009 UTC (15 years, 9 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.11: +34 -22 lines
Log Message:
Cleanup

File Contents

# User Rev Content
1 loizides 1.1 //
2 loizides 1.12 // $Id: TAMSelector.h,v 1.11 2009/03/02 12:34:51 loizides 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 loizides 1.12 // If SetDoProxy(kTRUE) is called TRef branch auto-loading will be done
57     // via TAM loaders.
58 loizides 1.11 public:
59     BranchProxy(TAMSelector *sel, Bool_t e=kFALSE);
60 loizides 1.12 virtual ~BranchProxy();
61 loizides 1.11 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 loizides 1.12 THashTable fEventObjs; //!table of objects available to any mod
79     // while the current event is processed
80     TAModule *fAModules; //!the top-most TAModule. Nothing but a
81     // container for more modules
82 loizides 1.1 Long64_t fCurEvt; //!the current event
83 loizides 1.12 TList *fOwnInput; //!keep pointer to own input list
84     // in case it was created by us
85     Bool_t fAnalysisAborted; //!if the analysis should be aborted
86     Bool_t fModAborted; //!if >=1 modules(s) are aborted
87     Bool_t fEventAborted; //!if the current event should be aborted
88     Bool_t fActNotify; //!if notify is active
89     // (avoiding recursive calls of Notify())
90     UInt_t fObjCounter; //!keep object counter for resetting it
91     // in the process loop
92     UInt_t fObjCounterRun; //!keep object counter for resetting it
93     // in process when end of run is reached
94     UInt_t fVerbosity; //if one wants to print debug info
95     BranchProxy fProxy; //proxy for reference resolving branch
96     // loading via TAM
97     Bool_t fDoProxy; //if TAMSelector should be proxy for
98     // TRef branch autoloads
99     Bool_t fDoObjTabClean; //true if TAMSelector should clean the
100     // object tables of process id's
101     Bool_t fObjTabClean; //bool to track whether object tables of
102     // process id's are currently clean
103 loizides 1.1 TList fLoaders; //list of data loaders
104    
105     void AddNewOutputLists();
106 bendavid 1.9 void CleanObjTable(TProcessID *pid, UInt_t lastKeptUID) const;
107 loizides 1.1 void ClearAllLoaders();
108     void CopyModsFromInput();
109     Bool_t FindLoader(TAMBranchInfo* brInfo);
110 loizides 1.7 void LoadBranch(TAMBranchInfo* brInfo);
111 loizides 1.1 void TakeModsFromInput();
112     void TakeLoadersFromInput();
113     void ZeroAllBranches();
114    
115     public:
116     TAMSelector();
117     virtual ~TAMSelector();
118    
119     void AbortAnalysis();
120     void AbortEvent();
121     void AbortModule(TAModule* mod);
122     virtual void AddInput(TAModule* mod);
123 loizides 1.12 void AddLoader(TAMVirtualLoader *loader)
124     { fLoaders.AddLast(loader); }
125 loizides 1.1 virtual Bool_t AddObjThisEvt(TObject* obj);
126     virtual Bool_t AddObjThisEvt(TObject* obj, const char *name);
127     void Begin(TTree* tree);
128 loizides 1.12 virtual Bool_t BeginRun() { return kFALSE; }
129     virtual Bool_t EndRun() { return kFALSE; }
130 loizides 1.1 TAMOutput *FindModOutput(const TAModule* mod);
131     virtual TObject *FindObjThisEvt(const Char_t* name) const;
132     virtual TObject *FindPublicObj(const Char_t* name) const;
133     Long64_t GetCurEvt() const { return fCurEvt; }
134 loizides 1.3 const TFile *GetCurrentFile() const;
135     TFile *GetCurrentFile();
136 loizides 1.1 const TAMOutput *GetModOutput() const;
137     TAMOutput *GetModOutput();
138 bendavid 1.10 TObject *GetObjectWithID(UInt_t uid, TProcessID *pid);
139 loizides 1.11 const TAModule *GetTopModule() const { return fAModules; }
140     const TTree *GetTree() const { return fTree; }
141     Bool_t GetObjTabClean() const { return fObjTabClean; }
142     TTree *GetTree() { return fTree; }
143     UInt_t GetVerbosity() const { return fVerbosity; }
144 loizides 1.1 void Init(TTree* tree);
145 loizides 1.11 Bool_t IsAModAborted() const { return fModAborted; }
146     Bool_t IsEventAborted() const { return fEventAborted; }
147 loizides 1.1 Bool_t IsAnalysisAborted() const { return fAnalysisAborted; }
148     void LoadBranch(const Char_t* bname);
149     Bool_t Notify();
150 loizides 1.12 Bool_t Process(Int_t entry)
151     { return Process(static_cast<Long64_t>(entry)); }
152 loizides 1.1 Bool_t Process(Long64_t entry);
153     virtual Bool_t PublishObj(TObject* obj);
154     template <typename T>
155     void ReqBranch(const Char_t* bname, T*& address);
156     virtual TObject *RemoveObjThisEvt(const Char_t* name);
157     virtual TObject *RetractObj(const Char_t* name);
158 loizides 1.11 void SetDoProxy(Bool_t b) { fDoProxy = b; }
159     void SetDoObjTabClean(Bool_t b) { fDoObjTabClean = b; }
160     void SetVerbosity(UInt_t vb) { fVerbosity = vb; }
161 loizides 1.1 void SlaveBegin(TTree* tree);
162     void SlaveTerminate();
163     void Terminate();
164     Int_t Version() const { return 1; }
165    
166 loizides 1.4 ClassDef(TAMSelector,8)
167 loizides 1.1 };
168    
169    
170     //______________________________________________________________________________
171     template <typename T>
172     inline void TAMSelector::ReqBranch(const Char_t* bname, T*& address)
173     {
174     // Tells the selector that a branch with the given name may be
175     // used by an TAModule and that the the module will access the branch
176     // using the pointer 'address'.
177    
178 loizides 1.4 TAMBranchInfo* brInfo =
179     dynamic_cast<TAMBranchInfo*>( fBranchTable.FindObject(bname) );
180 loizides 1.1
181     if (brInfo==0) {
182     brInfo = new TAMBranchInfo(bname);
183     fBranchTable.Add(brInfo);
184     }
185    
186 loizides 1.8 if (!brInfo->AddPtr(address))
187     AbortAnalysis();
188 loizides 1.1 }
189     #endif //ROOT_TAMSelector