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