1 |
//--------------------------------------------------------------------------------------------------
|
2 |
// $Id: PublisherMod.h,v 1.3 2008/12/09 10:18:33 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 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 |
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 |
|
36 |
protected:
|
37 |
TString fBranchName; //name of collection
|
38 |
TString fPublicName; //name of collection
|
39 |
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 |
|
43 |
void Process();
|
44 |
void SlaveBegin();
|
45 |
void SlaveTerminate();
|
46 |
|
47 |
ClassDefT(PublisherMod, 1) // Publisher module
|
48 |
};
|
49 |
}
|
50 |
|
51 |
//--------------------------------------------------------------------------------------------------
|
52 |
template<class T>
|
53 |
mithep::PublisherMod<T>::PublisherMod(const char *name, const char *title) :
|
54 |
BaseMod(name,title),
|
55 |
fBranchName("SetMe"),
|
56 |
fPublicName(""),
|
57 |
fPubPerEvent(kTRUE),
|
58 |
fColIn(0),
|
59 |
fColOut(0)
|
60 |
{
|
61 |
// Constructor.
|
62 |
}
|
63 |
|
64 |
//--------------------------------------------------------------------------------------------------
|
65 |
template<class T>
|
66 |
void mithep::PublisherMod<T>::Process()
|
67 |
{
|
68 |
// Load the branch, add pointers to the object array. Publish object array if needed.
|
69 |
|
70 |
LoadBranch(GetBranchName());
|
71 |
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 |
}
|
83 |
|
84 |
//--------------------------------------------------------------------------------------------------
|
85 |
template<class T>
|
86 |
void mithep::PublisherMod<T>::SlaveBegin()
|
87 |
{
|
88 |
// Request the branch to be published. Depending on the user's decision publish the array.
|
89 |
|
90 |
ReqBranch(GetBranchName(), fColIn);
|
91 |
|
92 |
if (fPublicName.IsNull())
|
93 |
fPublicName = fBranchName;
|
94 |
|
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 |
}
|
112 |
#endif
|