source: trunk/MagicSoft/Simulation/Detector/StarResponse/srreadparam.cxx@ 5254

Last change on this file since 5254 was 5248, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 8.3 KB
Line 
1//=//////////////////////////////////////////////////////////////////////
2//=
3//= srreadparam
4//=
5//= @file srreadparam.cxx
6//= @desc Reading of parameters file
7//= @author O Blanch Bigas
8//= @email blanch@ifae.es
9//= @date Wed Feb 21 17:43:07 CET 2001
10//=
11//=----------------------------------------------------------------------
12//=
13//= Created: Wed Feb 21 17:43:07 CET 2001
14//= Author: Oscar Blanch Bigas
15//= Purpose: Program for star response simulation
16//= Notes: See files README for details
17//=
18//=----------------------------------------------------------------------
19//=
20//= $RCSfile: srreadparam.cxx,v $
21//= $Revision: 1.6 $
22//= $Author: moralejo $
23//= $Date: 2004-10-12 13:41:09 $
24//=
25//=//////////////////////////////////////////////////////////////////////
26
27// @T \newpage
28
29//!@section Source code of |srreadparam.cxx|.
30
31/*!@"
32
33 This section describes briefly the source code for the file
34 |srreadparam.cxx|. This file is very closely related to the file
35 |readparams.cxx| from the |reflector| program. Actually, this later
36 file was the ancestror of the file you are looking at.
37
38 All the defines it uses are located in the file |srreadparam.h|. In
39 the first one we can see the definitions of the commands available
40 for the parameters file. We describe these commands in a later
41 section.
42
43 @"*/
44
45//!@subsection Includes and Global variables definition.
46
47/*!@"
48
49 All the defines are located in the file {\tt srreadparam.h}.
50
51 @"*/
52
53//!@{
54
55using namespace std;
56
57#include "srreadparam.h"
58
59//!@}
60
61//!@subsection Definition of global variables.
62
63/*!@"
64
65 Here we define the global variables where the values from the
66 parameters file are stored.
67
68 @"*/
69
70//!@{
71
72static char Database_path[PATH_MAX_LENGTH]; //@< path to store the database
73static float Simulated_Phe_l = 0.0; //@< lower limit for phe loop
74static float Simulated_Phe_u = 50.0; //@< higher limit for phe loop
75static float Simulated_Phe_p = 0.1; //@< precision for phe loop
76static int FADC_Shape=0;
77static float FADC_Integ = MFADC_RESPONSE_INTEGRAL;
78static float FADC_FWHM = MFADC_RESPONSE_FWHM;
79static float FADC_slices_per_ns = FADC_SLICES_PER_NSEC;
80static int Trig_Shape = 0;
81static float Trig_Ampl = 1.0;
82static float Trig_FWHM = 2.0;
83static int Write_Root = 0;
84//!@}
85
86//!@subsection The function |readparam()|.
87
88//!-----------------------------------------------------------
89// @name srreadparam
90//
91// @desc read parameters from the stdin / parameters file
92//
93// @var *filename Name of the parameters file (NULL->STDIN)
94//
95// @date Wed Feb 21 17:43:07 CET 2001
96//------------------------------------------------------------
97// @function
98
99//!@{
100void
101readparam(char * filename)
102{
103 char line[LINE_MAX_LENGTH]; //@< line to get from the stdin
104 char token[ITEM_MAX_LENGTH]; //@< a single token
105 int i; //@< dummy counters
106 ifstream ifile;
107
108 ifile.open( filename );
109
110 // loop till the "end" directive is reached
111 int is_end = FALSE;
112 while (! is_end) {
113
114 // get line from file or stdin
115 if ( filename != NULL )
116 ifile.getline(line, LINE_MAX_LENGTH);
117 else
118 cin.getline(line, LINE_MAX_LENGTH);
119
120 // skip comments (start with '#')
121 if (line[0] == '#')
122 continue;
123
124 // show user comments (start with '>')
125 if (line[0] == '>') {
126 cout << line << endl << flush;
127 continue;
128 }
129
130 // look for each item at the beginning of the line
131 for (i=0; i<=end_file; i++)
132 if (strstr(line, ITEM_NAMES[i]) == line)
133 break;
134
135 // if it is not a valid line, just ignore it
136 if (i == end_file+1) {
137 cerr << "Skipping unknown token in [" << line << "]\n";
138 continue;
139 }
140
141 // case block for each directive
142 switch ( i ) {
143
144 case database_path: //@< name of the output path
145
146 // get the path for the outcoming database
147 sscanf(line, "%s %s", token, Database_path);
148
149 break;
150
151 case simulated_phe: //@< limits for the phe loop
152
153 sscanf(line, "%s %f %f %f", token, &Simulated_Phe_l, &Simulated_Phe_u,
154 &Simulated_Phe_p);
155
156 break;
157
158 case trig_properties: //@< shape of trigger response
159
160 sscanf(line, "%s %d %f %f", token, &Trig_Shape, &Trig_Ampl,
161 &Trig_FWHM);
162
163 break;
164
165 case fadc_properties: //@< shape of fadc response
166
167 sscanf(line, "%s %d %f %f", token, &FADC_Shape, &FADC_Integ,
168 &FADC_FWHM);
169
170 break;
171
172 case fadc_GHz: // Get FADC sampling frequency in GHz
173
174 sscanf(line, "%s %f", token, &FADC_slices_per_ns);
175
176 break;
177
178 case write_root: //@< Write histogram
179
180 Write_Root = 1;
181
182 case end_file: //@< end of the parameters file
183
184 // show a short message
185 is_end = TRUE;
186
187 break;
188
189 } // switch ( i )
190
191 } // while (! is_end)
192
193 // after the loop is finished, return to the main function
194 return;
195}
196//!@}
197
198
199//!-----------------------------------------------------------
200// @name get_database_path
201//
202// @desc get name of the ouput path
203//
204// @return Name of the output path
205//
206// @date Wed Feb 21 17:57:19 CET 2001
207//------------------------------------------------------------
208// @function
209
210//!@{
211char *
212get_database_path(void)
213{
214 return (Database_path);
215}
216//!@}
217
218//!-----------------------------------------------------------
219// @name get_simulated_phe
220//
221// @desc return limits for the phe loop
222//
223// @var *lphe Lower limit in the phe loop
224// @var *uphe Higher limit in the phe loop
225// @var *pphe Precision in the phe loop
226// @return void
227//
228// @date Wed Feb 21 18:04:03 CET 2001
229//------------------------------------------------------------
230// @function
231
232//!@{
233void
234get_simulated_phe(float *lphe, float *uphe, float *pphe)
235{
236 *lphe = Simulated_Phe_l;
237 *uphe = Simulated_Phe_u;
238 *pphe = Simulated_Phe_p;
239}
240//!@}
241
242//!-----------------------------------------------------------
243// @name get_trig_properties
244//
245// @desc return shape of the single phe trigger response
246//
247// @var *shape number to indentify the shape (0 ->gaussian)
248// @var *ampl Amplitud of the gaussian response
249// @var *fwhm FWHM of the gaussian response
250// @return void
251//
252// @date Wed Feb 21 18:04:03 CET 2001
253//------------------------------------------------------------
254// @function
255
256//!@{
257void
258get_trig_properties(int *shape, float *ampl, float *fwhm)
259{
260 *shape = Trig_Shape;
261 *ampl = Trig_Ampl;
262 *fwhm = Trig_FWHM;
263}
264//!@}
265
266//!-----------------------------------------------------------
267// @name get_fadc_properties
268//
269// @desc return shape of the single phe FADC response
270//
271// @var *shape number to indentify the shape (0 ->gaussian)
272// @var *ampl Amplitud of the gaussian response
273// @var *fwhm FWHM of the gaussian response
274// @return void
275//
276// @date Wed Feb 21 18:04:03 CET 2001
277//------------------------------------------------------------
278// @function
279
280//!@{
281void
282get_fadc_properties(int *shape, float *integ, float *fwhm, float *fadc_spns)
283{
284 *shape = FADC_Shape;
285 *integ = FADC_Integ;
286 *fwhm = FADC_FWHM;
287 *fadc_spns = FADC_slices_per_ns;
288}
289//!@}
290
291//!-----------------------------------------------------------
292// @name get_write_root
293//
294// @desc get boolean to write root files
295//
296// @return 0 (false) or 1 (true)
297//
298// @date Fri Mar 2 16:17:26 CET 2001
299//------------------------------------------------------------
300// @function
301
302//!@{
303int
304get_write_root(void)
305{
306 return (Write_Root);
307}
308//!@}
309
310//=------------------------------------------------------------
311//!@subsection Log of this file.
312
313//!@{
314//
315// $Log: not supported by cvs2svn $
316// Revision 1.5 2004/09/17 13:51:02 moralejo
317//
318// Adapted headers to current c++ style, removed -Wno-deprecated from
319// compilation options.
320//
321// Revision 1.4 2004/09/16 16:20:13 moralejo
322// *** empty log message ***
323//
324// Revision 1.3 2004/01/30 10:34:59 blanch
325// Change in variables name to clarify the meaning.
326//
327// Revision 1.2 2001/03/05 11:01:44 blanch
328// Commads to enter the FADC and trigger properties have been added.
329// There is also a new command that allows to writte the root files or not
330//
331// Revision 1.1 2001/02/23 10:13:44 magicsol
332// It read form an input card (defeult=starresponse.par) the parameters that
333// are needed for the starresponse program.
334//
335//!@}
336
337//=EOF
Note: See TracBrowser for help on using the repository browser.