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