CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/PhysicsTools/UtilAlgos/src/VariableHelper.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/Event.h"
00002 #include "FWCore/Framework/interface/EventSetup.h"
00003 
00004 #include "PhysicsTools/UtilAlgos/interface/VariableHelper.h"
00005 #include "PhysicsTools/UtilAlgos/interface/CachingVariable.h"
00006 
00007 #include <iomanip>
00008 
00009 VariableHelper::VariableHelper(const edm::ParameterSet & iConfig){
00010   std::vector<std::string> psetNames;
00011   iConfig.getParameterSetNames(psetNames);
00012   for (unsigned int i=0;i!=psetNames.size();++i){
00013     std::string & vname=psetNames[i];
00014     edm::ParameterSet vPset=iConfig.getParameter<edm::ParameterSet>(psetNames[i]);
00015     std::string method=vPset.getParameter<std::string>("method");
00016 
00017     CachingVariableFactory::get()->create(method,CachingVariable::CachingVariableFactoryArg(vname,variables_,vPset));
00018   }
00019 
00020 }
00021 
00022 void VariableHelper::setHolder(std::string hn){
00023   iterator it = variables_.begin();
00024   iterator it_end = variables_.end();
00025   for (;it!=it_end;++it)  it->second->setHolder(hn);
00026 }
00027 
00028 void VariableHelper::print() const{
00029   iterator it = variables_.begin();
00030   iterator it_end = variables_.end();
00031   for (;it!=it_end;++it)  it->second->print();
00032 }
00033 
00034 std::string VariableHelper::printValues(const edm::Event & event) const{
00035   std::stringstream ss;
00036   iterator it = variables_.begin();
00037   iterator it_end = variables_.end();
00038   ss<<std::setw(10)<<event.id().run()<<" : "
00039     <<std::setw(10)<<event.id().event();    
00040   for (;it!=it_end;++it) {
00041     if (it->second->compute(event))
00042       ss<<" : "<<it->first<<"="<<(*it->second)(event);
00043     else
00044       ss<<" : "<<it->first<<" N/A";
00045   }
00046   return ss.str();
00047 }
00048 const CachingVariable* VariableHelper::variable(std::string name) const{ 
00049   iterator v=variables_.find(name);
00050   if (v!=variables_.end())
00051     return v->second;
00052   else
00053     {
00054       edm::LogError("VariableHelper")<<"I don't know anything named: "<<name
00055                                      <<" list of available variables follows.";
00056       print();
00057       return 0;
00058     }
00059 }