ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeService/src/TreeService.cc
(Generate patch)

Comparing UserCode/MitProd/TreeService/src/TreeService.cc (file contents):
Revision 1.7 by loizides, Tue Jul 1 16:33:55 2008 UTC vs.
Revision 1.10 by loizides, Mon Oct 6 15:56:51 2008 UTC

# Line 14 | Line 14 | using namespace std;
14   using namespace mithep;
15  
16   //--------------------------------------------------------------------------------------------------
17 < TreeService::TreeService(const ParameterSet &cfg, ActivityRegistry &r) :
18 <  tws_(0)
17 > TreeService::TreeService(const ParameterSet &cfg, ActivityRegistry &ar) :
18 >  tws_(0),
19 >  fDoReset_(cfg.getUntrackedParameter<bool>("doReset",1))
20   {
21 +  // Constructor.
22 +
23    if (cfg.exists("treeNames"))
24      treeNames_=cfg.getUntrackedParameter<vector<string>   >("treeNames");
25    else
# Line 66 | Line 69 | TreeService::TreeService(const Parameter
69    // init tree writers
70    for (unsigned int i=0; i<treeNames_.size(); ++i) {
71  
72 <    TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),1);
72 >    TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),0);
73      t->SetPrefix(fileNames_.at(i).c_str());
74  
75      if (i<pathNames_.size())
# Line 99 | Line 102 | TreeService::TreeService(const Parameter
102    }
103  
104    // set watchers
105 <  r.watchPreProcessEvent (this,&TreeService::preEventProcessing);
106 <  r.watchPostProcessEvent(this,&TreeService::postEventProcessing);
107 <  r.watchPostBeginJob    (this,&TreeService::postBeginJob);
108 <  r.watchPostEndJob      (this,&TreeService::postEndJob);
105 >  ar.watchPreProcessEvent (this,&TreeService::preEventProcessing);
106 >  ar.watchPostProcessEvent(this,&TreeService::postEventProcessing);
107 >  ar.watchPostBeginJob    (this,&TreeService::postBeginJob);
108 >  ar.watchPostEndJob      (this,&TreeService::postEndJob);
109   }
110  
111   //--------------------------------------------------------------------------------------------------
112   TreeService::~TreeService()
113   {
114 +  // Destructor.
115   }
116  
117   //--------------------------------------------------------------------------------------------------
118 < TreeWriter* TreeService::get(const char *name)
118 > TreeWriter *TreeService::get(const char *name)
119   {
120 +  // Get TreeWriter by name. If no name given, first one will be returned.
121 +
122    if (tws_.GetEntries()<=0)
123      return 0;
124  
# Line 127 | Line 133 | TreeWriter* TreeService::get(const char
133   //--------------------------------------------------------------------------------------------------
134   void TreeService::postBeginJob()
135   {
136 <  // nothing to be done for now
136 >  // Nothing to be done for now
137   }
138  
139   //--------------------------------------------------------------------------------------------------
140   void TreeService::postEndJob()
141   {
142 +  // Clear all TreeWriter objects.
143 +
144    tws_.Clear();
145   }
146  
147   //--------------------------------------------------------------------------------------------------
148   void TreeService::postEventProcessing(const Event&, const EventSetup&)
149   {
150 +  // Loop over all TreeWriter objects before processing of an event.
151 +
152    for (int i=0; i<tws_.GetEntries(); ++i) {
153      TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
154 <    if (tw)
155 <      tw->EndEvent();
154 >    if (tw) {
155 >      if (i<tws_.GetEntries()-1)
156 >        tw->EndEvent();
157 >      else // make sure objects are only reset at the end (if at all)
158 >        tw->EndEvent(fDoReset_);
159 >    }
160    }
161   }
162  
163   //--------------------------------------------------------------------------------------------------
164   void TreeService::preEventProcessing(const EventID&, const Timestamp&)
165   {
166 +  // Loop over all TreeWriter objects after processing of a events.
167 +
168    for (int i=0; i<tws_.GetEntries(); ++i) {
169      TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
170 <    if (tw)
171 <      tw->BeginEvent();
170 >    if (tw) {
171 >      if (i==0) // make sure objects are only reset at the beginning (if at all)
172 >        tw->BeginEvent(fDoReset_);
173 >      else
174 >        tw->BeginEvent();
175 >    }
176    }
177   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines