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

Last change on this file since 2977 was 2977, checked in by blanch, 21 years ago
Change in variables name to clarify the meaning.
File size: 7.8 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.3 $
22//= $Author: blanch $
23//= $Date: 2004-01-30 10:34:59 $
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
55#include "srreadparam.h"
56
57//!@}
58
59//!@subsection Definition of global variables.
60
61/*!@"
62
63 Here we define the global variables where the values from the
64 parameters file are stored.
65
66 @"*/
67
68//!@{
69
70static char Database_path[PATH_MAX_LENGTH]; //@< path to store the database
71static float Simulated_Phe_l = 0.0; //@< lower limit for phe loop
72static float Simulated_Phe_u = 50.0; //@< higher limit for phe loop
73static float Simulated_Phe_p = 0.1; //@< precision for phe loop
74static float FADC_Shape=0.0;
75static float FADC_Integ=MFADC_RESPONSE_INTEGRAL;
76static float FADC_FWHM=MFADC_RESPONSE_FWHM;
77static float Trig_Shape=0.0;
78static float Trig_Ampl=1.0;
79static float Trig_FWHM=2.0;
80static int Write_Root=0;
81//!@}
82
83//!@subsection The function |readparam()|.
84
85//!-----------------------------------------------------------
86// @name srreadparam
87//
88// @desc read parameters from the stdin / parameters file
89//
90// @var *filename Name of the parameters file (NULL->STDIN)
91//
92// @date Wed Feb 21 17:43:07 CET 2001
93//------------------------------------------------------------
94// @function
95
96//!@{
97void
98readparam(char * filename)
99{
100 char line[LINE_MAX_LENGTH]; //@< line to get from the stdin
101 char token[ITEM_MAX_LENGTH]; //@< a single token
102 int i; //@< dummy counters
103 ifstream ifile;
104
105 ifile.open( filename );
106
107 // loop till the "end" directive is reached
108 int is_end = FALSE;
109 while (! is_end) {
110
111 // get line from file or stdin
112 if ( filename != NULL )
113 ifile.getline(line, LINE_MAX_LENGTH);
114 else
115 cin.getline(line, LINE_MAX_LENGTH);
116
117 // skip comments (start with '#')
118 if (line[0] == '#')
119 continue;
120
121 // show user comments (start with '>')
122 if (line[0] == '>') {
123 cout << line << endl << flush;
124 continue;
125 }
126
127 // look for each item at the beginning of the line
128 for (i=0; i<=end_file; i++)
129 if (strstr(line, ITEM_NAMES[i]) == line)
130 break;
131
132 // if it is not a valid line, just ignore it
133 if (i == end_file+1) {
134 cerr << "Skipping unknown token in [" << line << "]\n";
135 continue;
136 }
137
138 // case block for each directive
139 switch ( i ) {
140
141 case database_path: //@< name of the output path
142
143 // get the path for the outcoming database
144 sscanf(line, "%s %s", token, Database_path);
145
146 break;
147
148 case simulated_phe: //@< limits for the phe loop
149
150 sscanf(line, "%s %f %f %f", token, &Simulated_Phe_l, &Simulated_Phe_u,
151 &Simulated_Phe_p);
152
153 break;
154
155 case trig_properties: //@< shape of trigger response
156
157 sscanf(line, "%s %f %f %f", token, &Trig_Shape, &Trig_Ampl,
158 &Trig_FWHM);
159
160 break;
161
162 case fadc_properties: //@< shape of fadc response
163
164 sscanf(line, "%s %f %f %f", token, &FADC_Shape, &FADC_Integ,
165 &FADC_FWHM);
166
167 break;
168
169 case write_root: //@< Write histogram
170
171 Write_Root = 1;
172
173 case end_file: //@< end of the parameters file
174
175 // show a short message
176 is_end = TRUE;
177
178 break;
179
180 } // switch ( i )
181
182 } // while (! is_end)
183
184 // after the loop is finished, return to the main function
185 return;
186}
187//!@}
188
189
190//!-----------------------------------------------------------
191// @name get_database_path
192//
193// @desc get name of the ouput path
194//
195// @return Name of the output path
196//
197// @date Wed Feb 21 17:57:19 CET 2001
198//------------------------------------------------------------
199// @function
200
201//!@{
202char *
203get_database_path(void)
204{
205 return (Database_path);
206}
207//!@}
208
209//!-----------------------------------------------------------
210// @name get_simulated_phe
211//
212// @desc return limits for the phe loop
213//
214// @var *lphe Lower limit in the phe loop
215// @var *uphe Higher limit in the phe loop
216// @var *pphe Precision in the phe loop
217// @return void
218//
219// @date Wed Feb 21 18:04:03 CET 2001
220//------------------------------------------------------------
221// @function
222
223//!@{
224void
225get_simulated_phe(float *lphe, float *uphe, float *pphe)
226{
227 *lphe = Simulated_Phe_l;
228 *uphe = Simulated_Phe_u;
229 *pphe = Simulated_Phe_p;
230}
231//!@}
232
233//!-----------------------------------------------------------
234// @name get_trig_properties
235//
236// @desc return shape of the single phe trigger response
237//
238// @var *shape number to indentify the shape (0 ->gaussian)
239// @var *ampl Amplitud of the gaussian response
240// @var *fwhm FWHM of the gaussian response
241// @return void
242//
243// @date Wed Feb 21 18:04:03 CET 2001
244//------------------------------------------------------------
245// @function
246
247//!@{
248void
249get_trig_properties(float *shape, float *ampl, float *fwhm)
250{
251 *shape = Trig_Shape;
252 *ampl = Trig_Ampl;
253 *fwhm = Trig_FWHM;
254}
255//!@}
256
257//!-----------------------------------------------------------
258// @name get_fadc_properties
259//
260// @desc return shape of the single phe FADC response
261//
262// @var *shape number to indentify the shape (0 ->gaussian)
263// @var *ampl Amplitud of the gaussian response
264// @var *fwhm FWHM of the gaussian response
265// @return void
266//
267// @date Wed Feb 21 18:04:03 CET 2001
268//------------------------------------------------------------
269// @function
270
271//!@{
272void
273get_fadc_properties(float *shape, float *integ, float *fwhm)
274{
275 *shape = FADC_Shape;
276 *integ = FADC_Integ;
277 *fwhm = FADC_FWHM;
278}
279//!@}
280
281//!-----------------------------------------------------------
282// @name get_write_root
283//
284// @desc get boolean to write root files
285//
286// @return 0 (false) or 1 (true)
287//
288// @date Fri Mar 2 16:17:26 CET 2001
289//------------------------------------------------------------
290// @function
291
292//!@{
293int
294get_write_root(void)
295{
296 return (Write_Root);
297}
298//!@}
299
300//=------------------------------------------------------------
301//!@subsection Log of this file.
302
303//!@{
304//
305// $Log: not supported by cvs2svn $
306// Revision 1.2 2001/03/05 11:01:44 blanch
307// Commads to enter the FADC and trigger properties have been added.
308// There is also a new command that allows to writte the root files or not
309//
310// Revision 1.1 2001/02/23 10:13:44 magicsol
311// It read form an input card (defeult=starresponse.par) the parameters that
312// are needed for the starresponse program.
313//
314//!@}
315
316//=EOF
Note: See TracBrowser for help on using the repository browser.