Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 #ifndef PHPARAMETER_PHPARAMETERS_H
0004 #define PHPARAMETER_PHPARAMETERS_H
0005 
0006 #include <phool/PHObject.h>
0007 
0008 #include <cstddef>
0009 #include <map>
0010 #include <string>
0011 #include <utility>
0012 
0013 class PdbParameterMap;
0014 class PdbParameterMapContainer;
0015 class PHCompositeNode;
0016 
0017 // contains parameters in our units,
0018 // convert to G4 units inside get access methods
0019 
0020 class PHParameters : public PHObject
0021 {
0022  public:
0023   typedef std::map<const std::string, double> dMap;
0024   typedef dMap::const_iterator dIter;
0025   typedef std::map<const std::string, int> iMap;
0026   typedef iMap::const_iterator iIter;
0027   typedef std::map<const std::string, std::string> strMap;
0028   typedef std::map<const std::string, std::string>::const_iterator strIter;
0029 
0030   explicit PHParameters(const std::string &name)
0031     : m_Detector(name)
0032   {
0033   }
0034 
0035   PHParameters(const PHParameters &params, const std::string &name);
0036 
0037   ~PHParameters() override;
0038 
0039   void Reset() override;
0040 
0041   void Print(Option_t *option = "") const override;
0042 
0043   //! hash of binary information for checking purpose
0044   size_t get_hash() const;
0045 
0046   void set_int_param(const std::string &name, const int ival);
0047   int get_int_param(const std::string &name) const;
0048   bool exist_int_param(const std::string &name) const;
0049   std::pair<std::map<const std::string, int>::const_iterator, std::map<const std::string, int>::const_iterator> get_all_int_params() { return std::make_pair(m_IntParMap.begin(), m_IntParMap.end()); }
0050 
0051   void set_double_param(const std::string &name, const double dval);
0052   double get_double_param(const std::string &name) const;
0053   bool exist_double_param(const std::string &name) const;
0054   std::pair<std::map<const std::string, double>::const_iterator, std::map<const std::string, double>::const_iterator> get_all_double_params() { return std::make_pair(m_DoubleParMap.begin(), m_DoubleParMap.end()); }
0055 
0056   void set_string_param(const std::string &name, const std::string &str);
0057   std::string get_string_param(const std::string &name) const;
0058   bool exist_string_param(const std::string &name) const;
0059   std::pair<std::map<const std::string, std::string>::const_iterator, std::map<const std::string, std::string>::const_iterator> get_all_string_params() { return std::make_pair(m_StringParMap.begin(), m_StringParMap.end()); }
0060 
0061   void set_name(const std::string &name) { m_Detector = name; }
0062   const std::string &Name() const { return m_Detector; }
0063 
0064   void FillFrom(const PdbParameterMap *saveparams);
0065   void FillFrom(const PdbParameterMapContainer *saveparamcontainer, const int detid);
0066   void FillFrom(const PHParameters *saveparams);
0067   // save parameters on node tree
0068   void SaveToNodeTree(PHCompositeNode *topNode, const std::string &nodename);
0069   // save parameters in container on node tree
0070   void SaveToNodeTree(PHCompositeNode *topNode, const std::string &nodename, const int detid);
0071 
0072   // update parameters on node tree (in case the subsystem modified them)
0073   void UpdateNodeTree(PHCompositeNode *topNode, const std::string &nodename);
0074   void UpdateNodeTree(PHCompositeNode *topNode, const std::string &nodename, const int detid);
0075 
0076   int WriteToCDBFile(const std::string &filename);
0077   int WriteToFile(const std::string &extension, const std::string &dir = ".");
0078 
0079   //! simple read without super detector and layer structures
0080   inline int ReadFromFile(const std::string &name, const std::string &extension, const std::string &dir = ".")
0081   {
0082     return ReadFromFile(name, extension, 0, 0, dir);
0083   }
0084   int ReadFromCDBFile(const std::string &url);
0085   //! Fully fledged read
0086   int ReadFromFile(const std::string &name, const std::string &extension, const int detid, const int issuper, const std::string &dir = ".");
0087   void CopyToPdbParameterMap(PdbParameterMap *myparm);
0088 
0089   void printint() const;
0090   void printdouble() const;
0091   void printstring() const;
0092 
0093  private:
0094   static unsigned int ConvertStringToUint(const std::string &str);
0095   std::string m_Detector;
0096   dMap m_DoubleParMap;
0097   iMap m_IntParMap;
0098   strMap m_StringParMap;
0099 
0100   // No Class Def since this class is not intended to be persistent
0101 };
0102 
0103 #endif  // PHPARAMETER_PHPARAMETERS_H