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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines