Beispiel #1
0
boost::tokenizer<boost::char_separator<char> >::iterator & Observable::ParseObservable(std::string& type, 
                                                                                       boost::tokenizer<boost::char_separator<char> >* tok, 
                                                                                       boost::tokenizer<boost::char_separator<char> >::iterator & beg, 
                                                                                       std::string& filepath,
                                                                                       std::string& infilename,
                                                                                       int rank) 
{
    if ((type.compare("Observable") == 0 || type.compare("HiggsObservable")) && std::distance(tok->begin(), tok->end()) < 8) {
        if(rank == 0) throw std::runtime_error("ERROR: lack of information on " + *beg + " in " + infilename);
        else sleep (2);
    } else if (type.compare("BinnedObservable") == 0 && std::distance(tok->begin(), tok->end()) < 10) {
        if(rank == 0) throw std::runtime_error("ERROR: lack of information on " + *beg + " in " + infilename);
        else sleep (2);
    } else if (type.compare("FunctionObservable") == 0 && std::distance(tok->begin(), tok->end()) < 9) {
        if(rank == 0) throw std::runtime_error("ERROR: lack of information on " + *beg + " in " + infilename);
        else sleep (2);
    } else {
        obsType = type;
        name = *beg;
        ++beg;
        thname = *beg;
        ++beg;
        label = *beg;
        size_t pos = 0;
        while ((pos = label.find("~", pos)) != std::string::npos)
            label.replace(pos++, 1, " ");
        ++beg;
        min = atof((*beg).c_str());
        ++beg;
        max = atof((*beg).c_str());
        ++beg;
        std::string toMCMC = *beg;
        if (toMCMC.compare("MCMC") == 0)
            tMCMC = true;
        else if (toMCMC.compare("noMCMC") == 0)
            tMCMC = false;
        else {
            if (rank == 0) throw std::runtime_error("ERROR: wrong MCMC flag in " + name + ".\n");
            else sleep (2);
        }

        if (obsType.compare("Observable") == 0 || obsType.compare("BinnedObservable") == 0 || obsType.compare("FunctionObservable") == 0) {
            ++beg;
            distr = *beg;
            if (distr.compare("file") == 0) {
                if (std::distance(tok->begin(), tok->end()) < 10) {
                    if (rank == 0) throw std::runtime_error("ERROR: lack of information on " + *beg + " in " + infilename + ".\n");
                    else sleep(2);
                } else {
                    filename = filepath + *(++beg);
                    histoname = *(++beg);
                    setLikelihoodFromHisto(filename, histoname);
                    if (rank == 0) std::cout << "added input histogram " << filename << "/" << histoname << std::endl;
                }
            } else if (distr.compare("weight") == 0) {
                if (std::distance(tok->begin(), tok->end()) < 11) {
                    if(rank == 0) throw std::runtime_error("ERROR: lack of information on " + *beg + " in " + infilename + ".\n");
                    else sleep (2);
                }
                ++beg;
                ave = atof((*beg).c_str());
                ++beg;
                errg = atof((*beg).c_str());
                ++beg;
                errf = atof((*beg).c_str());
                if (errf == 0. && errg == 0.) {
                    if (rank == 0) throw std::runtime_error("ERROR: The Gaussian and flat error in weight for " + name + " cannot both be 0. in the " + infilename + " .\n");
                    else sleep(2);
                }
            } else if (distr.compare("noweight") == 0) {
                if (obsType.compare("BinnedObservable") == 0 || obsType.compare("FunctionObservable") == 0) {
                    ++beg;
                    ++beg;
                    ++beg;
                }
            } else {
                if (rank == 0) throw std::runtime_error("ERROR: wrong distribution flag in " + name + " in file " + infilename + ".\n");
                else sleep(2);
            }
            ++beg;
            if (obsType.compare("BinnedObservable") == 0) {
                bin_min = atof((*beg).c_str());
                ++beg;
                bin_max = atof((*beg).c_str());
                ++beg;
            } else if (obsType.compare("FunctionObservable") == 0) {
                bin_min = atof((*beg).c_str());
                ++beg;
                ++beg;
            }
            if (beg != tok->end() && rank == 0) std::cout << "WARNING: unread information in observable " << name << std::endl;
        }
    }
    return beg;
}
Beispiel #2
0
int Observable2D::ParseObservable2D(std::string& type, 
                                     boost::tokenizer<boost::char_separator<char> >* tok, 
                                     boost::tokenizer<boost::char_separator<char> >::iterator& beg, 
                                     std::string& infilename, 
                                     std::ifstream& ifile,
                                     int lineNo,
                                     int rank)
{
    if (infilename.find("\\/") == std::string::npos) filepath = infilename.substr(0, infilename.find_last_of("\\/") + 1);
    if (std::distance(tok->begin(), tok->end()) < 12) {
        setName(*beg);
        ++beg;
        if (std::distance(tok->begin(), tok->end()) < 4) {
            if(rank == 0) throw std::runtime_error("ERROR: lack of information on " + name + " in " + infilename + " at line number" + boost::lexical_cast<std::string>(lineNo));
            else sleep (2);
        }
        std::string toMCMC = *beg;
        if (toMCMC.compare("MCMC") == 0)
            setTMCMC(true);
        else if (toMCMC.compare("noMCMC") == 0)
            setTMCMC(false);
        else {
            if (rank == 0) throw std::runtime_error("ERROR: wrong MCMC flag in Observable2D" + name + " at line number:" + boost::lexical_cast<std::string>(lineNo) + " of file " + infilename + ".\n");
            else sleep(2);
        }
        
        ++beg;
        setDistr(*beg);
        if (distr.compare("file") == 0) {
            if (std::distance(tok->begin(), tok->end()) < 6) {
                if(rank == 0) throw std::runtime_error("ERROR: lack of information on "+ *beg + " in " + infilename);
                else sleep (2);
            }
            setFilename(filepath + *(++beg));
            setHistoname(*(++beg));
        }

        std::vector<double> min(2, 0.);
        std::vector<double> max(2, 0.);
        std::vector<double> ave(2, 0.);
        std::vector<double> errg(2, 0.);
        std::vector<double> errf(2, 0.);
        std::vector<std::string> thname(2, "");
        std::vector<std::string> label(2, "");
        std::vector<std::string> type2D(2, "");
        std::string line;
        size_t pos = 0;
        boost::char_separator<char> sep(" \t");
        for (int i = 0; i < 2; i++) {
            IsEOF = getline(ifile, line).eof();
            if (line.empty() || line.at(0) == '#') {
                if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in Observable2D please! In file " + infilename + " at line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n");
                else sleep(2);
            }
            lineNo++;
            boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
            beg = mytok.begin();
            type2D[i] = *beg;
            if (type2D[i].compare("Observable") != 0 && type2D[i].compare("BinnedObservable") != 0 && type2D[i].compare("FunctionObservable") != 0) {
                if (rank == 0) throw std::runtime_error("ERROR: in line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + infilename + ", expecting an Observable or BinnedObservable or FunctionObservable type here...\n");
                else sleep(2);
            }
            ++beg;
            thname[i] = *beg;
            ++beg;
            label[i] = *beg;
            while ((pos = label[i].find("~", pos)) != std::string::npos)
                label[i].replace(pos++, 1, " ");
            ++beg;
            min[i] = atof((*beg).c_str());
            ++beg;
            max[i] = atof((*beg).c_str());
            if (distr.compare("weight") == 0) {
                ++beg;
                ave[i] = atof((*beg).c_str());
                ++beg;
                errg[i] = atof((*beg).c_str());
                ++beg;
                errf[i] = atof((*beg).c_str());
                if (errg[i] == 0. && errg[i] == 0.) {
                    if (rank == 0) throw std::runtime_error("ERROR: The Gaussian and flat error in weight for " + name + " cannot both be 0. in the " + infilename + " file, line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n");
                    else sleep(2);
                }
            } else if (distr.compare("noweight") == 0 || distr.compare("file") == 0) {
                if (type2D[i].compare("BinnedObservable") == 0 || type2D[i].compare("FunctionObservable") == 0) {
                    ++beg;
                    ++beg;
                    ++beg;
                }
            } else {
                if (rank == 0) throw std::runtime_error("ERROR: wrong distribution flag in " + name + " in file " + infilename + ".\n");
                else sleep(2);
            }
            if (type2D[i].compare("BinnedObservable") == 0) {
                ++beg;
                bin_min[i] = atof((*beg).c_str());
                ++beg;
                bin_max[i] = atof((*beg).c_str());
            } else if (type2D[i].compare("FunctionObservable") == 0) {
                ++beg;
                bin_min[i] = atof((*beg).c_str());
                ++beg;
            }
        }
        setObsType(type2D[0]);
        obsType2 = type2D[1];
        setThname(thname[0]);
        thname2 = thname[1];
        setLabel(label[0]);
        label2 = label[1];
        setMin(min[0]);
        min2 = min[1];
        setMax(max[0]);
        max2= max[1];
        setAve(ave[0]);
        ave2 = ave[1];
        setErrg(errg[0]);
        errg2 = errg[1];
        setErrf(errf[0]);
        errf2 = errf[1];
        if (distr.compare("file") == 0) {
            setLikelihoodFromHisto(filename, histoname);
            if (rank == 0) std::cout << "added input histogram " << filename << "/" << histoname << std::endl;
        }
        return lineNo;
    } else {
        beg = ParseObservable(type, tok, beg, filepath, filename, rank);
        ++beg;
        std::string distr = *beg;
        if (distr.compare("file") == 0) {
            if (std::distance(tok->begin(), tok->end()) < 14) {
                if (rank == 0) throw std::runtime_error("ERROR: lack of information on " + *beg + " in " + infilename + ".\n");
                else sleep(2);
            }
            setFilename(filepath + *(++beg));
            setHistoname(*(++beg));
            setLikelihoodFromHisto(filename, histoname);
            if (rank == 0) std::cout << "added input histogram " << filename << "/" << histoname << std::endl;
        } else if (distr.compare("noweight") == 0) {
        } else { 
            if (rank == 0) throw std::runtime_error("ERROR: wrong distribution flag in " + name);
            else sleep(2);
        }
        setDistr(distr);
        ++beg;
        thname2 = *beg;
        ++beg;
        std::string label = *beg;
        size_t pos = 0;
        while ((pos = label.find("~", pos)) != std::string::npos)
            label.replace(pos, 1, " ");
        label2 = label;
        ++beg;
        min2 = atof((*beg).c_str());
        ++beg;
        max2 = atof((*beg).c_str());
        ++beg;
        if (beg != tok->end())
            if (rank == 0) std::cout << "WARNING: unread information in observable2D " << name << std::endl;
        return lineNo;
    }
}