Fix Coverity
[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 #include <stdlib.h>
34
35 ReadPar::ReadPar()
36 {
37   fname = 0;
38 }
39
40 ReadPar::ReadPar(const char *aFName)
41 {
42   fname = strdup(aFName);
43   readFile(aFName);
44 }
45
46 ReadPar::ReadPar(const ReadPar &aPar)
47 {
48   fname = strdup(aPar.fname);
49   readFile(fname);
50 }
51
52 ReadPar::~ReadPar()
53 {
54   if (fname)
55     free(fname);
56 }
57
58 int ReadPar::readFile(const char *aFName) throw (int)
59 {
60   option read_opt;
61   STR buf_str;
62   char buff[200];
63   char dummy[200];
64
65   std::ifstream       infile(aFName);
66   std::istringstream  *instream;
67   
68   if (!infile.is_open())
69     throw RP_Exception_NoParFile;
70
71   while (!infile.eof())
72     {
73       infile.getline(buff, 200);
74       instream = new std::istringstream(buff);
75       memset(dummy,0,200);
76       *instream >> dummy;
77       
78       PRINT_DEBUG_3("Read " << dummy);;
79       read_opt.keyword = dummy;
80       memset(dummy,0,200);
81       *instream >> dummy;
82
83       PRINT_DEBUG_3("Read " << dummy);
84       if (strstr(dummy,"="))
85         {
86           dummy[0]='\0';
87           
88           memset(dummy,0,200);
89           *instream >> dummy;
90           PRINT_DEBUG_3("Read " << dummy);
91           
92           read_opt.value = dummy;
93           options.push_back(read_opt);
94         }
95     }
96   infile.close();
97
98   return 0; 
99 }
100
101 int ReadPar::printOptions()
102 {
103   VOPT::iterator c;
104
105   for (c=options.begin(); c != options.end(); c++)
106     PRINT_DEBUG_3("Keyword: " << c->keyword << " Value: " << c->value);
107
108   return 0;
109 }
110
111 STR ReadPar::getPar(const char *name) throw(STR)
112 {
113   VOPT::iterator c;
114   STR pname(name);
115
116   for (c=options.begin(); c != options.end(); c++)
117     if (c->keyword == pname)
118       {
119         PRINT_DEBUG_2("Returning value " << c->value << " for keyword " << c->keyword);
120         return c->value;
121       }
122   throw *(new STR(name));
123
124   //  return TString("");
125 }
126
127
128