[CMSSW] / CMSSW / PhysicsTools / UtilAlgos / src / VariableHelper.cc Repository:
ViewVC logotype

Annotation of /CMSSW/PhysicsTools/UtilAlgos/src/VariableHelper.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (view) (download)

1 : vlimant 1.1 #include "FWCore/Framework/interface/Event.h"
2 :     #include "FWCore/Framework/interface/EventSetup.h"
3 :    
4 : vlimant 1.2 #include "PhysicsTools/UtilAlgos/interface/VariableHelper.h"
5 :     #include "PhysicsTools/UtilAlgos/interface/CachingVariable.h"
6 : vlimant 1.1
7 : vlimant 1.7 #include <iomanip>
8 : vlimant 1.1
9 :     VariableHelper::VariableHelper(const edm::ParameterSet & iConfig){
10 :     std::vector<std::string> psetNames;
11 :     iConfig.getParameterSetNames(psetNames);
12 : srappocc 1.8 for (unsigned int i=0;i!=psetNames.size();++i){
13 : vlimant 1.1 std::string & vname=psetNames[i];
14 :     edm::ParameterSet vPset=iConfig.getParameter<edm::ParameterSet>(psetNames[i]);
15 : vlimant 1.3 std::string method=vPset.getParameter<std::string>("method");
16 :    
17 : vlimant 1.5 CachingVariableFactory::get()->create(method,CachingVariable::CachingVariableFactoryArg(vname,variables_,vPset));
18 : vlimant 1.1 }
19 : vlimant 1.5
20 : vlimant 1.1 }
21 :    
22 :     void VariableHelper::setHolder(std::string hn){
23 : vlimant 1.5 iterator it = variables_.begin();
24 :     iterator it_end = variables_.end();
25 : vlimant 1.1 for (;it!=it_end;++it) it->second->setHolder(hn);
26 :     }
27 :    
28 : vlimant 1.6 void VariableHelper::print() const{
29 : vlimant 1.5 iterator it = variables_.begin();
30 :     iterator it_end = variables_.end();
31 : vlimant 1.3 for (;it!=it_end;++it) it->second->print();
32 :     }
33 :    
34 : vlimant 1.7 std::string VariableHelper::printValues(const edm::Event & event) const{
35 :     std::stringstream ss;
36 :     iterator it = variables_.begin();
37 :     iterator it_end = variables_.end();
38 :     ss<<std::setw(10)<<event.id().run()<<" : "
39 :     <<std::setw(10)<<event.id().event();
40 :     for (;it!=it_end;++it) {
41 :     if (it->second->compute(event))
42 :     ss<<" : "<<it->first<<"="<<(*it->second)(event);
43 :     else
44 :     ss<<" : "<<it->first<<" N/A";
45 :     }
46 :     return ss.str();
47 :     }
48 : vlimant 1.1 const CachingVariable* VariableHelper::variable(std::string name) const{
49 : vlimant 1.5 iterator v=variables_.find(name);
50 : vlimant 1.1 if (v!=variables_.end())
51 :     return v->second;
52 :     else
53 :     {
54 : vlimant 1.6 edm::LogError("VariableHelper")<<"I don't know anything named: "<<name
55 :     <<" list of available variables follows.";
56 :     print();
57 : vlimant 1.1 return 0;
58 :     }
59 :     }

CERN LCG CVS service
ViewVC Help
Powered by ViewVC 1.0.9