MirrorParamsReader.cc
Go to the documentation of this file.
1 #include "MirrorParamsReader.hh"
2 
3 #include <utl/AugerException.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 
7 //#include <mysql.h>
8 using namespace TelescopeSimulatorLX ;
10 // CMirrorParamsReaderBase definition
11 
13 {
14  m_MirrorParams.clear();
15 }
16 
18 {
19  if(pparams==NULL || m_MirrorParams.size()==0) return false;
20 
21  G4int ncnt = ((int)m_MirrorParams.size()>nParamsCnt) ? nParamsCnt : m_MirrorParams.size();
22  nParamsCnt = ncnt;
23 
24  map<int,MIRRORPARAMS>::const_iterator iter;
25 
26  iter=m_MirrorParams.begin();
27  for(int i=0;i<ncnt;i++){
28  memcpy(pparams+i,&(iter->second),sizeof(MIRRORPARAMS));
29  iter++;
30  }
31 
32  return true;
33 }
34 
36 {
37  static MIRRORPARAMS s_paramsNull;
38 
39  if(m_MirrorParams.size()==0 || m_MirrorParams.find(nIndex)==m_MirrorParams.end()){
40  memset(&s_paramsNull,0,sizeof(s_paramsNull));
41  return s_paramsNull;
42  }
43 
44  return m_MirrorParams.find(nIndex)->second;
45 }
46 
48 // CMirrorParamsReaderFromFile definition
49 
52 {
53  strcpy(m_szFilename,szFilename);
54 }
55 
57 {
58  FILE* pfile;
59  char szbuff[512], szaux[32];
60  char szTelescopeFlag[4];
61  char* ppos1,*ppos2;
62  MIRRORPARAMS params;
63 
64  m_MirrorParams.clear();
65 
66  if ((pfile = fopen(m_szFilename, "r")) == NULL) {
67  G4cerr << "cannot open file with mirror params: " << m_szFilename << G4endl;
68  return 0;
69  }
70 
71  switch (eTelescopeName) {
72  case ET_CO1:
73  strcpy(szTelescopeFlag, "CO1");
74  break;
75  case ET_CO2:
76  strcpy(szTelescopeFlag, "CO2");
77  break;
78  case ET_CO3:
79  strcpy(szTelescopeFlag, "CO3");
80  break;
81  case ET_CO4:
82  strcpy(szTelescopeFlag, "CO4");
83  break;
84  case ET_CO5:
85  strcpy(szTelescopeFlag, "CO5");
86  break;
87  case ET_CO6:
88  strcpy(szTelescopeFlag, "CO6");
89  break;
90  case ET_LA1:
91  strcpy(szTelescopeFlag, "LA1");
92  break;
93  case ET_LA2:
94  strcpy(szTelescopeFlag, "LA2");
95  break;
96  case ET_LA3:
97  strcpy(szTelescopeFlag, "LA3");
98  break;
99  case ET_LA4:
100  strcpy(szTelescopeFlag, "LA4");
101  break;
102  case ET_LA5:
103  strcpy(szTelescopeFlag, "LA5");
104  break;
105  case ET_LA6:
106  strcpy(szTelescopeFlag, "LA6");
107  break;
108  case ET_LL1:
109  strcpy(szTelescopeFlag, "LL1");
110  break;
111  case ET_LL2:
112  strcpy(szTelescopeFlag, "LL2");
113  break;
114  case ET_LL3:
115  strcpy(szTelescopeFlag, "LL3");
116  break;
117  case ET_LL4:
118  strcpy(szTelescopeFlag, "LL4");
119  break;
120  case ET_LL5:
121  strcpy(szTelescopeFlag, "LL5");
122  break;
123  case ET_LL6:
124  strcpy(szTelescopeFlag, "LL6");
125  break;
126  case ET_LM1:
127  strcpy(szTelescopeFlag, "LM1");
128  break;
129  case ET_LM2:
130  strcpy(szTelescopeFlag, "LM2");
131  break;
132  case ET_LM3:
133  strcpy(szTelescopeFlag, "LM3");
134  break;
135  case ET_LM4:
136  strcpy(szTelescopeFlag, "LM4");
137  break;
138  case ET_LM5:
139  strcpy(szTelescopeFlag, "LM5");
140  break;
141  case ET_LM6:
142  strcpy(szTelescopeFlag, "LM6");
143  break;
144  default:
145  strcpy(szTelescopeFlag, "NaN");
146  break;
147  }
148 
149  while (!feof(pfile)) {
150  memset(szaux, 0, sizeof(szaux));
151  memset(szbuff, 0, sizeof(szbuff));
152  memset(&params, 0, sizeof(params));
153 
154  char* d = fgets(szbuff, 512, pfile);
155  if (!d && !feof(pfile))
156  throw utl::IOFailureException("parse failure in MirrorParametersReader");
157  if (szbuff[0] == '#')
158  continue;
159 
160  //select the right telescope
161  memcpy(szaux, szbuff, 3);
162  if (strcmp(szaux, szTelescopeFlag))
163  continue;
164 
165  //telescope name
166  params.eTelescopeName=eTelescopeName;
167 
168  //mirror position
169  if((ppos2=strchr(szbuff,'\t'))==NULL) G4cerr<<"parse file error at line "<<szbuff<<": cannot find delimiter"<<G4endl;
170  *ppos2=0;
171  strcpy(szaux,szbuff+4);
172  if((params.nPosition=atoi(szaux))==0) G4cerr<<"parse file error at line "<<szbuff<<": wrong position format"<<G4endl;
173  ppos1=ppos2+1;
174 
175  //mirror id
176  if((ppos2=strchr(ppos1,'\t'))==NULL) G4cerr<<"parse file error at position "<<params.nPosition<<": cannot find delimiter"<<G4endl;
177  *ppos2=0;
178  strcpy(szaux,ppos1);
179  if((params.nMirrorID=atoi(szaux))==0) G4cerr<<"parse file error at position "<<params.nPosition<<": wrong mirror id format"<<G4endl;
180  ppos1=ppos2+1;
181 
182  //mirror shape
183  if((ppos2=strchr(ppos1,'\t'))==NULL) G4cerr<<"parse file error at position "<<params.nPosition<<": cannot find delimiter"<<G4endl;
184  *ppos2=0;
185  strcpy(szaux,ppos1);
186  if(strcmp(szaux,"IV")==0) params.nType=4;
187  else if(strcmp(szaux,"III")==0) params.nType=3;
188  else if(strcmp(szaux,"II")==0) params.nType=2;
189  else if(strcmp(szaux,"I")==0) params.nType=1;
190  else if(strcmp(szaux,"XIII")==0)params.nType=13;
191  else if(strcmp(szaux,"XII")==0) params.nType=12;
192  else if(strcmp(szaux,"XI")==0) params.nType=11;
193  else G4cerr<<"parse file error at position "<<params.nPosition<<": wrong mirror shape format"<<G4endl;
194  ppos1=ppos2+1;
195 
196  //radius of curvature
197  if((ppos2=strchr(ppos1,'\t'))==NULL) G4cerr<<"parse file error at position "<<params.nPosition<<": cannot find delimiter"<<G4endl;
198  *ppos2=0;
199  strcpy(szaux,ppos1);
200  if((params.fRadius=atof(szaux))==0) G4cerr<<"parse file error at position "<<params.nPosition<<": wrong radius-of-curvature format"<<G4endl;
201  ppos1=ppos2+1;
202 
203  //reflectivity
204  if((ppos2=strchr(ppos1,'\t'))==NULL) G4cerr<<"parse file error at position "<<params.nPosition<<": cannot find delimiter"<<G4endl;
205  *ppos2=0;
206  strcpy(szaux,ppos1);
207  if((params.fReflec375=atof(szaux))==0) G4cerr<<"parse file error at position "<<params.nPosition<<": wrong radius-of-curvature format"<<G4endl;
208  ppos1=ppos2+1;
209 
210  //horizontal angle position
211  if((ppos2=strchr(ppos1,'\t'))==NULL) G4cerr<<"parse file error at position "<<params.nPosition<<": cannot find delimiter"<<G4endl;
212  *ppos2=0;
213  strcpy(szaux,ppos1);
214  params.fHorzAnglePos=atof(szaux);
215  ppos1=ppos2+1;
216 
217  //vertical angle position
218  if((ppos2=strchr(ppos1,'\t'))==NULL) G4cerr<<"parse file error at position "<<params.nPosition<<": cannot find delimiter"<<G4endl;
219  *ppos2=0;
220  strcpy(szaux,ppos1);
221  params.fVertAnglePos=atof(szaux);
222  ppos1=ppos2+1;
223 
224  //add to container
225  if(params.nPosition>=1 && params.nPosition<=60)
226  m_MirrorParams.insert(pair<int,MIRRORPARAMS>(params.nPosition,params));
227  }
228 
229  return m_MirrorParams.size();
230 }
231 
233 // CMirrorParamsReaderFromDb definition
234 
235 CMirrorParamsReaderFromDb::CMirrorParamsReaderFromDb(const char szUser[],const char szPassword[],
236  const char szServerIP[],const char szDbName[])
238 {
239  strcpy(m_szUser,szUser);
240  strcpy(m_szPassword,szPassword);
241  strcpy(m_szServerIP,szServerIP);
242  strcpy(m_szDbName,szDbName);
243 }
244 
245 
246 G4int
248 {
249  //MYSQL* pconn;
250  //pconn=mysql_init(NULL);
251 
252  return 0;
253 }
Base class to report exceptions in IO.
CMirrorParamsReaderFromDb(const char szUser[], const char szPassword[], const char szServerIP[], const char szDbName[])
virtual G4int ReadMirrorParams(eTelescope eTelescopeName)
G4bool GetMirrorParams(PMIRRORPARAMS pparams, G4int &nParamsCnt)
virtual G4int ReadMirrorParams(eTelescope eTelescopeName)

, generated on Tue Sep 26 2023.