]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TTherminator/Therminator/ReadPar.cxx
cb193f2631e9624e05ee0323701c5bb9faf7d47b
[u/mrichter/AliRoot.git] / TTherminator / Therminator / ReadPar.cxx
1 /******************************************************************************
2  *                      T H E R M I N A T O R                                 *
3  *                   THERMal heavy-IoN generATOR                              *
4  *                           version 1.0                                      *
5  *                                                                            *
6  * Authors of the model: Wojciech Broniowski, Wojciech.Broniowski@ifj.edu.pl, *
7  *                       Wojciech Florkowski, Wojciech.Florkowski@ifj.edu.pl  *
8  * Authors of the code:  Adam Kisiel, kisiel@if.pw.edu.pl                     *
9  *                       Tomasz Taluc, ttaluc@if.pw.edu.pl                    *
10  * Code designers: Adam Kisiel, Tomasz Taluc, Wojciech Broniowski,            *
11  *                 Wojciech Florkowski                                        *
12  *                                                                            *
13  * For the detailed description of the program and furhter references         * 
14  * to the description of the model plesase refer to: nucl-th/0504047,         *
15  * accessibile at: http://www.arxiv.org/nucl-th/0504047                       *
16  *                                                                            *
17  * Homepage: http://hirg.if.pw.edu.pl/en/therminator/                         *
18  *                                                                            *
19  * This code can be freely used and redistributed. However if you decide to   *
20  * make modifications to the code, please contact the authors, especially     *
21  * if you plan to publish the results obtained with such modified code.       *
22  * Any publication of results obtained using this code must include the       *
23  * reference to nucl-th/0504047 and the published version of it, when         *
24  * available.                                                                 *
25  *                                                                            *
26  *****************************************************************************/
27 #include "THGlobal.h"
28 #include "ReadPar.h"
29 #include <iostream>
30 #include <fstream>
31 #include <sstream>
32 #include <iosfwd>
33
34 ReadPar::ReadPar()
35 {
36   fname = 0;
37 }
38
39 ReadPar::ReadPar(const char *aFName)
40 {
41   fname = strdup(aFName);
42   readFile(aFName);
43 }
44
45 int ReadPar::readFile(const char *aFName) throw (int)
46 {
47   option read_opt;
48   STR buf_str;
49   char buff[200];
50   char dummy[200];
51
52   std::ifstream       infile(aFName);
53   std::istringstream  *instream;
54   
55   if (!infile.is_open())
56     throw RP_Exception_NoParFile;
57
58   while (!infile.eof())
59     {
60       infile.getline(buff, 200);
61       instream = new std::istringstream(buff);
62       memset(dummy,0,200);
63       *instream >> dummy;
64       
65       PRINT_DEBUG_3("Read " << dummy);;
66       read_opt.keyword = dummy;
67       memset(dummy,0,200);
68       *instream >> dummy;
69
70       PRINT_DEBUG_3("Read " << dummy);
71       if (strstr(dummy,"="))
72         {
73           dummy[0]='\0';
74           
75           memset(dummy,0,200);
76           *instream >> dummy;
77           PRINT_DEBUG_3("Read " << dummy);
78           
79           read_opt.value = dummy;
80           options.push_back(read_opt);
81         }
82     }
83   infile.close();
84
85   return 0; 
86 }
87
88 int ReadPar::printOptions()
89 {
90   VOPT::iterator c;
91
92   for (c=options.begin(); c != options.end(); c++)
93     PRINT_DEBUG_3("Keyword: " << c->keyword << " Value: " << c->value);
94
95   return 0;
96 }
97
98 STR ReadPar::getPar(const char *name) throw(STR)
99 {
100   VOPT::iterator c;
101   STR pname(name);
102
103   for (c=options.begin(); c != options.end(); c++)
104     if (c->keyword == pname)
105       {
106         PRINT_DEBUG_2("Returning value " << c->value << " for keyword " << c->keyword);
107         return c->value;
108       }
109   throw *(new STR(name));
110
111   return TString("");
112 }
113
114
115