// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_waxml_histos #define tools_waxml_histos #include "../histo/h1d" #include "../histo/h2d" #include "../histo/h3d" #include "../histo/p1d" #include "../histo/p2d" #include "../sout" #include "../num2s" #include "../srep" #include namespace tools { namespace waxml { inline std::string soutd(std::ostringstream& a_oss,double a_value) { a_oss.str(""); a_oss << a_value; std::string _s("\""); _s += a_oss.str(); _s += "\""; return _s; } inline std::string bin_to_string(std::ostringstream& a_oss,int a_index) { if(a_index==histo::axis_UNDERFLOW_BIN) { return "UNDERFLOW"; } else if(a_index==histo::axis_OVERFLOW_BIN) { return "OVERFLOW"; } else { a_oss.str(""); a_oss << a_index; return a_oss.str(); } } typedef std::map annotations_t; inline void write_annotations( const annotations_t& a_annotations ,std::ostream& a_writer ,int aShift ){ if(a_annotations.empty()) return; std::string spaces; for(int i=0;i" << std::endl; annotations_t::const_iterator it; for(it=a_annotations.begin();it!=a_annotations.end();++it){ a_writer << spaces << " " << std::endl; } a_writer << spaces << " " << std::endl; } inline void write_axis( const histo::axis& aAxis ,const std::string& aDirection ,std::ostream& a_writer ,std::ostringstream& a_oss ,int aShift ){ typedef histo::axis::bn_t bn_t; std::string spaces; for(int i=0;i" << std::endl; } else { a_writer << spaces << " " << std::endl; bn_t number = aAxis.bins()-1; for(bn_t index=0;index" << std::endl; } a_writer << spaces << " " << std::endl; } } inline void write_bin( std::ostream& a_writer ,std::ostringstream& a_oss ,const histo::h1d& aObject ,const std::string& aSpaces ,int aIndex ){ unsigned int entries = aObject.bin_entries(aIndex); if(entries) { a_writer << aSpaces << " " << std::endl; } } inline void write_bin( std::ostream& a_writer ,std::ostringstream& a_oss ,const histo::h2d& aObject ,const std::string& aSpaces ,int aIndexX ,int aIndexY ){ unsigned int entries = aObject.bin_entries(aIndexX,aIndexY); if(entries) { a_writer << aSpaces << " " << std::endl; } } inline void write_bin( std::ostream& a_writer ,std::ostringstream& a_oss ,const histo::h3d& aObject ,const std::string& aSpaces ,int aIndexX ,int aIndexY ,int aIndexZ ){ unsigned int entries = aObject.bin_entries(aIndexX,aIndexY,aIndexZ); if(entries) { a_writer << aSpaces << " " << std::endl; } } inline void write_bin( std::ostream& a_writer ,std::ostringstream& a_oss ,const histo::p1d& aObject ,const std::string& aSpaces ,int aIndex ){ if(aObject.bin_entries(aIndex)) { a_writer << aSpaces << " " << std::endl; } } inline void write_bin( std::ostream& a_writer ,std::ostringstream& a_oss ,const histo::p2d& aObject ,const std::string& aSpaces ,int aIndexX ,int aIndexY ){ if(aObject.bin_entries(aIndexX,aIndexY)) { a_writer << aSpaces << " " << std::endl; } } inline bool write( std::ostream& a_writer ,const histo::h1d& aObject ,const std::string& aPath ,const std::string& aName ,int aShift = 0 ){ std::ostringstream ossd; ossd.precision(25); typedef histo::axis::bn_t bn_t; std::ostream& writer = a_writer; std::string spaces; for(int i=0;i : writer << spaces << " " << std::endl; // : write_annotations(aObject.annotations(),writer,aShift); // : write_axis(aObject.axis(),"x",writer,ossd,aShift); // : writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; // bins : writer << spaces << " " << std::endl; bn_t xbins = aObject.axis().bins(); for(bn_t index=0;index" << std::endl; writer << spaces << " " << std::endl; return true; } inline bool write( std::ostream& a_writer ,const histo::h2d& aObject ,const std::string& aPath ,const std::string& aName ,int aShift = 0 ){ std::ostringstream ossd; ossd.precision(25); typedef histo::axis::bn_t bn_t; std::ostream& writer = a_writer; std::string spaces; for(int i=0;i : writer << spaces << " " << std::endl; // : write_annotations(aObject.annotations(),writer,aShift); // : write_axis(aObject.axis_x(),"x",writer,ossd,aShift); write_axis(aObject.axis_y(),"y",writer,ossd,aShift); // : writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; // bins : writer << spaces << " " << std::endl; bn_t xbins = aObject.axis_x().bins(); bn_t ybins = aObject.axis_y().bins(); bn_t indexX,indexY; for(indexX=0;indexX" << std::endl; writer << spaces << " " << std::endl; return true; } inline bool write( std::ostream& a_writer ,const histo::h3d& aObject ,const std::string& aPath ,const std::string& aName ,int aShift = 0 ){ std::ostringstream ossd; ossd.precision(25); typedef histo::axis::bn_t bn_t; std::ostream& writer = a_writer; std::string spaces; for(int i=0;i : writer << spaces << " " << std::endl; // : write_annotations(aObject.annotations(),writer,aShift); // : write_axis(aObject.axis_x(),"x",writer,ossd,aShift); write_axis(aObject.axis_y(),"y",writer,ossd,aShift); write_axis(aObject.axis_z(),"z",writer,ossd,aShift); // : writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; // bins : writer << spaces << " " << std::endl; bn_t xbins = aObject.axis_x().bins(); bn_t ybins = aObject.axis_y().bins(); bn_t zbins = aObject.axis_z().bins(); bn_t indexX,indexY,indexZ; for(indexX=0;indexX" << std::endl; writer << spaces << " " << std::endl; return true; } inline bool write( std::ostream& a_writer ,const histo::p1d& aObject ,const std::string& aPath ,const std::string& aName ,int aShift = 0 ){ std::ostringstream ossd; ossd.precision(25); typedef histo::axis::bn_t bn_t; std::ostream& writer = a_writer; std::string spaces; for(int i=0;i : writer << spaces << " " << std::endl; // : write_annotations(aObject.annotations(),writer,aShift); // : write_axis(aObject.axis(),"x",writer,ossd,aShift); // : writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; // bins : writer << spaces << " " << std::endl; bn_t xbins = aObject.axis().bins(); for(bn_t index=0;index" << std::endl; writer << spaces << " " << std::endl; return true; } inline bool write( std::ostream& a_writer ,const histo::p2d& aObject ,const std::string& aPath ,const std::string& aName ,int aShift = 0 ){ std::ostringstream ossd; ossd.precision(25); typedef histo::axis::bn_t bn_t; std::ostream& writer = a_writer; std::string spaces; for(int i=0;i : writer << spaces << " " << std::endl; // : write_annotations(aObject.annotations(),writer,aShift); // : write_axis(aObject.axis_x(),"x",writer,ossd,aShift); write_axis(aObject.axis_y(),"y",writer,ossd,aShift); // : writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; // bins : writer << spaces << " " << std::endl; {bn_t xbins = aObject.axis_x().bins(); bn_t ybins = aObject.axis_y().bins(); for(bn_t indexX=0;indexX" << std::endl; writer << spaces << " " << std::endl; return true; } }} #endif