ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAMSelector.h
Revision: 1.3
Committed: Sat Sep 27 06:02:54 2008 UTC (16 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_004
Changes since 1.2: +4 -2 lines
Log Message:
Added const GetCurrentFile, plus use rehash in THashTables.

File Contents

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