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.5 by loizides, Tue Jun 24 14:25:46 2008 UTC vs.
Revision 1.53 by bendavid, Sat Dec 12 22:33:52 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"
7 > #include "MitProd/ObjectService/interface/ObjectService.h"
8 > #include "MitProd/TreeFiller/interface/AssociationMaps.h"
9 > #include "MitProd/TreeFiller/interface/FillerBasicClusters.h"
10 > #include "MitProd/TreeFiller/interface/FillerBeamSpot.h"
11 > #include "MitProd/TreeFiller/interface/FillerCaloJets.h"
12 > #include "MitProd/TreeFiller/interface/FillerCaloMet.h"
13 > #include "MitProd/TreeFiller/interface/FillerCaloTaus.h"
14 > #include "MitProd/TreeFiller/interface/FillerCaloTowers.h"
15 > #include "MitProd/TreeFiller/interface/FillerConversions.h"
16 > #include "MitProd/TreeFiller/interface/FillerDecayParts.h"
17 > #include "MitProd/TreeFiller/interface/FillerElectrons.h"
18 > #include "MitProd/TreeFiller/interface/FillerEvtSelData.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"
27 < #include "MitProd/TreeFiller/interface/FillerGenParts.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/FillerStripHits.h"
36 > #include "MitProd/TreeFiller/interface/FillerSuperClusters.h"
37 > #include "MitProd/TreeFiller/interface/FillerTracks.h"
38 > #include "MitProd/TreeFiller/interface/FillerVertexes.h"
39 > #include "MitAna/DataTree/interface/Names.h"
40 > #include "MitAna/DataTree/interface/BranchTable.h"
41 > #include "MitCommon/OptIO/interface/OptInt.h"
42  
43   using namespace std;
44   using namespace edm;
45   using namespace mithep;
46  
47 < //-------------------------------------------------------------------------------------------------
48 < FillMitTree::FillMitTree(const edm::ParameterSet &cfg)
47 > mithep::ObjectService *mithep::FillMitTree::os_ = 0;
48 >
49 > //--------------------------------------------------------------------------------------------------
50 > FillMitTree::FillMitTree(const edm::ParameterSet &cfg) :
51 >  defactive_(cfg.getUntrackedParameter<bool>("defactive",1)),
52 >  brtable_(0),
53 >  acfnumber_(-1),
54 >  tws_(new TreeWriter(Names::gkEvtTreeName,0))
55   {
56 <  // Constructor: initialize fillers
56 >  // Constructor.
57  
58    if (!configure(cfg)) {
59      throw edm::Exception(edm::errors::Configuration, "FillMitTree::FillMitTree()\n")
# Line 23 | Line 61 | FillMitTree::FillMitTree(const edm::Para
61    }
62   }
63  
64 < //-------------------------------------------------------------------------------------------------
64 > //--------------------------------------------------------------------------------------------------
65   FillMitTree::~FillMitTree()
66   {
67 <  // Destructor: nothing to be done here.
67 >  // Destructor.
68 >
69 >  delete brtable_;
70 >  delete tws_;
71 > }
72 >
73 > //--------------------------------------------------------------------------------------------------
74 > bool FillMitTree::addActiveFiller(BaseFiller *bf)
75 > {
76 >  // Check if filler is active and add it to list of fillers. Otherwise delete it.
77 >
78 >  if (!bf)
79 >    return 0;
80 >
81 >  if (bf->Active()) {
82 >    fillers_.push_back(bf);
83 >    return 1;
84 >  }
85 >
86 >  delete bf;
87 >  bf = 0;
88 >  return 0;
89 > }
90 >
91 > //--------------------------------------------------------------------------------------------------
92 > void FillMitTree::beginRun(edm::Run const &run, edm::EventSetup const &setup)
93 > {
94 >  // Access and copy event content.
95 >
96 >  // first step: Loop over the data fillers of the various components
97 >  for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
98 >    (*iF)->FillRunBlock(run,setup);
99 >  }
100 >  
101   }
102  
103 < //-------------------------------------------------------------------------------------------------
103 > //--------------------------------------------------------------------------------------------------
104   void FillMitTree::analyze(const edm::Event      &event,
105                            const edm::EventSetup &setup)
106   {
107    // Access and copy event content.
108 +  
109 +  //tree writer begin event actions
110 +  tws_->BeginEvent(kTRUE);
111  
112 <  // First step: Loop over the data fillers of the various components
112 >  // first step: Loop over the data fillers of the various components
113    for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
114      (*iF)->FillDataBlock(event,setup);
115    }
116  
117 <  // Second step: Loop over the link resolution of the various components
117 >  // second step: Loop over the link resolution of the various components
118    for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
119      (*iF)->ResolveLinks(event,setup);
120    }
121 +
122 +  if (brtable_) { // only the first FillMitTree object has to deal with the branch table
123 +    if (acfnumber_==-1) {
124 +      brtable_->Rehash(brtable_->GetSize());
125 +      if (0)
126 +        brtable_->Print();
127 +    }
128 +    if (acfnumber_ != tws_->GetFileNumber()) {
129 +      tws_->StoreObject(brtable_);
130 +      acfnumber_ = tws_->GetFileNumber();
131 +    }
132 +  }
133 +  
134 +  //tree writer end of event actions
135 +  tws_->EndEvent(kTRUE);
136 +  
137   }
138  
139 < //-------------------------------------------------------------------------------------------------
139 > //--------------------------------------------------------------------------------------------------
140   void FillMitTree::beginJob(const edm::EventSetup &event)
141   {
142    // Access the tree and book branches.
143  
144 <  Service<TreeService> ts;
145 <  TreeWriter *tws = ts->get();
146 <  if (! tws) {
147 <    throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
148 <      << "Could not get pointer to tree." << "\n";
149 <    return;
144 >  if (os_==0) { // only the first FillMitTree object has to deal with this
145 >    Service<ObjectService> os;
146 >    if (!os.isAvailable()) {
147 >      throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
148 >        << "Could not get object service. "
149 >        << "Do you have the ObjectService defined in your config?" << "\n";
150 >      return;
151 >    }
152 >    os_ = &(*os);
153 >    brtable_ = new BranchTable;
154 >    brtable_->SetName(Names::gkBranchTable);
155 >    brtable_->SetOwner();
156 >    os->add(brtable_, brtable_->GetName());
157    }
158  
159 <  // Loop over the various components and book the branches
159 >  // loop over the various components and book the branches
160    for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
161 <    (*iF)->BookDataBlock(*tws);
161 >    edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl;
162 >    (*iF)->BookDataBlock(*tws_, event);
163    }
164 +
165 +  // call branch ref for the event tree
166 +  if (brtable_ && tws_->GetTree())
167 +    tws_->GetTree()->BranchRef();
168 +  
169   }
170  
171 < //-------------------------------------------------------------------------------------------------
171 > //--------------------------------------------------------------------------------------------------
172   bool FillMitTree::configure(const edm::ParameterSet &cfg)
173   {
71  // Configure our fillers.
174  
175 +  // Configure TreeWriter
176 +  const std::string twsConfigName("TreeWriter");
177 +  ParameterSet twsConfig;
178 +  if (cfg.existsAs<ParameterSet>(twsConfigName,0))
179 +    twsConfig = cfg.getUntrackedParameter<ParameterSet>(twsConfigName);
180 +  
181 +  configureTreeWriter(twsConfig);
182 +  
183 +  // Configure our fillers according to given parameter ("fillers").
184 +
185 +  std::vector<std::string> pars;
186 +  if (cfg.exists("fillers"))
187 +    pars=cfg.getUntrackedParameter<vector<string> >("fillers");
188 +  else
189 +    cfg.getParameterSetNames(pars, false);
190 +
191 +  // loop over psets
192 +  for (unsigned int i = 0; i<pars.size(); ++i) {
193 +
194 +    const string name(pars.at(i));
195 +
196 +    string ftype("Filler" + name);
197 +    if (cfg.existsAs<ParameterSet>(name,0)) {
198 +      ParameterSet next(cfg.getUntrackedParameter<ParameterSet>(name));
199 +      if (!next.exists("fillerType")) {
200 +        edm::LogError("FillMitTree") << "Cannot determine fillerType for pset named "
201 +                                     << name << std::endl;
202 +        throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
203 +          << "Cannot determine fillerType for pset named "
204 +          << name << std::endl;
205 +      }
206 +      ftype = next.getUntrackedParameter<string>("fillerType");
207 +    }
208 +
209 +    edm::LogInfo("FillMitTree") << "Attempting to configure '" << ftype
210 +                                << "' for '" << name << "'" << std::endl;
211 +
212 +    if (ftype.compare("FillerMetaInfos")==0) {
213 +      FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg, name.c_str(), defactive_);
214 +      addActiveFiller(fillerMetaInfos);
215 +      continue;
216 +    }
217 +
218 +    if (ftype.compare("FillerMCParticles")==0) {
219 +      FillerMCParticles *fillerMCParticles = new FillerMCParticles(cfg, name.c_str(), defactive_);
220 +      addActiveFiller(fillerMCParticles);
221 +      continue;
222 +    }
223 +
224 +    if (ftype.compare("FillerMCEventInfo")==0) {
225 +      FillerMCEventInfo *fillerMCEventInfo = new FillerMCEventInfo(cfg, name.c_str(), defactive_);
226 +      addActiveFiller(fillerMCEventInfo);
227 +      continue;
228 +    }
229 +
230 +    if (ftype.compare("FillerMCVertexes")==0) {
231 +      FillerMCVertexes *fillerMCVertexes = new FillerMCVertexes(cfg, name.c_str(), defactive_);
232 +      addActiveFiller(fillerMCVertexes);
233 +      continue;
234 +    }  
235 +
236 +    if (ftype.compare("FillerEvtSelData")==0) {
237 +      FillerEvtSelData *fillerEvtSelData = new FillerEvtSelData(cfg, name.c_str(), defactive_);
238 +      addActiveFiller(fillerEvtSelData);
239 +      continue;
240 +    }
241 +
242 +    if (ftype.compare("FillerBeamSpot")==0) {
243 +      FillerBeamSpot *fillerBeamSpot = new FillerBeamSpot(cfg, name.c_str(), defactive_);
244 +      addActiveFiller(fillerBeamSpot);
245 +      continue;
246 +    }
247 +
248 +    if (ftype.compare("FillerVertexes")==0) {
249 +      FillerVertexes *fillerVertexes = new FillerVertexes(cfg, name.c_str(), defactive_);
250 +      addActiveFiller(fillerVertexes);
251 +      continue;
252 +    }  
253 +
254 +    if (ftype.compare("FillerCaloTowers")==0) {
255 +      FillerCaloTowers *fillerCaloTowers = new FillerCaloTowers(cfg, name.c_str(), defactive_);
256 +      addActiveFiller(fillerCaloTowers);
257 +      continue;
258 +    }  
259 +
260 +    if (ftype.compare("FillerGenJets")==0) {
261 +      FillerGenJets *fillerGenJets = new FillerGenJets(cfg, name.c_str(), defactive_);
262 +      addActiveFiller(fillerGenJets);
263 +      continue;
264 +    }  
265 +
266 +    if (ftype.compare("FillerCaloJets")==0) {
267 +      FillerCaloJets *fillerCaloJets = new FillerCaloJets(cfg, name.c_str(), defactive_);
268 +      addActiveFiller(fillerCaloJets);
269 +      continue;
270 +    }  
271 +    
272 +    if (ftype.compare("FillerMet")==0) {
273 +      FillerMet *fillerMet = new FillerMet(cfg, name.c_str(), defactive_);
274 +      addActiveFiller(fillerMet);
275 +      continue;
276 +    }  
277 +    
278 +    if (ftype.compare("FillerGenMet")==0) {
279 +      FillerGenMet *fillerGenMet = new FillerGenMet(cfg, name.c_str(), defactive_);
280 +      addActiveFiller(fillerGenMet);
281 +      continue;
282 +    }  
283 +
284 +    if (ftype.compare("FillerCaloMet")==0) {
285 +      FillerCaloMet *fillerCaloMet = new FillerCaloMet(cfg, name.c_str(), defactive_);
286 +      addActiveFiller(fillerCaloMet);
287 +      continue;
288 +    }
289 +    
290 +    if (ftype.compare("FillerPFMet")==0) {
291 +      FillerPFMet *fillerPFMet = new FillerPFMet(cfg, name.c_str(), defactive_);
292 +      addActiveFiller(fillerPFMet);
293 +      continue;
294 +    }  
295 +
296 +    if (ftype.compare("FillerBasicClusters")==0) {
297 +      FillerBasicClusters *fillerBasicClusters =
298 +        new FillerBasicClusters(cfg, name.c_str(), defactive_);
299 +      addActiveFiller(fillerBasicClusters);
300 +      continue;
301 +    }  
302 +
303 +    if (ftype.compare("FillerSuperClusters")==0) {
304 +      FillerSuperClusters *fillerSuperClusters =  
305 +        new FillerSuperClusters(cfg, name.c_str(), defactive_);
306 +      addActiveFiller(fillerSuperClusters);
307 +      continue;
308 +    }  
309 +
310 +    if (ftype.compare("FillerPixelHits")==0) {
311 +      FillerPixelHits *fillerPixelHits =  
312 +        new FillerPixelHits(cfg, name.c_str(), defactive_);
313 +      addActiveFiller(fillerPixelHits);
314 +      continue;
315 +    }  
316 +
317 +    if (ftype.compare("FillerStripHits")==0) {
318 +      FillerStripHits *fillerStripHits =  
319 +        new FillerStripHits(cfg, name.c_str(), defactive_);
320 +      addActiveFiller(fillerStripHits);
321 +      continue;
322 +    }  
323 +
324 +    if (ftype.compare("FillerTracks")==0) {
325 +      FillerTracks *fillerTracks = new FillerTracks(cfg, name.c_str(), defactive_);
326 +      addActiveFiller(fillerTracks);
327 +      continue;
328 +    }  
329 +
330 +    if (ftype.compare("FillerMuons")==0) {
331 +      FillerMuons *fillerMuons = new FillerMuons(cfg, name.c_str(), defactive_);
332 +      addActiveFiller(fillerMuons);
333 +      continue;
334 +    }  
335 +
336 +    if (ftype.compare("FillerElectrons")==0) {
337 +      FillerElectrons *fillerElectrons = new FillerElectrons(cfg, name.c_str(), defactive_);
338 +      addActiveFiller(fillerElectrons);
339 +      continue;
340 +    }  
341 +
342 +    if (ftype.compare("FillerConversions")==0) {
343 +      FillerConversions *fillerConversions = new FillerConversions(cfg, name.c_str(), defactive_);
344 +      addActiveFiller(fillerConversions);
345 +      continue;
346 +    }  
347 +
348 +    if (ftype.compare("FillerPhotons")==0) {
349 +      FillerPhotons *fillerPhotons = new FillerPhotons(cfg, name.c_str(), defactive_);
350 +      addActiveFiller(fillerPhotons);
351 +      continue;
352 +    }  
353 +
354 +    if (ftype.compare("FillerStableParts")==0) {
355 +      FillerStableParts *fillerStableParts = new FillerStableParts(cfg, name.c_str(), defactive_);
356 +      addActiveFiller(fillerStableParts);
357 +      continue;
358 +    }  
359 +
360 +    if (ftype.compare("FillerDecayParts")==0) {
361 +      FillerDecayParts *fillerDecayParts = new FillerDecayParts(cfg, name.c_str(), defactive_);
362 +      addActiveFiller(fillerDecayParts);
363 +      continue;
364 +    }  
365 +    
366 +    if (ftype.compare("FillerPFCandidates")==0) {
367 +      FillerPFCandidates *fillerPFCands = new FillerPFCandidates(cfg, name.c_str(), defactive_);
368 +      addActiveFiller(fillerPFCands);
369 +      continue;
370 +    }  
371 +
372 +    if (ftype.compare("FillerPFJets")==0) {
373 +      FillerPFJets *fillerPFJets = new FillerPFJets(cfg, name.c_str(), defactive_);
374 +      addActiveFiller(fillerPFJets);
375 +      continue;
376 +    }  
377 +
378 +    if (ftype.compare("FillerCaloTaus")==0) {
379 +      FillerCaloTaus *fillerCaloTaus = new FillerCaloTaus(cfg, name.c_str(), defactive_);
380 +      addActiveFiller(fillerCaloTaus);
381 +      continue;
382 +    }
383 +    
384 +    if (ftype.compare("FillerPFTaus")==0) {
385 +      FillerPFTaus *fillerPFTaus = new FillerPFTaus(cfg, name.c_str(), defactive_);
386 +      addActiveFiller(fillerPFTaus);
387 +      continue;
388 +    }  
389 +    
390 +    edm::LogError("FillMitTree")
391 +      << "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
392 +    throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
393 +      << "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
394 +  }
395 +
396 +  return 1;
397 + }
398  
399 <  FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg);
400 <  if (fillerMetaInfos->Active())
401 <    fillers_.push_back(fillerMetaInfos);
402 <  else
78 <    delete fillerMetaInfos;
79 <
80 <  FillerGlobalMuons *fillerGlobalMuons = new FillerGlobalMuons(cfg);
81 <  if (fillerGlobalMuons->Active())
82 <    fillers_.push_back(fillerGlobalMuons);
83 <  else
84 <    delete fillerGlobalMuons;
85 <
86 <  FillerGenParts *fillerGenParts = new FillerGenParts(cfg);
87 <  if (fillerGenParts->Active())
88 <    fillers_.push_back(fillerGenParts);
89 <  else
90 <    delete fillerGenParts;
399 > //--------------------------------------------------------------------------------------------------
400 > bool FillMitTree::configureTreeWriter(const edm::ParameterSet &cfg)
401 > {
402 >  // Configure tree writer with options from config file.
403  
404 +  tws_->SetPrefix(cfg.getUntrackedParameter<string>("fileName","mit-test"));
405 +  tws_->SetBaseURL(cfg.getUntrackedParameter<string>("pathName","."));
406 +  tws_->SetMaxSize((Long64_t)cfg.getUntrackedParameter<unsigned>("maxSize",1024)*1024*1024);
407 +  tws_->SetCompressLevel(cfg.getUntrackedParameter<unsigned>("compLevel",9));
408 +  tws_->SetDefaultSL(cfg.getUntrackedParameter<unsigned>("splitLevel",99));
409 +  tws_->SetDefaultBrSize(cfg.getUntrackedParameter<unsigned>("brSize",16*1024));
410 +  
411 +  if (OptInt::IsActivated()) {
412 +    OptInt::SetZipMode(cfg.getUntrackedParameter<unsigned>("zipMode",99));
413 +    OptInt::SetGzipFraction(cfg.getUntrackedParameter<double>("gZipThres",1.0));
414 +    OptInt::SetBzipFraction(cfg.getUntrackedParameter<double>("bZipThres",-1.0));
415 +    OptInt::SetLzoFraction(cfg.getUntrackedParameter<double>("lzoThres",-1.0));
416 +    OptInt::SetLzmaFraction(cfg.getUntrackedParameter<double>("lzmaThres",0.95));
417 +    OptInt::SetVerbose(cfg.getUntrackedParameter<unsigned>("optIOVerbose",0));
418 +
419 +  } else {
420 +
421 +    if (cfg.exists("zipMode")   || cfg.exists("bZipThres") ||
422 +        cfg.exists("gZipThres") || cfg.exists("lzoThres")  ||
423 +        cfg.exists("lzmaThres")) {
424 +      edm::LogError("FillMitTree") <<
425 +        "OptIO interface not properly pre-loaded, ignoring given settings." << std::endl;
426 +    }
427 +  }
428 +  
429    return 1;
430   }
431  
432 < //-------------------------------------------------------------------------------------------------
432 > //--------------------------------------------------------------------------------------------------
433   void FillMitTree::endJob()
434   {
435    // Delete fillers.
# Line 101 | Line 438 | void FillMitTree::endJob()
438      delete *iF;
439    }
440  
441 +  tws_->Clear();
442 +  
443    edm::LogInfo("FillMitTree::endJob") << "Ending Job" << endl;
444   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines