// 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 "../sto" namespace tools { namespace waxml { inline std::string bin_to_string(int a_index) { if(a_index==histo::axis::UNDERFLOW_BIN) { return "UNDERFLOW"; } else if(a_index==histo::axis::OVERFLOW_BIN) { return "OVERFLOW"; } else { std::ostringstream strm; strm << a_index; return strm.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 ,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 ,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 ,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 ,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 ,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 ,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 ){ 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,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::UNDERFLOW_BIN); write_bin(writer,aObject,spaces,histo::axis::OVERFLOW_BIN); writer << spaces << " " << 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 ){ 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,aShift); write_axis(aObject.axis_y(),"y",writer,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::UNDERFLOW_BIN,histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN,histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::UNDERFLOW_BIN,histo::axis::OVERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN,histo::axis::OVERFLOW_BIN); for(indexX=0;indexX::UNDERFLOW_BIN); write_bin(writer,aObject,spaces,indexX,histo::axis::OVERFLOW_BIN); } for(indexY=0;indexY::UNDERFLOW_BIN,indexY); write_bin(writer,aObject,spaces,histo::axis::OVERFLOW_BIN,indexY); } writer << spaces << " " << 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 ){ 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,aShift); write_axis(aObject.axis_y(),"y",writer,aShift); write_axis(aObject.axis_z(),"z",writer,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::UNDERFLOW_BIN, histo::axis::UNDERFLOW_BIN, histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN, histo::axis::UNDERFLOW_BIN, histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::UNDERFLOW_BIN, histo::axis::OVERFLOW_BIN, histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN, histo::axis::OVERFLOW_BIN, histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::UNDERFLOW_BIN, histo::axis::UNDERFLOW_BIN, histo::axis::OVERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN, histo::axis::UNDERFLOW_BIN, histo::axis::OVERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::UNDERFLOW_BIN, histo::axis::OVERFLOW_BIN, histo::axis::OVERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN, histo::axis::OVERFLOW_BIN, histo::axis::OVERFLOW_BIN); // Edges : for(indexX=0;indexX::UNDERFLOW_BIN, histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, indexX, histo::axis::OVERFLOW_BIN, histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, indexX, histo::axis::UNDERFLOW_BIN, histo::axis::OVERFLOW_BIN); write_bin(writer,aObject,spaces, indexX, histo::axis::OVERFLOW_BIN, histo::axis::OVERFLOW_BIN); } for(indexY=0;indexY::UNDERFLOW_BIN, indexY, histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN, indexY, histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::UNDERFLOW_BIN, indexY, histo::axis::OVERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN, indexY, histo::axis::OVERFLOW_BIN); } for(indexZ=0;indexZ::UNDERFLOW_BIN, histo::axis::UNDERFLOW_BIN, indexZ); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN, histo::axis::UNDERFLOW_BIN, indexZ); write_bin(writer,aObject,spaces, histo::axis::UNDERFLOW_BIN, histo::axis::OVERFLOW_BIN, indexZ); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN, histo::axis::OVERFLOW_BIN, indexZ); } // Faces : for(indexX=0;indexX::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, indexX,indexY,histo::axis::OVERFLOW_BIN); } } for(indexY=0;indexY::UNDERFLOW_BIN,indexY,indexZ); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN,indexY,indexZ); } } for(indexX=0;indexX::UNDERFLOW_BIN,indexZ); write_bin(writer,aObject,spaces, indexX,histo::axis::OVERFLOW_BIN,indexZ); } } writer << spaces << " " << 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 ){ 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,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::UNDERFLOW_BIN); write_bin(writer,aObject,spaces,histo::axis::OVERFLOW_BIN); writer << spaces << " " << 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 ){ 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,aShift); write_axis(aObject.axis_y(),"y",writer,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::UNDERFLOW_BIN,histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN,histo::axis::UNDERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::UNDERFLOW_BIN,histo::axis::OVERFLOW_BIN); write_bin(writer,aObject,spaces, histo::axis::OVERFLOW_BIN,histo::axis::OVERFLOW_BIN); for(bn_t indexX=0;indexX::UNDERFLOW_BIN); write_bin(writer,aObject,spaces,indexX,histo::axis::OVERFLOW_BIN); } for(bn_t indexY=0;indexY::UNDERFLOW_BIN,indexY); write_bin(writer,aObject,spaces,histo::axis::OVERFLOW_BIN,indexY); } writer << spaces << " " << std::endl; writer << spaces << " " << std::endl; return true; } }} #endif