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