StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsDbConfig.h
1 /**************************************************************************
2  * $Id: StFmsDbConfig.h,v 1.1 2015/03/10 14:38:54 jeromel Exp $
3  * $Author: jeromel $
4  **************************************************************************
5  *
6  * Description: This helper class faciliates the maintenance work and access
7  * to FMS reconstruction-related parameters fmsRec
8  *
9  **************************************************************************
10  *
11  * $Log: StFmsDbConfig.h,v $
12  * Revision 1.1 2015/03/10 14:38:54 jeromel
13  * First version of FmsUtil from Yuxi Pan - reviewd 2015/02
14  *
15  *
16  **************************************************************************/
17 
18 
19 #ifndef STFMSDBCONFIG_H
20 #define STFMSDBCONFIG_H
21 #include "StMessMgr.h"
22 #include "Stypes.h"
23 #include "TObject.h"
24 #include <map>
25 #include <cstdlib>
26 #include <string>
27 #include "tables/St_fmsRec_Table.h"
28 #include <iostream>
29 #include <sstream>
31 
32 public:
33 
34  /* create singleton the first time it is used */
35  inline static StFmsDbConfig& Instance() {
36  static StFmsDbConfig theConfig;
37  return theConfig;
38  }
39 
40  /* fill internal map from text file*/
41  Int_t fillMap(const char*);
42 
43  /* fill fmsRec_st structure with internal map*/
44  Int_t fillFmsRec(fmsRec_st&);
45 
46  /* read database table fmsRe_st* into internal map*/
47  Int_t readMap(const fmsRec_st&);
48 
49  /* write internal map to text file*/
50  Int_t writeMap(const char*);
51 
52  Bool_t isMapEmpty();
53 
54  Bool_t keyExist(std::string);
55 
56  /* do not invoke conversion if user asked for std::string, can be used with macros */
57  const std::string& getParameter(std::string);
58 
59  /* do not invoke conversion if user is setting parameters with std::string */
60  void setParameter(std::string, std::string);
61 
62  /* retrieve specific parameter by name, only works with compiled code
63  the user code need to make sure key exists in map (using keyExist()) */
64  template<class T>
65  T getParameter(std::string param){
66 
67  const std::string& val = getParameter(param);
68 
69  T value;
70  std::istringstream buffer(val);
71  buffer >> value;
72 
73  return value;
74  }
75 
76  template<class T>
77  void setParameter(std::string param, T value){
78  std::ostringstream buffer;
79  buffer << value;
80  mRecPar[param] = buffer.str();
81 
82  }
83 
84 
85 private:
86 
87  StFmsDbConfig(){}; //hide constructor and destructor
88  ~StFmsDbConfig(){};
90  StFmsDbConfig& operator=(const StFmsDbConfig&);
91 
92  std::map<std::string, std::string> mRecPar; //name to value mapping
93 
94  ClassDef(StFmsDbConfig,1)
95 
96 };
97 
98 #endif