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.51 by loizides, Wed Nov 25 14:45:40 2009 UTC

# Line 4 | Line 4
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/FillerConversionElectrons.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/FillerMetaInfos.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/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;
# 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) {
110 <    throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
111 <      << "Could not get pointer to tree. "
112 <      << "Do you have the TreeServie define in your config?" << "\n";
113 <    return;
114 <  }
115 <
116 <  if (os_==0) {
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")
# Line 122 | Line 137 | void FillMitTree::beginJob(const edm::Ev
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
147    for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
148      edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl;
149 <    (*iF)->BookDataBlock(*tws);
149 >    (*iF)->BookDataBlock(*tws_, event);
150    }
151 +
152 +  // call branch ref for the event tree
153 +  if (brtable_ && tws_->GetTree())
154 +    tws_->GetTree()->BranchRef();
155 +  
156   }
157  
158   //--------------------------------------------------------------------------------------------------
159   bool FillMitTree::configure(const edm::ParameterSet &cfg)
160   {
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;
# Line 152 | Line 184 | bool FillMitTree::configure(const edm::P
184      if (cfg.existsAs<ParameterSet>(name,0)) {
185        ParameterSet next(cfg.getUntrackedParameter<ParameterSet>(name));
186        if (!next.exists("fillerType")) {
187 <        edm::LogError("FillMitTree") << "Can not determine fillerType for pset named "
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 <          << "Can not determine fillerType for pset named "
190 >          << "Cannot determine fillerType for pset named "
191            << name << std::endl;
192        }
193        ftype = next.getUntrackedParameter<string>("fillerType");
# Line 182 | Line 214 | bool FillMitTree::configure(const edm::P
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);
# Line 216 | Line 255 | bool FillMitTree::configure(const edm::P
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_);
# Line 243 | Line 288 | bool FillMitTree::configure(const edm::P
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);
# 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 +  // 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 + //--------------------------------------------------------------------------------------------------
414   void FillMitTree::endJob()
415   {
416    // Delete fillers.
# Line 322 | 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