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.37 by loizides, Thu Mar 19 16:15:35 2009 UTC vs.
Revision 1.49 by bendavid, Tue Nov 3 14:02:32 2009 UTC

# Line 11 | Line 11
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"
15 #include "MitProd/TreeFiller/interface/FillerConversionElectrons.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/FillerMetaInfos.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/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;
# Line 43 | Line 48 | mithep::ObjectService *mithep::FillMitTr
48   //--------------------------------------------------------------------------------------------------
49   FillMitTree::FillMitTree(const edm::ParameterSet &cfg) :
50    defactive_(cfg.getUntrackedParameter<bool>("defactive",1)),
51 <  brtable_(new BranchTable)
51 >  brtable_(0),
52 >  acfnumber_(-1),
53 >  tws_(new TreeWriter(Names::gkEvtTreeName,0))
54   {
55    // Constructor.
56  
# Line 51 | Line 58 | FillMitTree::FillMitTree(const edm::Para
58      throw edm::Exception(edm::errors::Configuration, "FillMitTree::FillMitTree()\n")
59        << "Could not configure fillers." << "\n";
60    }
54
55  brtable_->SetName(Names::gkBranchTable);
56  brtable_->SetOwner();
61   }
62  
63   //--------------------------------------------------------------------------------------------------
# Line 62 | Line 66 | FillMitTree::~FillMitTree()
66    // Destructor.
67  
68    delete brtable_;
69 +  delete tws_;
70   }
71  
72   //--------------------------------------------------------------------------------------------------
# Line 87 | Line 92 | void FillMitTree::analyze(const edm::Eve
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
100    for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
# Line 97 | Line 105 | void FillMitTree::analyze(const edm::Eve
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   //--------------------------------------------------------------------------------------------------
# Line 104 | Line 128 | void FillMitTree::beginJob(const edm::Ev
128   {
129    // Access the tree and book branches.
130  
131 <  Service<TreeService> ts;
108 <  TreeWriter *tws = ts->get();
109 <  if (! tws) {
131 >  if (!tws_) {
132      throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
133        << "Could not get pointer to tree. "
134        << "Do you have the TreeServie define in your config?" << "\n";
135      return;
136    }
137  
138 <  if (os_==0) {
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")
# Line 122 | Line 144 | void FillMitTree::beginJob(const edm::Ev
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      edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl;
156 <    (*iF)->BookDataBlock(*tws);
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   //--------------------------------------------------------------------------------------------------
166   bool FillMitTree::configure(const edm::ParameterSet &cfg)
167   {
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;
# Line 152 | Line 191 | bool FillMitTree::configure(const edm::P
191      if (cfg.existsAs<ParameterSet>(name,0)) {
192        ParameterSet next(cfg.getUntrackedParameter<ParameterSet>(name));
193        if (!next.exists("fillerType")) {
194 <        edm::LogError("FillMitTree") << "Can not determine fillerType for pset named "
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 <          << "Can not determine fillerType for pset named "
197 >          << "Cannot determine fillerType for pset named "
198            << name << std::endl;
199        }
200        ftype = next.getUntrackedParameter<string>("fillerType");
# Line 182 | Line 221 | bool FillMitTree::configure(const edm::P
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);
# Line 216 | Line 262 | bool FillMitTree::configure(const edm::P
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_);
# Line 243 | Line 295 | bool FillMitTree::configure(const edm::P
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);
# Line 261 | Line 320 | bool FillMitTree::configure(const edm::P
320        continue;
321      }  
322  
264    if (ftype.compare("FillerConversionElectrons")==0) {
265      FillerConversionElectrons *fillerConversionElectrons =
266        new FillerConversionElectrons(cfg, name.c_str(), defactive_);
267      addActiveFiller(fillerConversionElectrons);
268      continue;
269    }  
270
323      if (ftype.compare("FillerConversions")==0) {
324        FillerConversions *fillerConversions = new FillerConversions(cfg, name.c_str(), defactive_);
325        addActiveFiller(fillerConversions);
# Line 303 | Line 355 | bool FillMitTree::configure(const edm::P
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;
# Line 314 | Line 378 | bool FillMitTree::configure(const edm::P
378   }
379  
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 + //--------------------------------------------------------------------------------------------------
413   void FillMitTree::endJob()
414   {
415    // Delete fillers.
# Line 322 | 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