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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines