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.2 by loizides, Wed Jun 18 19:17:21 2008 UTC vs.
Revision 1.55 by bendavid, Wed Feb 24 17:38:27 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines