ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/PhysicsMod/interface/PublisherMod.h
Revision: 1.7
Committed: Tue May 12 18:41:40 2009 UTC (15 years, 11 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.6: +1 -2 lines
Log Message:
Save number of triggered events.

File Contents

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