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.37 by loizides, Thu Mar 19 16:15:35 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/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"
21 < #include "MitProd/TreeFiller/interface/FillerGlobalMuons.h"
21 > #include "MitProd/TreeFiller/interface/FillerMCEventInfo.h"
22 > #include "MitProd/TreeFiller/interface/FillerMCParticles.h"
23 > #include "MitProd/TreeFiller/interface/FillerMet.h"
24 > #include "MitProd/TreeFiller/interface/FillerMetaInfos.h"
25 > #include "MitProd/TreeFiller/interface/FillerMuons.h"
26 > #include "MitProd/TreeFiller/interface/FillerPFCandidates.h"
27 > #include "MitProd/TreeFiller/interface/FillerPFJets.h"
28 > #include "MitProd/TreeFiller/interface/FillerPFMet.h"
29 > #include "MitProd/TreeFiller/interface/FillerPhotons.h"
30 > #include "MitProd/TreeFiller/interface/FillerStableParts.h"
31 > #include "MitProd/TreeFiller/interface/FillerSuperClusters.h"
32 > #include "MitProd/TreeFiller/interface/FillerTracks.h"
33 > #include "MitProd/TreeFiller/interface/FillerVertexes.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 < //-------------------------------------------------------------------------------------------------
42 < FillMitTree::FillMitTree(const edm::ParameterSet &cfg)
41 > mithep::ObjectService *mithep::FillMitTree::os_ = 0;
42 >
43 > //--------------------------------------------------------------------------------------------------
44 > FillMitTree::FillMitTree(const edm::ParameterSet &cfg) :
45 >  defactive_(cfg.getUntrackedParameter<bool>("defactive",1)),
46 >  brtable_(new BranchTable)
47   {
48 <  // Constructor: initialize fillers
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 <  // Destructor: nothing to be done here.
62 >  // Destructor.
63 >
64 >  delete brtable_;
65   }
66  
67 < //-------------------------------------------------------------------------------------------------
67 > //--------------------------------------------------------------------------------------------------
68 > bool FillMitTree::addActiveFiller(BaseFiller *bf)
69 > {
70 >  // Check if filler is active and add it to list of fillers. Otherwise delete it.
71 >
72 >  if (!bf)
73 >    return 0;
74 >
75 >  if (bf->Active()) {
76 >    fillers_.push_back(bf);
77 >    return 1;
78 >  }
79 >
80 >  delete bf;
81 >  bf = 0;
82 >  return 0;
83 > }
84 >
85 > //--------------------------------------------------------------------------------------------------
86   void FillMitTree::analyze(const edm::Event      &event,
87                            const edm::EventSetup &setup)
88   {
89    // Access and copy event content.
90  
91 <  // First step: Loop over the data fillers of the various components
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.
# Line 54 | Line 108 | void FillMitTree::beginJob(const edm::Ev
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." << "\n";
111 >      << "Could not get pointer to tree. "
112 >      << "Do you have the TreeServie define in your config?" << "\n";
113      return;
114    }
115  
116 <  // Loop over the various components and book the branches
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 <    (*iF)->BookDataBlock(tws);
130 >    edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl;
131 >    (*iF)->BookDataBlock(*tws);
132    }
65  return;
133   }
134  
135 < //-------------------------------------------------------------------------------------------------
135 > //--------------------------------------------------------------------------------------------------
136   bool FillMitTree::configure(const edm::ParameterSet &cfg)
137   {
138 <  // Configure our fillers.
72 <
138 >  // Configure our fillers according to given parameter ("fillers").
139  
140 <  FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg);
141 <  if (fillerMetaInfos->Active())
142 <    fillers_.push_back(fillerMetaInfos);
143 <  else
144 <    delete fillerMetaInfos;
145 <
146 <  FillerGlobalMuons *fillerGlobalMuons = new FillerGlobalMuons(cfg);
147 <  if (fillerGlobalMuons->Active())
148 <    fillers_.push_back(fillerGlobalMuons);
149 <  else
150 <    delete fillerGlobalMuons;
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 >
151 >    string ftype("Filler" + name);
152 >    if (cfg.existsAs<ParameterSet>(name,0)) {
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 >      ftype = next.getUntrackedParameter<string>("fillerType");
162 >    }
163 >
164 >    edm::LogInfo("FillMitTree") << "Attempting to configure '" << ftype
165 >                                << "' for '" << 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 >
173 >    if (ftype.compare("FillerMCParticles")==0) {
174 >      FillerMCParticles *fillerMCParticles = new FillerMCParticles(cfg, name.c_str(), defactive_);
175 >      addActiveFiller(fillerMCParticles);
176 >      continue;
177 >    }
178 >
179 >    if (ftype.compare("FillerMCEventInfo")==0) {
180 >      FillerMCEventInfo *fillerMCEventInfo = new FillerMCEventInfo(cfg, name.c_str(), defactive_);
181 >      addActiveFiller(fillerMCEventInfo);
182 >      continue;
183 >    }
184 >
185 >    if (ftype.compare("FillerBeamSpot")==0) {
186 >      FillerBeamSpot *fillerBeamSpot = new FillerBeamSpot(cfg, name.c_str(), defactive_);
187 >      addActiveFiller(fillerBeamSpot);
188 >      continue;
189 >    }
190 >    if (ftype.compare("FillerVertexes")==0) {
191 >      FillerVertexes *fillerVertexes = new FillerVertexes(cfg, name.c_str(), defactive_);
192 >      addActiveFiller(fillerVertexes);
193 >      continue;
194 >    }  
195 >
196 >    if (ftype.compare("FillerCaloTowers")==0) {
197 >      FillerCaloTowers *fillerCaloTowers = new FillerCaloTowers(cfg, name.c_str(), defactive_);
198 >      addActiveFiller(fillerCaloTowers);
199 >      continue;
200 >    }  
201 >
202 >    if (ftype.compare("FillerGenJets")==0) {
203 >      FillerGenJets *fillerGenJets = new FillerGenJets(cfg, name.c_str(), defactive_);
204 >      addActiveFiller(fillerGenJets);
205 >      continue;
206 >    }  
207 >
208 >    if (ftype.compare("FillerCaloJets")==0) {
209 >      FillerCaloJets *fillerCaloJets = new FillerCaloJets(cfg, name.c_str(), defactive_);
210 >      addActiveFiller(fillerCaloJets);
211 >      continue;
212 >    }  
213 >    
214 >    if (ftype.compare("FillerMet")==0) {
215 >      FillerMet *fillerMet = new FillerMet(cfg, name.c_str(), defactive_);
216 >      addActiveFiller(fillerMet);
217 >      continue;
218 >    }  
219 >
220 >    if (ftype.compare("FillerCaloMet")==0) {
221 >      FillerCaloMet *fillerCaloMet = new FillerCaloMet(cfg, name.c_str(), defactive_);
222 >      addActiveFiller(fillerCaloMet);
223 >      continue;
224 >    }
225 >    
226 >    if (ftype.compare("FillerPFMet")==0) {
227 >      FillerPFMet *fillerPFMet = new FillerPFMet(cfg, name.c_str(), defactive_);
228 >      addActiveFiller(fillerPFMet);
229 >      continue;
230 >    }  
231 >
232 >    if (ftype.compare("FillerBasicClusters")==0) {
233 >      FillerBasicClusters *fillerBasicClusters =
234 >        new FillerBasicClusters(cfg, name.c_str(), defactive_);
235 >      addActiveFiller(fillerBasicClusters);
236 >      continue;
237 >    }  
238 >
239 >    if (ftype.compare("FillerSuperClusters")==0) {
240 >      FillerSuperClusters *fillerSuperClusters =  
241 >        new FillerSuperClusters(cfg, name.c_str(), defactive_);
242 >      addActiveFiller(fillerSuperClusters);
243 >      continue;
244 >    }  
245 >
246 >    if (ftype.compare("FillerTracks")==0) {
247 >      FillerTracks *fillerTracks = new FillerTracks(cfg, name.c_str(), defactive_);
248 >      addActiveFiller(fillerTracks);
249 >      continue;
250 >    }  
251 >
252 >    if (ftype.compare("FillerMuons")==0) {
253 >      FillerMuons *fillerMuons = new FillerMuons(cfg, name.c_str(), defactive_);
254 >      addActiveFiller(fillerMuons);
255 >      continue;
256 >    }  
257 >
258 >    if (ftype.compare("FillerElectrons")==0) {
259 >      FillerElectrons *fillerElectrons = new FillerElectrons(cfg, name.c_str(), defactive_);
260 >      addActiveFiller(fillerElectrons);
261 >      continue;
262 >    }  
263 >
264 >    if (ftype.compare("FillerConversionElectrons")==0) {
265 >      FillerConversionElectrons *fillerConversionElectrons =
266 >        new FillerConversionElectrons(cfg, name.c_str(), defactive_);
267 >      addActiveFiller(fillerConversionElectrons);
268 >      continue;
269 >    }  
270 >
271 >    if (ftype.compare("FillerConversions")==0) {
272 >      FillerConversions *fillerConversions = new FillerConversions(cfg, name.c_str(), defactive_);
273 >      addActiveFiller(fillerConversions);
274 >      continue;
275 >    }  
276 >
277 >    if (ftype.compare("FillerPhotons")==0) {
278 >      FillerPhotons *fillerPhotons = new FillerPhotons(cfg, name.c_str(), defactive_);
279 >      addActiveFiller(fillerPhotons);
280 >      continue;
281 >    }  
282 >
283 >    if (ftype.compare("FillerStableParts")==0) {
284 >      FillerStableParts *fillerStableParts = new FillerStableParts(cfg, name.c_str(), defactive_);
285 >      addActiveFiller(fillerStableParts);
286 >      continue;
287 >    }  
288 >
289 >    if (ftype.compare("FillerDecayParts")==0) {
290 >      FillerDecayParts *fillerDecayParts = new FillerDecayParts(cfg, name.c_str(), defactive_);
291 >      addActiveFiller(fillerDecayParts);
292 >      continue;
293 >    }  
294 >    
295 >    if (ftype.compare("FillerPFCandidates")==0) {
296 >      FillerPFCandidates *fillerPFCands = new FillerPFCandidates(cfg, name.c_str(), defactive_);
297 >      addActiveFiller(fillerPFCands);
298 >      continue;
299 >    }  
300 >
301 >    if (ftype.compare("FillerPFJets")==0) {
302 >      FillerPFJets *fillerPFJets = new FillerPFJets(cfg, name.c_str(), defactive_);
303 >      addActiveFiller(fillerPFJets);
304 >      continue;
305 >    }  
306 >    
307 >    edm::LogError("FillMitTree")
308 >      << "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
309 >    throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
310 >      << "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
311 >  }
312  
313    return 1;
314   }
315  
316 < //-------------------------------------------------------------------------------------------------
316 > //--------------------------------------------------------------------------------------------------
317   void FillMitTree::endJob()
318   {
319    // Delete fillers.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines