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.49 by bendavid, Tue Nov 3 14:02:32 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"
8 + #include "MitProd/ObjectService/interface/ObjectService.h"
9 + #include "MitProd/TreeFiller/interface/AssociationMaps.h"
10 + #include "MitProd/TreeFiller/interface/FillerBasicClusters.h"
11 + #include "MitProd/TreeFiller/interface/FillerBeamSpot.h"
12 + #include "MitProd/TreeFiller/interface/FillerCaloJets.h"
13 + #include "MitProd/TreeFiller/interface/FillerCaloMet.h"
14 + #include "MitProd/TreeFiller/interface/FillerCaloTaus.h"
15 + #include "MitProd/TreeFiller/interface/FillerCaloTowers.h"
16 + #include "MitProd/TreeFiller/interface/FillerConversions.h"
17 + #include "MitProd/TreeFiller/interface/FillerDecayParts.h"
18 + #include "MitProd/TreeFiller/interface/FillerElectrons.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/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 < //-------------------------------------------------------------------------------------------------
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 > //--------------------------------------------------------------------------------------------------
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;
54 <  TreeWriter *tws = ts->get();
55 <  if (! tws) {
131 >  if (!tws_) {
132      throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
133 <      << "Could not get pointer to tree." << "\n";
133 >      << "Could not get pointer to tree. "
134 >      << "Do you have the TreeServie define in your config?" << "\n";
135      return;
136    }
137  
138 <  // Loop over the various components and book the branches
138 >  if (os_==0) { // only the first FillMitTree object has to deal with this
139 >    Service<ObjectService> os;
140 >    if (!os.isAvailable()) {
141 >      throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
142 >        << "Could not get object service. "
143 >        << "Do you have the ObjectService defined in your config?" << "\n";
144 >      return;
145 >    }
146 >    os_ = &(*os);
147 >    brtable_ = new BranchTable;
148 >    brtable_->SetName(Names::gkBranchTable);
149 >    brtable_->SetOwner();
150 >    os->add(brtable_, brtable_->GetName());
151 >  }
152 >
153 >  // loop over the various components and book the branches
154    for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
155 <    (*iF)->BookDataBlock(*tws);
155 >    edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl;
156 >    (*iF)->BookDataBlock(*tws_, event);
157    }
158 +
159 +  // call branch ref for the event tree
160 +  if (brtable_ && tws_->GetTree())
161 +    tws_->GetTree()->BranchRef();
162 +  
163   }
164  
165 < //-------------------------------------------------------------------------------------------------
165 > //--------------------------------------------------------------------------------------------------
166   bool FillMitTree::configure(const edm::ParameterSet &cfg)
167   {
70  // Configure our fillers.
168  
169 +  // Configure TreeWriter
170 +  const std::string twsConfigName("TreeWriter");
171 +  ParameterSet twsConfig;
172 +  if (cfg.existsAs<ParameterSet>(twsConfigName,0))
173 +    twsConfig = cfg.getUntrackedParameter<ParameterSet>(twsConfigName);
174 +  
175 +  configureTreeWriter(twsConfig);
176 +  
177 +  // Configure our fillers according to given parameter ("fillers").
178 +
179 +  std::vector<std::string> pars;
180 +  if (cfg.exists("fillers"))
181 +    pars=cfg.getUntrackedParameter<vector<string> >("fillers");
182 +  else
183 +    cfg.getParameterSetNames(pars, false);
184 +
185 +  // loop over psets
186 +  for (unsigned int i = 0; i<pars.size(); ++i) {
187 +
188 +    const string name(pars.at(i));
189 +
190 +    string ftype("Filler" + name);
191 +    if (cfg.existsAs<ParameterSet>(name,0)) {
192 +      ParameterSet next(cfg.getUntrackedParameter<ParameterSet>(name));
193 +      if (!next.exists("fillerType")) {
194 +        edm::LogError("FillMitTree") << "Cannot determine fillerType for pset named "
195 +                                     << name << std::endl;
196 +        throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
197 +          << "Cannot determine fillerType for pset named "
198 +          << name << std::endl;
199 +      }
200 +      ftype = next.getUntrackedParameter<string>("fillerType");
201 +    }
202 +
203 +    edm::LogInfo("FillMitTree") << "Attempting to configure '" << ftype
204 +                                << "' for '" << name << "'" << std::endl;
205 +
206 +    if (ftype.compare("FillerMetaInfos")==0) {
207 +      FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg, name.c_str(), defactive_);
208 +      addActiveFiller(fillerMetaInfos);
209 +      continue;
210 +    }
211 +
212 +    if (ftype.compare("FillerMCParticles")==0) {
213 +      FillerMCParticles *fillerMCParticles = new FillerMCParticles(cfg, name.c_str(), defactive_);
214 +      addActiveFiller(fillerMCParticles);
215 +      continue;
216 +    }
217 +
218 +    if (ftype.compare("FillerMCEventInfo")==0) {
219 +      FillerMCEventInfo *fillerMCEventInfo = new FillerMCEventInfo(cfg, name.c_str(), defactive_);
220 +      addActiveFiller(fillerMCEventInfo);
221 +      continue;
222 +    }
223 +
224 +    if (ftype.compare("FillerMCVertexes")==0) {
225 +      FillerMCVertexes *fillerMCVertexes = new FillerMCVertexes(cfg, name.c_str(), defactive_);
226 +      addActiveFiller(fillerMCVertexes);
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("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 +  return 1;
378 + }
379  
380 <  FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg);
381 <  if (fillerMetaInfos->Active())
382 <    fillers_.push_back(fillerMetaInfos);
76 <  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;
380 > //--------------------------------------------------------------------------------------------------
381 > bool FillMitTree::configureTreeWriter(const edm::ParameterSet &cfg)
382 > {
383  
384 +  tws_->SetPrefix(cfg.getUntrackedParameter<string>("fileName","mit-test"));
385 +  tws_->SetBaseURL(cfg.getUntrackedParameter<string>("pathName","."));
386 +  tws_->SetMaxSize((Long64_t)cfg.getUntrackedParameter<unsigned>("maxSize",1024)*1024*1024);
387 +  tws_->SetCompressLevel(cfg.getUntrackedParameter<unsigned>("compLevel",9));
388 +  tws_->SetDefaultSL(cfg.getUntrackedParameter<unsigned>("splitLevel",99));
389 +  tws_->SetDefaultBrSize(cfg.getUntrackedParameter<unsigned>("brSize",16*1024));
390 +  
391 +  if (OptInt::IsActivated()) {
392 +    OptInt::SetZipMode(cfg.getUntrackedParameter<unsigned>("zipMode",99));
393 +    OptInt::SetGzipFraction(cfg.getUntrackedParameter<double>("gZipThres",1.0));
394 +    OptInt::SetBzipFraction(cfg.getUntrackedParameter<double>("bZipThres",-1.0));
395 +    OptInt::SetLzoFraction(cfg.getUntrackedParameter<double>("lzoThres",-1.0));
396 +    OptInt::SetLzmaFraction(cfg.getUntrackedParameter<double>("lzmaThres",0.95));
397 +    OptInt::SetVerbose(cfg.getUntrackedParameter<unsigned>("optIOVerbose",0));
398 +
399 +  } else {
400 +
401 +    if (cfg.exists("zipMode")   || cfg.exists("bZipThres") ||
402 +        cfg.exists("gZipThres") || cfg.exists("lzoThres")  ||
403 +        cfg.exists("lzmaThres")) {
404 +      edm::LogError("TreeService") << "OptIO interface not properly pre-loaded, "
405 +        "ignoring given settings." << std::endl;
406 +    }
407 +  }
408 +  
409    return 1;
410   }
411  
412 < //-------------------------------------------------------------------------------------------------
412 > //--------------------------------------------------------------------------------------------------
413   void FillMitTree::endJob()
414   {
415    // Delete fillers.
# Line 94 | Line 418 | void FillMitTree::endJob()
418      delete *iF;
419    }
420  
421 +  tws_->Clear();
422 +  
423    edm::LogInfo("FillMitTree::endJob") << "Ending Job" << endl;
424   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines