143 {
145 ++beg;
146 int size = atoi((*beg).c_str());
147 int nlines = 0;
148 std::vector<bool> lines;
149 std::string line;
150 boost::char_separator<char>sep(" \t");
151 for (int i = 0; i < size; i++) {
152 IsEOF = getline(ifile, line).eof();
153 if (line.empty() || line.at(0) == '#') {
154 if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in CorrelatedGaussianParameters please! In line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + filename);
155 else sleep(2);
156 }
157 lineNo++;
158 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
159 beg = tok.begin();
160 std::string type = *beg;
161 ++beg;
162 if (type.compare("ModelParameter") != 0) {
163 if (rank == 0) throw std::runtime_error("ERROR: in line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + filename + ", expecting a ModelParameter type here...\n");
164 else sleep(2);
165 }
168 lines.push_back(!tmpMP.
IsFixed());
169 if (beg != tok.end())
170 if (rank == 0) std::cout <<
"WARNING: unread information in parameter " << tmpMP.
getname() << std::endl;
174 nlines++;
175 } else {
176 ModPars.push_back(tmpMP);
177 }
178 }
179 if (nlines > 1) {
180 TMatrixD myCorr(nlines, nlines);
181 int ni = 0;
182 for (int i = 0; i < size; i++) {
183 IsEOF = getline(ifile, line).eof();
184 if (line.empty() || line.at(0) == '#') {
185 if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in CorrelatedGaussianParameters please! In line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + filename);
186 else sleep(2);
187 }
188 lineNo++;
189 if (lines.at(i)) {
190 boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
191 beg = mytok.begin();
192 int nj = 0;
193 for (int j = 0; j < size; j++) {
194 if ((*beg).compare(0, 1, "0") == 0
195 || (*beg).compare(0, 1, "1") == 0
196 || (*beg).compare(0, 1, "-") == 0) {
197 if (std::distance(mytok.begin(), mytok.end()) < size) {
198 if (rank == 0)
throw std::runtime_error(
"ERROR: invalid correlation matrix for " +
name +
". Check element (" + boost::lexical_cast<std::string>(ni + 1) +
"," + boost::lexical_cast<std::string>(nj + 1) +
") in line number " + boost::lexical_cast<std::string>(lineNo) +
" in file " + filename +
".\n");
199 else sleep(2);
200 }
201 if (lines.at(j)) {
202 myCorr(ni, nj) = atof((*beg).c_str());
203 nj++;
204 }
205 beg++;
206 } else {
207 if (rank == 0) std::cout << "ERROR: invalid correlation matrix for "
208 <<
name <<
". Check element (" << ni + 1 <<
"," << nj + 1 <<
") in line number " + boost::lexical_cast<std::string>(lineNo) << std::endl;
209 exit(EXIT_FAILURE);
210 }
211 }
212 ni++;
213 }
214 }
215 if (!myCorr.IsSymmetric()) {
216 if (rank == 0) std::cout << "ERROR: invalid correlation matrix for "
217 <<
name <<
". Correlation matrix is not symmetric." << std::endl;
218 exit(EXIT_FAILURE);
219 } else {
220 TMatrixDSym mySCorr(nlines);
221 for (int i = 0; i < nlines; i++) {
222 for (int j = 0; j <= i; j++) {
223 mySCorr(i, j) = myCorr(i, j);
224 mySCorr(j, i) = mySCorr(i, j);
225 }
226 }
229 }
230 } else {
231 if (rank == 0) std::cout <<
"\nWARNING: Correlated Gaussian Parameters " <<
name.c_str() <<
" defined with less than two correlated parameters. The set is being marked as normal Parameters." << std::endl;
233 for (int i = 0; i < size; i++) {
234 IsEOF = getline(ifile, line).eof();
235 lineNo++;
236 }
237 }
238 return lineNo;
239}
boost::tokenizer< boost::char_separator< char > >::iterator & ParseModelParameter(boost::tokenizer< boost::char_separator< char > >::iterator &beg)
Parser for model parameters.
void setCgp_name(std::string cgp_name)
A set method to set the name of the set of correlated parameter.
std::string getname() const
A get method to get the name of each parameter.
bool IsFixed() const
A method to check if the parameter is fixed.