ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/PhysicsMod/interface/PublisherMod.h
(Generate patch)

Comparing UserCode/MitAna/PhysicsMod/interface/PublisherMod.h (file contents):
Revision 1.2 by loizides, Thu Dec 4 13:52:27 2008 UTC vs.
Revision 1.7 by loizides, Tue May 12 18:41:40 2009 UTC

# Line 3 | Line 3
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  
# Line 14 | Line 18
18  
19   namespace mithep
20   {
21 <  template<class T>
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");
23      ~PublisherMod() {}
27  
28 <      const char              *GetBranchName()              const { return fBranchName; }
29 <      void                     SetBranchName(const char *n)       { fBranchName=n; }
30 <      const char              *GetPublicName()              const { return fPublicName; }
31 <      void                     SetPublicName(const char *n)       { fPublicName=n; }
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 <      T                       *fObj;           //!pointer to 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
50 >      ClassDefT(PublisherMod, 1) // Publisher module
51    };
52   }
53  
54   //--------------------------------------------------------------------------------------------------
55 < template<class T>
56 < mithep::PublisherMod<T>::PublisherMod(const char *name, const char *title) :
55 > template<class TIn, class TOut>
56 > mithep::PublisherMod<TIn, TOut>::PublisherMod(const char *name, const char *title) :
57    BaseMod(name,title),
58 <  fBranchName(""),
58 >  fBranchName("SetMe"),
59    fPublicName(""),
60 <  fObj(0)
60 >  fPubPerEvent(kTRUE),
61 >  fColIn(0),
62 >  fColOut(0)
63   {
64    // Constructor.
65   }
66  
67   //--------------------------------------------------------------------------------------------------
68 < template<class T>
69 < void mithep::PublisherMod<T>::Process()
68 > template<class TIn, class TOut>
69 > void mithep::PublisherMod<TIn, TOut>::Process()
70   {
71 <  // Process entries of the tree: Just load the branch and fill the histograms.
71 >  // Load the branch, add pointers to the object array. Publish object array if needed.
72  
73    LoadBranch(GetBranchName());
74 <  AddObjThisEvt(fObj, GetPublicName());
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 T>
89 < void mithep::PublisherMod<T>::SlaveBegin()
88 > template<class TIn, class TOut>
89 > void mithep::PublisherMod<TIn, TOut>::SlaveBegin()
90   {
91 <  // Request a branch and create the histograms.
91 >  // Request the branch to be published. Depending on the user's decision publish the array.
92  
93 <  ReqBranch(GetBranchName(), fObj);
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines