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.36 by loizides, Tue Mar 17 14:26:07 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/TreeService/interface/TreeService.h"
8 > #include "MitProd/ObjectService/interface/ObjectService.h"
9 > #include "MitProd/TreeFiller/interface/AssociationMaps.h"
10 > #include "MitProd/TreeFiller/interface/FillerMetaInfos.h"
11 > #include "MitProd/TreeFiller/interface/FillerVertexes.h"
12 > #include "MitProd/TreeFiller/interface/FillerBeamSpot.h"
13 > #include "MitProd/TreeFiller/interface/FillerTracks.h"
14 > #include "MitProd/TreeFiller/interface/FillerBasicClusters.h"
15 > #include "MitProd/TreeFiller/interface/FillerSuperClusters.h"
16 > #include "MitProd/TreeFiller/interface/FillerCaloTowers.h"
17 > #include "MitProd/TreeFiller/interface/FillerMuons.h"
18 > #include "MitProd/TreeFiller/interface/FillerElectrons.h"
19 > #include "MitProd/TreeFiller/interface/FillerGenJets.h"
20 > #include "MitProd/TreeFiller/interface/FillerCaloJets.h"
21 > #include "MitProd/TreeFiller/interface/FillerPFJets.h"
22 > #include "MitProd/TreeFiller/interface/FillerMet.h"
23 > #include "MitProd/TreeFiller/interface/FillerCaloMet.h"
24 > #include "MitProd/TreeFiller/interface/FillerPFMet.h"
25 > #include "MitProd/TreeFiller/interface/FillerConversions.h"
26 > #include "MitProd/TreeFiller/interface/FillerConversionElectrons.h"
27 > #include "MitProd/TreeFiller/interface/FillerPhotons.h"
28 > #include "MitProd/TreeFiller/interface/FillerMCParticles.h"
29 > #include "MitProd/TreeFiller/interface/FillerDecayParts.h"
30 > #include "MitProd/TreeFiller/interface/FillerStableParts.h"
31 > #include "MitProd/TreeFiller/interface/FillerPFCandidates.h"
32 > #include "MitProd/TreeFiller/interface/FillerPATMuons.h"
33 > #include "MitProd/TreeFiller/interface/FillerPATElectrons.h"
34 > #include "MitAna/DataTree/interface/Names.h"
35 > #include "MitAna/DataTree/interface/BranchTable.h"
36  
37   using namespace std;
38   using namespace edm;
39   using namespace mithep;
40  
41 < //-------------------------------------------------------------------------------------------------
41 > mithep::ObjectService *mithep::FillMitTree::os_ = 0;
42 >
43 > //--------------------------------------------------------------------------------------------------
44   FillMitTree::FillMitTree(const edm::ParameterSet &cfg) :
45 <  fillerGlobalMuons_(0)
45 >  defactive_(cfg.getUntrackedParameter<bool>("defactive",1)),
46 >  brtable_(new BranchTable)
47   {
48 <  // initialize fillers
49 <  fillerGlobalMuons_ = new FillerGlobalMuons(cfg);
50 <  if (fillerGlobalMuons_->Active())
51 <    fillers_.push_back(fillerGlobalMuons_);
48 >  // Constructor.
49 >
50 >  if (!configure(cfg)) {
51 >    throw edm::Exception(edm::errors::Configuration, "FillMitTree::FillMitTree()\n")
52 >      << "Could not configure fillers." << "\n";
53 >  }
54 >
55 >  brtable_->SetName(Names::gkBranchTable);
56 >  brtable_->SetOwner();
57   }
58  
59 < //-------------------------------------------------------------------------------------------------
59 > //--------------------------------------------------------------------------------------------------
60   FillMitTree::~FillMitTree()
61   {
62 <  // We own the fillers so we have to delete them
63 <  delete fillerGlobalMuons_;
62 >  // Destructor.
63 >
64 >  delete brtable_;
65   }
66  
67 < //-------------------------------------------------------------------------------------------------
68 < void FillMitTree::beginJob(edm::EventSetup const &event)
67 > //--------------------------------------------------------------------------------------------------
68 > bool FillMitTree::addActiveFiller(BaseFiller *bf)
69   {
70 <  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 <  }
70 >  // Check if filler is active and add it to list of fillers. Otherwise delete it.
71  
72 <  // Loop over the various components and book the branches
73 <  for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
74 <    (*iF)->BookDataBlock(tws);
72 >  if (!bf)
73 >    return 0;
74 >
75 >  if (bf->Active()) {
76 >    fillers_.push_back(bf);
77 >    return 1;
78    }
79 <  return;
79 >
80 >  delete bf;
81 >  bf = 0;
82 >  return 0;
83   }
84  
85 < //-------------------------------------------------------------------------------------------------
85 > //--------------------------------------------------------------------------------------------------
86   void FillMitTree::analyze(const edm::Event      &event,
87                            const edm::EventSetup &setup)
88   {
89 <  // First step: Loop over the data fillers of the various components
89 >  // Access and copy event content.
90 >
91 >  // first step: Loop over the data fillers of the various components
92    for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
93      (*iF)->FillDataBlock(event,setup);
94    }
95  
96 <  // Second step: Loop over the link resolution of the various components
96 >  // second step: Loop over the link resolution of the various components
97    for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
98      (*iF)->ResolveLinks(event,setup);
99    }
100   }
101  
102 < //-------------------------------------------------------------------------------------------------
102 > //--------------------------------------------------------------------------------------------------
103 > void FillMitTree::beginJob(const edm::EventSetup &event)
104 > {
105 >  // Access the tree and book branches.
106 >
107 >  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) {
117 >    Service<ObjectService> os;
118 >    if (!os.isAvailable()) {
119 >      throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
120 >        << "Could not get object service. "
121 >        << "Do you have the ObjectService defined in your config?" << "\n";
122 >      return;
123 >    }
124 >    os_ = &(*os);
125 >    os->add(brtable_, brtable_->GetName());
126 >  }
127 >
128 >  // loop over the various components and book the branches
129 >  for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
130 >    edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl;
131 >    (*iF)->BookDataBlock(*tws);
132 >  }
133 > }
134 >
135 > //--------------------------------------------------------------------------------------------------
136 > bool FillMitTree::configure(const edm::ParameterSet &cfg)
137 > {
138 >  // Configure our fillers according to given parameter ("fillers").
139 >
140 >  std::vector<std::string> pars;
141 >  if (cfg.exists("fillers"))
142 >    pars=cfg.getUntrackedParameter<vector<string> >("fillers");
143 >  else
144 >    cfg.getParameterSetNames(pars, false);
145 >
146 >  // loop over psets
147 >  for (unsigned int i = 0; i<pars.size(); ++i) {
148 >
149 >    const string name(pars.at(i));
150 >    if (!cfg.existsAs<ParameterSet>(name,0))
151 >      continue;
152 >
153 >    ParameterSet next(cfg.getUntrackedParameter<ParameterSet>(name));
154 >    if (!next.exists("fillerType")) {
155 >      edm::LogError("FillMitTree") << "Can not determine fillerType for pset named "
156 >                                   << name << std::endl;
157 >      throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
158 >        << "Can not determine fillerType for pset named "
159 >        << name << std::endl;
160 >    }
161 >
162 >    string ftype(next.getUntrackedParameter<string>("fillerType"));
163 >
164 >    edm::LogInfo("FillMitTree") << "Configure '" << ftype << "' for '"
165 >                                << name << "'" << std::endl;
166 >
167 >    if (ftype.compare("FillerMetaInfos")==0) {
168 >      FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg, name.c_str(), defactive_);
169 >      addActiveFiller(fillerMetaInfos);
170 >      continue;
171 >    }
172 >    if (ftype.compare("FillerMCParticles")==0) {
173 >      FillerMCParticles *fillerMCParticles = new FillerMCParticles(cfg, name.c_str(), defactive_);
174 >      addActiveFiller(fillerMCParticles);
175 >      continue;
176 >    }
177 >    if (ftype.compare("FillerBeamSpot")==0) {
178 >      FillerBeamSpot *fillerBeamSpot = new FillerBeamSpot(cfg, name.c_str(), defactive_);
179 >      addActiveFiller(fillerBeamSpot);
180 >      continue;
181 >    }
182 >    if (ftype.compare("FillerVertexes")==0) {
183 >      FillerVertexes *fillerVertexes = new FillerVertexes(cfg, name.c_str(), defactive_);
184 >      addActiveFiller(fillerVertexes);
185 >      continue;
186 >    }  
187 >
188 >    if (ftype.compare("FillerCaloTowers")==0) {
189 >      FillerCaloTowers *fillerCaloTowers = new FillerCaloTowers(cfg, name.c_str(), defactive_);
190 >      addActiveFiller(fillerCaloTowers);
191 >      continue;
192 >    }  
193 >
194 >    if (ftype.compare("FillerGenJets")==0) {
195 >      FillerGenJets *fillerGenJets = new FillerGenJets(cfg, name.c_str(), defactive_);
196 >      addActiveFiller(fillerGenJets);
197 >      continue;
198 >    }  
199 >
200 >    if (ftype.compare("FillerCaloJets")==0) {
201 >      FillerCaloJets *fillerCaloJets = new FillerCaloJets(cfg, name.c_str(), defactive_);
202 >      addActiveFiller(fillerCaloJets);
203 >      continue;
204 >    }  
205 >    
206 >    if (ftype.compare("FillerMet")==0) {
207 >      FillerMet *fillerMet = new FillerMet(cfg, name.c_str(), defactive_);
208 >      addActiveFiller(fillerMet);
209 >      continue;
210 >    }  
211 >
212 >    if (ftype.compare("FillerCaloMet")==0) {
213 >      FillerCaloMet *fillerCaloMet = new FillerCaloMet(cfg, name.c_str(), defactive_);
214 >      addActiveFiller(fillerCaloMet);
215 >      continue;
216 >    }
217 >    
218 >    if (ftype.compare("FillerPFMet")==0) {
219 >      FillerPFMet *fillerPFMet = new FillerPFMet(cfg, name.c_str(), defactive_);
220 >      addActiveFiller(fillerPFMet);
221 >      continue;
222 >    }  
223 >
224 >    if (ftype.compare("FillerBasicClusters")==0) {
225 >      FillerBasicClusters *fillerBasicClusters =
226 >        new FillerBasicClusters(cfg, name.c_str(), defactive_);
227 >      addActiveFiller(fillerBasicClusters);
228 >      continue;
229 >    }  
230 >
231 >    if (ftype.compare("FillerSuperClusters")==0) {
232 >      FillerSuperClusters *fillerSuperClusters =  
233 >        new FillerSuperClusters(cfg, name.c_str(), defactive_);
234 >      addActiveFiller(fillerSuperClusters);
235 >      continue;
236 >    }  
237 >
238 >    if (ftype.compare("FillerTracks")==0) {
239 >      FillerTracks *fillerTracks = new FillerTracks(cfg, name.c_str(), defactive_);
240 >      addActiveFiller(fillerTracks);
241 >      continue;
242 >    }  
243 >
244 >    if (ftype.compare("FillerMuons")==0) {
245 >      FillerMuons *fillerMuons = new FillerMuons(cfg, name.c_str(), defactive_);
246 >      addActiveFiller(fillerMuons);
247 >      continue;
248 >    }  
249 >
250 >    if (ftype.compare("FillerElectrons")==0) {
251 >      FillerElectrons *fillerElectrons = new FillerElectrons(cfg, name.c_str(), defactive_);
252 >      addActiveFiller(fillerElectrons);
253 >      continue;
254 >    }  
255 >
256 >    if (ftype.compare("FillerConversionElectrons")==0) {
257 >      FillerConversionElectrons *fillerConversionElectrons =
258 >        new FillerConversionElectrons(cfg, name.c_str(), defactive_);
259 >      addActiveFiller(fillerConversionElectrons);
260 >      continue;
261 >    }  
262 >
263 >    if (ftype.compare("FillerConversions")==0) {
264 >      FillerConversions *fillerConversions = new FillerConversions(cfg, name.c_str(), defactive_);
265 >      addActiveFiller(fillerConversions);
266 >      continue;
267 >    }  
268 >
269 >    if (ftype.compare("FillerPhotons")==0) {
270 >      FillerPhotons *fillerPhotons = new FillerPhotons(cfg, name.c_str(), defactive_);
271 >      addActiveFiller(fillerPhotons);
272 >      continue;
273 >    }  
274 >
275 >    if (ftype.compare("FillerStableParts")==0) {
276 >      FillerStableParts *fillerStableParts = new FillerStableParts(cfg, name.c_str(), defactive_);
277 >      addActiveFiller(fillerStableParts);
278 >      continue;
279 >    }  
280 >
281 >    if (ftype.compare("FillerDecayParts")==0) {
282 >      FillerDecayParts *fillerDecayParts = new FillerDecayParts(cfg, name.c_str(), defactive_);
283 >      addActiveFiller(fillerDecayParts);
284 >      continue;
285 >    }  
286 >    
287 >    if (ftype.compare("FillerPFCandidates")==0) {
288 >      FillerPFCandidates *fillerPFCands = new FillerPFCandidates(cfg, name.c_str(), defactive_);
289 >      addActiveFiller(fillerPFCands);
290 >      continue;
291 >    }  
292 >
293 >    if (ftype.compare("FillerPFJets")==0) {
294 >      FillerPFJets *fillerPFJets = new FillerPFJets(cfg, name.c_str(), defactive_);
295 >      addActiveFiller(fillerPFJets);
296 >      continue;
297 >    }  
298 >    
299 >    edm::LogError("FillMitTree")
300 >      << "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
301 >    throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
302 >      << "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
303 >  }
304 >
305 >  return 1;
306 > }
307 >
308 > //--------------------------------------------------------------------------------------------------
309   void FillMitTree::endJob()
310   {
311 +  // Delete fillers.
312 +
313 +  for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
314 +    delete *iF;
315 +  }
316 +
317    edm::LogInfo("FillMitTree::endJob") << "Ending Job" << endl;
318   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines