StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsDbConfig.cxx
1 #include "StFmsDbConfig.h"
2 #include <fstream>
3 #include <stdexcept>
4 
5 ClassImp(StFmsDbConfig)
6 
7 Int_t StFmsDbConfig::fillMap(const char* filename = "fmsrecpar.txt"){
8 
9  mRecPar.clear();
10  LOG_INFO << "reading text file " << filename << endm;
11  std::fstream fp(filename, std::ios::in);
12  if(fp.is_open()){
13  std::string field;
14  std::string val;
15  while(fp>>field>>val)mRecPar[field] = val;
16  }
17  else{
18  LOG_ERROR << "ERROR opening text file " << filename << endm;
19  return kStErr;
20  }
21 
22  LOG_INFO << "map filled with " << mRecPar.size() << " entries" << endm;
23 
24  return kStOk;
25 }
26 
27 
28 Int_t StFmsDbConfig::fillFmsRec(fmsRec_st& rec){
29 
30  if(mRecPar.empty()){
31  LOG_ERROR << "internal map is empty" << endm;
32  return kStErr;
33  }
34 
35  //manually assign table fields
36  rec.ROW_LOW_LIMIT = getParameter<unsigned short>("ROW_LOW_LIMIT");
37  rec.COL_LOW_LIMIT = getParameter<unsigned short>("COL_LOW_LIMIT");
38  rec.CEN_ROW_LRG = getParameter<float>("CEN_ROW_LRG");
39  rec.CEN_ROW_WIDTH_LRG = getParameter<unsigned short>("CEN_ROW_WIDTH_LRG");
40  rec.CEN_UPPER_COL_LRG = getParameter<unsigned short>("CEN_UPPER_COL_LRG");
41  rec.CEN_ROW_SML = getParameter<float>("CEN_ROW_SML");
42  rec.CEN_ROW_WIDTH_SML = getParameter<unsigned short>("CEN_ROW_WIDTH_SML");
43  rec.CEN_UPPER_COL_SML = getParameter<unsigned short>("CEN_UPPER_COL_SML");
44  rec.CORNER_ROW = getParameter<float>("CORNER_ROW");
45  rec.CORNER_LOW_COL = getParameter<float>("CORNER_LOW_COL");
46  rec.CLUSTER_BASE = getParameter<unsigned short>("CLUSTER_BASE");
47  rec.CLUSTER_ID_FACTOR_DET = getParameter<unsigned short>("CLUSTER_ID_FACTOR_DET");
48  rec.TOTAL_TOWERS = getParameter<unsigned short>("TOTAL_TOWERS");
49  rec.PEAK_TOWER_FACTOR = getParameter<float>("PEAK_TOWER_FACTOR");
50  rec.TOWER_E_THRESHOLD = getParameter<float>("TOWER_E_THRESHOLD");
51  rec.BAD_2PH_CHI2 = getParameter<float>("BAD_2PH_CHI2");
52  rec.BAD_MIN_E_LRG = getParameter<float>("BAD_MIN_E_LRG");
53  rec.BAD_MAX_TOW_LRG = getParameter<float>("BAD_MAX_TOW_LRG");
54  rec.BAD_MIN_E_SML = getParameter<float>("BAD_MIN_E_SML");
55  rec.BAD_MAX_TOW_SML = getParameter<float>("BAD_MAX_TOW_SML");
56  rec.VALID_FT = getParameter<float>("VALID_FT");
57  rec.VALID_2ND_FT = getParameter<float>("VALID_2ND_FT");
58  rec.VALID_E_OWN = getParameter<float>("VALID_E_OWN");
59  rec.SS_C = getParameter<float>("SS_C");
60  rec.SS_A1 = getParameter<float>("SS_A1");
61  rec.SS_A2 = getParameter<float>("SS_A2");
62  rec.SS_A3 = getParameter<float>("SS_A3");
63  rec.SS_B1 = getParameter<float>("SS_B1");
64  rec.SS_B2 = getParameter<float>("SS_B2");
65  rec.SS_B3 = getParameter<float>("SS_B3");
66  rec.CAT_NTOWERS_PH1 = getParameter<unsigned short>("CAT_NTOWERS_PH1");
67  rec.CAT_EP1_PH2 = getParameter<float>("CAT_EP1_PH2");
68  rec.CAT_EP0_PH2 = getParameter<float>("CAT_EP0_PH2");
69  rec.CAT_SIGMAMAX_MIN_PH2 = getParameter<float>("CAT_SIGMAMAX_MIN_PH2");
70  rec.CAT_EP1_PH1 = getParameter<float>("CAT_EP1_PH1");
71  rec.CAT_EP0_PH1 = getParameter<float>("CAT_EP0_PH1");
72  rec.CAT_SIGMAMAX_MAX_PH1 = getParameter<float>("CAT_SIGMAMAX_MAX_PH1");
73  rec.PH1_START_NPH = getParameter<float>("PH1_START_NPH");
74  rec.PH1_DELTA_N = getParameter<float>("PH1_DELTA_N");
75  rec.PH1_DELTA_X = getParameter<float>("PH1_DELTA_X");
76  rec.PH1_DELTA_Y = getParameter<float>("PH1_DELTA_Y");
77  rec.PH1_DELTA_E = getParameter<float>("PH1_DELTA_E");
78  rec.PH2_START_NPH = getParameter<unsigned short>("PH2_START_NPH");
79  rec.PH2_START_FSIGMAMAX = getParameter<float>("PH2_START_FSIGMAMAX");
80  rec.PH2_RAN_LOW = getParameter<float>("PH2_RAN_LOW");
81  rec.PH2_RAN_HIGH = getParameter<float>("PH2_RAN_HIGH");
82  rec.PH2_STEP_0 = getParameter<float>("PH2_STEP_0");
83  rec.PH2_STEP_1 = getParameter<float>("PH2_STEP_1");
84  rec.PH2_STEP_2 = getParameter<float>("PH2_STEP_2");
85  rec.PH2_STEP_3 = getParameter<float>("PH2_STEP_3");
86  rec.PH2_STEP_4 = getParameter<float>("PH2_STEP_4");
87  rec.PH2_STEP_5 = getParameter<float>("PH2_STEP_5");
88  rec.PH2_STEP_6 = getParameter<float>("PH2_STEP_6");
89  rec.PH2_MAXTHETA_F = getParameter<float>("PH2_MAXTHETA_F");
90  rec.PH2_LOWER_NPH = getParameter<float>("PH2_LOWER_NPH");
91  rec.PH2_LOWER_XF = getParameter<float>("PH2_LOWER_XF");
92  rec.PH2_LOWER_YF = getParameter<float>("PH2_LOWER_YF");
93  rec.PH2_LOWER_XMAX_F = getParameter<float>("PH2_LOWER_XMAX_F");
94  rec.PH2_LOWER_XMAX_POW = getParameter<float>("PH2_LOWER_XMAX_POW");
95  rec.PH2_LOWER_XMAX_LIMIT = getParameter<float>("PH2_LOWER_XMAX_LIMIT");
96  rec.PH2_LOWER_5_F = getParameter<float>("PH2_LOWER_5_F");
97  rec.PH2_LOWER_6_F = getParameter<float>("PH2_LOWER_6_F");
98  rec.PH2_UPPER_NPH = getParameter<float>("PH2_UPPER_NPH");
99  rec.PH2_UPPER_XF = getParameter<float>("PH2_UPPER_XF");
100  rec.PH2_UPPER_YF = getParameter<float>("PH2_UPPER_YF");
101  rec.PH2_UPPER_XMIN_F = getParameter<float>("PH2_UPPER_XMIN_F");
102  rec.PH2_UPPER_XMIN_P0 = getParameter<float>("PH2_UPPER_XMIN_P0");
103  rec.PH2_UPPER_XMIN_LIMIT = getParameter<float>("PH2_UPPER_XMIN_LIMIT");
104  rec.PH2_UPPER_5_F = getParameter<float>("PH2_UPPER_5_F");
105  rec.PH2_UPPER_6_F = getParameter<float>("PH2_UPPER_6_F");
106  rec.PH2_3_LIMIT_LOWER = getParameter<float>("PH2_3_LIMIT_LOWER");
107  rec.PH2_3_LIMIT_UPPER = getParameter<float>("PH2_3_LIMIT_UPPER");
108  rec.GL_LOWER_1 = getParameter<float>("GL_LOWER_1");
109  rec.GL_UPPER_DELTA_MAXN = getParameter<float>("GL_UPPER_DELTA_MAXN");
110  rec.GL_0_DLOWER = getParameter<float>("GL_0_DLOWER");
111  rec.GL_0_DUPPER = getParameter<float>("GL_0_DUPPER");
112  rec.GL_1_DLOWER = getParameter<float>("GL_1_DLOWER");
113  rec.GL_1_DUPPER = getParameter<float>("GL_1_DUPPER");
114  rec.GL_2_DLOWER = getParameter<float>("GL_2_DLOWER");
115  rec.GL_2_DUPPER = getParameter<float>("GL_2_DUPPER");
116 
117 
118  return kStOk;
119 }
120 
121 
122 Int_t StFmsDbConfig::readMap(const fmsRec_st& rec){
123  /* read db tables and populate the internal map mRecPar */
124 
125  mRecPar.clear();
126 
127  setParameter<unsigned short>("ROW_LOW_LIMIT", rec.ROW_LOW_LIMIT);
128  setParameter<unsigned short>("COL_LOW_LIMIT", rec.COL_LOW_LIMIT);
129  setParameter<float>("CEN_ROW_LRG", rec.CEN_ROW_LRG);
130  setParameter<unsigned short>("CEN_ROW_WIDTH_LRG", rec.CEN_ROW_WIDTH_LRG);
131  setParameter<unsigned short>("CEN_UPPER_COL_LRG", rec.CEN_UPPER_COL_LRG);
132  setParameter<float>("CEN_ROW_SML", rec.CEN_ROW_SML);
133  setParameter<unsigned short>("CEN_ROW_WIDTH_SML", rec.CEN_ROW_WIDTH_SML);
134  setParameter<unsigned short>("CEN_UPPER_COL_SML", rec.CEN_UPPER_COL_SML);
135  setParameter<float>("CORNER_ROW", rec.CORNER_ROW);
136  setParameter<float>("CORNER_LOW_COL", rec.CORNER_LOW_COL);
137  setParameter<unsigned short>("CLUSTER_BASE", rec.CLUSTER_BASE);
138  setParameter<unsigned short>("CLUSTER_ID_FACTOR_DET", rec.CLUSTER_ID_FACTOR_DET);
139  setParameter<unsigned short>("TOTAL_TOWERS", rec.TOTAL_TOWERS);
140  setParameter<float>("PEAK_TOWER_FACTOR", rec.PEAK_TOWER_FACTOR);
141  setParameter<float>("TOWER_E_THRESHOLD", rec.TOWER_E_THRESHOLD);
142  setParameter<float>("BAD_2PH_CHI2", rec.BAD_2PH_CHI2);
143  setParameter<float>("BAD_MIN_E_LRG", rec.BAD_MIN_E_LRG);
144  setParameter<float>("BAD_MAX_TOW_LRG", rec.BAD_MAX_TOW_LRG);
145  setParameter<float>("BAD_MIN_E_SML", rec.BAD_MIN_E_SML);
146  setParameter<float>("BAD_MAX_TOW_SML", rec.BAD_MAX_TOW_SML);
147  setParameter<float>("VALID_FT", rec.VALID_FT);
148  setParameter<float>("VALID_2ND_FT", rec.VALID_2ND_FT);
149  setParameter<float>("VALID_E_OWN", rec.VALID_E_OWN);
150  setParameter<float>("SS_C", rec.SS_C);
151  setParameter<float>("SS_A1", rec.SS_A1);
152  setParameter<float>("SS_A2", rec.SS_A2);
153  setParameter<float>("SS_A3", rec.SS_A3);
154  setParameter<float>("SS_B1", rec.SS_B1);
155  setParameter<float>("SS_B2", rec.SS_B2);
156  setParameter<float>("SS_B3", rec.SS_B3);
157  setParameter<unsigned short>("CAT_NTOWERS_PH1", rec.CAT_NTOWERS_PH1);
158  setParameter<float>("CAT_EP1_PH2", rec.CAT_EP1_PH2);
159  setParameter<float>("CAT_EP0_PH2", rec.CAT_EP0_PH2);
160  setParameter<float>("CAT_SIGMAMAX_MIN_PH2", rec.CAT_SIGMAMAX_MIN_PH2);
161  setParameter<float>("CAT_EP1_PH1", rec.CAT_EP1_PH1);
162  setParameter<float>("CAT_EP0_PH1", rec.CAT_EP0_PH1);
163  setParameter<float>("CAT_SIGMAMAX_MAX_PH1", rec.CAT_SIGMAMAX_MAX_PH1);
164  setParameter<float>("PH1_START_NPH", rec.PH1_START_NPH);
165  setParameter<float>("PH1_DELTA_N", rec.PH1_DELTA_N);
166  setParameter<float>("PH1_DELTA_X", rec.PH1_DELTA_X);
167  setParameter<float>("PH1_DELTA_Y", rec.PH1_DELTA_Y);
168  setParameter<float>("PH1_DELTA_E", rec.PH1_DELTA_E);
169  setParameter<unsigned short>("PH2_START_NPH", rec.PH2_START_NPH);
170  setParameter<float>("PH2_START_FSIGMAMAX", rec.PH2_START_FSIGMAMAX);
171  setParameter<float>("PH2_RAN_LOW", rec.PH2_RAN_LOW);
172  setParameter<float>("PH2_RAN_HIGH", rec.PH2_RAN_HIGH);
173  setParameter<float>("PH2_STEP_0", rec.PH2_STEP_0);
174  setParameter<float>("PH2_STEP_1", rec.PH2_STEP_1);
175  setParameter<float>("PH2_STEP_2", rec.PH2_STEP_2);
176  setParameter<float>("PH2_STEP_3", rec.PH2_STEP_3);
177  setParameter<float>("PH2_STEP_4", rec.PH2_STEP_4);
178  setParameter<float>("PH2_STEP_5", rec.PH2_STEP_5);
179  setParameter<float>("PH2_STEP_6", rec.PH2_STEP_6);
180  setParameter<float>("PH2_MAXTHETA_F", rec.PH2_MAXTHETA_F);
181  setParameter<float>("PH2_LOWER_NPH", rec.PH2_LOWER_NPH);
182  setParameter<float>("PH2_LOWER_XF", rec.PH2_LOWER_XF);
183  setParameter<float>("PH2_LOWER_YF", rec.PH2_LOWER_YF);
184  setParameter<float>("PH2_LOWER_XMAX_F", rec.PH2_LOWER_XMAX_F);
185  setParameter<float>("PH2_LOWER_XMAX_POW", rec.PH2_LOWER_XMAX_POW);
186  setParameter<float>("PH2_LOWER_XMAX_LIMIT", rec.PH2_LOWER_XMAX_LIMIT);
187  setParameter<float>("PH2_LOWER_5_F", rec.PH2_LOWER_5_F);
188  setParameter<float>("PH2_LOWER_6_F", rec.PH2_LOWER_6_F);
189  setParameter<float>("PH2_UPPER_NPH", rec.PH2_UPPER_NPH);
190  setParameter<float>("PH2_UPPER_XF", rec.PH2_UPPER_XF);
191  setParameter<float>("PH2_UPPER_YF", rec.PH2_UPPER_YF);
192  setParameter<float>("PH2_UPPER_XMIN_F", rec.PH2_UPPER_XMIN_F);
193  setParameter<float>("PH2_UPPER_XMIN_P0", rec.PH2_UPPER_XMIN_P0);
194  setParameter<float>("PH2_UPPER_XMIN_LIMIT", rec.PH2_UPPER_XMIN_LIMIT);
195  setParameter<float>("PH2_UPPER_5_F", rec.PH2_UPPER_5_F);
196  setParameter<float>("PH2_UPPER_6_F", rec.PH2_UPPER_6_F);
197  setParameter<float>("PH2_3_LIMIT_LOWER", rec.PH2_3_LIMIT_LOWER);
198  setParameter<float>("PH2_3_LIMIT_UPPER", rec.PH2_3_LIMIT_UPPER);
199  setParameter<float>("GL_LOWER_1", rec.GL_LOWER_1);
200  setParameter<float>("GL_UPPER_DELTA_MAXN", rec.GL_UPPER_DELTA_MAXN);
201  setParameter<float>("GL_0_DLOWER", rec.GL_0_DLOWER);
202  setParameter<float>("GL_0_DUPPER", rec.GL_0_DUPPER);
203  setParameter<float>("GL_1_DLOWER", rec.GL_1_DLOWER);
204  setParameter<float>("GL_1_DUPPER", rec.GL_1_DUPPER);
205  setParameter<float>("GL_2_DLOWER", rec.GL_2_DLOWER);
206  setParameter<float>("GL_2_DUPPER", rec.GL_2_DUPPER);
207 
208  return kStOk;
209 }
210 
211 
212 Int_t StFmsDbConfig::writeMap(const char* filename = "outfmsrec.txt"){
213 
214  if(mRecPar.empty()){
215  LOG_ERROR << "internal map is empty, call fillMap() first" << endm;
216  return kStErr;
217  }
218  std::cout << "writing map to " << filename << endl;
219  std::fstream outfile(filename, std::ios::out);
220  for(std::map<std::string, std::string>::iterator it = mRecPar.begin(); it != mRecPar.end(); ++it){
221  outfile << (it->first) << " " << (it->second) << endl;
222  }
223 
224  return kStOk;
225 }
226 
227 
228 Bool_t StFmsDbConfig::isMapEmpty(){
229 
230  if(mRecPar.empty()) return true;
231  else return false;
232 }
233 
234 Bool_t StFmsDbConfig::keyExist(std::string param){
235 
236  if(mRecPar.find(param) != mRecPar.end()) return true;
237  else return false;
238 }
239 
240 /* do not invoke conversion if user asked for std::string */
241 const std::string& StFmsDbConfig::getParameter(std::string param){
242 
243  return mRecPar[param]; //return string will be empty if there is no such key in mRecPar
244 
245 }
246 
247 /*do not invoke conversion if user is setting parameters with std::string */
248 void StFmsDbConfig::setParameter(std::string param, std::string value){
249 
250  mRecPar[param] = value;
251 
252 }
Definition: Stypes.h:44
Definition: Stypes.h:41