ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAMSelector.h
Revision: 1.1
Committed: Tue May 27 19:13:21 2008 UTC (16 years, 11 months ago) by loizides
Content type: text/plain
Branch: MAIN
Log Message:
TAM trunk 5120

File Contents

# User Rev Content
1 loizides 1.1 //
2     // $Id: TAMSelector.h 3116 2006-07-30 22:11:44Z loizides $
3     //
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    
38    
39     class TAMSelector : public TSelector {
40     private:
41    
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     TObject* fObj; // the object
49     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    
54     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     UInt_t fObjCounter; //keep object counter for resetting it in the process loop
65     UInt_t fVerbosity; //true if one wants to print debug info
66     TList fLoaders; //list of data loaders
67    
68     void AddNewOutputLists();
69     void ClearAllLoaders();
70     void CopyModsFromInput();
71     Bool_t FindLoader(TAMBranchInfo* brInfo);
72     void TakeModsFromInput();
73     void TakeLoadersFromInput();
74     void ZeroAllBranches();
75    
76     public:
77     TAMSelector();
78     virtual ~TAMSelector();
79    
80     void AbortAnalysis();
81     void AbortEvent();
82     void AbortModule(TAModule* mod);
83     virtual void AddInput(TAModule* mod);
84     void AddLoader(TAMVirtualLoader *loader) { fLoaders.AddLast(loader); }
85     virtual Bool_t AddObjThisEvt(TObject* obj);
86     virtual Bool_t AddObjThisEvt(TObject* obj, const char *name);
87     void Begin(TTree* tree);
88     TAMOutput *FindModOutput(const TAModule* mod);
89     virtual TObject *FindObjThisEvt(const Char_t* name) const;
90     virtual TObject *FindPublicObj(const Char_t* name) const;
91     Long64_t GetCurEvt() const { return fCurEvt; }
92     TFile* GetCurrentFile() const;
93     const TAMOutput *GetModOutput() const;
94     TAMOutput *GetModOutput();
95     UInt_t GetVerbosity() const { return fVerbosity; }
96     void Init(TTree* tree);
97     Bool_t IsAModAborted() const { return fModAborted; }
98     Bool_t IsEventAborted() const { return fEventAborted; }
99     Bool_t IsAnalysisAborted() const { return fAnalysisAborted; }
100     void LoadBranch(const Char_t* bname);
101     Bool_t Notify();
102     Bool_t Process(Int_t entry) { return Process(static_cast<Long64_t>(entry)); }
103     Bool_t Process(Long64_t entry);
104     virtual Bool_t PublishObj(TObject* obj);
105     template <typename T>
106     void ReqBranch(const Char_t* bname, T*& address);
107     virtual TObject *RemoveObjThisEvt(const Char_t* name);
108     virtual TObject *RetractObj(const Char_t* name);
109     void SetVerbosity(UInt_t vb) { fVerbosity = vb; }
110     void SlaveBegin(TTree* tree);
111     void SlaveTerminate();
112     void Terminate();
113     Int_t Version() const { return 1; }
114    
115     ClassDef(TAMSelector,7)
116     };
117    
118    
119     //______________________________________________________________________________
120     template <typename T>
121     inline void TAMSelector::ReqBranch(const Char_t* bname, T*& address)
122     {
123     // Tells the selector that a branch with the given name may be
124     // used by an TAModule and that the the module will access the branch
125     // using the pointer 'address'.
126    
127     TAMBranchInfo* brInfo = dynamic_cast<TAMBranchInfo*>( fBranchTable.FindObject(bname) );
128    
129     if (brInfo==0) {
130     brInfo = new TAMBranchInfo(bname);
131     fBranchTable.Add(brInfo);
132     }
133    
134     if (!brInfo->AddPtr(address)) AbortAnalysis();
135     }
136    
137     #endif //ROOT_TAMSelector