ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/PhysicsMod/interface/MergerMod.h
Revision: 1.2
Committed: Sun Jan 24 21:00:19 2010 UTC (15 years, 3 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, HEAD
Branch point for: Mit_025c_branch
Changes since 1.1: +2 -2 lines
Log Message:
Fix compiler errors and warnings moving to slc5_ia32_gcc434

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: MergerMod.h,v 1.1 2009/10/22 18:44:14 loizides Exp $
3 //
4 // MergerMod
5 //
6 // This templated module merges arbitrarily many collections of objects. It puts them into an
7 // object array of the templated type.
8 //
9 // Authors: C.Loizides
10 //--------------------------------------------------------------------------------------------------
11
12 #ifndef MITANA_PHYSICSMOD_MERGERMOD_H
13 #define MITANA_PHYSICSMOD_MERGERMOD_H
14
15 #include "MitAna/TreeMod/interface/BaseMod.h"
16 #include "MitAna/DataCont/interface/ObjArray.h"
17
18 namespace mithep
19 {
20 template <class T>
21 class MergerMod : public BaseMod
22 {
23 public:
24 MergerMod(const char *name="MergerMod",
25 const char *title="Merger module");
26
27 void AddInputName(const char *n);
28 const char *GetMergedName() const { return fMergedName; }
29 const char *GetOutputName() const { return GetMergedName(); }
30 void SetMergedName(const char *n) { fMergedName=n; }
31 void SetOutputName(const char *n) { SetMergedName(n); }
32
33 protected:
34 void SlaveBegin();
35 void Process();
36
37 std::vector<std::string> fInList; //list of to be merged objects (input)
38 TString fMergedName; //name of merged collection (output)
39
40 ClassDef(MergerMod, 1) // Generic collection merging module
41 };
42 }
43 #endif
44
45 //--------------------------------------------------------------------------------------------------
46 template <class T>
47 mithep::MergerMod<T>::MergerMod(const char *name, const char *title) :
48 BaseMod(name,title),
49 fInList(0)
50 {
51 // Constructor.
52 }
53
54 template <class T>
55 void mithep::MergerMod<T>::AddInputName(const char *n)
56 {
57 // Add name to the list of input collections.
58
59 if (!n)
60 return;
61 fInList.push_back(std::string(n));
62 }
63
64 //--------------------------------------------------------------------------------------------------
65 template <class T>
66 void mithep::MergerMod<T>::Process()
67 {
68 // Merge the input objects and publish merged collection.
69
70 ObjArray<T> *colout = new mithep::ObjArray<T>(0);
71 colout->SetName(GetMergedName());
72
73 UInt_t n = fInList.size();
74 for (UInt_t i=0; i<n; ++i) {
75 const TObject *in = GetObjThisEvt<TObject>(fInList.at(i).c_str());
76 if (!in)
77 continue;
78
79 const BaseCollection *bcol = dynamic_cast<const BaseCollection*>(in);
80 if (bcol)
81 colout->Add(bcol);
82 else {
83 const T *optr = dynamic_cast<const T*>(in);
84 if (optr)
85 colout->Add(optr);
86 }
87 }
88
89 // attempt sorting (if implemented by underlying objects)
90 colout->Sort();
91
92 // add to event for other modules to use
93 AddObjThisEvt(colout);
94 }
95
96 //--------------------------------------------------------------------------------------------------
97 template <class T>
98 void mithep::MergerMod<T>::SlaveBegin()
99 {
100 // Check if output name was set.
101
102 if (!fMergedName.IsNull())
103 return;
104
105 SendError(kAbortModule, "SlaveBegin", "No output name given.");
106 }