Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:16:05

0001 #include "PHParameterInterface.h"
0002 #include "PHParameters.h"
0003 
0004 #include <phool/PHCompositeNode.h>
0005 #include <phool/PHDataNode.h>
0006 #include <phool/phool.h>
0007 
0008 #include <TSystem.h>
0009 
0010 #include <iostream>
0011 #include <utility>
0012 
0013 PHParameterInterface::PHParameterInterface(const std::string &name)
0014   : m_Params(new PHParameters(name))
0015 {
0016 }
0017 
0018 PHParameterInterface::~PHParameterInterface()
0019 {
0020   delete m_Params;
0021 }
0022 
0023 void PHParameterInterface::set_paramname(const std::string &name)
0024 {
0025   m_Params->set_name(name);
0026 }
0027 
0028 void PHParameterInterface::set_default_double_param(const std::string &name, const double dval)
0029 {
0030   if (m_DefaultDoubleParMap.find(name) == m_DefaultDoubleParMap.end())
0031   {
0032     m_DefaultDoubleParMap[name] = dval;
0033   }
0034   else
0035   {
0036     std::cout << "trying to overwrite default double " << name << " "
0037               << m_DefaultDoubleParMap[name] << " with " << dval << std::endl;
0038     gSystem->Exit(1);
0039   }
0040   return;
0041 }
0042 
0043 void PHParameterInterface::set_default_int_param(const std::string &name, const int ival)
0044 {
0045   if (m_DefaultIntParMap.find(name) == m_DefaultIntParMap.end())
0046   {
0047     m_DefaultIntParMap[name] = ival;
0048   }
0049   else
0050   {
0051     std::cout << "trying to overwrite default int " << name << " "
0052               << m_DefaultIntParMap[name] << " with " << ival << std::endl;
0053     gSystem->Exit(1);
0054   }
0055   return;
0056 }
0057 
0058 void PHParameterInterface::set_default_string_param(const std::string &name, const std::string &sval)
0059 {
0060   if (m_DefaultStringParMap.find(name) == m_DefaultStringParMap.end())
0061   {
0062     m_DefaultStringParMap[name] = sval;
0063   }
0064   else
0065   {
0066     std::cout << "trying to overwrite default string " << name << " "
0067               << m_DefaultStringParMap[name] << " with " << sval << std::endl;
0068     gSystem->Exit(1);
0069   }
0070   return;
0071 }
0072 void PHParameterInterface::set_double_param(const std::string &name, const double dval)
0073 {
0074   if (m_Locked)
0075   {
0076     std::cout << PHWHERE << " PHParameterInterface is locked, no modifictions allowd" << std::endl;
0077     gSystem->Exit(1);
0078   }
0079   if (m_DefaultDoubleParMap.find(name) == m_DefaultDoubleParMap.end())
0080   {
0081     std::cout << "double parameter " << name << " not implemented" << std::endl;
0082     std::cout << "implemented double parameters are:" << std::endl;
0083     for (std::map<const std::string, double>::const_iterator iter = m_DefaultDoubleParMap.begin(); iter != m_DefaultDoubleParMap.end(); ++iter)
0084     {
0085       std::cout << iter->first << std::endl;
0086     }
0087     return;
0088   }
0089   m_DoubleParMap[name] = dval;
0090 }
0091 
0092 double
0093 PHParameterInterface::get_double_param(const std::string &name) const
0094 {
0095   return m_Params->get_double_param(name);
0096 }
0097 
0098 void PHParameterInterface::set_int_param(const std::string &name, const int ival)
0099 {
0100   if (m_Locked)
0101   {
0102     std::cout << PHWHERE << " PHParameterInterface is locked, no modifictions allowd" << std::endl;
0103     gSystem->Exit(1);
0104   }
0105   if (m_DefaultIntParMap.find(name) == m_DefaultIntParMap.end())
0106   {
0107     std::cout << "integer parameter " << name << " not implemented" << std::endl;
0108     std::cout << "implemented integer parameters are:" << std::endl;
0109     for (std::map<const std::string, int>::const_iterator iter = m_DefaultIntParMap.begin(); iter != m_DefaultIntParMap.end(); ++iter)
0110     {
0111       std::cout << iter->first << std::endl;
0112     }
0113     return;
0114   }
0115   m_IntParMap[name] = ival;
0116 }
0117 
0118 int PHParameterInterface::get_int_param(const std::string &name) const
0119 {
0120   return m_Params->get_int_param(name);
0121 }
0122 
0123 void PHParameterInterface::set_string_param(const std::string &name, const std::string &sval)
0124 {
0125   if (m_Locked)
0126   {
0127     std::cout << PHWHERE << " PHParameterInterface is locked, no modifictions allowd" << std::endl;
0128     gSystem->Exit(1);
0129   }
0130   if (m_DefaultStringParMap.find(name) == m_DefaultStringParMap.end())
0131   {
0132     std::cout << "string parameter " << name << " not implemented" << std::endl;
0133     std::cout << "implemented string parameters are:" << std::endl;
0134     for (std::map<const std::string, std::string>::const_iterator iter = m_DefaultStringParMap.begin(); iter != m_DefaultStringParMap.end(); ++iter)
0135     {
0136       std::cout << iter->first << std::endl;
0137     }
0138     return;
0139   }
0140   m_StringParMap[name] = sval;
0141 }
0142 
0143 std::string
0144 PHParameterInterface::get_string_param(const std::string &name) const
0145 {
0146   return m_Params->get_string_param(name);
0147 }
0148 
0149 void PHParameterInterface::UpdateParametersWithMacro()
0150 {
0151   for (std::map<const std::string, double>::const_iterator iter = m_DoubleParMap.begin(); iter != m_DoubleParMap.end(); ++iter)
0152   {
0153     m_Params->set_double_param(iter->first, iter->second);
0154   }
0155   for (std::map<const std::string, int>::const_iterator iter = m_IntParMap.begin(); iter != m_IntParMap.end(); ++iter)
0156   {
0157     m_Params->set_int_param(iter->first, iter->second);
0158   }
0159   for (std::map<const std::string, std::string>::const_iterator iter = m_StringParMap.begin(); iter != m_StringParMap.end(); ++iter)
0160   {
0161     m_Params->set_string_param(iter->first, iter->second);
0162   }
0163   return;
0164 }
0165 
0166 void PHParameterInterface::SaveToNodeTree(PHCompositeNode *runNode, const std::string &nodename)
0167 {
0168   m_Locked = true;  // no more modifications after it it on the node tree
0169   m_Params->SaveToNodeTree(runNode, nodename);
0170   return;
0171 }
0172 
0173 void PHParameterInterface::PutOnParNode(PHCompositeNode *parNode, const std::string &nodename)
0174 {
0175   m_Locked = true;  // no more modifications after it it on the node tree
0176   PHParameters *newparams = new PHParameters(*m_Params, m_Params->Name());
0177   parNode->addNode(new PHDataNode<PHParameters>(newparams, nodename));
0178 }
0179 
0180 void PHParameterInterface::InitializeParameters()
0181 {
0182   SetDefaultParameters();  // call method from specific subsystem
0183   // now load those parameters to our params class
0184   for (std::map<const std::string, double>::const_iterator iter = m_DefaultDoubleParMap.begin(); iter != m_DefaultDoubleParMap.end(); ++iter)
0185   {
0186     m_Params->set_double_param(iter->first, iter->second);
0187   }
0188   for (std::map<const std::string, int>::const_iterator iter = m_DefaultIntParMap.begin(); iter != m_DefaultIntParMap.end(); ++iter)
0189   {
0190     m_Params->set_int_param(iter->first, iter->second);
0191   }
0192   for (std::map<const std::string, std::string>::const_iterator iter = m_DefaultStringParMap.begin(); iter != m_DefaultStringParMap.end(); ++iter)
0193   {
0194     m_Params->set_string_param(iter->first, iter->second);
0195   }
0196 }
0197 
0198 void PHParameterInterface::Print() const
0199 {
0200   if (m_Params)
0201   {
0202     m_Params->Print();
0203   }
0204 }