ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/PhysicsMod/interface/PublisherMod.h
Revision: 1.3
Committed: Tue Dec 9 10:18:33 2008 UTC (16 years, 4 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.2: +50 -12 lines
Log Message:
Tweaks to get modules uptodate.

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.3 // $Id: PublisherMod.h,v 1.2 2008/12/04 13:52:27 loizides Exp $
3 loizides 1.1 //
4     // PublisherMod
5     //
6 loizides 1.3 // This module simply loads a branch and publishes its content into an ObjArray.
7     // Using PublisherPerEvent() one can chose whether the array will be published
8     // globally (ie only in SlaveBegin) or on per-event basis.
9     //
10 loizides 1.1 // Authors: C.Loizides
11     //--------------------------------------------------------------------------------------------------
12    
13     #ifndef MITANA_PHYSICSMOD_PUBLISHERMOD_H
14     #define MITANA_PHYSICSMOD_PUBLISHERMOD_H
15    
16     #include "MitAna/TreeMod/interface/BaseMod.h"
17     #include "MitAna/DataTree/interface/Collections.h"
18    
19     namespace mithep
20     {
21     template<class T>
22     class PublisherMod : public BaseMod
23     {
24     public:
25     PublisherMod(const char *name="PublisherMod",
26     const char *title="Publisher module");
27     ~PublisherMod() {}
28    
29 loizides 1.3 const char *GetBranchName() const { return fBranchName; }
30     const char *GetPublicName() const { return fPublicName; }
31     Bool_t GetPubPerEvent() const { return fPubPerEvent; }
32     void SetBranchName(const char *n) { fBranchName=n; }
33     void SetPublicName(const char *n) { fPublicName=n; }
34     void PublishPerEvent(Bool_t b) { fPubPerEvent = b; }
35 loizides 1.1
36     protected:
37     TString fBranchName; //name of collection
38     TString fPublicName; //name of collection
39 loizides 1.3 Bool_t fPubPerEvent; //=true then publish per event (def=1)
40     const Collection<T> *fColIn; //!pointer to collection (in)
41     ObjArray<T> *fColOut; //!pointer to collection (out)
42 loizides 1.1
43     void Process();
44     void SlaveBegin();
45 loizides 1.3 void SlaveTerminate();
46 loizides 1.1
47 loizides 1.2 ClassDefT(PublisherMod,1) // Publisher module
48 loizides 1.1 };
49     }
50    
51     //--------------------------------------------------------------------------------------------------
52     template<class T>
53     mithep::PublisherMod<T>::PublisherMod(const char *name, const char *title) :
54     BaseMod(name,title),
55 loizides 1.3 fBranchName("SetMe"),
56 loizides 1.1 fPublicName(""),
57 loizides 1.3 fPubPerEvent(kTRUE),
58     fColIn(0),
59     fColOut(0)
60 loizides 1.1 {
61     // Constructor.
62     }
63    
64     //--------------------------------------------------------------------------------------------------
65     template<class T>
66     void mithep::PublisherMod<T>::Process()
67     {
68 loizides 1.3 // Load the branch, add pointers to the object array. Publish object array if needed.
69 loizides 1.1
70     LoadBranch(GetBranchName());
71 loizides 1.3 if (fPubPerEvent)
72     fColOut = new mithep::ObjArray<T>(0, GetPublicName());
73     else
74     fColOut->Reset();
75    
76     UInt_t entries = fColIn->GetEntries();
77     for(UInt_t i=0; i<entries; ++i)
78     fColOut->Add(fColIn->At(i));
79    
80     if (fPubPerEvent)
81     AddObjThisEvt(fColOut);
82 loizides 1.1 }
83    
84     //--------------------------------------------------------------------------------------------------
85     template<class T>
86     void mithep::PublisherMod<T>::SlaveBegin()
87     {
88 loizides 1.3 // Request the branch to be published. Depending on the user's decision publish the array.
89 loizides 1.1
90 loizides 1.3 ReqBranch(GetBranchName(), fColIn);
91 loizides 1.1
92     if (fPublicName.IsNull())
93     fPublicName = fBranchName;
94 loizides 1.3
95     if (!GetPubPerEvent()) {
96     fColOut = new mithep::ObjArray<T>(0, GetPublicName());
97     PublishObj(fColOut);
98     }
99     }
100    
101     //--------------------------------------------------------------------------------------------------
102     template<class T>
103     void mithep::PublisherMod<T>::SlaveTerminate()
104     {
105     // Cleanup in case objects are published only once.
106    
107     if (!fPubPerEvent) {
108     RetractObj(GetPublicName());
109     delete fColOut;
110     }
111 loizides 1.1 }
112     #endif