1 |
loizides |
1.1 |
//--------------------------------------------------------------------------------------------------
|
2 |
loizides |
1.8 |
// $Id: PublisherMod.h,v 1.7 2009/05/12 18:41:40 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 |
bendavid |
1.6 |
template<class TIn, class TOut=TIn>
|
22 |
loizides |
1.1 |
class PublisherMod : public BaseMod
|
23 |
|
|
{
|
24 |
|
|
public:
|
25 |
|
|
PublisherMod(const char *name="PublisherMod",
|
26 |
|
|
const char *title="Publisher module");
|
27 |
|
|
|
28 |
loizides |
1.5 |
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 |
loizides |
1.1 |
|
39 |
|
|
protected:
|
40 |
|
|
TString fBranchName; //name of collection
|
41 |
|
|
TString fPublicName; //name of collection
|
42 |
loizides |
1.3 |
Bool_t fPubPerEvent; //=true then publish per event (def=1)
|
43 |
bendavid |
1.6 |
const Collection<TIn> *fColIn; //!pointer to collection (in)
|
44 |
|
|
ObjArray<TOut> *fColOut; //!pointer to collection (out)
|
45 |
loizides |
1.1 |
|
46 |
|
|
void Process();
|
47 |
|
|
void SlaveBegin();
|
48 |
loizides |
1.3 |
void SlaveTerminate();
|
49 |
loizides |
1.1 |
|
50 |
loizides |
1.4 |
ClassDefT(PublisherMod, 1) // Publisher module
|
51 |
loizides |
1.1 |
};
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
//--------------------------------------------------------------------------------------------------
|
55 |
bendavid |
1.6 |
template<class TIn, class TOut>
|
56 |
|
|
mithep::PublisherMod<TIn, TOut>::PublisherMod(const char *name, const char *title) :
|
57 |
loizides |
1.1 |
BaseMod(name,title),
|
58 |
loizides |
1.3 |
fBranchName("SetMe"),
|
59 |
loizides |
1.1 |
fPublicName(""),
|
60 |
loizides |
1.3 |
fPubPerEvent(kTRUE),
|
61 |
|
|
fColIn(0),
|
62 |
|
|
fColOut(0)
|
63 |
loizides |
1.1 |
{
|
64 |
|
|
// Constructor.
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
//--------------------------------------------------------------------------------------------------
|
68 |
bendavid |
1.6 |
template<class TIn, class TOut>
|
69 |
|
|
void mithep::PublisherMod<TIn, TOut>::Process()
|
70 |
loizides |
1.1 |
{
|
71 |
loizides |
1.3 |
// Load the branch, add pointers to the object array. Publish object array if needed.
|
72 |
loizides |
1.1 |
|
73 |
|
|
LoadBranch(GetBranchName());
|
74 |
loizides |
1.3 |
if (fPubPerEvent)
|
75 |
bendavid |
1.6 |
fColOut = new mithep::ObjArray<TOut>(0, GetPublicName());
|
76 |
loizides |
1.3 |
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 |
loizides |
1.1 |
}
|
86 |
|
|
|
87 |
|
|
//--------------------------------------------------------------------------------------------------
|
88 |
bendavid |
1.6 |
template<class TIn, class TOut>
|
89 |
|
|
void mithep::PublisherMod<TIn, TOut>::SlaveBegin()
|
90 |
loizides |
1.1 |
{
|
91 |
loizides |
1.3 |
// Request the branch to be published. Depending on the user's decision publish the array.
|
92 |
loizides |
1.1 |
|
93 |
loizides |
1.3 |
ReqBranch(GetBranchName(), fColIn);
|
94 |
loizides |
1.1 |
|
95 |
|
|
if (fPublicName.IsNull())
|
96 |
loizides |
1.8 |
fPublicName = GetBranchName();
|
97 |
loizides |
1.3 |
|
98 |
|
|
if (!GetPubPerEvent()) {
|
99 |
bendavid |
1.6 |
fColOut = new mithep::ObjArray<TOut>(0, GetPublicName());
|
100 |
loizides |
1.3 |
PublishObj(fColOut);
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
//--------------------------------------------------------------------------------------------------
|
105 |
bendavid |
1.6 |
template<class TIn, class TOut>
|
106 |
|
|
void mithep::PublisherMod<TIn, TOut>::SlaveTerminate()
|
107 |
loizides |
1.3 |
{
|
108 |
|
|
// Cleanup in case objects are published only once.
|
109 |
|
|
|
110 |
|
|
if (!fPubPerEvent) {
|
111 |
|
|
RetractObj(GetPublicName());
|
112 |
|
|
delete fColOut;
|
113 |
|
|
}
|
114 |
loizides |
1.1 |
}
|
115 |
|
|
#endif
|