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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines