ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/PhysicsMod/interface/PublisherMod.h
Revision: 1.6
Committed: Wed Mar 11 18:13:10 2009 UTC (16 years, 1 month ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009, Mit_008, Mit_008pre2
Changes since 1.5: +14 -14 lines
Log Message:
Added second template parameter to publisher mod for base type output

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: PublisherMod.h,v 1.5 2008/12/12 16:03:34 loizides Exp $
3 //
4 // PublisherMod
5 //
6 // 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 // 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 TIn, class TOut=TIn>
22 class PublisherMod : public BaseMod
23 {
24 public:
25 PublisherMod(const char *name="PublisherMod",
26 const char *title="Publisher module");
27 ~PublisherMod() {}
28
29 const char *GetBranchName() const { return fBranchName; }
30 const char *GetInputName() const { return GetBranchName(); }
31 const char *GetOutputName() const { return GetPublicName(); }
32 const char *GetPublicName() const { return fPublicName; }
33 Bool_t GetPubPerEvent() const { return fPubPerEvent; }
34 void SetBranchName(const char *n) { fBranchName=n; }
35 void SetInputName(const char *n) { SetBranchName(n); }
36 void SetOutputName(const char *n) { SetPublicName(n); }
37 void SetPublicName(const char *n) { fPublicName=n; }
38 void PublishPerEvent(Bool_t b) { fPubPerEvent = b; }
39
40 protected:
41 TString fBranchName; //name of collection
42 TString fPublicName; //name of collection
43 Bool_t fPubPerEvent; //=true then publish per event (def=1)
44 const Collection<TIn> *fColIn; //!pointer to collection (in)
45 ObjArray<TOut> *fColOut; //!pointer to collection (out)
46
47 void Process();
48 void SlaveBegin();
49 void SlaveTerminate();
50
51 ClassDefT(PublisherMod, 1) // Publisher module
52 };
53 }
54
55 //--------------------------------------------------------------------------------------------------
56 template<class TIn, class TOut>
57 mithep::PublisherMod<TIn, TOut>::PublisherMod(const char *name, const char *title) :
58 BaseMod(name,title),
59 fBranchName("SetMe"),
60 fPublicName(""),
61 fPubPerEvent(kTRUE),
62 fColIn(0),
63 fColOut(0)
64 {
65 // Constructor.
66 }
67
68 //--------------------------------------------------------------------------------------------------
69 template<class TIn, class TOut>
70 void mithep::PublisherMod<TIn, TOut>::Process()
71 {
72 // Load the branch, add pointers to the object array. Publish object array if needed.
73
74 LoadBranch(GetBranchName());
75 if (fPubPerEvent)
76 fColOut = new mithep::ObjArray<TOut>(0, GetPublicName());
77 else
78 fColOut->Reset();
79
80 UInt_t entries = fColIn->GetEntries();
81 for(UInt_t i=0; i<entries; ++i)
82 fColOut->Add(fColIn->At(i));
83
84 if (fPubPerEvent)
85 AddObjThisEvt(fColOut);
86 }
87
88 //--------------------------------------------------------------------------------------------------
89 template<class TIn, class TOut>
90 void mithep::PublisherMod<TIn, TOut>::SlaveBegin()
91 {
92 // Request the branch to be published. Depending on the user's decision publish the array.
93
94 ReqBranch(GetBranchName(), fColIn);
95
96 if (fPublicName.IsNull())
97 fPublicName = fBranchName;
98
99 if (!GetPubPerEvent()) {
100 fColOut = new mithep::ObjArray<TOut>(0, GetPublicName());
101 PublishObj(fColOut);
102 }
103 }
104
105 //--------------------------------------------------------------------------------------------------
106 template<class TIn, class TOut>
107 void mithep::PublisherMod<TIn, TOut>::SlaveTerminate()
108 {
109 // Cleanup in case objects are published only once.
110
111 if (!fPubPerEvent) {
112 RetractObj(GetPublicName());
113 delete fColOut;
114 }
115 }
116 #endif