Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:18

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 
0004 #include "PhysicsTools/UtilAlgos/interface/VariableHelper.h"
0005 #include "PhysicsTools/UtilAlgos/interface/CachingVariable.h"
0006 
0007 #include <iomanip>
0008 
0009 VariableHelper::VariableHelper(const edm::ParameterSet& iConfig, edm::ConsumesCollector& iC) {
0010   std::vector<std::string> psetNames;
0011   iConfig.getParameterSetNames(psetNames);
0012   for (unsigned int i = 0; i != psetNames.size(); ++i) {
0013     std::string& vname = psetNames[i];
0014     edm::ParameterSet vPset = iConfig.getParameter<edm::ParameterSet>(psetNames[i]);
0015     std::string method = vPset.getParameter<std::string>("method");
0016 
0017     CachingVariableFactory::get()->create(
0018         method, CachingVariable::CachingVariableFactoryArg(vname, variables_, vPset), iC);
0019   }
0020 }
0021 
0022 void VariableHelper::setHolder(std::string hn) {
0023   iterator it = variables_.begin();
0024   iterator it_end = variables_.end();
0025   for (; it != it_end; ++it)
0026     it->second->setHolder(hn);
0027 }
0028 
0029 void VariableHelper::print() const {
0030   iterator it = variables_.begin();
0031   iterator it_end = variables_.end();
0032   for (; it != it_end; ++it)
0033     it->second->print();
0034 }
0035 
0036 std::string VariableHelper::printValues(const edm::Event& event) const {
0037   std::stringstream ss;
0038   iterator it = variables_.begin();
0039   iterator it_end = variables_.end();
0040   ss << std::setw(10) << event.id().run() << " : " << std::setw(10) << event.id().event();
0041   for (; it != it_end; ++it) {
0042     if (it->second->compute(event))
0043       ss << " : " << it->first << "=" << (*it->second)(event);
0044     else
0045       ss << " : " << it->first << " N/A";
0046   }
0047   return ss.str();
0048 }
0049 const CachingVariable* VariableHelper::variable(std::string name) const {
0050   iterator v = variables_.find(name);
0051   if (v != variables_.end())
0052     return v->second;
0053   else {
0054     edm::LogError("VariableHelper") << "I don't know anything named: " << name
0055                                     << " list of available variables follows.";
0056     print();
0057     return nullptr;
0058   }
0059 }