Commit 1135bb2f authored by Plaszczynski Stephane's avatar Plaszczynski Stephane
Browse files

strange sigsev happening when istringstream.fail is called; back to old...

strange sigsev happening when istringstream.fail is called; back to old method- rationalize requirements
parent 57b8f7d1
......@@ -31,7 +31,7 @@ template<typename T> std::string str(const T &x){
std::ostringstream os;
os << x;
return os.str();
}
};
//specilization
template<> std::string str (const float &x){
std::ostringstream os;
......@@ -86,7 +86,7 @@ void ClassParams::updateVal(const unsigned& i,const string& newval) {pars[i].sec
// Constructors --
//----------------
ClassEngine::ClassEngine(const ClassParams& pars): cl(0),dofree(true),pvecback(0){
_lmax=-1; //default
cout << "Running CLASS version " << _VERSION_ << endl;
......@@ -95,7 +95,7 @@ ClassEngine::ClassEngine(const ClassParams& pars): cl(0),dofree(true),pvecback(0
size_t n=pars.size();
//
parser_init(&fc,n,"pipo",_errmsg);
//config
for (size_t i=0;i<pars.size();i++){
strcpy(fc.name[i],pars.key(i).c_str());
......@@ -116,7 +116,7 @@ ClassEngine::ClassEngine(const ClassParams& pars): cl(0),dofree(true),pvecback(0
}
//input
if (input_init(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg) == _FAILURE_)
if (input_init(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg) == _FAILURE_)
throw invalid_argument(_errmsg);
//protection parametres mal defini
......@@ -126,7 +126,7 @@ ClassEngine::ClassEngine(const ClassParams& pars): cl(0),dofree(true),pvecback(0
//calcul class
computeCls();
//cout <<"creating " << sp.ct_size << " arrays" <<endl;
cl=new double[sp.ct_size];
......@@ -174,9 +174,9 @@ ClassEngine::ClassEngine(const ClassParams& pars,const string & precision_file):
//parser_free(&fc_input);
parser_free(&fc_precision);
//input
if (input_init(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg) == _FAILURE_)
if (input_init(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg) == _FAILURE_)
throw invalid_argument(_errmsg);
//protection parametres mal defini
......@@ -186,12 +186,12 @@ ClassEngine::ClassEngine(const ClassParams& pars,const string & precision_file):
//calcul class
computeCls();
//cout <<"creating " << sp.ct_size << " arrays" <<endl;
cl=new double[sp.ct_size];
printFC();
}
......@@ -237,7 +237,7 @@ bool ClassEngine::updateParValues(const ClassParams& pars){
strcpy(fc.value[i],pars.value(i).c_str());
}
int status=computeCls();
return (status==_SUCCESS_);
}
......@@ -263,7 +263,7 @@ int ClassEngine::class_main(
struct lensing * ple,
struct output * pop,
ErrorMsg errmsg) {
if (input_init(pfc,ppr,pba,pth,ppt,ptr,ppm,psp,pnl,ple,pop,errmsg) == _FAILURE_) {
printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg);
......@@ -358,8 +358,8 @@ int ClassEngine::class_main(
int
ClassEngine::freeStructs(){
if (lensing_free(&le) == _FAILURE_) {
printf("\n\nError in spectra_free \n=>%s\n",le.error_message);
return _FAILURE_;
......@@ -369,23 +369,23 @@ ClassEngine::freeStructs(){
printf("\n\nError in spectra_free \n=>%s\n",sp.error_message);
return _FAILURE_;
}
if (transfer_free(&tr) == _FAILURE_) {
printf("\n\nError in transfer_free \n=>%s\n",tr.error_message);
return _FAILURE_;
}
}
if (nonlinear_free(&nl) == _FAILURE_) {
printf("\n\nError in nonlinear_free \n=>%s\n",nl.error_message);
return _FAILURE_;
}
if (primordial_free(&pm) == _FAILURE_) {
printf("\n\nError in primordial_free \n=>%s\n",pm.error_message);
return _FAILURE_;
}
if (perturb_free(&pt) == _FAILURE_) {
printf("\n\nError in perturb_free \n=>%s\n",pt.error_message);
......@@ -411,7 +411,7 @@ ClassEngine::getCl(Engine::cltype t,const long &l){
if (!dofree) throw out_of_range("no Cl available because CLASS failed");
if (output_total_cl_at_l(&sp,&le,&op,static_cast<double>(l),cl) == _FAILURE_){
cerr << ">>>fail getting Cl type=" << (int)t << " @l=" << l <<endl;
cerr << ">>>fail getting Cl type=" << (int)t << " @l=" << l <<endl;
throw out_of_range(sp.error_message);
}
......@@ -427,7 +427,7 @@ ClassEngine::getCl(Engine::cltype t,const long &l){
break;
case TE:
(sp.has_te==_TRUE_) ? zecl=tomuk2*cl[sp.index_ct_te] : throw invalid_argument("no ClTE available");
break;
break;
case EE:
(sp.has_ee==_TRUE_) ? zecl=tomuk2*cl[sp.index_ct_ee] : throw invalid_argument("no ClEE available");
break;
......@@ -444,7 +444,7 @@ ClassEngine::getCl(Engine::cltype t,const long &l){
(sp.has_ep==_TRUE_) ? zecl=tomuk*cl[sp.index_ct_ep] : throw invalid_argument("no ClE-Phi available");
break;
}
return zecl;
}
......@@ -466,18 +466,18 @@ int ClassEngine::computeCls(){
}
void
ClassEngine::getCls(const std::vector<unsigned>& lvec, //input
std::vector<double>& cltt,
std::vector<double>& clte,
std::vector<double>& clee,
void
ClassEngine::getCls(const std::vector<unsigned>& lvec, //input
std::vector<double>& cltt,
std::vector<double>& clte,
std::vector<double>& clee,
std::vector<double>& clbb)
{
cltt.resize(lvec.size());
clte.resize(lvec.size());
clee.resize(lvec.size());
clbb.resize(lvec.size());
for (size_t i=0;i<lvec.size();i++){
try{
cltt[i]=getCl(ClassEngine::TT,lvec[i]);
......@@ -491,18 +491,18 @@ ClassEngine::getCls(const std::vector<unsigned>& lvec, //input
}
}
bool
ClassEngine::getLensing(const std::vector<unsigned>& lvec, //input
std::vector<double>& clpp ,
std::vector<double>& cltp ,
bool
ClassEngine::getLensing(const std::vector<unsigned>& lvec, //input
std::vector<double>& clpp ,
std::vector<double>& cltp ,
std::vector<double>& clep ){
clpp.resize(lvec.size());
cltp.resize(lvec.size());
clep.resize(lvec.size());
for (size_t i=0;i<lvec.size();i++){
try{
/*
......@@ -565,7 +565,7 @@ double ClassEngine::get_Pklin(double k, double z){
background_tau_of_z(&ba,z,&tau);
background_at_tau(&ba,tau,ba.long_info,ba.inter_normal, &index, pvecback);
spectra_pk_at_k_and_z(&ba,&pm,&sp,k,z,&mypk,pk_ic);
int ret=spectra_pk_at_k_and_z(&ba,&pm,&sp,k,z,&mypk,pk_ic);
return mypk;
}
......@@ -577,7 +577,7 @@ double ClassEngine::get_PkNL(double k, double z){
//cout << "pknl after bkg "<<tau<< endl;
background_at_tau(&ba,tau,ba.long_info,ba.inter_normal, &index, pvecback);
//cout << "pknl after bkg @tau "<<tau<< " z "<<z<< " k "<< k << endl;
spectra_pk_nl_at_k_and_z(&ba,&pm,&sp,k,z,&mypk);
int ret = spectra_pk_nl_at_k_and_z(&ba,&pm,&sp,k,z,&mypk);
return mypk;
}
......@@ -598,7 +598,7 @@ double ClassEngine::get_sigma8(double z)
#ifdef DBUG
cout << "sigma_8= " << sigma8 <<" at "<<z<<" tau "<<tau<<" bah "<<ba.h<< "size " << ba.bg_size << " index "<< index<<endl;
#endif
planck_assert( sigma8 != -99. , " sigma8 could not be computed at " +str(z) + " \n 1) check z_pk and z_max_pk parameters for class \n 2) that you have enabled the Pk computation with : do_mPk = true \n ");
planck_assert( sigma8 != -99. , " sigma8 could not be computed at " +str(z) + " \n 1) check z_pk and z_max_pk parameters for class \n 2) that you have enabled the Pk computation with : do_mPk = true \n ");
return sigma8;
}
......@@ -648,7 +648,7 @@ double ClassEngine::get_Fz(double z)
cout << "H_z= "<< H_z <<endl;
cout << "D_ang= "<< D_ang <<endl;
#endif
double F_z = (1.+z) * D_ang * H_z /(3.e8) ; // is there speed of light somewhere ?
double F_z = (1.+z) * D_ang * H_z /(3.e8) ; // is there speed of light somewhere ?
return F_z;
}
......@@ -693,9 +693,10 @@ double ClassEngine::get_Da(double z)
//call to fill pvecback
background_at_tau(&ba,tau,ba.long_info,ba.inter_normal, &index, pvecback);
double H_z=pvecback[ba.index_bg_H];
double D_ang=pvecback[ba.index_bg_ang_distance];
#ifdef DBUG
double H_z=pvecback[ba.index_bg_H];
cout << "H_z= "<< H_z <<endl;
cout << "D_ang= "<< D_ang <<endl;
#endif
......@@ -709,7 +710,7 @@ double ClassEngine::get_DMod(double z){
int index;
//transform redshift in conformal time
background_tau_of_z(&ba,z,&tau);
//pvecback must be allocated
//pvecback must be allocated
background_at_tau(&ba,tau,ba.long_info,ba.inter_normal, &index, pvecback);
double mu = 5.*log10(pvecback[ba.index_bg_lum_distance]) + 25.;
......@@ -721,8 +722,8 @@ double ClassEngine::get_DMod(double z){
bool
ClassEngine::get_Pkvec(const std::vector<double>& knodes, const std::vector<double>& zvec, std::vector<double>& pks)
{
return ( has_PkNL() ?
(spectra_fast_pk_nl_at_kvec_and_zvec(&ba,&sp,const_cast<double*>(&knodes[0]),knodes.size(),const_cast<double*>(&zvec[0]), zvec.size(),&pks[0])==_TRUE_)
return ( has_PkNL() ?
(spectra_fast_pk_nl_at_kvec_and_zvec(&ba,&sp,const_cast<double*>(&knodes[0]),knodes.size(),const_cast<double*>(&zvec[0]), zvec.size(),&pks[0])==_TRUE_)
: (spectra_fast_pk_at_kvec_and_zvec(&ba,&sp,const_cast<double*>(&knodes[0]),knodes.size(),const_cast<double*>(&zvec[0]), zvec.size(),&pks[0])==_TRUE_) );
}
......@@ -736,7 +737,7 @@ ClassEngine::get_PklinNodes(std::vector<double>& knodes,std::vector<double>& pkn
int index_mode=0;
int index_ic1_ic2=0;
int index_eta = sp.ln_tau_size-1;
for (int index_k=0; index_k < sp.ln_k_size; index_k++){
knodes[index_k]=std::exp(sp.ln_k[index_k]);
pknodes[index_k]=std::exp(sp.ln_pk[(index_eta * sp.ln_k_size + index_k) * sp.ic_ic_size[index_mode] + index_ic1_ic2]);
......@@ -752,7 +753,7 @@ ClassEngine::get_PkNLNodes(std::vector<double>& knodes,std::vector<double>& pkno
pknodes.resize(sp.ln_k_size);
int index_eta = sp.ln_tau_size-1;
for (int index_k=0; index_k < sp.ln_k_size; index_k++){
knodes[index_k]=std::exp(sp.ln_k[index_k]);
pknodes[index_k]=std::exp(sp.ln_pk_nl[index_eta * sp.ln_k_size + index_k]);
......
......@@ -9,7 +9,7 @@
// Stephane Plaszczynski (plaszczy@lal.in2p3.fr)
//
// History (add to end):
// creation: ven. nov. 4 11:02:20 CET 2011
// creation: ven. nov. 4 11:02:20 CET 2011
//
//-----------------------------------------------------------------------
......@@ -18,7 +18,6 @@
//CLASS
extern "C"{
#include"class.h"
}
#include"Engine.hh"
......@@ -49,7 +48,7 @@ public:
ClassParams( const ClassParams& o):pars(o.pars){};
//add class parameter with single value
template<typename T> unsigned inline
template<typename T> unsigned inline
add(const string& key,const T& val){
pars.push_back(make_pair(key,str(val)));
return pars.size();
......@@ -98,7 +97,7 @@ public:
ClassEngine(const ClassParams& pars);
//with a class .pre file
ClassEngine(const ClassParams& pars,const string & precision_file);
// destructor
~ClassEngine();
......@@ -124,27 +123,27 @@ public:
//throws std::execption if pb
virtual std::string name() const {return "ClassEngine";}
double getCl(Engine::cltype t,const long &l);
void getCls(const std::vector<unsigned>& lVec, //input
std::vector<double>& cltt,
std::vector<double>& clte,
std::vector<double>& clee,
double getCl(Engine::cltype t,const long &l);
void getCls(const std::vector<unsigned>& lVec, //input
std::vector<double>& cltt,
std::vector<double>& clte,
std::vector<double>& clee,
std::vector<double>& clbb);
bool getLensing(const std::vector<unsigned>& lVec, //input
std::vector<double>& clphiphi,
std::vector<double>& cltphi,
bool getLensing(const std::vector<unsigned>& lVec, //input
std::vector<double>& clphiphi,
std::vector<double>& cltphi,
std::vector<double>& clephi);
//recombination
inline double z_rec() const {return th.z_rec;}
inline double rs_rec() const {return th.rs_rec;}
inline double rs_rec() const {return th.rs_rec;}
//baryon drag
//baryon drag
inline double z_drag() const {return th.z_d;}
inline double rs_drag() const {return th.rs_d;}
inline double rs_drag() const {return th.rs_d;}
double get_Dv(double z);
double get_Da(double z);
......@@ -165,13 +164,13 @@ public:
bool get_PklinNodes(std::vector<double>& knodes,std::vector<double>& Pknodes);
bool get_PkNLNodes(std::vector<double>& knodes,std::vector<double>& Pknodes);
// the followingdepends on switch (prefer previous methods)
inline bool get_PkNodes(std::vector<double>& knodes,std::vector<double>& Pknodes)
{return (has_PkNL()? get_PkNLNodes(knodes,Pknodes) : get_PklinNodes(knodes,Pknodes));}
inline bool get_PkNodes(std::vector<double>& knodes,std::vector<double>& Pknodes)
{return (has_PkNL()? get_PkNLNodes(knodes,Pknodes) : get_PklinNodes(knodes,Pknodes));}
//vectorized access: faster (uses class_extra from camel)
// outout vector pks must be already sized (see Engine.hh)
bool get_Pkvec(const std::vector<double>& kin, const std::vector<double>& z,std::vector<double>& pks);
bool get_Pkvec(const std::vector<double>& kin, const std::vector<double>& z,std::vector<double>& pks);
inline bool get_Pkvec(const std::vector<double>& kvec,const double& z, std::vector<double>& pks){
std::vector<double> zvec(1,z);
return this->get_Pkvec(kvec,zvec,pks);
......@@ -252,7 +251,7 @@ private:
protected:
std::string _output;
double* pvecback; // helper to avoid too much allocations
......@@ -260,3 +259,4 @@ protected:
};
#endif
......@@ -104,8 +104,12 @@ Engine::get(const std::string& key)
planck_assert(key.substr(key.size()-1,1)==")",key+": keyword not finishing with )");
var=key.substr(0,index);
istringstream isNum(key.substr(index+1,key.size()-index-1));
isNum >> z;
planck_assert(isNum.fail(),key+": Engine canot decode z value in keyword");
//isNum >> z;
//planck_assert(isNum.fail(),key+": Engine canot decode z value in keyword");
//SP: 5sep18 previuous lines fail (don't lnow why) so back to previous method
planck_assert(isNum>>z,key+": Engine canot decode z value in keyword");
}
if (var=="z_drag") return z_drag();
else if (var=="rs_drag") return rs_drag();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment