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

Comparing UserCode/MitProd/TreeFiller/src/FillMitTree.cc (file contents):
Revision 1.3 by loizides, Thu Jun 19 16:53:43 2008 UTC vs.
Revision 1.48 by loizides, Fri Sep 25 08:43:19 2009 UTC

# Line 2 | Line 2
2  
3   #include "MitProd/TreeFiller/interface/FillMitTree.h"
4   #include "FWCore/MessageLogger/interface/MessageLogger.h"
5 + #include "FWCore/ParameterSet/interface/ParameterSet.h"
6   #include "FWCore/ServiceRegistry/interface/Service.h"
7   #include "MitProd/TreeService/interface/TreeService.h"
8 + #include "MitProd/ObjectService/interface/ObjectService.h"
9 + #include "MitProd/TreeFiller/interface/AssociationMaps.h"
10 + #include "MitProd/TreeFiller/interface/FillerBasicClusters.h"
11 + #include "MitProd/TreeFiller/interface/FillerBeamSpot.h"
12 + #include "MitProd/TreeFiller/interface/FillerCaloJets.h"
13 + #include "MitProd/TreeFiller/interface/FillerCaloMet.h"
14 + #include "MitProd/TreeFiller/interface/FillerCaloTaus.h"
15 + #include "MitProd/TreeFiller/interface/FillerCaloTowers.h"
16 + #include "MitProd/TreeFiller/interface/FillerConversions.h"
17 + #include "MitProd/TreeFiller/interface/FillerDecayParts.h"
18 + #include "MitProd/TreeFiller/interface/FillerElectrons.h"
19 + #include "MitProd/TreeFiller/interface/FillerGenJets.h"
20 + #include "MitProd/TreeFiller/interface/FillerGenMet.h"
21 + #include "MitProd/TreeFiller/interface/FillerMCEventInfo.h"
22 + #include "MitProd/TreeFiller/interface/FillerMCParticles.h"
23 + #include "MitProd/TreeFiller/interface/FillerMCVertexes.h"
24 + #include "MitProd/TreeFiller/interface/FillerMet.h"
25   #include "MitProd/TreeFiller/interface/FillerMetaInfos.h"
26 < #include "MitProd/TreeFiller/interface/FillerGlobalMuons.h"
26 > #include "MitProd/TreeFiller/interface/FillerMetaInfos.h"
27 > #include "MitProd/TreeFiller/interface/FillerMuons.h"
28 > #include "MitProd/TreeFiller/interface/FillerPFCandidates.h"
29 > #include "MitProd/TreeFiller/interface/FillerPFJets.h"
30 > #include "MitProd/TreeFiller/interface/FillerPFMet.h"
31 > #include "MitProd/TreeFiller/interface/FillerPFTaus.h"
32 > #include "MitProd/TreeFiller/interface/FillerPhotons.h"
33 > #include "MitProd/TreeFiller/interface/FillerPixelHits.h"
34 > #include "MitProd/TreeFiller/interface/FillerStableParts.h"
35 > #include "MitProd/TreeFiller/interface/FillerSuperClusters.h"
36 > #include "MitProd/TreeFiller/interface/FillerTracks.h"
37 > #include "MitProd/TreeFiller/interface/FillerVertexes.h"
38 > #include "MitAna/DataTree/interface/Names.h"
39 > #include "MitAna/DataTree/interface/BranchTable.h"
40  
41   using namespace std;
42   using namespace edm;
43   using namespace mithep;
44  
45 < //-------------------------------------------------------------------------------------------------
46 < FillMitTree::FillMitTree(const edm::ParameterSet &cfg)
45 > mithep::ObjectService *mithep::FillMitTree::os_ = 0;
46 >
47 > //--------------------------------------------------------------------------------------------------
48 > FillMitTree::FillMitTree(const edm::ParameterSet &cfg) :
49 >  defactive_(cfg.getUntrackedParameter<bool>("defactive",1)),
50 >  brtable_(0),
51 >  acfnumber_(-1)
52   {
53 <  // Constructor: initialize fillers
53 >  // Constructor.
54  
55    if (!configure(cfg)) {
56      throw edm::Exception(edm::errors::Configuration, "FillMitTree::FillMitTree()\n")
# Line 22 | Line 58 | FillMitTree::FillMitTree(const edm::Para
58    }
59   }
60  
61 < //-------------------------------------------------------------------------------------------------
61 > //--------------------------------------------------------------------------------------------------
62   FillMitTree::~FillMitTree()
63   {
64 <  // Destructor: nothing to be done here.
64 >  // Destructor.
65 >
66 >  delete brtable_;
67   }
68  
69 < //-------------------------------------------------------------------------------------------------
69 > //--------------------------------------------------------------------------------------------------
70 > bool FillMitTree::addActiveFiller(BaseFiller *bf)
71 > {
72 >  // Check if filler is active and add it to list of fillers. Otherwise delete it.
73 >
74 >  if (!bf)
75 >    return 0;
76 >
77 >  if (bf->Active()) {
78 >    fillers_.push_back(bf);
79 >    return 1;
80 >  }
81 >
82 >  delete bf;
83 >  bf = 0;
84 >  return 0;
85 > }
86 >
87 > //--------------------------------------------------------------------------------------------------
88   void FillMitTree::analyze(const edm::Event      &event,
89                            const edm::EventSetup &setup)
90   {
91    // Access and copy event content.
92  
93 <  // First step: Loop over the data fillers of the various components
93 >  // first step: Loop over the data fillers of the various components
94    for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
95      (*iF)->FillDataBlock(event,setup);
96    }
97  
98 <  // Second step: Loop over the link resolution of the various components
98 >  // second step: Loop over the link resolution of the various components
99    for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
100      (*iF)->ResolveLinks(event,setup);
101    }
102 +
103 +  if (brtable_) { // only the first FillMitTree object has to deal with the branch table
104 +    if (acfnumber_==-1) {
105 +      brtable_->Rehash(brtable_->GetSize());
106 +      if (0)
107 +        brtable_->Print();
108 +    }
109 +    if (acfnumber_ != tws_->GetFileNumber()) {
110 +      tws_->StoreObject(brtable_);
111 +      acfnumber_ = tws_->GetFileNumber();
112 +    }
113 +  }
114   }
115  
116 < //-------------------------------------------------------------------------------------------------
116 > //--------------------------------------------------------------------------------------------------
117   void FillMitTree::beginJob(const edm::EventSetup &event)
118   {
119    // Access the tree and book branches.
120  
121    Service<TreeService> ts;
122 <  TreeWriter *tws = ts->get();
123 <  if (! tws) {
122 >  tws_ = ts->get();
123 >  if (!tws_) {
124      throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
125 <      << "Could not get pointer to tree." << "\n";
125 >      << "Could not get pointer to tree. "
126 >      << "Do you have the TreeServie define in your config?" << "\n";
127      return;
128    }
129  
130 <  // Loop over the various components and book the branches
130 >  if (os_==0) { // only the first FillMitTree object has to deal with this
131 >    Service<ObjectService> os;
132 >    if (!os.isAvailable()) {
133 >      throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
134 >        << "Could not get object service. "
135 >        << "Do you have the ObjectService defined in your config?" << "\n";
136 >      return;
137 >    }
138 >    os_ = &(*os);
139 >    brtable_ = new BranchTable;
140 >    brtable_->SetName(Names::gkBranchTable);
141 >    brtable_->SetOwner();
142 >    os->add(brtable_, brtable_->GetName());
143 >  }
144 >
145 >  // loop over the various components and book the branches
146    for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
147 <    (*iF)->BookDataBlock(tws);
147 >    edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl;
148 >    (*iF)->BookDataBlock(*tws_, event);
149    }
150 <  return;
150 >
151 >  // call branch ref for the event tree
152 >  if (brtable_ && tws_->GetTree())
153 >    tws_->GetTree()->BranchRef();
154   }
155  
156 < //-------------------------------------------------------------------------------------------------
156 > //--------------------------------------------------------------------------------------------------
157   bool FillMitTree::configure(const edm::ParameterSet &cfg)
158   {
159 <  // Configure our fillers.
159 >  // Configure our fillers according to given parameter ("fillers").
160  
161 <
162 <  FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg);
163 <  if (fillerMetaInfos->Active())
164 <    fillers_.push_back(fillerMetaInfos);
165 <  else
166 <    delete fillerMetaInfos;
167 <
168 <  FillerGlobalMuons *fillerGlobalMuons = new FillerGlobalMuons(cfg);
169 <  if (fillerGlobalMuons->Active())
170 <    fillers_.push_back(fillerGlobalMuons);
171 <  else
172 <    delete fillerGlobalMuons;
161 >  std::vector<std::string> pars;
162 >  if (cfg.exists("fillers"))
163 >    pars=cfg.getUntrackedParameter<vector<string> >("fillers");
164 >  else
165 >    cfg.getParameterSetNames(pars, false);
166 >
167 >  // loop over psets
168 >  for (unsigned int i = 0; i<pars.size(); ++i) {
169 >
170 >    const string name(pars.at(i));
171 >
172 >    string ftype("Filler" + name);
173 >    if (cfg.existsAs<ParameterSet>(name,0)) {
174 >      ParameterSet next(cfg.getUntrackedParameter<ParameterSet>(name));
175 >      if (!next.exists("fillerType")) {
176 >        edm::LogError("FillMitTree") << "Cannot determine fillerType for pset named "
177 >                                     << name << std::endl;
178 >        throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
179 >          << "Cannot determine fillerType for pset named "
180 >          << name << std::endl;
181 >      }
182 >      ftype = next.getUntrackedParameter<string>("fillerType");
183 >    }
184 >
185 >    edm::LogInfo("FillMitTree") << "Attempting to configure '" << ftype
186 >                                << "' for '" << name << "'" << std::endl;
187 >
188 >    if (ftype.compare("FillerMetaInfos")==0) {
189 >      FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg, name.c_str(), defactive_);
190 >      addActiveFiller(fillerMetaInfos);
191 >      continue;
192 >    }
193 >
194 >    if (ftype.compare("FillerMCParticles")==0) {
195 >      FillerMCParticles *fillerMCParticles = new FillerMCParticles(cfg, name.c_str(), defactive_);
196 >      addActiveFiller(fillerMCParticles);
197 >      continue;
198 >    }
199 >
200 >    if (ftype.compare("FillerMCEventInfo")==0) {
201 >      FillerMCEventInfo *fillerMCEventInfo = new FillerMCEventInfo(cfg, name.c_str(), defactive_);
202 >      addActiveFiller(fillerMCEventInfo);
203 >      continue;
204 >    }
205 >
206 >    if (ftype.compare("FillerMCVertexes")==0) {
207 >      FillerMCVertexes *fillerMCVertexes = new FillerMCVertexes(cfg, name.c_str(), defactive_);
208 >      addActiveFiller(fillerMCVertexes);
209 >      continue;
210 >    }  
211 >
212 >    if (ftype.compare("FillerBeamSpot")==0) {
213 >      FillerBeamSpot *fillerBeamSpot = new FillerBeamSpot(cfg, name.c_str(), defactive_);
214 >      addActiveFiller(fillerBeamSpot);
215 >      continue;
216 >    }
217 >  
218 >    if (ftype.compare("FillerVertexes")==0) {
219 >      FillerVertexes *fillerVertexes = new FillerVertexes(cfg, name.c_str(), defactive_);
220 >      addActiveFiller(fillerVertexes);
221 >      continue;
222 >    }  
223 >
224 >    if (ftype.compare("FillerCaloTowers")==0) {
225 >      FillerCaloTowers *fillerCaloTowers = new FillerCaloTowers(cfg, name.c_str(), defactive_);
226 >      addActiveFiller(fillerCaloTowers);
227 >      continue;
228 >    }  
229 >
230 >    if (ftype.compare("FillerGenJets")==0) {
231 >      FillerGenJets *fillerGenJets = new FillerGenJets(cfg, name.c_str(), defactive_);
232 >      addActiveFiller(fillerGenJets);
233 >      continue;
234 >    }  
235 >
236 >    if (ftype.compare("FillerCaloJets")==0) {
237 >      FillerCaloJets *fillerCaloJets = new FillerCaloJets(cfg, name.c_str(), defactive_);
238 >      addActiveFiller(fillerCaloJets);
239 >      continue;
240 >    }  
241 >    
242 >    if (ftype.compare("FillerMet")==0) {
243 >      FillerMet *fillerMet = new FillerMet(cfg, name.c_str(), defactive_);
244 >      addActiveFiller(fillerMet);
245 >      continue;
246 >    }  
247 >    
248 >    if (ftype.compare("FillerGenMet")==0) {
249 >      FillerGenMet *fillerGenMet = new FillerGenMet(cfg, name.c_str(), defactive_);
250 >      addActiveFiller(fillerGenMet);
251 >      continue;
252 >    }  
253 >
254 >    if (ftype.compare("FillerCaloMet")==0) {
255 >      FillerCaloMet *fillerCaloMet = new FillerCaloMet(cfg, name.c_str(), defactive_);
256 >      addActiveFiller(fillerCaloMet);
257 >      continue;
258 >    }
259 >    
260 >    if (ftype.compare("FillerPFMet")==0) {
261 >      FillerPFMet *fillerPFMet = new FillerPFMet(cfg, name.c_str(), defactive_);
262 >      addActiveFiller(fillerPFMet);
263 >      continue;
264 >    }  
265 >
266 >    if (ftype.compare("FillerBasicClusters")==0) {
267 >      FillerBasicClusters *fillerBasicClusters =
268 >        new FillerBasicClusters(cfg, name.c_str(), defactive_);
269 >      addActiveFiller(fillerBasicClusters);
270 >      continue;
271 >    }  
272 >
273 >    if (ftype.compare("FillerSuperClusters")==0) {
274 >      FillerSuperClusters *fillerSuperClusters =  
275 >        new FillerSuperClusters(cfg, name.c_str(), defactive_);
276 >      addActiveFiller(fillerSuperClusters);
277 >      continue;
278 >    }  
279 >
280 >    if (ftype.compare("FillerPixelHits")==0) {
281 >      FillerPixelHits *fillerPixelHits =  
282 >        new FillerPixelHits(cfg, name.c_str(), defactive_);
283 >      addActiveFiller(fillerPixelHits);
284 >      continue;
285 >    }  
286 >
287 >    if (ftype.compare("FillerTracks")==0) {
288 >      FillerTracks *fillerTracks = new FillerTracks(cfg, name.c_str(), defactive_);
289 >      addActiveFiller(fillerTracks);
290 >      continue;
291 >    }  
292 >
293 >    if (ftype.compare("FillerMuons")==0) {
294 >      FillerMuons *fillerMuons = new FillerMuons(cfg, name.c_str(), defactive_);
295 >      addActiveFiller(fillerMuons);
296 >      continue;
297 >    }  
298 >
299 >    if (ftype.compare("FillerElectrons")==0) {
300 >      FillerElectrons *fillerElectrons = new FillerElectrons(cfg, name.c_str(), defactive_);
301 >      addActiveFiller(fillerElectrons);
302 >      continue;
303 >    }  
304 >
305 >    if (ftype.compare("FillerConversions")==0) {
306 >      FillerConversions *fillerConversions = new FillerConversions(cfg, name.c_str(), defactive_);
307 >      addActiveFiller(fillerConversions);
308 >      continue;
309 >    }  
310 >
311 >    if (ftype.compare("FillerPhotons")==0) {
312 >      FillerPhotons *fillerPhotons = new FillerPhotons(cfg, name.c_str(), defactive_);
313 >      addActiveFiller(fillerPhotons);
314 >      continue;
315 >    }  
316 >
317 >    if (ftype.compare("FillerStableParts")==0) {
318 >      FillerStableParts *fillerStableParts = new FillerStableParts(cfg, name.c_str(), defactive_);
319 >      addActiveFiller(fillerStableParts);
320 >      continue;
321 >    }  
322 >
323 >    if (ftype.compare("FillerDecayParts")==0) {
324 >      FillerDecayParts *fillerDecayParts = new FillerDecayParts(cfg, name.c_str(), defactive_);
325 >      addActiveFiller(fillerDecayParts);
326 >      continue;
327 >    }  
328 >    
329 >    if (ftype.compare("FillerPFCandidates")==0) {
330 >      FillerPFCandidates *fillerPFCands = new FillerPFCandidates(cfg, name.c_str(), defactive_);
331 >      addActiveFiller(fillerPFCands);
332 >      continue;
333 >    }  
334 >
335 >    if (ftype.compare("FillerPFJets")==0) {
336 >      FillerPFJets *fillerPFJets = new FillerPFJets(cfg, name.c_str(), defactive_);
337 >      addActiveFiller(fillerPFJets);
338 >      continue;
339 >    }  
340 >
341 >    if (ftype.compare("FillerCaloTaus")==0) {
342 >      FillerCaloTaus *fillerCaloTaus = new FillerCaloTaus(cfg, name.c_str(), defactive_);
343 >      addActiveFiller(fillerCaloTaus);
344 >      continue;
345 >    }
346 >    
347 >    if (ftype.compare("FillerPFTaus")==0) {
348 >      FillerPFTaus *fillerPFTaus = new FillerPFTaus(cfg, name.c_str(), defactive_);
349 >      addActiveFiller(fillerPFTaus);
350 >      continue;
351 >    }  
352 >    
353 >    edm::LogError("FillMitTree")
354 >      << "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
355 >    throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
356 >      << "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
357 >  }
358  
359    return 1;
360   }
361  
362 < //-------------------------------------------------------------------------------------------------
362 > //--------------------------------------------------------------------------------------------------
363   void FillMitTree::endJob()
364   {
365    // Delete fillers.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines