ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAMSelector.h
Revision: 1.9
Committed: Tue Feb 17 14:21:42 2009 UTC (16 years, 2 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.8: +2 -1 lines
Log Message:
Add Object table cleaning to speed up Refs

File Contents

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