Import Geant4 10.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-12-09 12:35:28 +01:00
parent 4ec577e5c4
commit a3452e42ac
3514 changed files with 210500 additions and 89628 deletions
+54 -161
View File
@@ -4,6 +4,11 @@
#ifndef tools_args
#define tools_args
#ifdef TOOLS_MEM
#include "mem"
#include "S_STRING"
#endif
#include "sout"
#include "strip"
#include "words"
@@ -16,11 +21,21 @@
namespace tools {
class args {
#ifdef TOOLS_MEM
TOOLS_SCLASS(tools::args)
#endif
public:
typedef std::pair<std::string,std::string> arg;
public:
args(){}
args(){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
args(int a_argc,char* a_argv[]){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
for(int index=0;index<a_argc;index++) {
std::string s(a_argv[index]);
std::string::size_type pos = s.find('=');
@@ -34,17 +49,37 @@ public:
}
}
}
args(const std::vector<std::string>& a_args){add(a_args);}
args(const std::vector<arg>& a_args):m_args(a_args){}
args(const std::vector<std::string>& a_args){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
add(a_args);
}
args(const std::vector<arg>& a_args):m_args(a_args){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
//args(const std::string& a_args,const std::string& a_sep = " ",bool a_strip = false){
args(const std::string& a_args,const std::string& a_sep,bool a_strip){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
std::vector<std::string> _args;
words(a_args,a_sep,false,_args);
add(_args,a_strip);
}
virtual ~args(){}
virtual ~args(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
public:
args(const args& a_from):m_args(a_from.m_args){}
args(const args& a_from):m_args(a_from.m_args){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
args& operator=(const args& a_from){
m_args = a_from.m_args;
return *this;
@@ -59,8 +94,8 @@ public:
return false;
}
bool is_empty() const {return m_args.size()?false:true;}
unsigned int size() const {return m_args.size();}
unsigned int number() const {return m_args.size();} //back comp.
size_t size() const {return m_args.size();}
size_t number() const {return m_args.size();} //back comp.
bool find(const std::string& a_key,std::string& a_value,const std::string& a_def = "") const {
tools_vforcit(arg,m_args,it) {
if((*it).first==a_key) {
@@ -139,7 +174,7 @@ public:
void add_keyvals(const std::vector<std::string>& a_args,bool a_strip = false) {
//a_args must contain an even number of strings.
unsigned int sz_half = a_args.size()/2;
size_t sz_half = a_args.size()/2;
if((2*sz_half)!=a_args.size()) return;
for(std::vector<std::string>::const_iterator it = a_args.begin();it!=a_args.end();it+=2) {
if(a_strip) {
@@ -159,7 +194,7 @@ public:
}
int remove(const std::string& a_key){
unsigned int nbeg = m_args.size();
size_t nbeg = m_args.size();
for(std::vector<arg>::iterator it = m_args.begin();it!=m_args.end();) {
if(a_key==(*it).first) {
it = m_args.erase(it);
@@ -167,7 +202,7 @@ public:
++it;
}
}
return nbeg - m_args.size();
return int(nbeg) - int(m_args.size());
}
void remove_first(){m_args.erase(m_args.begin());}
@@ -202,25 +237,25 @@ public:
return false;
}
}
std::vector<std::string> files(bool a_skip_first = true) const {
void files(std::vector<std::string>& a_files,bool a_skip_first = true) const {
a_files.clear();
// Get the serie of trailing args not beginning with '-'
// and without a value (not of the form [-]xxx=yyy).
// Note that an argument like that in between arguments
// is NOT taken into account.
std::vector<std::string> _files;
if(m_args.empty()) return _files;
if(m_args.empty()) return;
std::vector<arg>::const_iterator it = m_args.begin();
if(a_skip_first) it++;
for(;it!=m_args.end();++it) {
if( ((*it).first.find('-')==0) || (*it).second.size() ) {
_files.clear();
a_files.clear();
} else {
_files.push_back((*it).first);
a_files.push_back((*it).first);
}
}
return _files;
}
bool argcv(int& a_argc,char**& a_argv) const {
// If using with :
// int argc;
@@ -330,15 +365,11 @@ inline bool check_min(const std::vector<std::string>& a_args,unsigned int a_numb
a_last.clear();
} else {
a_last = a_args[0];
for(unsigned int index=1;index<a_args.size();index++) {
a_last += " " + a_args[index];
}
for(size_t index=1;index<a_args.size();index++) a_last += " " + a_args[index];
}
} else {
a_last = a_args[a_number-1];
for(unsigned int index=a_number;index<a_args.size();index++) {
a_last += " " + a_args[index];
}
for(size_t index=a_number;index<a_args.size();index++) a_last += " " + a_args[index];
}
return true;
}
@@ -367,144 +398,6 @@ inline bool check_or_args(const std::vector<std::string>& aArgs,unsigned int a_1
return false;
}
inline std::string gui_toolkit(args& a_args,bool a_rm_in_args){
std::string driver;
a_args.find("-toolkit",driver);
if(a_rm_in_args) a_args.remove("-toolkit");
if(driver.empty()) {
if(a_args.is_arg("-Xt")||
a_args.is_arg("-xt")||
a_args.is_arg("-Xm")||
a_args.is_arg("-xm")||
a_args.is_arg("-Motif")||
a_args.is_arg("-motif")) {
driver = "Xt";
if(a_rm_in_args) {
a_args.remove("-Xt");
a_args.remove("-xt");
a_args.remove("-Xm");
a_args.remove("-xm");
a_args.remove("-Motif");
a_args.remove("-motif");
}
} else if(a_args.is_arg("-Win")||
a_args.is_arg("-win")||
a_args.is_arg("-Win32")||
a_args.is_arg("-win32")) {
driver = "Win";
if(a_rm_in_args) {
a_args.remove("-Win");
a_args.remove("-win");
a_args.remove("-Win32");
a_args.remove("-win32");
}
} else if(a_args.is_arg("-NextStep")||
a_args.is_arg("-nextstep")) {
driver = "NextStep";
if(a_rm_in_args) {
a_args.remove("-NextStep");
a_args.remove("-nextstep");
}
} else if(a_args.is_arg("-Gtk")||
a_args.is_arg("-gtk")) {
driver = "Gtk";
if(a_rm_in_args) {
a_args.remove("-Gtk");
a_args.remove("-gtk");
}
} else if(a_args.is_arg("-Qt")||
a_args.is_arg("-qt")) {
driver = "Qt";
if(a_rm_in_args) {
a_args.remove("-Qt");
a_args.remove("-qt");
}
} else if(a_args.is_arg("-SDL")||
a_args.is_arg("-sdl")) {
driver = "SDL";
if(a_rm_in_args) {
a_args.remove("-SDL");
a_args.remove("-sdl");
}
} else if(a_args.is_arg("-Net")||
a_args.is_arg("-net")) {
driver = "Net";
if(a_rm_in_args) {
a_args.remove("-Net");
a_args.remove("-net");
}
} else if(a_args.is_arg("-inex")) {
driver = "inex";
if(a_rm_in_args) {
a_args.remove("-inex");
}
}
}
return driver;
}
inline void window_size_from_args(const args& a_args,unsigned int& a_ww,unsigned int& a_wh) {
// return some common window size (in pixels).
if(a_args.is_arg("-iPod")||a_args.is_arg("-iPhone")) {
a_ww = 320;
a_wh = 480;
} else if(a_args.is_arg("-iPad")) {
a_ww = 768;
a_wh = 1024;
} else if(a_args.is_arg("-iPhone4")) {
a_ww = 640;
a_wh = 960;
} else if(a_args.is_arg("-wallino")) { //emulate LAL/wallino aspect ratio.
a_ww = 1024;
a_wh = 512;
} else if(a_args.is_arg("-SGS")) { //Samsung Galaxy S
//a_ww = 320;
//a_wh = 533;
a_ww = 480;
a_wh = 800;
} else {
if(a_args.find<unsigned int>("-ww",a_ww)) {
if(a_args.find<unsigned int>("-wh",a_wh)) return;
//A4 : we have ww but not wh :
a_wh = (unsigned int)(a_ww*(29.7f/21.0f)); //29.7/21 = 1.414
} else { //we don't have ww.
if(a_args.find<unsigned int>("-wh",a_wh)) {
//A4 : we have wh but not ww :
a_ww = (unsigned int)(a_wh*(21.0f/29.7f));
} else {
//we have nothing. Take a ww of 700. With A4 wh is then 990.
a_ww = 700;
a_wh = (unsigned int)(a_ww*(29.7f/21.0f)); //29.7/21 = 1.414
}
}
}
if(a_args.is_arg("-land")){
unsigned int _ww = a_ww;
unsigned int _wh = a_wh;
a_ww = mx(_ww,_wh);
a_wh = mn(_ww,_wh);
}
if(a_args.is_arg("-portrait")){
unsigned int _ww = a_ww;
unsigned int _wh = a_wh;
a_ww = mn(_ww,_wh);
a_wh = mx(_ww,_wh);
}
}
inline void remove_window_size_args(args& a_args) {
//use with Wt apps.
a_args.remove("-iPod");
a_args.remove("-iPhone");
a_args.remove("-iPad");
a_args.remove("-iPhone4");
a_args.remove("-SGS");
a_args.remove("-ww");
a_args.remove("-wh");
a_args.remove("-land");
}
inline std::vector<std::string> to(int a_argc,char** a_argv) {
std::vector<std::string> v;
for(int index=0;index<a_argc;index++) v.push_back(a_argv[index]);
+13 -13
View File
@@ -109,13 +109,13 @@ public:
}
bool configure(const uints_t& a_orders) {
m_orders = a_orders;
unsigned int dim = m_orders.size();
size_t dim = m_orders.size();
if(dim==0) {
clear();
return false;
}
unsigned int _size = 1;
for(unsigned int index=0;index<dim;index++) {
for(size_t index=0;index<dim;index++) {
//if(m_orders[index]<0) {
//clear();
//return false;
@@ -126,15 +126,15 @@ public:
m_vector.assign(_size,zero());
m_offsets.resize(dim,0);
m_offsets[0] = 1;
for(unsigned int iaxis=1;iaxis<dim;iaxis++)
for(size_t iaxis=1;iaxis<dim;iaxis++)
m_offsets[iaxis] = m_offsets[iaxis-1] * m_orders[iaxis-1];
m_is.resize(dim);
m_is.assign(dim,0);
return true;
}
unsigned int dimension() const { return m_orders.size();}
size_t dimension() const { return m_orders.size();}
const uints_t& orders() const { return m_orders;}
unsigned int size() const {return m_vector.size();}
size_t size() const {return m_vector.size();}
bool set_value(const uints_t& a_is,const T& a_value) {
unsigned int off = 0;
if(!offset(a_is,off)) return false;
@@ -161,8 +161,8 @@ public:
const std::vector<T>& vector() const { return m_vector;}
std::vector<T>& vector() { return m_vector;}
bool fill(const std::vector<T>& a_values,cut_t* a_cut = 0) {
unsigned int dsize = a_values.size();
unsigned int di = 0;
size_t dsize = a_values.size();
size_t di = 0;
unsigned int index = 0;
for(vec_it_t it=m_vector.begin();it!=m_vector.end();++it,index++) {
if(!a_cut || (a_cut && accept(index,*a_cut)) ) {
@@ -312,11 +312,11 @@ public:
return status;
}
bool offset(const uints_t& a_is,unsigned int& a_offset) const {
unsigned int dim = m_orders.size();
size_t dim = m_orders.size();
a_offset = 0;
if(a_is.size()!=dim) return false;
if(dim==0) return false;
for(unsigned int iaxis=0;iaxis<dim;iaxis++) {
for(size_t iaxis=0;iaxis<dim;iaxis++) {
unsigned int i = a_is[iaxis];
if(i>=m_orders[iaxis]) {
a_offset = 0;
@@ -328,20 +328,20 @@ public:
}
bool indices(unsigned int a_offset,uints_t& a_is) const {
if(a_offset>=m_vector.size()) return false;
unsigned int dim = m_orders.size();
size_t dim = m_orders.size();
unsigned int off = a_offset;
for(int iaxis=dim-1;iaxis>=0;iaxis--) {
for(int iaxis=int(dim)-1;iaxis>=0;iaxis--) {
a_is[iaxis] = off/m_offsets[iaxis];
off -= a_is[iaxis] * m_offsets[iaxis];
}
return true;
}
bool accept(unsigned int a_index,const cut_t& a_cut) const {
unsigned int dim = m_orders.size();
size_t dim = m_orders.size();
if(a_cut.size()!=dim) return false;
if(!indices(a_index,const_cast<uints_t&>(m_is))) return false;
bool good = true;
for(unsigned int iaxis=0;iaxis<dim;iaxis++) {
for(size_t iaxis=0;iaxis<dim;iaxis++) {
if(m_is[iaxis]<a_cut[iaxis].first) {good = false;break;}
if(m_is[iaxis]>a_cut[iaxis].second) {good = false;break;}
}
+2 -2
View File
@@ -24,11 +24,11 @@ namespace tools {
inline void b2s(const std::vector<bool>& a_vals,std::string& a_s,const std::string& a_sep = "\n",bool a_sep_at_end = false) {
a_s.clear();
unsigned int number = a_vals.size();
size_t number = a_vals.size();
if(number<=0) return;
number--;
std::string stmp;
for(unsigned int index=0;index<number;index++) {
for(size_t index=0;index<number;index++) {
b2s(a_vals[index],stmp);
a_s += stmp;
a_s += a_sep;
+3 -3
View File
@@ -21,7 +21,7 @@ inline float _fabs(const float& a_x) {return ::fabsf(a_x);}
inline float _tan(const float& a_x) {return ::tanf(a_x);}
inline void _half_pi(float& a_v) {a_v = float(1.5707963267948965580E0);}
inline void _pi(float& a_v) {a_v = float(3.1415926535897931160E0);}
inline float _conj(const float& a_x) {return a_x;}
//inline float _conj(const float& a_x) {return a_x;}
//double
inline double _pow(const double& a_x,const double& a_y) {return ::pow(a_x,a_y);}
@@ -34,7 +34,7 @@ inline double _fabs(const double& a_x) {return ::fabs(a_x);}
inline double _tan(const double& a_x) {return ::tan(a_x);}
inline void _half_pi(double& a_v) {a_v = 1.5707963267948965580E0;}
inline void _pi(double& a_v) {a_v = 3.1415926535897931160E0;}
inline double _conj(const double& a_x) {return a_x;}
//inline double _conj(const double& a_x) {return a_x;}
//long double
#ifndef ANDROID
@@ -48,7 +48,7 @@ inline long double _fabs(const long double& a_x) {return ::fabsl(a_x);}
inline long double _tan(const long double& a_x) {return ::tanl(a_x);}
inline void _half_pi(long double& a_v) {a_v = 1.5707963267948965580E0;}
inline void _pi(long double& a_v) {a_v = 3.1415926535897931160E0;}
inline long double _conj(const long double& a_x) {return a_x;}
//inline long double _conj(const long double& a_x) {return a_x;}
#endif
}
+3 -3
View File
@@ -23,7 +23,7 @@ inline void cmem_free(T*& a_p){
}
template <class T>
inline T* cmem_alloc(unsigned int a_num){
inline T* cmem_alloc(size_t a_num){
if(a_num<=0) return 0;
T* p = (T*)::malloc(a_num*sizeof(T));
if(!p) return 0;
@@ -34,7 +34,7 @@ inline T* cmem_alloc(unsigned int a_num){
}
template <class T>
inline T* cmem_alloc_copy(const T* a_from,unsigned int a_num){
inline T* cmem_alloc_copy(const T* a_from,size_t a_num){
if(a_num<=0) return 0;
T* p = (T*)::malloc(a_num*sizeof(T));
if(!p) return 0;
@@ -42,7 +42,7 @@ inline T* cmem_alloc_copy(const T* a_from,unsigned int a_num){
mem::increment("cmem");
#endif
//::memcpy(p,a_from,a_num*sizeof(T));
for(unsigned int i=0;i<a_num;i++) p[i] = a_from[i];
for(size_t i=0;i<a_num;i++) p[i] = a_from[i];
return p;
}
+11 -4
View File
@@ -9,18 +9,19 @@
namespace tools {
class colorf : public vec4f {
typedef vec4f parent;
public: //for swig
typedef unsigned char uchar;
public:
TOOLS_SCLASS(tools::colorf) //for stype()
public:
colorf():vec4f(0,0,0,1){}
colorf(float a_r,float a_g,float a_b,float a_a = 1):vec4f(a_r,a_g,a_b,a_a){}
colorf():parent(0,0,0,1){}
colorf(float a_r,float a_g,float a_b,float a_a = 1,bool a_inc = true):parent(a_r,a_g,a_b,a_a,a_inc){}
virtual ~colorf() {}
public:
colorf(const colorf& a_from):vec4f(a_from){}
colorf(const colorf& a_from):parent(a_from){}
colorf& operator=(const colorf& a_from){
vec4f::operator=(a_from);
parent::operator=(a_from);
return *this;
}
public:
@@ -39,6 +40,11 @@ public:
uchar bchar() const {return uchar(255.0f*m_data[2]);}
public:
//#define tools_stat_colorfs
#ifdef tools_stat_colorfs
//NOTE : the below are deprecated, use functions in inlib/colorfs.
// tools::colorf::white() replaced by tools::colorf_white()
// our forever 65 named colors taken long time ago from X11.
//NOTE : don't handle a static object because of mem balance.
@@ -120,6 +126,7 @@ public:
static colorf white() {return colorf(1,1,1);}
static colorf yellow() {return colorf(1,1,0);}
static colorf greenyellow() {return colorf(0.675792F,0.996109F,0.18359F);}
#endif
};
struct cmp_colorf {
@@ -0,0 +1,100 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_colorfs
#define tools_colorfs
#include "colors"
#include "colorf"
namespace tools {
#define TOOLS_COLORFS_STAT(a__name,a__r,a__g,a__b) \
inline const colorf& colorf_##a__name() {return get_color_##a__name<colorf>();}
//NOTE : false in the upper so that mem balance is ok at exit.
//0-9
TOOLS_COLORFS_STAT(aquamarine,0.496101F,0.996109F,0.828138F)
TOOLS_COLORFS_STAT(mediumaquamarine,0.398444F,0.800793F,0.664073F)
TOOLS_COLORFS_STAT(black,0,0,0)
TOOLS_COLORFS_STAT(blue,0,0,1)
TOOLS_COLORFS_STAT(cadetblue,0.371099F,0.617197F,0.62501F)
TOOLS_COLORFS_STAT(cornflowerblue,0.390631F,0.58204F,0.925795F)
TOOLS_COLORFS_STAT(darkslateblue,0.281254F,0.238285F,0.542977F)
TOOLS_COLORFS_STAT(lightblue,0.675792F,0.843763F,0.898451F)
TOOLS_COLORFS_STAT(lightsteelblue,0.68751F,0.765637F,0.867201F)
TOOLS_COLORFS_STAT(mediumblue,0,0,0.800793F)
//10-19
TOOLS_COLORFS_STAT(mediumslateblue,0.480476F,0.406256F,0.929702F)
TOOLS_COLORFS_STAT(midnightblue,0.0976577F,0.0976577F,0.437507F)
TOOLS_COLORFS_STAT(navyblue,0,0,0.500008F)
TOOLS_COLORFS_STAT(navy,0,0,0.500008F)
TOOLS_COLORFS_STAT(skyblue,0.527352F,0.8047F,0.917983F)
TOOLS_COLORFS_STAT(slateblue,0.414069F,0.351568F,0.800793F)
TOOLS_COLORFS_STAT(steelblue,0.273442F,0.50782F,0.703136F)
TOOLS_COLORFS_STAT(coral,0.996109F,0.496101F,0.312505F)
TOOLS_COLORFS_STAT(cyan,0,1,1)
TOOLS_COLORFS_STAT(firebrick,0.695323F,0.132815F,0.132815F)
//20-29
TOOLS_COLORFS_STAT(brown,0.644541F,0.164065F,0.164065F)
TOOLS_COLORFS_STAT(gold,0.996109F,0.839857F,0)
TOOLS_COLORFS_STAT(goldenrod,0.851575F,0.644541F,0.125002F)
TOOLS_COLORFS_STAT(green,0,1,0)
TOOLS_COLORFS_STAT(darkgreen,0,0.390631F,0)
TOOLS_COLORFS_STAT(darkolivegreen,0.332036F,0.417975F,0.183597F)
TOOLS_COLORFS_STAT(forestgreen,0.132815F,0.542977F,0.132815F)
TOOLS_COLORFS_STAT(limegreen,0.195315F,0.800793F,0.195315F)
TOOLS_COLORFS_STAT(mediumseagreen,0.234379F,0.699229F,0.441413F)
TOOLS_COLORFS_STAT(mediumspringgreen,0,0.976577F,0.601572F)
//30-39
TOOLS_COLORFS_STAT(palegreen,0.593759F,0.980484F,0.593759F)
TOOLS_COLORFS_STAT(seagreen,0.17969F,0.542977F,0.339849F)
TOOLS_COLORFS_STAT(springgreen,0,0.996109F,0.496101F)
TOOLS_COLORFS_STAT(yellowgreen,0.601572F,0.800793F,0.195315F)
TOOLS_COLORFS_STAT(darkslategrey,0.183597F,0.308598F,0.308598F)
TOOLS_COLORFS_STAT(dimgrey,0.410163F,0.410163F,0.410163F)
TOOLS_COLORFS_STAT(lightgrey,0.824231F,0.824231F,0.824231F)
TOOLS_COLORFS_STAT(grey,0.750011F,0.750011F,0.750011F)
TOOLS_COLORFS_STAT(khaki,0.937514F,0.898451F,0.546883F)
TOOLS_COLORFS_STAT(magenta,1,0,1)
//40-49
TOOLS_COLORFS_STAT(maroon,0.68751F,0.187503F,0.375006F)
TOOLS_COLORFS_STAT(orange,0.996109F,0.644541F,0)
TOOLS_COLORFS_STAT(orchid,0.851575F,0.437507F,0.83595F)
TOOLS_COLORFS_STAT(darkorchid,0.597665F,0.195315F,0.796887F)
TOOLS_COLORFS_STAT(mediumorchid,0.726574F,0.332036F,0.824231F)
TOOLS_COLORFS_STAT(pink,0.996109F,0.750011F,0.792981F)
TOOLS_COLORFS_STAT(plum,0.863294F,0.62501F,0.863294F)
TOOLS_COLORFS_STAT(red,1,0,0)
TOOLS_COLORFS_STAT(indianred,0.800793F,0.35938F,0.35938F)
TOOLS_COLORFS_STAT(mediumvioletred,0.777356F,0.0820325F,0.519539F)
//50-59
TOOLS_COLORFS_STAT(orangered,0.996109F,0.269535F,0)
TOOLS_COLORFS_STAT(violetred,0.812512F,0.125002F,0.562509F)
TOOLS_COLORFS_STAT(salmon,0.976577F,0.500008F,0.445319F)
TOOLS_COLORFS_STAT(sienna,0.62501F,0.320317F,0.175784F)
TOOLS_COLORFS_STAT(tan,0.820325F,0.703136F,0.546883F)
TOOLS_COLORFS_STAT(thistle,0.843763F,0.746105F,0.843763F)
TOOLS_COLORFS_STAT(turquoise,0.250004F,0.875013F,0.812512F)
TOOLS_COLORFS_STAT(darkturquoise,0,0.8047F,0.816419F)
TOOLS_COLORFS_STAT(mediumturquoise,0.281254F,0.816419F,0.796887F)
TOOLS_COLORFS_STAT(violet,0.929702F,0.50782F,0.929702F)
//60-64
TOOLS_COLORFS_STAT(blueviolet,0.539071F,0.167971F,0.882826F)
TOOLS_COLORFS_STAT(wheat,0.957046F,0.867201F,0.699229F)
TOOLS_COLORFS_STAT(white,1,1,1)
TOOLS_COLORFS_STAT(yellow,1,1,0)
TOOLS_COLORFS_STAT(greenyellow,0.675792F,0.996109F,0.18359F)
#undef TOOLS_COLORFS_STAT
}
#endif
@@ -0,0 +1,185 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_colors
#define tools_colors
// our forever 65 named colors taken long time ago from X11.
namespace tools {
#define TOOLS_COLORS_SET(a__name,a__r,a__g,a__b) \
template <class COLOR>\
inline void set_color_##a__name(COLOR& a_color) {a_color.set_value(a__r,a__g,a__b,1);}
//0-9
TOOLS_COLORS_SET(aquamarine,0.496101F,0.996109F,0.828138F)
TOOLS_COLORS_SET(mediumaquamarine,0.398444F,0.800793F,0.664073F)
TOOLS_COLORS_SET(black,0,0,0)
TOOLS_COLORS_SET(blue,0,0,1)
TOOLS_COLORS_SET(cadetblue,0.371099F,0.617197F,0.62501F)
TOOLS_COLORS_SET(cornflowerblue,0.390631F,0.58204F,0.925795F)
TOOLS_COLORS_SET(darkslateblue,0.281254F,0.238285F,0.542977F)
TOOLS_COLORS_SET(lightblue,0.675792F,0.843763F,0.898451F)
TOOLS_COLORS_SET(lightsteelblue,0.68751F,0.765637F,0.867201F)
TOOLS_COLORS_SET(mediumblue,0,0,0.800793F)
//10-19
TOOLS_COLORS_SET(mediumslateblue,0.480476F,0.406256F,0.929702F)
TOOLS_COLORS_SET(midnightblue,0.0976577F,0.0976577F,0.437507F)
TOOLS_COLORS_SET(navyblue,0,0,0.500008F)
TOOLS_COLORS_SET(navy,0,0,0.500008F)
TOOLS_COLORS_SET(skyblue,0.527352F,0.8047F,0.917983F)
TOOLS_COLORS_SET(slateblue,0.414069F,0.351568F,0.800793F)
TOOLS_COLORS_SET(steelblue,0.273442F,0.50782F,0.703136F)
TOOLS_COLORS_SET(coral,0.996109F,0.496101F,0.312505F)
TOOLS_COLORS_SET(cyan,0,1,1)
TOOLS_COLORS_SET(firebrick,0.695323F,0.132815F,0.132815F)
//20-29
TOOLS_COLORS_SET(brown,0.644541F,0.164065F,0.164065F)
TOOLS_COLORS_SET(gold,0.996109F,0.839857F,0)
TOOLS_COLORS_SET(goldenrod,0.851575F,0.644541F,0.125002F)
TOOLS_COLORS_SET(green,0,1,0)
TOOLS_COLORS_SET(darkgreen,0,0.390631F,0)
TOOLS_COLORS_SET(darkolivegreen,0.332036F,0.417975F,0.183597F)
TOOLS_COLORS_SET(forestgreen,0.132815F,0.542977F,0.132815F)
TOOLS_COLORS_SET(limegreen,0.195315F,0.800793F,0.195315F)
TOOLS_COLORS_SET(mediumseagreen,0.234379F,0.699229F,0.441413F)
TOOLS_COLORS_SET(mediumspringgreen,0,0.976577F,0.601572F)
//30-39
TOOLS_COLORS_SET(palegreen,0.593759F,0.980484F,0.593759F)
TOOLS_COLORS_SET(seagreen,0.17969F,0.542977F,0.339849F)
TOOLS_COLORS_SET(springgreen,0,0.996109F,0.496101F)
TOOLS_COLORS_SET(yellowgreen,0.601572F,0.800793F,0.195315F)
TOOLS_COLORS_SET(darkslategrey,0.183597F,0.308598F,0.308598F)
TOOLS_COLORS_SET(dimgrey,0.410163F,0.410163F,0.410163F)
TOOLS_COLORS_SET(lightgrey,0.824231F,0.824231F,0.824231F)
TOOLS_COLORS_SET(grey,0.750011F,0.750011F,0.750011F)
TOOLS_COLORS_SET(khaki,0.937514F,0.898451F,0.546883F)
TOOLS_COLORS_SET(magenta,1,0,1)
//40-49
TOOLS_COLORS_SET(maroon,0.68751F,0.187503F,0.375006F)
TOOLS_COLORS_SET(orange,0.996109F,0.644541F,0)
TOOLS_COLORS_SET(orchid,0.851575F,0.437507F,0.83595F)
TOOLS_COLORS_SET(darkorchid,0.597665F,0.195315F,0.796887F)
TOOLS_COLORS_SET(mediumorchid,0.726574F,0.332036F,0.824231F)
TOOLS_COLORS_SET(pink,0.996109F,0.750011F,0.792981F)
TOOLS_COLORS_SET(plum,0.863294F,0.62501F,0.863294F)
TOOLS_COLORS_SET(red,1,0,0)
TOOLS_COLORS_SET(indianred,0.800793F,0.35938F,0.35938F)
TOOLS_COLORS_SET(mediumvioletred,0.777356F,0.0820325F,0.519539F)
//50-59
TOOLS_COLORS_SET(orangered,0.996109F,0.269535F,0)
TOOLS_COLORS_SET(violetred,0.812512F,0.125002F,0.562509F)
TOOLS_COLORS_SET(salmon,0.976577F,0.500008F,0.445319F)
TOOLS_COLORS_SET(sienna,0.62501F,0.320317F,0.175784F)
TOOLS_COLORS_SET(tan,0.820325F,0.703136F,0.546883F)
TOOLS_COLORS_SET(thistle,0.843763F,0.746105F,0.843763F)
TOOLS_COLORS_SET(turquoise,0.250004F,0.875013F,0.812512F)
TOOLS_COLORS_SET(darkturquoise,0,0.8047F,0.816419F)
TOOLS_COLORS_SET(mediumturquoise,0.281254F,0.816419F,0.796887F)
TOOLS_COLORS_SET(violet,0.929702F,0.50782F,0.929702F)
//60-64
TOOLS_COLORS_SET(blueviolet,0.539071F,0.167971F,0.882826F)
TOOLS_COLORS_SET(wheat,0.957046F,0.867201F,0.699229F)
TOOLS_COLORS_SET(white,1,1,1)
TOOLS_COLORS_SET(yellow,1,1,0)
TOOLS_COLORS_SET(greenyellow,0.675792F,0.996109F,0.18359F)
#undef TOOLS_COLORS_SET
#define TOOLS_COLORS_STAT(a__name,a__r,a__g,a__b) \
template <class COLOR>\
inline const COLOR& get_color_##a__name() {static const COLOR s_v(a__r,a__g,a__b,1,false);return s_v;}
//NOTE : false in the upper so that mem balance is ok at exit.
//0-9
TOOLS_COLORS_STAT(aquamarine,0.496101F,0.996109F,0.828138F)
TOOLS_COLORS_STAT(mediumaquamarine,0.398444F,0.800793F,0.664073F)
TOOLS_COLORS_STAT(black,0,0,0)
TOOLS_COLORS_STAT(blue,0,0,1)
TOOLS_COLORS_STAT(cadetblue,0.371099F,0.617197F,0.62501F)
TOOLS_COLORS_STAT(cornflowerblue,0.390631F,0.58204F,0.925795F)
TOOLS_COLORS_STAT(darkslateblue,0.281254F,0.238285F,0.542977F)
TOOLS_COLORS_STAT(lightblue,0.675792F,0.843763F,0.898451F)
TOOLS_COLORS_STAT(lightsteelblue,0.68751F,0.765637F,0.867201F)
TOOLS_COLORS_STAT(mediumblue,0,0,0.800793F)
//10-19
TOOLS_COLORS_STAT(mediumslateblue,0.480476F,0.406256F,0.929702F)
TOOLS_COLORS_STAT(midnightblue,0.0976577F,0.0976577F,0.437507F)
TOOLS_COLORS_STAT(navyblue,0,0,0.500008F)
TOOLS_COLORS_STAT(navy,0,0,0.500008F)
TOOLS_COLORS_STAT(skyblue,0.527352F,0.8047F,0.917983F)
TOOLS_COLORS_STAT(slateblue,0.414069F,0.351568F,0.800793F)
TOOLS_COLORS_STAT(steelblue,0.273442F,0.50782F,0.703136F)
TOOLS_COLORS_STAT(coral,0.996109F,0.496101F,0.312505F)
TOOLS_COLORS_STAT(cyan,0,1,1)
TOOLS_COLORS_STAT(firebrick,0.695323F,0.132815F,0.132815F)
//20-29
TOOLS_COLORS_STAT(brown,0.644541F,0.164065F,0.164065F)
TOOLS_COLORS_STAT(gold,0.996109F,0.839857F,0)
TOOLS_COLORS_STAT(goldenrod,0.851575F,0.644541F,0.125002F)
TOOLS_COLORS_STAT(green,0,1,0)
TOOLS_COLORS_STAT(darkgreen,0,0.390631F,0)
TOOLS_COLORS_STAT(darkolivegreen,0.332036F,0.417975F,0.183597F)
TOOLS_COLORS_STAT(forestgreen,0.132815F,0.542977F,0.132815F)
TOOLS_COLORS_STAT(limegreen,0.195315F,0.800793F,0.195315F)
TOOLS_COLORS_STAT(mediumseagreen,0.234379F,0.699229F,0.441413F)
TOOLS_COLORS_STAT(mediumspringgreen,0,0.976577F,0.601572F)
//30-39
TOOLS_COLORS_STAT(palegreen,0.593759F,0.980484F,0.593759F)
TOOLS_COLORS_STAT(seagreen,0.17969F,0.542977F,0.339849F)
TOOLS_COLORS_STAT(springgreen,0,0.996109F,0.496101F)
TOOLS_COLORS_STAT(yellowgreen,0.601572F,0.800793F,0.195315F)
TOOLS_COLORS_STAT(darkslategrey,0.183597F,0.308598F,0.308598F)
TOOLS_COLORS_STAT(dimgrey,0.410163F,0.410163F,0.410163F)
TOOLS_COLORS_STAT(lightgrey,0.824231F,0.824231F,0.824231F)
TOOLS_COLORS_STAT(grey,0.750011F,0.750011F,0.750011F)
TOOLS_COLORS_STAT(khaki,0.937514F,0.898451F,0.546883F)
TOOLS_COLORS_STAT(magenta,1,0,1)
//40-49
TOOLS_COLORS_STAT(maroon,0.68751F,0.187503F,0.375006F)
TOOLS_COLORS_STAT(orange,0.996109F,0.644541F,0)
TOOLS_COLORS_STAT(orchid,0.851575F,0.437507F,0.83595F)
TOOLS_COLORS_STAT(darkorchid,0.597665F,0.195315F,0.796887F)
TOOLS_COLORS_STAT(mediumorchid,0.726574F,0.332036F,0.824231F)
TOOLS_COLORS_STAT(pink,0.996109F,0.750011F,0.792981F)
TOOLS_COLORS_STAT(plum,0.863294F,0.62501F,0.863294F)
TOOLS_COLORS_STAT(red,1,0,0)
TOOLS_COLORS_STAT(indianred,0.800793F,0.35938F,0.35938F)
TOOLS_COLORS_STAT(mediumvioletred,0.777356F,0.0820325F,0.519539F)
//50-59
TOOLS_COLORS_STAT(orangered,0.996109F,0.269535F,0)
TOOLS_COLORS_STAT(violetred,0.812512F,0.125002F,0.562509F)
TOOLS_COLORS_STAT(salmon,0.976577F,0.500008F,0.445319F)
TOOLS_COLORS_STAT(sienna,0.62501F,0.320317F,0.175784F)
TOOLS_COLORS_STAT(tan,0.820325F,0.703136F,0.546883F)
TOOLS_COLORS_STAT(thistle,0.843763F,0.746105F,0.843763F)
TOOLS_COLORS_STAT(turquoise,0.250004F,0.875013F,0.812512F)
TOOLS_COLORS_STAT(darkturquoise,0,0.8047F,0.816419F)
TOOLS_COLORS_STAT(mediumturquoise,0.281254F,0.816419F,0.796887F)
TOOLS_COLORS_STAT(violet,0.929702F,0.50782F,0.929702F)
//60-64
TOOLS_COLORS_STAT(blueviolet,0.539071F,0.167971F,0.882826F)
TOOLS_COLORS_STAT(wheat,0.957046F,0.867201F,0.699229F)
TOOLS_COLORS_STAT(white,1,1,1)
TOOLS_COLORS_STAT(yellow,1,1,0)
TOOLS_COLORS_STAT(greenyellow,0.675792F,0.996109F,0.18359F)
#undef TOOLS_COLORS_STAT
}
#endif
+17 -33
View File
@@ -27,25 +27,6 @@ inline bool exists(const std::string& a_string) {
return true;
}
inline bool size(const std::string& a_file,long& a_size){
FILE* file = ::fopen(a_file.c_str(),"rb");
if(!file) {
a_size = 0L;
return false;
}
//::rewind(file);
::fseek(file,0L,SEEK_END);
a_size = ::ftell(file);
::fclose(file);
return true;
}
inline bool is_empty(const std::string& a_file){
long sz;
if(!size(a_file,sz)) return true; //if not existing, consider it empty.
return (sz==0L)?true:false;
}
inline bool write(const std::string& a_file,const std::string& a_string) {
// a_string could contain \n separated lines.
FILE* file = ::fopen(a_file.c_str(),"wb");
@@ -198,20 +179,6 @@ inline bool write_bytes(const std::string& a_file,const char* a_buffer,size_t a_
return (nitem!=1?false:true);
}
inline bool is_aida(const std::string& a_file,bool& a_is){
long sz;
if(!size(a_file,sz)) {a_is = false;return false;}
//NOTE : it assumes that the file is not compressed.
unsigned char head[1024];
{unsigned int num = 1024;
if(!signature(a_file,head,num)) {a_is = false;return false;}
if(num!=1024) {a_is = false;return true;}}
head[1023] = 0; //to have a C string.
a_is = ::strstr((const char*)head,"<aida")?true:false;
return true;
}
inline bool num_csv_doubles(const std::string& a_string,char& a_sep,unsigned int& a_number){
if(a_string.empty()) {a_sep=0;a_number=0;return true;} //it is ok.
@@ -354,6 +321,22 @@ inline bool is_csv(const std::string& a_file,bool& a_is){
return is_csv(txt,a_is);
}
inline bool is_lua(const std::string& a_file,bool& a_is){
// look at suffix. Some file can't be guessed.
if(suffix(a_file)=="lua") {a_is = true;return true;}
//try to guess ?
a_is = false;
return true;
}
inline bool is_py(const std::string& a_file,bool& a_is){
// look at suffix. Some file can't be guessed.
if(suffix(a_file)=="py") {a_is = true;return true;}
//try to guess ?
a_is = false;
return true;
}
}}
#include "fileis"
@@ -616,5 +599,6 @@ protected:
}
#include "file_format" //backcomp
#include "fsize" //backcomp
#endif
@@ -34,6 +34,11 @@ TOOLS_GLOBAL_STRING(format_mac)
TOOLS_GLOBAL_STRING(format_cmnd)
TOOLS_GLOBAL_STRING(format_aida)
TOOLS_GLOBAL_STRING(format_bsg)
TOOLS_GLOBAL_STRING(format_jive)
TOOLS_GLOBAL_STRING(format_heprep)
TOOLS_GLOBAL_STRING(format_zheprep)
TOOLS_GLOBAL_STRING(format_lua)
TOOLS_GLOBAL_STRING(format_py)
#define TOOLS_GLOBAL_EXT(a_name)\
inline const std::string& s_ext_##a_name() {\
@@ -64,6 +69,11 @@ TOOLS_GLOBAL_EXT(mac)
TOOLS_GLOBAL_EXT(cmnd)
TOOLS_GLOBAL_EXT(aida)
TOOLS_GLOBAL_EXT(bsg)
TOOLS_GLOBAL_EXT(jive)
TOOLS_GLOBAL_EXT(heprep)
TOOLS_GLOBAL_EXT(zheprep)
TOOLS_GLOBAL_EXT(lua)
TOOLS_GLOBAL_EXT(py)
#undef TOOLS_GLOBAL_EXT
@@ -91,6 +101,11 @@ inline void formats(std::vector<std::string>& a_v) {
a_v.push_back(s_format_mac());
a_v.push_back(s_format_cmnd());
a_v.push_back(s_format_aida());
a_v.push_back(s_format_jive());
a_v.push_back(s_format_heprep());
a_v.push_back(s_format_zheprep());
a_v.push_back(s_format_lua());
a_v.push_back(s_format_py());
}
inline std::string ext_fmt(const std::string& a_ext) {
@@ -117,6 +132,11 @@ inline std::string ext_fmt(const std::string& a_ext) {
if(a_ext==s_ext_gdml()) return s_format_gdml();
if(a_ext==s_ext_mac()) return s_format_mac();
if(a_ext==s_ext_cmnd()) return s_format_cmnd();
if(a_ext==s_ext_jive()) return s_format_jive();
if(a_ext==s_ext_heprep()) return s_format_heprep();
if(a_ext==s_ext_zheprep()) return s_format_zheprep();
if(a_ext==s_ext_lua()) return s_format_lua();
if(a_ext==s_ext_py()) return s_format_py();
return s_format_guessed();
}
@@ -270,4 +270,54 @@ inline bool is_ps(const std::string& a_file,bool& a_is){
}}
#include "fsize"
namespace tools {
namespace file {
inline bool is_aida(const std::string& a_file,bool& a_is){
long sz;
if(!size(a_file,sz)) {a_is = false;return false;}
//NOTE : it assumes that the file is not compressed.
unsigned char head[1024];
{unsigned int num = 1024;
if(!signature(a_file,head,num)) {a_is = false;return false;}
if(num!=1024) {a_is = false;return true;}}
head[1023] = 0; //to have a C string.
a_is = ::strstr((const char*)head,"<aida")?true:false;
return true;
}
inline bool is_jive(const std::string& a_file,bool& a_is){
long sz;
if(!size(a_file,sz)) {a_is = false;return false;}
//NOTE : it assumes that the file is not compressed.
unsigned char head[1024];
{unsigned int num = 1024;
if(!signature(a_file,head,num)) {a_is = false;return false;}
if(num!=1024) {a_is = false;return true;}}
head[1023] = 0; //to have a C string.
if(::strstr((const char*)head,"<?ATLAS")) {a_is = true;return true;}
a_is = ::strstr((const char*)head,"<!DOCTYPE Event")?true:false;
return true;
}
inline bool is_heprep(const std::string& a_file,bool& a_is){
long sz;
if(!size(a_file,sz)) {a_is = false;return false;}
//NOTE : it assumes that the file is not compressed.
unsigned char head[1024];
{unsigned int num = 1024;
if(!signature(a_file,head,num)) {a_is = false;return false;}
if(num!=1024) {a_is = false;return true;}}
head[1023] = 0; //to have a C string.
a_is = ::strstr((const char*)head,"<heprep")?true:false;
return true;
}
}}
#endif
+5 -5
View File
@@ -61,11 +61,11 @@ inline bool find_with_dirs(std::ostream& a_out,
namespace tools {
inline bool find_with_path(std::ostream& a_out,
const std::string& a_env,
const std::string& a_file,
std::string& a_path,
bool a_verbose = false ) {
inline bool find_with_env(std::ostream& a_out,
const std::string& a_env,
const std::string& a_file,
std::string& a_path,
bool a_verbose = false ) {
std::string PATH;
if(!tools::getenv(a_env,PATH)) {
//look for a a_file in current directory.
@@ -10,6 +10,12 @@
#define tools_vforit(a__T,a__v,a__it) \
for(std::vector< a__T >::iterator (a__it) = (a__v).begin();(a__it)!=(a__v).end();++(a__it))
#define tools_vforcrit(a__T,a__v,a__it) \
for(std::vector< a__T >::const_reverse_iterator (a__it) = (a__v).rbegin();(a__it)!=(a__v).rend();++(a__it))
#define tools_vforrit(a__T,a__v,a__it) \
for(std::vector< a__T >::reverse_iterator (a__it) = (a__v).rbegin();(a__it)!=(a__v).rend();++(a__it))
#define tools_vforit_npp(a__T,a__v,a__it) \
for(std::vector< a__T >::iterator (a__it) = (a__v).begin();(a__it)!=(a__v).end();)
@@ -0,0 +1,34 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_fsize
#define tools_fsize
#include <string>
#include <cstdio>
namespace tools {
namespace file {
inline bool size(const std::string& a_file,long& a_size){
FILE* file = ::fopen(a_file.c_str(),"rb");
if(!file) {
a_size = 0L;
return false;
}
//::rewind(file);
::fseek(file,0L,SEEK_END);
a_size = ::ftell(file);
::fclose(file);
return true;
}
inline bool is_empty(const std::string& a_file){
long sz;
if(!size(a_file,sz)) return true; //if not existing, consider it empty.
return (sz==0L)?true:false;
}
}}
#endif
@@ -0,0 +1,46 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_get_lines
#define tools_get_lines
#include "cstr"
#include <string>
#include <vector>
namespace tools {
inline void get_lines(const std::string& a_string,std::vector<std::string>& a_lines){
// a_string is a list separated by "\n" or "\\n".
// For "xxx\n\nxxx", {"xxx","","xxx"} will be created.
// WARNING : if a_string is a Windows file name, it may
// contains a \n which is not a delimiter ; like ..\data\ntuples.hbook.
a_lines.clear();
size_t length = a_string.length();
if(!length) return;
char* cstring = str_dup(a_string.c_str());
if(!cstring) return;
size_t pos = 0;
length++;
for(size_t count=0;count<length;count++) {
if( (cstring[count]=='\n') ||
(cstring[count]=='\0') ||
( (cstring[count]=='\\') && (cstring[count+1]=='n') ) ) {
char shift_one = (cstring[count]=='\n' ? 1 : 0);
cstring[count] = '\0';
a_lines.push_back(cstring+pos);
if(shift_one==1) {
pos = count+1;
} else {
pos = count+2;
count++;
}
}
}
str_del(cstring);
}
}
#endif
+20 -28
View File
@@ -6,6 +6,8 @@
//same as OpenGL GL_[POINTS,etc...], but for the case we don't have OpenGL.
#include <cstddef> //size_t
namespace tools {
namespace gl {
@@ -34,10 +36,10 @@ inline bool is_line(mode_t a_mode) {
return false;
}
inline void cvt_2to3(unsigned int a_npt,const float* a_xys,float*& a_xyzs) {
inline void cvt_2to3(size_t a_npt,const float* a_xys,float*& a_xyzs) {
const float* vpos = a_xys;
float x,y;
for(unsigned int i=0;i<a_npt;i++) {
for(size_t i=0;i<a_npt;i++) {
x = *vpos;vpos++;
y = *vpos;vpos++;
*a_xyzs = x;a_xyzs++;
@@ -47,11 +49,9 @@ inline void cvt_2to3(unsigned int a_npt,const float* a_xys,float*& a_xyzs) {
}
inline void triangle_fan_to_triangles(unsigned int a_npt,
const float* a_fxyzs,
const float* a_fnms,
float*& a_xyzs,
float*& a_nms) {
inline void triangle_fan_to_triangles(size_t a_npt,
const float* a_fxyzs,const float* a_fnms,
float*& a_xyzs,float*& a_nms) {
{const float* vpos = a_fxyzs;
@@ -64,7 +64,7 @@ inline void triangle_fan_to_triangles(unsigned int a_npt,
float z2 = *vpos;vpos++;
float x3,y3,z3;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
z3 = *vpos;vpos++;
@@ -96,7 +96,7 @@ inline void triangle_fan_to_triangles(unsigned int a_npt,
float z2 = *vpos;vpos++;
float x3,y3,z3;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
z3 = *vpos;vpos++;
@@ -118,11 +118,9 @@ inline void triangle_fan_to_triangles(unsigned int a_npt,
}}
}
inline void triangle_strip_to_triangles(unsigned int a_npt,
const float* a_fxyzs,
const float* a_fnms,
float*& a_xyzs,
float*& a_nms) {
inline void triangle_strip_to_triangles(size_t a_npt,
const float* a_fxyzs,const float* a_fnms,
float*& a_xyzs,float*& a_nms) {
{const float* vpos = a_fxyzs;
@@ -136,7 +134,7 @@ inline void triangle_strip_to_triangles(unsigned int a_npt,
float x3,y3,z3;
bool flip = false;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
z3 = *vpos;vpos++;
@@ -190,7 +188,7 @@ inline void triangle_strip_to_triangles(unsigned int a_npt,
float x3,y3,z3;
bool flip = false;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
z3 = *vpos;vpos++;
@@ -232,9 +230,7 @@ inline void triangle_strip_to_triangles(unsigned int a_npt,
}}
}
inline void triangle_fan_to_triangles_2to3(unsigned int a_npt,
const float* a_xys,
float*& a_xyzs) {
inline void triangle_fan_to_triangles_2to3(size_t a_npt,const float* a_xys,float*& a_xyzs) {
const float* vpos = a_xys;
@@ -245,7 +241,7 @@ inline void triangle_fan_to_triangles_2to3(unsigned int a_npt,
float y2 = *vpos;vpos++;
float x3,y3;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
@@ -267,9 +263,7 @@ inline void triangle_fan_to_triangles_2to3(unsigned int a_npt,
}
inline void triangle_strip_to_triangles_2to3(unsigned int a_npt,
const float* a_xys,
float*& a_xyzs) {
inline void triangle_strip_to_triangles_2to3(size_t a_npt,const float* a_xys,float*& a_xyzs) {
const float* vpos = a_xys;
@@ -281,7 +275,7 @@ inline void triangle_strip_to_triangles_2to3(unsigned int a_npt,
float x3,y3;
bool flip = false;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
@@ -322,9 +316,7 @@ inline void triangle_strip_to_triangles_2to3(unsigned int a_npt,
}
inline void line_strip_to_lines_2to3(unsigned int a_npt,
const float* a_xys,
float*& a_xyzs) {
inline void line_strip_to_lines_2to3(size_t a_npt,const float* a_xys,float*& a_xyzs) {
const float* vpos = a_xys;
@@ -332,7 +324,7 @@ inline void line_strip_to_lines_2to3(unsigned int a_npt,
float y1 = *vpos;vpos++;
float x2,y2;
for(unsigned int i=1;i<a_npt;i++) {
for(size_t i=1;i<a_npt;i++) {
x2 = *vpos;vpos++;
y2 = *vpos;vpos++;
@@ -8,19 +8,19 @@
////////////////////////////////////////////////////////
#ifdef TOOLS_MEM
#include <tools/mem>
#include "../mem"
#include <cstdlib>
namespace tools {
inline void* mem_alloc(size_t a_size){
tools::mem::increment(tools::s_malloc().c_str());
mem::increment(tools::s_malloc().c_str());
return ::malloc(a_size);
}
inline void* mem_realloc(void* a_ptr,size_t a_size){
if(a_ptr==NULL) tools::mem::increment(tools::s_malloc().c_str());
if(a_ptr==NULL) mem::increment(tools::s_malloc().c_str());
return ::realloc(a_ptr,a_size);
}
inline void mem_free(void* a_ptr){
if(a_ptr!=NULL) tools::mem::decrement(tools::s_malloc().c_str());
if(a_ptr!=NULL) mem::decrement(tools::s_malloc().c_str());
::free(a_ptr);
}
inline int mem_init( size_t /*maxFast*/) {return 1;}
@@ -2,78 +2,78 @@
#define tools_glutess_rename
/* G.Barrand : namespace protection : */
#define gluTessBeginContour inlib_gluTessBeginContour
#define gluTessBeginPolygon inlib_gluTessBeginPolygon
#define gluTessCallback inlib_gluTessCallback
#define gluTessEndContour inlib_gluTessEndContour
#define gluTessEndPolygon inlib_gluTessEndPolygon
#define gluTessNormal inlib_gluTessNormal
#define gluTessProperty inlib_gluTessProperty
#define gluTessVertex inlib_gluTessVertex
#define gluTessBeginContour tools_gluTessBeginContour
#define gluTessBeginPolygon tools_gluTessBeginPolygon
#define gluTessCallback tools_gluTessCallback
#define gluTessEndContour tools_gluTessEndContour
#define gluTessEndPolygon tools_gluTessEndPolygon
#define gluTessNormal tools_gluTessNormal
#define gluTessProperty tools_gluTessProperty
#define gluTessVertex tools_gluTessVertex
/* internal */
#define gluBeginPolygon inlib_gluBeginPolygon
#define gluDeleteTess inlib_gluDeleteTess
#define gluEndPolygon inlib_gluEndPolygon
#define gluGetTessProperty inlib_gluGetTessProperty
#define gluNewTess inlib_gluNewTess
#define gluNextContour inlib_gluNextContour
#define gluBeginPolygon tools_gluBeginPolygon
#define gluDeleteTess tools_gluDeleteTess
#define gluEndPolygon tools_gluEndPolygon
#define gluGetTessProperty tools_gluGetTessProperty
#define gluNewTess tools_gluNewTess
#define gluNextContour tools_gluNextContour
#define __gl_computeInterior inlib__gl_computeInterior
#define __gl_dictListDelete inlib__gl_dictListDelete
#define __gl_dictListDeleteDict inlib__gl_dictListDeleteDict
#define __gl_dictListInsertBefore inlib__gl_dictListInsertBefore
#define __gl_dictListNewDict inlib__gl_dictListNewDict
#define __gl_dictListSearch inlib__gl_dictListSearch
#define __gl_computeInterior tools__gl_computeInterior
#define __gl_dictListDelete tools__gl_dictListDelete
#define __gl_dictListDeleteDict tools__gl_dictListDeleteDict
#define __gl_dictListInsertBefore tools__gl_dictListInsertBefore
#define __gl_dictListNewDict tools__gl_dictListNewDict
#define __gl_dictListSearch tools__gl_dictListSearch
#define __gl_edgeEval inlib__gl_edgeEval
#define __gl_edgeIntersect inlib__gl_edgeIntersect
#define __gl_edgeSign inlib__gl_edgeSign
#define __gl_edgeEval tools__gl_edgeEval
#define __gl_edgeIntersect tools__gl_edgeIntersect
#define __gl_edgeSign tools__gl_edgeSign
/* done in memalloc.h :
#define __gl_memInit inlib__gl_memInit
#define __gl_memInit tools__gl_memInit
*/
#define __gl_meshAddEdgeVertex inlib__gl_meshAddEdgeVertex
#define __gl_meshCheckMesh inlib__gl_meshCheckMesh
#define __gl_meshConnect inlib__gl_meshConnect
#define __gl_meshDelete inlib__gl_meshDelete
#define __gl_meshDeleteMesh inlib__gl_meshDeleteMesh
#define __gl_meshDiscardExterior inlib__gl_meshDiscardExterior
#define __gl_meshMakeEdge inlib__gl_meshMakeEdge
#define __gl_meshNewMesh inlib__gl_meshNewMesh
#define __gl_meshSetWindingNumber inlib__gl_meshSetWindingNumber
#define __gl_meshSplice inlib__gl_meshSplice
#define __gl_meshSplitEdge inlib__gl_meshSplitEdge
#define __gl_meshTessellateInterior inlib__gl_meshTessellateInterior
#define __gl_meshTessellateMonoRegion inlib__gl_meshTessellateMonoRegion
#define __gl_meshUnion inlib__gl_meshUnion
#define __gl_meshZapFace inlib__gl_meshZapFace
#define __gl_noBeginData inlib__gl_noBeginData
#define __gl_noCombineData inlib__gl_noCombineData
#define __gl_noEdgeFlagData inlib__gl_noEdgeFlagData
#define __gl_noEndData inlib__gl_noEndData
#define __gl_noErrorData inlib__gl_noErrorData
#define __gl_noVertexData inlib__gl_noVertexData
#define __gl_pqHeapDelete inlib__gl_pqHeapDelete
#define __gl_pqHeapDeletePriorityQ inlib__gl_pqHeapDeletePriorityQ
#define __gl_pqHeapExtractMin inlib__gl_pqHeapExtractMin
#define __gl_pqHeapInit inlib__gl_pqHeapInit
#define __gl_pqHeapInsert inlib__gl_pqHeapInsert
#define __gl_pqHeapNewPriorityQ inlib__gl_pqHeapNewPriorityQ
#define __gl_pqSortDelete inlib__gl_pqSortDelete
#define __gl_pqSortDeletePriorityQ inlib__gl_pqSortDeletePriorityQ
#define __gl_pqSortExtractMin inlib__gl_pqSortExtractMin
#define __gl_pqSortInit inlib__gl_pqSortInit
#define __gl_pqSortInsert inlib__gl_pqSortInsert
#define __gl_pqSortIsEmpty inlib__gl_pqSortIsEmpty
#define __gl_pqSortMinimum inlib__gl_pqSortMinimum
#define __gl_pqSortNewPriorityQ inlib__gl_pqSortNewPriorityQ
#define __gl_projectPolygon inlib__gl_projectPolygon
#define __gl_renderBoundary inlib__gl_renderBoundary
#define __gl_renderCache inlib__gl_renderCache
#define __gl_renderMesh inlib__gl_renderMesh
#define __gl_transEval inlib__gl_transEval
#define __gl_transSign inlib__gl_transSign
#define __gl_vertCCW inlib__gl_vertCCW
#define __gl_vertLeq inlib__gl_vertLeq
#define __gl_meshAddEdgeVertex tools__gl_meshAddEdgeVertex
#define __gl_meshCheckMesh tools__gl_meshCheckMesh
#define __gl_meshConnect tools__gl_meshConnect
#define __gl_meshDelete tools__gl_meshDelete
#define __gl_meshDeleteMesh tools__gl_meshDeleteMesh
#define __gl_meshDiscardExterior tools__gl_meshDiscardExterior
#define __gl_meshMakeEdge tools__gl_meshMakeEdge
#define __gl_meshNewMesh tools__gl_meshNewMesh
#define __gl_meshSetWindingNumber tools__gl_meshSetWindingNumber
#define __gl_meshSplice tools__gl_meshSplice
#define __gl_meshSplitEdge tools__gl_meshSplitEdge
#define __gl_meshTessellateInterior tools__gl_meshTessellateInterior
#define __gl_meshTessellateMonoRegion tools__gl_meshTessellateMonoRegion
#define __gl_meshUnion tools__gl_meshUnion
#define __gl_meshZapFace tools__gl_meshZapFace
#define __gl_noBeginData tools__gl_noBeginData
#define __gl_noCombineData tools__gl_noCombineData
#define __gl_noEdgeFlagData tools__gl_noEdgeFlagData
#define __gl_noEndData tools__gl_noEndData
#define __gl_noErrorData tools__gl_noErrorData
#define __gl_noVertexData tools__gl_noVertexData
#define __gl_pqHeapDelete tools__gl_pqHeapDelete
#define __gl_pqHeapDeletePriorityQ tools__gl_pqHeapDeletePriorityQ
#define __gl_pqHeapExtractMin tools__gl_pqHeapExtractMin
#define __gl_pqHeapInit tools__gl_pqHeapInit
#define __gl_pqHeapInsert tools__gl_pqHeapInsert
#define __gl_pqHeapNewPriorityQ tools__gl_pqHeapNewPriorityQ
#define __gl_pqSortDelete tools__gl_pqSortDelete
#define __gl_pqSortDeletePriorityQ tools__gl_pqSortDeletePriorityQ
#define __gl_pqSortExtractMin tools__gl_pqSortExtractMin
#define __gl_pqSortInit tools__gl_pqSortInit
#define __gl_pqSortInsert tools__gl_pqSortInsert
#define __gl_pqSortIsEmpty tools__gl_pqSortIsEmpty
#define __gl_pqSortMinimum tools__gl_pqSortMinimum
#define __gl_pqSortNewPriorityQ tools__gl_pqSortNewPriorityQ
#define __gl_projectPolygon tools__gl_projectPolygon
#define __gl_renderBoundary tools__gl_renderBoundary
#define __gl_renderCache tools__gl_renderCache
#define __gl_renderMesh tools__gl_renderMesh
#define __gl_transEval tools__gl_transEval
#define __gl_transSign tools__gl_transSign
#define __gl_vertCCW tools__gl_vertCCW
#define __gl_vertLeq tools__gl_vertLeq
#endif
+16 -7
View File
@@ -25,6 +25,11 @@ public:
base_handle(){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
base_handle(const std::string& a_class):m_class(a_class){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
virtual ~base_handle(){
@@ -33,15 +38,20 @@ public:
#endif
}
protected:
base_handle(base_handle&){
base_handle(base_handle& a_from):m_class(a_from.m_class){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
private:
//base_handle(const base_handle&){}
//base_handle& operator=(const base_handle&){return *this;}
base_handle& operator=(base_handle&){return *this;}
base_handle& operator=(base_handle& a_from){
m_class = a_from.m_class;
return *this;
}
public:
const std::string& object_class() const {return m_class;}
private:
std::string m_class;
};
template <class T>
@@ -52,9 +62,8 @@ public:
virtual base_handle* copy() {return new handle<T>(*this);}
virtual void disown() {m_owner = false;}
public:
handle(T* a_obj,bool a_owner = true)
:parent()
,m_obj(a_obj),m_owner(a_owner){}
handle(T* a_obj,bool a_owner = true):parent(),m_obj(a_obj),m_owner(a_owner){}
handle(const std::string& a_class,T* a_obj,bool a_owner = true):parent(a_class),m_obj(a_obj),m_owner(a_owner){}
virtual ~handle(){if(m_owner) delete m_obj;}
private:
handle(handle& a_from):parent(a_from){
@@ -161,7 +161,7 @@ public:
public:
// Partition :
bool configure(const std::vector<TC>& aEdges) {
bool configure(const std::vector<TC>& a_edges) {
// init :
m_number_of_bins = 0;
m_minimum_value = 0;
@@ -170,17 +170,17 @@ public:
m_bin_width = 0;
m_edges.clear();
// setup :
if(aEdges.size()<=1) return false;
bn_t number = (bn_t)aEdges.size()-1;
if(a_edges.size()<=1) return false;
bn_t number = (bn_t)a_edges.size()-1;
for(bn_t index=0;index<number;index++) {
if((aEdges[index]>=aEdges[index+1])) {
if((a_edges[index]>=a_edges[index+1])) {
return false;
}
}
m_edges = aEdges;
m_edges = a_edges;
m_number_of_bins = number;
m_minimum_value = aEdges[0];
m_maximum_value = aEdges[m_number_of_bins];
m_minimum_value = a_edges[0];
m_maximum_value = a_edges[m_number_of_bins];
m_fixed = false;
return true;
}
@@ -156,10 +156,10 @@ protected:
maxs.push_back(aXmax);
parent::configure(1,nbins,mins,maxs);
}
b1(const std::string& a_title,const std::vector<TC>& aEdges) {
b1(const std::string& a_title,const std::vector<TC>& a_edges) {
parent::m_title = a_title;
std::vector< std::vector<TC> > edges(1);
edges[0] = aEdges;
edges[0] = a_edges;
parent::configure(1,edges);
}
@@ -177,9 +177,9 @@ public:
maxs.push_back(aXmax);
return parent::configure(1,nbins,mins,maxs);
}
bool configure(const std::vector<TC>& aEdges) {
bool configure(const std::vector<TC>& a_edges) {
std::vector< std::vector<TC> > edges(1);
edges[0] = aEdges;
edges[0] = a_edges;
return parent::configure(1,edges);
}
protected:
@@ -302,11 +302,11 @@ protected:
parent::configure(2,nbins,mins,maxs);
}
b2(const std::string& a_title,const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY) {
b2(const std::string& a_title,const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y) {
parent::m_title = a_title;
std::vector< std::vector<TC> > edges(2);
edges[0] = aEdgesX;
edges[1] = aEdgesY;
edges[0] = a_edges_x;
edges[1] = a_edges_y;
parent::configure(2,edges);
}
@@ -328,10 +328,10 @@ public:
return parent::configure(2,nbins,mins,maxs);
}
bool configure(const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY){
bool configure(const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y){
std::vector< std::vector<TC> > edges(2);
edges[0] = aEdgesX;
edges[1] = aEdgesY;
edges[0] = a_edges_x;
edges[1] = a_edges_y;
return parent::configure(2,edges);
}
+12 -12
View File
@@ -328,15 +328,15 @@ public:
}
b3(const std::string& a_title,
const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY,
const std::vector<TC>& aEdgesZ)
const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y,
const std::vector<TC>& a_edges_z)
{
parent::m_title = a_title;
std::vector< std::vector<TC> > edges(3);
edges[0] = aEdgesX;
edges[1] = aEdgesY;
edges[2] = aEdgesZ;
edges[0] = a_edges_x;
edges[1] = a_edges_y;
edges[2] = a_edges_z;
parent::configure(3,edges);
}
@@ -363,13 +363,13 @@ public:
return parent::configure(3,nbins,mins,maxs);
}
bool configure(const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY,
const std::vector<TC>& aEdgesZ){
bool configure(const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y,
const std::vector<TC>& a_edges_z){
std::vector< std::vector<TC> > edges(3);
edges[0] = aEdgesX;
edges[1] = aEdgesY;
edges[2] = aEdgesZ;
edges[0] = a_edges_x;
edges[1] = a_edges_y;
edges[2] = a_edges_z;
return parent::configure(3,edges);
}
@@ -12,6 +12,7 @@
#include <cmath>
#include <map> //for annotations
#include <ostream>
namespace tools {
namespace histo {
@@ -277,7 +278,7 @@ protected:
return true;
}
bool configure(dim_t a_dim,const std::vector< std::vector<TC> >& aEdges) {
bool configure(dim_t a_dim,const std::vector< std::vector<TC> >& a_edges) {
// Clear :
parent::m_bin_entries.clear();
parent::m_bin_Sw.clear();
@@ -304,7 +305,7 @@ protected:
parent::m_axes.resize(a_dim);
// Setup axes :
for(dim_t iaxis=0;iaxis<a_dim;iaxis++) {
if(!parent::m_axes[iaxis].configure(aEdges[iaxis])) {
if(!parent::m_axes[iaxis].configure(a_edges[iaxis])) {
//m_axes.clear();
return false;
}
@@ -392,6 +393,17 @@ public: //annotations :
return true;
}
void set_annotations(const annotations_t& a_annotations) {parent::m_annotations = a_annotations;}
void hprint_annotations(std::ostream& a_out) {
a_out << " * ANNOTATIONS :" << std::endl;
annotations_t::const_iterator it;
for(it=parent::m_annotations.begin();it!=parent::m_annotations.end();++it) {
//out << " * (" << index << ") "
a_out << " * " << (*it).first << " = " << (*it).second << std::endl;
}
}
protected:
bool is_compatible(const base_histo& a_histo){
if(parent::m_dimension!=a_histo.m_dimension) return false;
@@ -412,8 +424,9 @@ protected:
parent::m_bin_Sx2w[ibin][iaxis] += a_histo.m_bin_Sx2w[ibin][iaxis];
}
}
{dim_t nplane = parent::m_in_range_plane_Sxyw.size();
for(dim_t iplane=0;iplane<nplane;iplane++) parent::m_in_range_plane_Sxyw[iplane] += a_histo.m_in_range_plane_Sxyw[iplane];}
{size_t nplane = parent::m_in_range_plane_Sxyw.size();
for(size_t iplane=0;iplane<nplane;iplane++)
parent::m_in_range_plane_Sxyw[iplane] += a_histo.m_in_range_plane_Sxyw[iplane];}
parent::update_fast_getters();
}
@@ -527,8 +540,8 @@ protected:
parent::m_bin_Sx2w[ibin][iaxis] *= a_factor;
}
}
{dim_t nplane = parent::m_in_range_plane_Sxyw.size();
for(dim_t iplane=0;iplane<nplane;iplane++) parent::m_in_range_plane_Sxyw[iplane] *= a_factor;}
{size_t nplane = parent::m_in_range_plane_Sxyw.size();
for(size_t iplane=0;iplane<nplane;iplane++) parent::m_in_range_plane_Sxyw[iplane] *= a_factor;}
parent::update_fast_getters();
return true;
}
@@ -34,7 +34,7 @@ public:
return true;
}
unsigned int entries() const {
return m_histo ? m_histo->all_entries() : m_ws.size();
return m_histo ? m_histo->all_entries() : (unsigned int)m_ws.size();
}
public:
double sum_of_weights() const {
@@ -56,8 +56,8 @@ public:
if(m_histo) {
return m_histo->scale(a_scale);
} else {
unsigned int number = m_ws.size();
for(unsigned int index=0;index<number;index++) m_ws[index] *= a_scale;
size_t number = m_ws.size();
for(size_t index=0;index<number;index++) m_ws[index] *= a_scale;
m_Sw *= a_scale;
m_Sxw *= a_scale;
m_Sx2w *= a_scale;
@@ -132,9 +132,9 @@ public:
return status;
}
bool convert(const std::vector<double>& aEdges) {
bool convert(const std::vector<double>& a_edges) {
if(m_histo) return true;
m_histo = new histo::h1d(base_cloud::title(),aEdges);
m_histo = new histo::h1d(base_cloud::title(),a_edges);
if(!m_histo) return false;
bool status = fill_histogram(*m_histo);
clear();
@@ -146,8 +146,8 @@ public:
return *m_histo;
}
bool fill_histogram(histo::h1d& a_histo) const {
unsigned int number = m_xs.size();
for(unsigned int index=0;index<number;index++) {
size_t number = m_xs.size();
for(size_t index=0;index<number;index++) {
if(!a_histo.fill(m_xs[index],m_ws[index])) return false;
}
return true;
@@ -47,8 +47,8 @@ public:
bool convert(const std::vector<double>&,const std::vector<double>&);
const histo::h2d& histogram() const;
bool fill_histogram(histo::h2d& a_histo) const {
unsigned int number = m_xs.size();
for(unsigned int index=0;index<number;index++) {
size_t number = m_xs.size();
for(size_t index=0;index<number;index++) {
if(!a_histo.fill(m_xs[index],m_ys[index],m_ws[index])) return false;
}
return true;
@@ -248,8 +248,8 @@ bool c2d::scale(double a_scale) {
if(m_histo) {
return m_histo->scale(a_scale);
} else {
unsigned int number = m_ws.size();
for(unsigned int index=0;index<number;index++) m_ws[index] *= a_scale;
size_t number = m_ws.size();
for(size_t index=0;index<number;index++) m_ws[index] *= a_scale;
m_Sw *= a_scale;
m_Sxw *= a_scale;
m_Sx2w *= a_scale;
@@ -305,10 +305,10 @@ bool c2d::fill(double aX,double aY,double aW){
}
inline
bool c2d::convert(const std::vector<double>& aEdgesX,const std::vector<double>& aEdgesY) {
bool c2d::convert(const std::vector<double>& a_edges_x,const std::vector<double>& a_edges_y) {
if(m_histo) return true;
m_histo = new histo::h2d(base_cloud::title(),
aEdgesX,aEdgesY);
a_edges_x,a_edges_y);
if(!m_histo) return false;
bool status = fill_histogram(*m_histo);
clear();
@@ -337,7 +337,7 @@ const h2d& c2d::histogram() const {
inline
unsigned int c2d::entries() const {
return m_histo ? m_histo->all_entries() : m_ws.size();
return m_histo ? m_histo->all_entries() : (unsigned int)m_ws.size();
}
inline
+10 -11
View File
@@ -55,10 +55,9 @@ public:
const std::vector<double>&);
const histo::h3d& histogram() const;
bool fill_histogram(histo::h3d& a_histo) const {
unsigned int number = m_xs.size();
for(unsigned int index=0;index<number;index++) {
if(!a_histo.fill(m_xs[index],m_ys[index],m_zs[index],m_ws[index]))
return false;
size_t number = m_xs.size();
for(size_t index=0;index<number;index++) {
if(!a_histo.fill(m_xs[index],m_ys[index],m_zs[index],m_ws[index])) return false;
}
return true;
}
@@ -307,8 +306,8 @@ bool c3d::scale(double a_scale) {
if(m_histo) {
return m_histo->scale(a_scale);
} else {
unsigned int number = m_ws.size();
for(unsigned int index=0;index<number;index++) m_ws[index] *= a_scale;
size_t number = m_ws.size();
for(size_t index=0;index<number;index++) m_ws[index] *= a_scale;
m_Sw *= a_scale;
m_Sxw *= a_scale;
m_Sx2w *= a_scale;
@@ -403,13 +402,13 @@ bool c3d::fill(double aX,double aY,double aZ,double aW){
inline
bool c3d::convert(
const std::vector<double>& aEdgesX
,const std::vector<double>& aEdgesY
,const std::vector<double>& aEdgesZ
const std::vector<double>& a_edges_x
,const std::vector<double>& a_edges_y
,const std::vector<double>& a_edges_z
) {
if(m_histo) return true;
m_histo = new histo::h3d(base_cloud::title(),
aEdgesX,aEdgesY,aEdgesZ);
a_edges_x,a_edges_y,a_edges_z);
if(!m_histo) return false;
bool status = fill_histogram(*m_histo);
clear();
@@ -423,7 +422,7 @@ double c3d::sum_of_weights() const {
inline
unsigned int c3d::entries() const {
return m_histo ? m_histo->all_entries() : m_ws.size();
return m_histo ? m_histo->all_entries() : (unsigned int)m_ws.size();
}
inline
@@ -102,7 +102,7 @@ public:
return *this;
}
public: //AIDA/Idata_point
unsigned int dimension() const {return m_measurements.size();}
size_t dimension() const {return m_measurements.size();}
measurement& coordinate(unsigned int a_coord) {
//WARNING : no check done on a_coord vs m_dim.
return m_measurements[a_coord];
@@ -150,7 +150,7 @@ public:
unsigned int dimension() const {return m_dim;}
void clear() {m_points.clear();}
unsigned int size() const {return m_points.size();}
size_t size() const {return m_points.size();}
const data_point& point(unsigned int a_index) const {
//WARNING : no check done on a_index.
@@ -203,8 +203,8 @@ public:
h1(const std::string& a_title,bn_t aXnumber,TC aXmin,TC aXmax)
:parent(a_title,aXnumber,aXmin,aXmax){}
h1(const std::string& a_title,const std::vector<TC>& aEdges)
:parent(a_title,aEdges){}
h1(const std::string& a_title,const std::vector<TC>& a_edges)
:parent(a_title,a_edges){}
virtual ~h1(){}
public:
@@ -23,8 +23,8 @@ public:
h1d(const std::string& a_title,unsigned int aXnumber,double aXmin,double aXmax)
:parent(a_title,aXnumber,aXmin,aXmax){}
h1d(const std::string& a_title,const std::vector<double>& aEdges)
:parent(a_title,aEdges){}
h1d(const std::string& a_title,const std::vector<double>& a_edges)
:parent(a_title,a_edges){}
virtual ~h1d(){}
public:
@@ -24,8 +24,8 @@ public:
h1df(const std::string& a_title,unsigned int aXnumber,float aXmin,float aXmax)
:parent(a_title,aXnumber,aXmin,aXmax){}
h1df(const std::string& a_title,const std::vector<double>& aEdges)
:parent(a_title,aEdges){}
h1df(const std::string& a_title,const std::vector<double>& a_edges)
:parent(a_title,a_edges){}
virtual ~h1df(){}
public:
@@ -160,8 +160,8 @@ public:
h2(const std::string& a_title,bn_t aXnumber,TC aXmin,TC aXmax,bn_t aYnumber,TC aYmin,TC aYmax)
:parent(a_title,aXnumber,aXmin,aXmax,aYnumber,aYmin,aYmax)
{}
h2(const std::string& a_title,const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
h2(const std::string& a_title,const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
{}
virtual ~h2(){}
@@ -24,9 +24,9 @@ public:
:parent(a_title,aXnumber,aXmin,aXmax,aYnumber,aYmin,aYmax)
{}
h2d(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
{}
virtual ~h2d(){}
@@ -27,9 +27,9 @@ public:
:parent(a_title,aXnumber,aXmin,aXmax,aYnumber,aYmin,aYmax)
{}
h2df(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
{}
virtual ~h2df(){}
@@ -197,10 +197,10 @@ public:
{}
h3(const std::string& a_title,
const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY,
const std::vector<TC>& aEdgesZ)
:parent(a_title,aEdgesX,aEdgesY,aEdgesZ)
const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y,
const std::vector<TC>& a_edges_z)
:parent(a_title,a_edges_x,a_edges_y,a_edges_z)
{}
virtual ~h3(){}
@@ -28,10 +28,10 @@ public:
{}
h3d(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY,
const std::vector<double>& aEdgesZ)
:parent(a_title,aEdgesX,aEdgesY,aEdgesZ)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y,
const std::vector<double>& a_edges_z)
:parent(a_title,a_edges_x,a_edges_y,a_edges_z)
{}
virtual ~h3d(){}
@@ -31,10 +31,10 @@ public:
{}
h3df(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY,
const std::vector<double>& aEdgesZ)
:parent(a_title,aEdgesX,aEdgesY,aEdgesZ)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y,
const std::vector<double>& a_edges_z)
:parent(a_title,a_edges_x,a_edges_y,a_edges_z)
{}
virtual ~h3df(){}
@@ -279,8 +279,8 @@ public:
m_bin_Sv2w.resize(parent::m_bin_number,0);
}
p1(const std::string& a_title,const std::vector<TC>& aEdges)
:parent(a_title,aEdges)
p1(const std::string& a_title,const std::vector<TC>& a_edges)
:parent(a_title,a_edges)
,m_cut_v(false)
,m_min_v(0)
,m_max_v(0)
@@ -289,8 +289,8 @@ public:
m_bin_Sv2w.resize(parent::m_bin_number,0);
}
p1(const std::string& a_title,const std::vector<TC>& aEdges,TV aVmin,TV aVmax)
:parent(a_title,aEdges)
p1(const std::string& a_title,const std::vector<TC>& a_edges,TV aVmin,TV aVmax)
:parent(a_title,a_edges)
,m_cut_v(true)
,m_min_v(aVmin)
,m_max_v(aVmax)
@@ -330,8 +330,8 @@ public:
m_max_v = 0;
return true;
}
bool configure(const std::vector<TC>& aEdges) {
if(!parent::configure(aEdges)) return false;
bool configure(const std::vector<TC>& a_edges) {
if(!parent::configure(a_edges)) return false;
m_bin_Svw.clear();
m_bin_Sv2w.clear();
m_bin_Svw.resize(parent::m_bin_number,0);
@@ -352,8 +352,8 @@ public:
m_max_v = aVmax;
return true;
}
bool configure(const std::vector<TC>& aEdges,TV aVmin,TV aVmax) {
if(!parent::configure(aEdges)) return false;
bool configure(const std::vector<TC>& a_edges,TV aVmin,TV aVmax) {
if(!parent::configure(a_edges)) return false;
m_bin_Svw.clear();
m_bin_Sv2w.clear();
m_bin_Svw.resize(parent::m_bin_number,0);
@@ -26,12 +26,12 @@ public:
:parent(a_title,aXnumber,aXmin,aXmax,aVmin,aVmax)
{}
p1d(const std::string& a_title,const std::vector<double>& aEdges)
:parent(a_title,aEdges)
p1d(const std::string& a_title,const std::vector<double>& a_edges)
:parent(a_title,a_edges)
{}
p1d(const std::string& a_title,const std::vector<double>& aEdges,double aVmin,double aVmax)
:parent(a_title,aEdges,aVmin,aVmax)
p1d(const std::string& a_title,const std::vector<double>& a_edges,double aVmin,double aVmax)
:parent(a_title,a_edges,aVmin,aVmax)
{}
virtual ~p1d(){}
+10 -10
View File
@@ -217,9 +217,9 @@ public:
}
p2(const std::string& a_title,
const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
,m_cut_v(false)
,m_min_v(0)
,m_max_v(0)
@@ -229,10 +229,10 @@ public:
}
p2(const std::string& a_title,
const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY,
const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y,
TV aVmin,TV aVmax)
:parent(a_title,aEdgesX,aEdgesY)
:parent(a_title,a_edges_x,a_edges_y)
,m_cut_v(true)
,m_min_v(aVmin)
,m_max_v(aVmax)
@@ -272,8 +272,8 @@ public:
m_max_v = 0;
return true;
}
bool configure(const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY) {
if(!parent::configure(aEdgesX,aEdgesY)) return false;
bool configure(const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y) {
if(!parent::configure(a_edges_x,a_edges_y)) return false;
m_bin_Svw.clear();
m_bin_Sv2w.clear();
m_bin_Svw.resize(parent::m_bin_number,0);
@@ -294,8 +294,8 @@ public:
m_max_v = aVmax;
return true;
}
bool configure(const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY,TV aVmin,TV aVmax) {
if(!parent::configure(aEdgesX,aEdgesY)) return false;
bool configure(const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y,TV aVmin,TV aVmax) {
if(!parent::configure(a_edges_x,a_edges_y)) return false;
m_bin_Svw.clear();
m_bin_Sv2w.clear();
m_bin_Svw.resize(parent::m_bin_number,0);
@@ -32,16 +32,16 @@ public:
{}
p2d(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
{}
p2d(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY,
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y,
double aVmin,double aVmax)
:parent(a_title,aEdgesX,aEdgesY,aVmin,aVmax)
:parent(a_title,a_edges_x,a_edges_y,aVmin,aVmax)
{}
virtual ~p2d(){}
+11 -13
View File
@@ -148,7 +148,7 @@ private:
static void TGaxis_LabelsLimits(std::ostream& a_out,const char *label,
int &first,int &last) {
last = ::strlen(label)-1;
last = int(::strlen(label))-1;
for (int i=0; i<=last; i++) {
if (::strchr("1234567890-+.", label[i]) ) { first = i; return; }
}
@@ -457,9 +457,8 @@ public:
double timeoffset = 0;
if (OptionTime) {
if (IdF!=std::string::npos) {
int LnF = fTimeFormat.size();
std::string stringtimeoffset =
fTimeFormat.substr(IdF+2,LnF-(IdF+2));
int LnF = int(fTimeFormat.size());
std::string stringtimeoffset = fTimeFormat.substr(IdF+2,LnF-(IdF+2));
int yy, mm, dd, hh, mi, ss;
if (::sscanf(stringtimeoffset.c_str(),
"%d-%d-%d %d:%d:%d", &yy, &mm, &dd, &hh, &mi, &ss) == 6) {
@@ -482,7 +481,7 @@ public:
std::string::size_type Ids = stringtimeoffset.find("s");
if (Ids != std::string::npos) {
float dp;
int Lns = stringtimeoffset.size();
size_t Lns = stringtimeoffset.size();
std::string sdp = stringtimeoffset.substr(Ids+1,Lns-(Ids+1));
::sscanf(sdp.c_str(),"%g",&dp);
timeoffset += dp;
@@ -1268,7 +1267,7 @@ public:
snpf(CHTEMP,sizeof(CHTEMP),"%g",DWlabel);
int ndecimals = 0;
size_t ndecimals = 0;
if (OptionDecimals) {
char *dot = ::strchr(CHTEMP,'.');
if (dot) ndecimals = CHTEMP + ::strlen(CHTEMP) -dot;
@@ -1299,13 +1298,13 @@ public:
::strcpy(CHTEMP, "0");
::strcat(CHTEMP, &LABEL[first]);
::strcpy(LABEL, CHTEMP);
first = 1; last = ::strlen(LABEL);
first = 1; last = int(::strlen(LABEL));
}
if (LABEL[first] == '-' && LABEL[first+1] == '.') {
::strcpy(CHTEMP, "-0");
::strcat(CHTEMP, &LABEL[first+1]);
::strcpy(LABEL, CHTEMP);
first = 1; last = ::strlen(LABEL);
first = 1; last = int(::strlen(LABEL));
}
// We eliminate the non significant 0 after '.'
@@ -1339,9 +1338,8 @@ public:
// Appends fractionnal part if seconds displayed
if (DWlabel<0.9) {
double tmpdb;
int tmplast;
snpf(LABEL,sizeof(LABEL),
"%%S%7.5f",modf(timed,&tmpdb));
size_t tmplast;
snpf(LABEL,sizeof(LABEL),"%%S%7.5f",modf(timed,&tmpdb));
tmplast = ::strlen(LABEL)-1;
// We eliminate the non significiant 0 after '.'
@@ -1357,7 +1355,7 @@ public:
::strftime(LABEL,256,timeformattmp.c_str(),utctis);
::strcpy(CHTEMP,&LABEL[0]);
first = 0; last=::strlen(LABEL)-1;
first = 0; last=int(::strlen(LABEL))-1;
Wlabel = wTimeIni + (k+1)*DWlabel;
}
@@ -1793,7 +1791,7 @@ public:
std::string::size_type IdF = fTimeFormat.find("%F");
if (IdF!=std::string::npos) {
int LnF = fTimeFormat.size();
size_t LnF = fTimeFormat.size();
std::string stringtimeoffset = fTimeFormat.substr(IdF,LnF-IdF);
fTimeFormat = a_format;
fTimeFormat += stringtimeoffset;
+148 -92
View File
@@ -278,79 +278,7 @@ public:
return true;
}
bool contract(unsigned int a_factor,img<T>& a_res,bool a_force_res_owner = true) const {
// a_factor pixels are contracted in one.
if(a_factor==1) {
if(a_force_res_owner) {
a_res.copy(m_w,m_h,m_n,m_buffer);
} else {
a_res.set(m_w,m_h,m_n,m_buffer,false);
}
return true;
}
if(!a_factor) {
a_res.make_empty();
return false;
}
unsigned int nw = m_w/a_factor;
unsigned int nh = m_h/a_factor;
unsigned int sz = nh*nw*m_n;
if(!sz) {
a_res.make_empty();
return false;
}
T* nb = new T[sz];
if(!nb) {
a_res.make_empty();
return false;
}
//T* npos = nb;
//for(unsigned int ipix=0;ipix<sz;ipix++) {*npos = 125;npos++;}
double* pixels = new double[m_n]; //for mean value.
if(!pixels) {
delete [] nb;
a_res.make_empty();
return false;
}
unsigned int nfac = a_factor*a_factor;
for(unsigned int j=0;j<nh;j++) {
for(unsigned int i=0;i<nw;i++) {
// take mean value of a_factor*a_factor pixels :
for(unsigned int ipix=0;ipix<m_n;ipix++) pixels[ipix] = 0;
for(unsigned int fr=0;fr<a_factor;fr++) {
for(unsigned int fc=0;fc<a_factor;fc++) {
T* pos = m_buffer + (j*a_factor+fr)*(m_w*m_n) +(i*a_factor+fc)*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
pixels[ipix] += double(*pos);pos++;
}
}
}
for(unsigned int ipix=0;ipix<m_n;ipix++) {
pixels[ipix] /= double(nfac);
}
//position in the result image.
T* npos = nb + j * (nw * m_n) + i*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
*npos = T(pixels[ipix]);npos++;
}
}
}
delete [] pixels;
a_res.set(nw,nh,m_n,nb,true);
return true;
}
bool contract(unsigned int a_w,unsigned int a_h,img<T>& a_res,bool a_force_res_owner = true) const {
bool contract_raw(unsigned int a_w,unsigned int a_h,img<T>& a_res,bool a_force_res_owner = true) const {
if((a_w==m_w)&&(a_h==m_h)) {
if(a_force_res_owner) {
a_res.copy(m_w,m_h,m_n,m_buffer);
@@ -415,6 +343,129 @@ public:
return true;
}
bool contract(unsigned int a_w,unsigned int a_h,img<T>& a_res,bool a_force_res_owner = true) const {
//optimized version of contract_raw().
if((a_w==m_w)&&(a_h==m_h)) {
if(a_force_res_owner) {
a_res.copy(m_w,m_h,m_n,m_buffer);
} else {
a_res.set(m_w,m_h,m_n,m_buffer,false);
}
return true;
}
size_t sz = a_h*a_w*m_n;
if(!sz) {
a_res.make_empty();
return false;
}
T* rb = new T[sz];
if(!rb) {
a_res.make_empty();
return false;
}
double* pixels = new double[m_n]; //for mean value.
if(!pixels) {
delete [] rb;
a_res.make_empty();
return false;
}
{for(unsigned int ipix=0;ipix<m_n;ipix++) pixels[ipix] = 0;}
unsigned int wfac = double(m_w)/double(a_w);
unsigned int hfac = double(m_h)/double(a_h);
if(!wfac) wfac = 1;
if(!hfac) hfac = 1;
double wfac_hfac = wfac*hfac;
//::printf("debug : %d %d, %d %d\n",a_h,a_w,hfac,wfac);
T* hpos;T* pos;T* hrpos;T* rpos;T* hhpos;T* _pos;double* ppos;
unsigned int i,j,fr,fc,ipix,i0;
unsigned int astride = a_w * m_n;
unsigned int mstride = m_w * m_n;
unsigned int wfacstride = wfac * m_n;
for(j=0;j<a_h;j++) {
hrpos = rb + j * astride;
hhpos = m_buffer + j*hfac*mstride;
for(i=0;i<a_w;i++) {
// take mean value of wfac*hfac pixels :
i0 = i*wfacstride;
hpos = hhpos;
for(fr=0;fr<hfac;fr++,hpos+=mstride) {
_pos = hpos + i0;
for(fc=0;fc<wfac;fc++,_pos+=m_n) {
pos = _pos;
ppos = pixels;
for(ipix=0;ipix<m_n;ipix++,pos++,ppos++) {
*ppos += double(*pos)/wfac_hfac;
// *ppos += double(*pos); //NOTE : doing the wfac_hfac division in the below loop is slower !
}
}
}
//position in the result image.
rpos = hrpos + i*m_n;
ppos = pixels;
for(ipix=0;ipix<m_n;ipix++,rpos++,ppos++) {
*rpos = T(*ppos);
// *rpos = T((*ppos)/wfac_hfac); //slower !
*ppos = 0;
}
}
}
delete [] pixels;
a_res.set(a_w,a_h,m_n,rb,true);
return true;
}
bool contract(unsigned int a_factor,img<T>& a_res,bool a_force_res_owner = true) const {
// a_factor pixels are contracted in one.
unsigned int nw = m_w/a_factor;
unsigned int nh = m_h/a_factor;
return contract(nw,nh,a_res,a_force_res_owner);
}
template <class TTO>
bool convert(img<TTO>& a_res) const {
a_res.make_empty();
unsigned int sz = m_w*m_h*m_n;
if(!sz) return false;
TTO* _buffer = new TTO[sz];
if(!_buffer) return false;
unsigned int i,j,ipix,imn;
unsigned int mwn = m_w*m_n;
T* _pos;T* pos;
TTO* _rpos;TTO* rpos;
for(j=0;j<m_h;j++) {
_pos = m_buffer + j*mwn;
_rpos = _buffer + j*mwn;
for(i=0;i<m_w;i++) {
imn = i*m_n;
pos = _pos + imn;
rpos = _rpos + imn;
for(ipix=0;ipix<m_n;ipix++,pos++,rpos++) *rpos = *pos;
}
}
a_res.set(m_w,m_h,m_n,_buffer,true);
return true;
}
bool get_part(unsigned int a_sx,unsigned int a_sy,unsigned int a_sw,unsigned int a_sh,img<T>& a_res) const {
if((a_sx>=m_w)||(a_sy>=m_h)){
@@ -767,34 +818,39 @@ public:
return false;
}
//unsigned int wbwn = wbw*an;
unsigned int awn = aw*an;
unsigned int rwn = rw*an;
bool has_border = a_bw||a_bh?true:false;
if(has_border) {
::memset(rb,a_bc,rsz*sizeof(T));
}
//optimize :
//unsigned int wbwn = wbw*an;
unsigned int awn = aw*an;
unsigned int rwn = rw*an;
unsigned int i,j,r;
//unsigned int c;
T* tile;T* pos;T* ptile;T* _pos;
//copy tiles :
unsigned int index = 0;
for(unsigned int j=0;j<a_rows;j++) {
for(unsigned int i=0;i<a_cols;i++) {
T* tile = a_imgs[index].buffer();
for(j=0;j<a_rows;j++) {
for(i=0;i<a_cols;i++) {
// index = a_cols*j+i
tile = a_imgs[index].buffer();
/*
if(has_border) {
for(unsigned int r=0;r<hbh;r++) {
T* pos = rb + (j*hbh+r)*rwn + i*wbwn;
::memset(pos,a_bc,wbwn*sizeof(T));
}
}
*/
//if(has_border) {
// for(unsigned int r=0;r<hbh;r++) {
// T* pos = rb + (j*hbh+r)*rwn + i*wbwn;
// ::memset(pos,a_bc,wbwn*sizeof(T));
// }
//}
{for(unsigned int r=0;r<ah;r++) {
T* pos = rb + (j*hbh+r+a_bh)*rwn + (i*wbw+a_bw)*rn;
T* ptile = tile+r*awn;
for(unsigned int c=0;c<awn;c++) *pos++ = *ptile++;
_pos = rb + (j*hbh+a_bh)*rwn + (i*wbw+a_bw)*rn;
{for(r=0;r<ah;r++) {
// pos = _pos + r*rwn;
// ptile = tile + r*awn;
// for(c=0;c<awn;c++,pos++,ptile++) *pos = *ptile;
::memcpy(_pos+r*rwn,tile+r*awn,awn*sizeof(T)); //optimize. (bof, we do not gain a lot).
}}
index++;
@@ -7,6 +7,8 @@
#include <string>
#include <vector>
#include "typedefs"
namespace tools {
class impi {
@@ -14,18 +16,32 @@ public:
virtual ~impi(){}
public:
virtual bool pack(unsigned int) = 0;
virtual bool pack(uint64) = 0;
virtual bool pack(int64) = 0;
virtual bool pack(double) = 0;
virtual bool bpack(bool) = 0;
virtual bool spack(const std::string&) = 0;
virtual bool vpack(const std::vector<unsigned int>&) = 0;
virtual bool vpack(const std::vector<int>&) = 0;
virtual bool vpack(const std::vector<double>&) = 0;
virtual bool pack(uint32,const char*) = 0;
virtual bool pack(uint32,const int*) = 0;
virtual bool unpack(unsigned int&) = 0;
virtual bool unpack(uint64&) = 0;
virtual bool unpack(int64&) = 0;
virtual bool unpack(double&) = 0;
virtual bool bunpack(bool&) = 0;
virtual bool sunpack(std::string&) = 0;
virtual bool vunpack(std::vector<unsigned int>&) = 0;
virtual bool vunpack(std::vector<int>&) = 0;
virtual bool vunpack(std::vector<double>&) = 0;
virtual bool unpack(uint32&,char*&) = 0;
virtual bool unpack(uint32&,int*&) = 0;
// for tools::mpi::pntuple :
virtual void pack_reset() = 0;
virtual bool send_buffer(int,int) = 0;
};
}
@@ -59,7 +59,7 @@ public:
virtual bool write_std_vec_vec(const std_vec_vec_string_t&) = 0;
public:
virtual const char* buf() const = 0;
virtual uint32 length() const = 0;
virtual size_t length() const = 0;
};
}}
@@ -47,6 +47,10 @@ inline void vec_sub(const T* a_1,const T* a_2,T* a_res,unsigned int a_number) {
}
*/
#include "eqT"
#include <cstddef> //size_t
// common code to class mat and nmat.
#define TOOLS_MATCOM \
@@ -101,6 +105,32 @@ public:\
void set_random(RANDOM& a_random) {\
for(unsigned int i=0;i<dim2();i++) m_vec[i] = a_random.shoot();\
}\
template <class RANDOM>\
void set_symmetric_random(RANDOM& a_random) {\
unsigned int _D = dimension();\
{for(unsigned int r=0;r<_D;r++) set_value(r,r,a_random.shoot());}\
T rd;\
{for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=(r+1);c<_D;c++) {\
rd = a_random.shoot();\
set_value(r,c,rd);\
set_value(c,r,rd);\
}\
}}\
}\
template <class RANDOM>\
void set_antisymmetric_random(RANDOM& a_random) {\
unsigned int _D = dimension();\
{for(unsigned int r=0;r<_D;r++) set_value(r,r,zero());}\
T rd;\
{for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=(r+1);c<_D;c++) {\
rd = a_random.shoot();\
set_value(r,c,rd);\
set_value(c,r,minus_one()*rd);\
}\
}}\
}\
public:\
template <class VEC>\
bool mul_vec(VEC& a_vec,T a_tmp[]) const {\
@@ -122,6 +152,25 @@ public:\
delete [] res;\
return status;\
}\
\
bool mul_array(T a_vec[],T a_tmp[]) const {\
/* a_vec = this *= a_vec */\
unsigned int _dim = dimension();\
T* pos = a_tmp;\
for(unsigned int r=0;r<_dim;r++,pos++) {\
*pos = T();\
for(unsigned int c=0;c<_dim;c++) *pos += m_vec[r+c*_dim]*a_vec[c];\
}\
{for(unsigned int i=0;i<_dim;i++) a_vec[i] = a_tmp[i];}\
return true;\
}\
bool mul_array(T a_vec[]) const {\
T* res = new T[dimension()];\
bool status = mul_array(a_vec,res);\
delete [] res;\
return status;\
}\
\
void mul_mtx(const TOOLS_MAT_CLASS& a_m) {\
_mul_mtx(a_m.m_vec);\
}\
@@ -151,6 +200,18 @@ public:\
}\
return true;\
}\
\
template <class PREC>\
bool equal_prec(const TOOLS_MAT_CLASS& a_m,const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
if(&a_m==this) return true;\
T* tp = (T*)m_vec;\
T* mp = (T*)a_m.m_vec;\
for(unsigned int i=0;i<dim2();i++,tp++,mp++) {\
T diff = (*tp) - (*mp);\
if(a_fabs(diff)>=a_prec) return false;\
}\
return true;\
}\
\
void mx_diff(const TOOLS_MAT_CLASS& a_m,T& a_mx_diff) const {\
T* tp = (T*)m_vec;\
@@ -191,6 +252,49 @@ public:\
}\
return true;\
}\
\
public:\
template <class PREC>\
bool is_proportional_prec(const TOOLS_MAT_CLASS& a_right,const PREC& a_prec,PREC(*a_fabs)(const T&),T& a_factor) const {\
/* If true, then : a_right = a_factor * this.*/\
if(this==&a_right) {a_factor=T(1);return true;}\
T _zero = zero();\
a_factor = _zero;\
if(dimension()!=a_right.dimension()) return false;\
T* lp = (T*)m_vec;\
T* rp = (T*)a_right.m_vec;\
bool first = true;\
size_t _data_size = data_size();\
for(size_t i=0;i<_data_size;i++,lp++,rp++) {\
if( numbers_are_equals(*lp,_zero,a_prec,a_fabs) && numbers_are_equals(*rp,_zero,a_prec,a_fabs) ) {\
continue;\
} else if( !numbers_are_equals(*lp,_zero,a_prec,a_fabs) && numbers_are_equals(*rp,_zero,a_prec,a_fabs) ) {\
return false;\
} else if( numbers_are_equals(*lp,_zero,a_prec,a_fabs) && !numbers_are_equals(*rp,_zero,a_prec,a_fabs) ) {\
return false;\
} else {\
if(first) {\
a_factor = (*rp)/(*lp);\
first = false;\
} else {\
if(!numbers_are_equals((*lp)*a_factor,*rp,a_prec,a_fabs)) return false;\
}\
}\
}\
return true;\
}\
\
template <class PREC>\
bool is_diagonal_prec(const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
T _zero = zero();\
unsigned int _D = dimension();\
for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=0;c<_D;c++) {\
if(c!=r) {if(!numbers_are_equals(value(r,c),_zero,a_prec,a_fabs)) return false;}\
}\
}\
return true;\
}\
\
const T* data() const {return m_vec;}\
unsigned int size() const {return dim2();}\
@@ -228,6 +332,18 @@ public:\
}\
return true;\
}\
\
template <class PREC>\
bool is_symmetric_prec(const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
unsigned int _D = dimension();\
for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=(r+1);c<_D;c++) {\
T diff = value(r,c)-value(c,r);\
if(a_fabs(diff)>=a_prec) return false;\
}\
}\
return true;\
}\
\
bool is_antisymmetric() const {\
unsigned int _D = dimension();\
@@ -479,11 +595,11 @@ public: /*operators*/\
return m_vec[a_r + a_c * dimension()];\
}\
\
T& operator[](unsigned int a_index) { /*for inlib/sg/sf_vec*/\
T& operator[](size_t a_index) { /*for inlib/sg/sf_vec*/\
/*WARNING : no check on a_index.*/\
return m_vec[a_index];\
}\
const T& operator[](unsigned int a_index) const {\
const T& operator[](size_t a_index) const {\
/*WARNING : no check on a_index.*/\
return m_vec[a_index];\
}\
@@ -16,6 +16,7 @@ class box3 {
protected:
typedef typename VEC3::elem_t T_t;
//static T_t num_max() {return std::numeric_limits<T_t>::max();} //max is a forever pain on Windows.
static T_t zero() {return T_t();}
protected:
box3(){
//make_empty();
@@ -120,6 +121,29 @@ public:
}
}
bool get_cube_size(T_t& a_dx,T_t& a_dy,T_t& a_dz,T_t(*a_sqrt)(T_t)) const {
if(!get_size(a_dx,a_dy,a_dz)) return false;
if((a_dx<=zero())&&(a_dy<=zero())&&(a_dz<=zero())) return false;
if((a_dx<=zero())&&(a_dy<=zero())) { //dz not 0 :
a_dx = T_t(0.1)*a_dz;
a_dy = T_t(0.1)*a_dz;
} else if((a_dy<=zero())&&(a_dz<=zero())) { //dx not 0 :
a_dy = T_t(0.1)*a_dx;
a_dz = T_t(0.1)*a_dx;
} else if((a_dz<=zero())&&(a_dx<=zero())) { //dy not 0 :
a_dz = T_t(0.1)*a_dy;
a_dx = T_t(0.1)*a_dy;
} else if(a_dx<=zero()) { //dy,dz not 0 :
a_dx = T_t(0.1)*a_sqrt(a_dy*a_dy+a_dz*a_dz);
} else if(a_dy<=zero()) { //dx,dz not 0 :
a_dy = T_t(0.1)*a_sqrt(a_dx*a_dx+a_dz*a_dz);
} else if(a_dz<=zero()) { //dx,dy not 0 :
a_dz = T_t(0.1)*a_sqrt(a_dx*a_dx+a_dy*a_dy);
}
return true;
}
//NOTE : print is a Python keyword.
void dump(std::ostream& a_out) {
T_t dx,dy,dz;
@@ -27,6 +27,9 @@ public:
m_min.set_value( num_max(), num_max(), num_max());
m_max.set_value(-num_max(), -num_max(), -num_max());
}
bool get_cube_size(float& a_dx,float& a_dy,float& a_dz) const {
return parent::get_cube_size(a_dx,a_dy,a_dz,::sqrtf);
}
};
}
@@ -0,0 +1,18 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_eqT
#define tools_eqT
namespace tools {
template <class NUMBER,class PREC>
inline bool numbers_are_equals(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
NUMBER diff = a_left - a_right;
if(a_fabs(diff)>=a_prec) return false;
return true;
}
}
#endif
@@ -0,0 +1,94 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_geom2
#define tools_geom2
#include <vector>
#include <cstddef>
namespace tools {
template <class VEC2>
inline double is_left(const VEC2& P0,const VEC2& P1,const VEC2& P2){
return ( (P1.v0() - P0.v0()) * (P2.v1() - P0.v1())
- (P2.v0() - P0.v0()) * (P1.v1() - P0.v1()) );
}
template <class VEC2>
inline bool is_inside(const VEC2& a_P,const std::vector<VEC2>& a_V) {
// V[] = vertex points of a polygon V[n+1] with V[n]=V[0]
// From :
// http://softsurfer.com/Archive/algorithm_0103/algorithm_0103.htm
// Copyright 2001, softSurfer (www.softsurfer.com)
// This code may be freely used and modified for any purpose
// providing that this copyright notice is included with it.
// SoftSurfer makes no warranty for this code, and cannot be held
// liable for any real or imagined damage resulting from its use.
// Users of this code must verify correctness for their application.
size_t n = a_V.size()-1;
int wn = 0; // the winding number counter
// loop through all edges of the polygon
for (size_t i=0; i<n; i++) { // edge from V[i] to V[i+1]
if (a_V[i].v1() <= a_P.v1()) { // start y <= P[1]
if (a_V[i+1].v1() > a_P.v1()) // an upward crossing
if (is_left( a_V[i], a_V[i+1], a_P) > 0) // P left of edge
++wn; // have a valid up intersect
} else { // start y > P[1] (no test needed)
if (a_V[i+1].v1() <= a_P.v1()) // a downward crossing
if (is_left( a_V[i], a_V[i+1], a_P) < 0) // P right of edge
--wn; // have a valid down intersect
}
}
return ((wn!=0)?true:false);
}
// the same done with std::pair.
template <class T>
inline double is_left(const std::pair<T,T>& P0,const std::pair<T,T>& P1,const std::pair<T,T>& P2){
return ( (P1.first - P0.first) * (P2.second - P0.second)
- (P2.first - P0.first) * (P1.second - P0.second) );
}
template <class T>
inline bool inside(const std::pair<T,T>& a_P,const std::vector< std::pair<T,T> >& a_V) {
// V[] = vertex points of a polygon V[n+1] with V[n]=V[0]
// From :
// http://softsurfer.com/Archive/algorithm_0103/algorithm_0103.htm
// Copyright 2001, softSurfer (www.softsurfer.com)
// This code may be freely used and modified for any purpose
// providing that this copyright notice is included with it.
// SoftSurfer makes no warranty for this code, and cannot be held
// liable for any real or imagined damage resulting from its use.
// Users of this code must verify correctness for their application.
size_t n = a_V.size()-1;
int wn = 0; // the winding number counter
// loop through all edges of the polygon
for (size_t i=0; i<n; i++) { // edge from V[i] to V[i+1]
if (a_V[i].second <= a_P.second) { // start y <= P[1]
if (a_V[i+1].second > a_P.second) // an upward crossing
if (is_left( a_V[i], a_V[i+1], a_P) > 0) // P left of edge
++wn; // have a valid up intersect
} else { // start y > P[1] (no test needed)
if (a_V[i+1].second <= a_P.second) // a downward crossing
if (is_left( a_V[i], a_V[i+1], a_P) < 0) // P right of edge
--wn; // have a valid down intersect
}
}
return ((wn!=0)?true:false);
}
}
#endif
@@ -6,6 +6,7 @@
#include "line"
#include "plane"
#include "vec3"
namespace tools {
+18 -18
View File
@@ -4,18 +4,18 @@
#ifndef tools_line
#define tools_line
#include "vec3"
namespace tools {
// Parametric description:
// l(t) = pos + t * dir
template <class T>
template <class VEC3>
class line {
protected:
typedef typename VEC3::elem_t T;
public:
line(){}
line(const vec3<T>& a_p0,const vec3<T>& a_p1) {
line(const VEC3& a_p0,const VEC3& a_p1) {
// Construct a line from two points lying on the line. If you
// want to construct a line from a position and a direction, use
// line(p, p + d).
@@ -45,7 +45,7 @@ public:
return *this;
}
public:
void set_value(const vec3<T>& a_p0,const vec3<T>& a_p1) {
void set_value(const VEC3& a_p0,const VEC3& a_p1) {
m_pos = a_p0;
m_dir = a_p0;
m_dir.multiply(-1);
@@ -59,11 +59,11 @@ public:
m_dir.normalize();
}
const vec3<T>& position() const {return m_pos;}
const vec3<T>& direction() const {return m_dir;}
const VEC3& position() const {return m_pos;}
const VEC3& direction() const {return m_dir;}
/* not tested :
vec3<T> closest_point(const vec3<T>& a_point) const {
VEC3 closest_point(const VEC3& a_point) const {
//from coin3d/SbLine.cpp.
//
@@ -81,7 +81,7 @@ public:
bool closest_points(const line<T>& a_line,
vec3<T>& a_on_this,vec3<T>& a_on_line) const {
VEC3& a_on_this,VEC3& a_on_line) const {
//from coin3d/SbLine.cpp.
//WARNING : if ret false, a_on_this, a_on_line not set.
@@ -91,11 +91,11 @@ public:
if(a_line.m_dir == m_dir) return false;
if(a_line.m_dir == T(-1)*m_dir) return false;
vec3<T> P0 = m_pos;
vec3<T> P1 = a_line.m_pos;
vec3<T> D0 = m_dir;
vec3<T> D1 = a_line.m_dir;
vec3<T> D0N = D0;
VEC3 P0 = m_pos;
VEC3 P1 = a_line.m_pos;
VEC3 D0 = m_dir;
VEC3 D1 = a_line.m_dir;
VEC3 D0N = D0;
T c[3], d[3];
@@ -116,8 +116,8 @@ public:
return true;
}
bool intersect(const line<T>& a_line,vec3<T>& a_out,const T& a_prec) const {
vec3<T> p,q;
bool intersect(const line<T>& a_line,VEC3& a_out,const T& a_prec) const {
VEC3 p,q;
if(!closest_points(a_line,p,q)) return false;
if((q-p).length()>a_prec) return false;
a_out = p;
@@ -126,8 +126,8 @@ public:
*/
protected:
vec3<T> m_pos;
vec3<T> m_dir; //normalized.
VEC3 m_pos;
VEC3 m_dir; //normalized.
};
}
+25 -105
View File
@@ -5,7 +5,7 @@
#define tools_mat
#ifdef TOOLS_MEM
#include "mem"
#include "../mem"
#endif
#include "MATCOM"
@@ -30,9 +30,11 @@ private:
}
#endif
public:
mat() {
mat(bool a_inc = true) {
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
if(a_inc) mem::increment(s_class().c_str());
#else
(void)a_inc;
#endif
#ifdef TOOLS_MAT_NEW
m_vec = new T[D*D];
@@ -160,18 +162,18 @@ inline nmat<T> copy(const mat<T,D>& a_from) {
}
template <class MAT>
inline void conjugate(MAT& a_m) {
inline void conjugate(MAT& a_m,typename MAT::elem_t (*a_conj)(const typename MAT::elem_t&)) {
typedef typename MAT::elem_t T;
T* pos = const_cast<T*>(a_m.data());
unsigned int D2 = a_m.dimension()*a_m.dimension();
for(unsigned int i=0;i<D2;i++,pos++) {
*pos = _conj(*pos); //T = std::complex<>
*pos = a_conj(*pos); //T = std::complex<>
}
}
template <class MAT>
inline void dagger(MAT& a_m) {
conjugate<MAT>(a_m);
inline void dagger(MAT& a_m,typename MAT::elem_t (*a_conj)(const typename MAT::elem_t&)) {
conjugate<MAT>(a_m,a_conj);
a_m.transpose();
}
@@ -359,37 +361,6 @@ inline void matrix_set(MAT& a_m
vec[1] = a_10;vec[3] = a_11;
}
template <class MAT>
inline void set_epsilon(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 1,
-1, 0);
}
// Pauli matrices :
// P1 P2 P3
// 0 1 0 -i 1 0
// 1 0 i 0 0 -1
template <class MAT>
inline void set_P1(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 1,
1, 0);
}
template <class MAT>
inline void set_P2(MAT& a_m) {
typedef typename MAT::elem_t T;
//T i;set_i(i); //with inlib::symbol
T i(0,1);
T _i = T(-1)*i;
matrix_set<MAT>(a_m, 0, _i,
i, 0);
}
template <class MAT>
inline void set_P3(MAT& a_m) {
matrix_set<MAT>(a_m, 1, 0,
0,-1);
}
////////////////////////////////////////////////
/// specific D=3 ///////////////////////////////
////////////////////////////////////////////////
@@ -407,27 +378,6 @@ inline void matrix_set(MAT& a_m
vec[2] = a_20;vec[5] = a_21;vec[8] = a_22;
}
// Generators of rotation group :
// Rk(i,j) = epsilon(k,i,j) i,j,k=1,2,3
template <class MAT>
inline void set_R1(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 0, 0,
0, 0, 1,
0,-1, 0);
}
template <class MAT>
inline void set_R2(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 0,-1,
0, 0, 0,
1, 0, 0);
}
template <class MAT>
inline void set_R3(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 1, 0,
-1, 0, 0,
0, 0, 0);
}
////////////////////////////////////////////////
/// specific D=4 ///////////////////////////////
////////////////////////////////////////////////
@@ -447,56 +397,26 @@ inline void matrix_set(MAT& a_m
vec[3] = a_30;vec[7] = a_31;vec[11] = a_32;vec[15] = a_33;
}
template <class MAT,class RANDOM>
inline void set_random_antisym(MAT& a_m,RANDOM& a_rd) {
typedef typename MAT::elem_t T;
T v01 = a_rd.shoot();
T v02 = a_rd.shoot();
T v03 = a_rd.shoot();
T v12 = a_rd.shoot();
T v13 = a_rd.shoot();
T v23 = a_rd.shoot();
matrix_set(a_m,
0, v01, v02, v03,
-v01, 0, v12, v13,
-v02,-v12, 0, v23,
-v03,-v13,-v23, 0);
}
////////////////////////////////////////////////
/// specific D=5 ///////////////////////////////
////////////////////////////////////////////////
template <class MAT>
inline void set_eta(MAT& a_m) {
a_m.set_zero();
a_m.set_value(0,0, 1);
a_m.set_value(1,1,-1);
a_m.set_value(2,2,-1);
a_m.set_value(3,3,-1);
}
////////////////////////////////////////////////
/// specific D=6 ///////////////////////////////
////////////////////////////////////////////////
/*
template <class T>
inline void set_matrix(mat<T,6>& a_m
,const T& a_00,const T& a_01,const T& a_02,const T& a_03,const T& a_04,const T& a_05 //1 row
,const T& a_10,const T& a_11,const T& a_12,const T& a_13,const T& a_14,const T& a_15 //2 row
,const T& a_20,const T& a_21,const T& a_22,const T& a_23,const T& a_24,const T& a_25 //3 row
,const T& a_30,const T& a_31,const T& a_32,const T& a_33,const T& a_34,const T& a_35 //4 row
,const T& a_40,const T& a_41,const T& a_42,const T& a_43,const T& a_44,const T& a_45 //5 row
,const T& a_50,const T& a_51,const T& a_52,const T& a_53,const T& a_54,const T& a_55 //6 row
inline void matrix_set(MAT& a_m
,const typename MAT::elem_t& a_00,const typename MAT::elem_t& a_01,const typename MAT::elem_t& a_02,const typename MAT::elem_t& a_03,const typename MAT::elem_t& a_04 //1 row
,const typename MAT::elem_t& a_10,const typename MAT::elem_t& a_11,const typename MAT::elem_t& a_12,const typename MAT::elem_t& a_13,const typename MAT::elem_t& a_14 //2 row
,const typename MAT::elem_t& a_20,const typename MAT::elem_t& a_21,const typename MAT::elem_t& a_22,const typename MAT::elem_t& a_23,const typename MAT::elem_t& a_24 //3 row
,const typename MAT::elem_t& a_30,const typename MAT::elem_t& a_31,const typename MAT::elem_t& a_32,const typename MAT::elem_t& a_33,const typename MAT::elem_t& a_34 //4 row
,const typename MAT::elem_t& a_40,const typename MAT::elem_t& a_41,const typename MAT::elem_t& a_42,const typename MAT::elem_t& a_43,const typename MAT::elem_t& a_44 //5 row
){
//a_<R><C>
//vec[R + C * 6];
T* vec = const_cast<T*>(a_m.data());
vec[0] = a_00;vec[6] = a_01;vec[12] = a_02;vec[18] = a_03;vec[24] = a_04;vec[30] = a_05;
vec[1] = a_10;vec[7] = a_11;vec[13] = a_12;vec[19] = a_13;vec[25] = a_14;vec[31] = a_15;
vec[2] = a_20;vec[8] = a_21;vec[14] = a_22;vec[20] = a_23;vec[26] = a_24;vec[32] = a_25;
vec[3] = a_30;vec[9] = a_31;vec[15] = a_32;vec[21] = a_33;vec[27] = a_34;vec[33] = a_35;
vec[4] = a_40;vec[10] = a_41;vec[16] = a_42;vec[22] = a_43;vec[28] = a_44;vec[34] = a_45;
vec[5] = a_50;vec[11] = a_51;vec[17] = a_52;vec[23] = a_53;vec[29] = a_54;vec[35] = a_55;
//vec[R + C * 4];
typename MAT::elem_t* vec = const_cast<typename MAT::elem_t*>(a_m.data());
vec[0] = a_00;vec[5] = a_01;vec[10] = a_02;vec[15] = a_03;vec[20] = a_04;
vec[1] = a_10;vec[6] = a_11;vec[11] = a_12;vec[16] = a_13;vec[21] = a_14;
vec[2] = a_20;vec[7] = a_21;vec[12] = a_22;vec[17] = a_23;vec[22] = a_24;
vec[3] = a_30;vec[8] = a_31;vec[13] = a_32;vec[18] = a_33;vec[23] = a_34;
vec[4] = a_40;vec[9] = a_41;vec[14] = a_42;vec[19] = a_43;vec[24] = a_44;
}
*/
}
+47 -13
View File
@@ -6,7 +6,7 @@
#include "mat"
#include <cmath>
//#include <cmath>
namespace tools {
@@ -15,7 +15,7 @@ class mat4 : public mat<T,4> {
typedef mat<T,4> parent;
typedef mat<T,4> pr;
public:
mat4():parent() {}
mat4(bool a_inc = true):parent(a_inc) {}
mat4(const mat<T,4>& a_from):parent(a_from){}
virtual ~mat4() {}
public:
@@ -62,8 +62,8 @@ public:
void set_translate(const T& a_x,const T& a_y,const T& a_z) {
_set_translate(a_x,a_y,a_z,pr::m_vec);
}
void set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle) {
_set_rotate(a_x,a_y,a_z,a_angle,pr::m_vec);
void set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
_set_rotate(a_x,a_y,a_z,a_angle,pr::m_vec,a_sin,a_cos);
}
void set_ortho(const T& a_l,const T& a_r, //left,right
const T& a_b,const T& a_t, //bottom,top
@@ -155,6 +155,13 @@ public:
a_y = pr::m_vec[13];
a_z = pr::m_vec[14];
}
//void set_translate_only(const T& a_x,const T& a_y,const T& a_z) {
// pr::m_vec[12] = a_x;
// pr::m_vec[13] = a_y;
// pr::m_vec[14] = a_z;
//}
public:
void mul_4(T& a_x,T& a_y,T& a_z,T& a_p) const {
// a_[x,y,z,p] = this * a_[x,y,z,p]
@@ -211,6 +218,14 @@ public:
a_z = z;
}
void mul_trans_3(T& a_x,T& a_y,T& a_z) const {
// used in sg::healpix.
// a_[x,y,z] = trans_part(this) * a_[x,y,z]
a_x += pr::m_vec[12];
a_y += pr::m_vec[13];
a_z += pr::m_vec[14];
}
template <class VEC>
void mul_dir_3(VEC& a_dir) const {
mul_dir_3(a_dir[0],a_dir[1],a_dir[2]);
@@ -261,16 +276,15 @@ public:
pr::m_vec[15] = pr::m_vec[3]*a_x+pr::m_vec[7]*a_y+pr::m_vec[11]*a_z+pr::m_vec[15];
}
void mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle) {
void mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
T rot[16];
_set_rotate(a_x,a_y,a_z,a_angle,rot);
_set_rotate(a_x,a_y,a_z,a_angle,rot,a_sin,a_cos);
parent::_mul_mtx(rot);
}
void left_mul_rotate(const T& a_x,const T& a_y,const T& a_z,
const T& a_angle) {
void left_mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
T _m[16];
_set_rotate(a_x,a_y,a_z,a_angle,_m);
_set_rotate(a_x,a_y,a_z,a_angle,_m,a_sin,a_cos);
parent::_left_mul_mtx(_m);
}
@@ -340,11 +354,11 @@ protected:
v[2] = 0;v[6] = 0;v[10] = a_3;v[14] = 0;
v[3] = 0;v[7] = 0;v[11] = 0;v[15] = T(1);
}
static void _set_rotate(const T& a_x,const T& a_y,const T& a_z,
const T& a_angle,T v[]) {
static void _set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T v[],T(*a_sin)(T),T(*a_cos)(T)) {
//WARNING : (a_x,a_y,a_z) must be a normalized vector.
T co = (T)::cos(a_angle);
T si = (T)::sin(a_angle);
T si = a_sin(a_angle);
T co = a_cos(a_angle);
T x = a_x;
T y = a_y;
T z = a_z;
@@ -447,6 +461,26 @@ public:
private:static void check_instantiation() {mat4<float> dummy;}
};
////////////////////////////////////////////////
/// common matrices : //////////////////////////
////////////////////////////////////////////////
template <class T>
inline const mat4<T>& mat4_zero() {
static const mat4<T> s_v(false); //inc mem count = false
return s_v;
}
/*
template <class T>
inline const mat4<T>& mat4_identity() {
static mat4<T> s_v(false);
static bool s_first = true;
if(s_first) {s_v.set_identity();s_first=false;}
return s_v;
}
*/
//for sf, mf :
template <class T>
inline const T* get_data(const mat4<T>& a_v) {return a_v.data();}
@@ -5,17 +5,19 @@
#define tools_mat4f
#include "mat4"
#include <cmath>
namespace tools {
class mat4f : public mat4<float> {
typedef mat4<float> parent;
public:
mat4f(){}
virtual ~mat4f() {}
public:
mat4f(const mat4f& a_from):mat4<float>(a_from){}
mat4f(const mat4f& a_from):parent(a_from){}
mat4f& operator=(const mat4f& a_from){
mat4<float>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
public:
@@ -23,28 +25,38 @@ public:
float a_10,float a_11,float a_12,float a_13, //second row
float a_20,float a_21,float a_22,float a_23, //third row
float a_30,float a_31,float a_32,float a_33) //fourth row
:mat4<float>(a_00,a_01,a_02,a_03,
a_10,a_11,a_12,a_13,
a_20,a_21,a_22,a_23,
a_30,a_31,a_32,a_33)
:parent(a_00,a_01,a_02,a_03,
a_10,a_11,a_12,a_13,
a_20,a_21,a_22,a_23,
a_30,a_31,a_32,a_33)
{}
mat4f(const mat4<float>& a_from):mat4<float>(a_from){}
mat4f& operator=(const mat4<float>& a_from){
mat4<float>::operator=(a_from);
mat4f(const parent& a_from):parent(a_from){}
mat4f& operator=(const parent& a_from){
parent::operator=(a_from);
return *this;
}
public:
void set_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
parent::set_rotate(a_x,a_y,a_z,a_angle,::sinf,::cosf);
}
void mul_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
parent::mul_rotate(a_x,a_y,a_z,a_angle,::sinf,::cosf);
}
void left_mul_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
parent::left_mul_rotate(a_x,a_y,a_z,a_angle,::sinf,::cosf);
}
public: //backward compatibility
void mul_2f(float& a_x,float& a_y) const {
mat4<float>::mul_2(a_x,a_y);
}
void mul_3f(float& a_x,float& a_y,float& a_z) const {
mat4<float>::mul_3(a_x,a_y,a_z);
}
void mul_dir_3f(float& a_x,float& a_y,float& a_z) const {
mat4<float>::mul_dir_3(a_x,a_y,a_z);
}
void mul_4f(float& a_x,float& a_y,float& a_z,float& a_w) const {
mat4<float>::mul_4(a_x,a_y,a_z,a_w);
void mul_2f(float& a_x,float& a_y) const {parent::mul_2(a_x,a_y);}
void mul_3f(float& a_x,float& a_y,float& a_z) const {parent::mul_3(a_x,a_y,a_z);}
void mul_dir_3f(float& a_x,float& a_y,float& a_z) const {parent::mul_dir_3(a_x,a_y,a_z);}
void mul_trans_3f(float& a_x,float& a_y,float& a_z) const {parent::mul_trans_3(a_x,a_y,a_z);}
void mul_4f(float& a_x,float& a_y,float& a_z,float& a_w) const {parent::mul_4(a_x,a_y,a_z,a_w);}
void mul_dir_3d(double& a_x,double& a_y,double& a_z) const { //used in sg::healpix
float x = float(a_x);
float y = float(a_y);
float z = float(a_z);
parent::mul_dir_3(x,y,z);
a_x = x;a_y = y;a_z = z;
}
public: //operators
};
@@ -8,21 +8,23 @@
namespace tools {
template <class T>
template <class VEC3>
class plane {
protected:
typedef typename VEC3::elem_t T;
public:
plane(){}
plane(const vec3<T>& a_p0,const vec3<T>& a_p1,const vec3<T>& a_p2) {
plane(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2) {
// Construct a plane given 3 points.
// Orientation is computed by taking (p1 - p0) x (p2 - p0) and
// pointing the normal in that direction.
vec3<T> P = a_p1;
VEC3 P = a_p1;
P.subtract(a_p0);
vec3<T> P2 = a_p2;
VEC3 P2 = a_p2;
P2.subtract(a_p0);
m_normal = P.cross(P2);
P.cross(P2,m_normal);
if(!m_normal.normalize()) {} //throw
m_distance =
m_normal.v0() * a_p0.v0() +
@@ -30,11 +32,11 @@ public:
m_normal.v2() * a_p0.v2();
}
plane(const vec3<T>& a_normal,const T& a_distance){
plane(const VEC3& a_normal,const T& a_distance){
set(a_normal,a_distance);
}
plane(const vec3<T>& a_normal,const vec3<T>& a_point){
plane(const VEC3& a_normal,const VEC3& a_point){
set(a_normal,a_point);
}
@@ -58,11 +60,11 @@ public:
m_distance += a_distance;
}
bool intersect(const line<T>& a_line,vec3<T>& a_intersection) const {
bool intersect(const line<VEC3>& a_line,VEC3& a_intersection) const {
// Intersect line and plane, returning true if there is an intersection
// false if line is parallel to plane
const vec3<T>& pos = a_line.position();
const vec3<T>& dir = a_line.direction();
const VEC3& pos = a_line.position();
const VEC3& dir = a_line.direction();
T d = m_normal.dot(dir);
if(d==T()) return false;
T t = (m_distance - m_normal.dot(pos))/d;
@@ -73,33 +75,33 @@ public:
return true;
}
bool is_in_half_space(const vec3<T>& a_point) const {
bool is_in_half_space(const VEC3& a_point) const {
// Returns true if the given point is within the half-space
// defined by the plane
//vec pos = m_normal * m_distance;
vec3<T> pos = m_normal;
VEC3 pos = m_normal;
pos.multiply(-m_distance);
pos.add(a_point);
return (m_normal.dot(pos) >= T() ? true : false);
}
const vec3<T>& normal() const {return m_normal;}
const VEC3& normal() const {return m_normal;}
T distance_from_origin() const {return m_distance;}
T distance(const vec3<T>& a_point) const {
T distance(const VEC3& a_point) const {
// Return the distance from point to plane. Positive distance means
// the point is in the plane's half space.
return a_point.dot(m_normal) - m_distance;
}
void set(const vec3<T>& a_normal,const T& a_distance){
void set(const VEC3& a_normal,const T& a_distance){
m_normal = a_normal;
if(!m_normal.normalize()) {} //throw
m_distance = a_distance;
}
void set(const vec3<T>& a_normal,const vec3<T>& a_point){
void set(const VEC3& a_normal,const VEC3& a_point){
// Construct a plane given normal and a point to pass through
// Orientation is given by the normal vector n.
m_normal = a_normal;
@@ -111,12 +113,12 @@ public:
}
public: //iv2sg
const vec3<T>& getNormal() const {return m_normal;}
const VEC3& getNormal() const {return m_normal;}
protected:
// equation of the plane is :
// norm[0]*x+norm[1]*y+norm[2]*z = dist
vec3<T> m_normal; //normalized.
VEC3 m_normal; //normalized.
T m_distance;
};
+35 -35
View File
@@ -6,23 +6,21 @@
// rotation done with quaternion.
#include "vec4"
#include "vec3"
#include "mat4"
namespace tools {
template <class T>
template <class VEC3,class VEC4>
class qrot {
protected:
//typedef typename VEC3::elem_t T3;
typedef typename VEC4::elem_t T; //we assume = T3
public:
qrot()
:m_quat(0,0,0,1) //zero rotation around the positive Z axis.
{}
qrot(const vec3<T>& a_axis,T a_radians){
if(!set_value(a_axis,a_radians)) {} //FIXME : throw
qrot(const VEC3& a_axis,T a_radians,T(*a_sin)(T),T(*a_cos)(T)){
if(!set_value(a_axis,a_radians,a_sin,a_cos)) {} //FIXME : throw
}
qrot(const vec3<T>& a_from,const vec3<T>& a_to){set_value(a_from,a_to);}
qrot(const VEC3& a_from,const VEC3& a_to,T(*a_sqrt)(T),T(*a_fabs)(T)){set_value(a_from,a_to,a_sqrt,a_fabs);}
virtual ~qrot(){}
public:
qrot(const qrot& a_from)
@@ -108,14 +106,14 @@ public:
}
bool set_value(const vec3<T>& a_axis,T a_radians) {
bool set_value(const VEC3& a_axis,T a_radians,T(*a_sin)(T),T(*a_cos)(T)) {
// Reset rotation with the given axis-of-rotation and rotation angle.
// Make sure axis is not the null vector when calling this method.
// From <http://www.automation.hut.fi/~jaro/thesis/hyper/node9.html>.
if(a_axis.length()==T()) return false;
m_quat.v3(::cos(a_radians/2));
T sineval = ::sin(a_radians/2);
vec3<T> a = a_axis;
m_quat.v3(a_cos(a_radians/2));
T sineval = a_sin(a_radians/2);
VEC3 a = a_axis;
a.normalize();
m_quat.v0(a.v0() * sineval);
m_quat.v1(a.v1() * sineval);
@@ -123,15 +121,15 @@ public:
return true;
}
bool set_value(const vec3<T>& a_from,const vec3<T>& a_to) {
bool set_value(const VEC3& a_from,const VEC3& a_to,T(*a_sqrt)(T),T(*a_fabs)(T)) {
// code taken from coin3d/SbRotation.
vec3<T> from(a_from);
VEC3 from(a_from);
if(from.normalize()==T()) return false;
vec3<T> to(a_to);
VEC3 to(a_to);
if(to.normalize()==T()) return false;
T dot = from.dot(to);
vec3<T> crossvec = from.cross(to);
VEC3 crossvec;from.cross(to,crossvec);
T crosslen = crossvec.normalize();
if(crosslen == T()) { // Parallel vectors
@@ -142,10 +140,10 @@ public:
// Ok, so they are parallel and pointing in the opposite direction
// of each other.
// Try crossing with x axis.
vec3<T> t = from.cross(vec3<T>(1,0,0));
VEC3 t;from.cross(VEC3(1,0,0),t);
// If not ok, cross with y axis.
if(t.normalize() == T()) {
t = from.cross(vec3<T>(0,1,0));
from.cross(VEC3(0,1,0),t);
t.normalize();
}
m_quat.set_value(t[0],t[1],t[2],0);
@@ -153,17 +151,17 @@ public:
} else { // Vectors are not parallel
// The fabs() wrapping is to avoid problems when `dot' "overflows"
// a tiny wee bit, which can lead to sqrt() returning NaN.
crossvec *= (T)::sqrt(half() * ::fabs(one() - dot));
crossvec *= (T)a_sqrt(half() * a_fabs(one() - dot));
// The fabs() wrapping is to avoid problems when `dot' "underflows"
// a tiny wee bit, which can lead to sqrt() returning NaN.
m_quat.set_value(crossvec[0], crossvec[1], crossvec[2],(T)::sqrt(half()*::fabs(one()+dot)));
m_quat.set_value(crossvec[0], crossvec[1], crossvec[2],(T)a_sqrt(half()*a_fabs(one()+dot)));
}
return true;
}
bool value(vec3<T>& a_axis,T& a_radians) const {
bool value(VEC3& a_axis,T& a_radians,T(*a_sin)(T),T(*a_acos)(T)) const { //WARNING a_acos and NOT a_cos
//WARNING : can fail.
if( (m_quat.v3()<minus_one()) || (m_quat.v3()> one()) ){ ////???
a_axis.set_value(0,0,1);
@@ -171,8 +169,8 @@ public:
return false;
}
a_radians = ::acos(m_quat.v3()) * 2;
T sineval = ::sin(a_radians/2);
a_radians = a_acos(m_quat.v3()) * 2;
T sineval = a_sin(a_radians/2);
if(sineval==T()) { //???
a_axis.set_value(0,0,1);
@@ -185,14 +183,15 @@ public:
return true;
}
void set_value(const mat4<T>& a_m) {
template <class MAT4>
void set_value(const MAT4& a_m,T(*a_sqrt)(T)) {
//WARNING : not tested.
//Set the rotation from the components of the given matrix.
T scalerow = a_m.v00() + a_m.v11() + a_m.v22();
if (scalerow > T()) {
T _s = ::sqrt(scalerow + a_m.v33());
T _s = a_sqrt(scalerow + a_m.v33());
m_quat.v3(_s * half());
_s = half() / _s;
@@ -207,7 +206,7 @@ public:
unsigned int j = (i+1)%3;
unsigned int k = (j+1)%3;
T _s = ::sqrt((a_m.value(i,i) - (a_m.value(j,j) + a_m.value(k,k))) + a_m.v33());
T _s = a_sqrt((a_m.value(i,i) - (a_m.value(j,j) + a_m.value(k,k))) + a_m.v33());
m_quat.set_value(i,_s * half());
_s = half() / _s;
@@ -218,11 +217,12 @@ public:
}
if (a_m.v33()!=one()) {
m_quat.multiply(one()/::sqrt(a_m.v33()));
m_quat.multiply(one()/a_sqrt(a_m.v33()));
}
}
void value(mat4<T>& a_m) const {
template <class MAT4>
void value(MAT4& a_m) const {
//Return this rotation in the form of a matrix.
const T x = m_quat.v0();
const T y = m_quat.v1();
@@ -255,7 +255,7 @@ public:
a_m.v33(w*w + x*x + y*y + z*z);
}
void mul_vec(const vec3<T>& a_in,vec3<T>& a_out) const {
void mul_vec(const VEC3& a_in,VEC3& a_out) const {
const T x = m_quat.v0();
const T y = m_quat.v1();
const T z = m_quat.v2();
@@ -277,7 +277,7 @@ public:
a_out.set_value(v0,v1,v2);
}
void mul_vec(vec3<T>& a_v) const {
void mul_vec(VEC3& a_v) const {
const T x = m_quat.v0();
const T y = m_quat.v1();
const T z = m_quat.v2();
@@ -324,8 +324,8 @@ public:
}
public: //for io::streamer
const vec4<T>& quat() const {return m_quat;}
vec4<T>& quat() {return m_quat;}
const VEC4& quat() const {return m_quat;}
VEC4& quat() {return m_quat;}
protected:
static T one() {return T(1);}
@@ -333,7 +333,7 @@ protected:
static T half() {return T(0.5);}
protected:
vec4<T> m_quat;
VEC4 m_quat;
public:
//NOTE : don't handle a static object because of mem balance.
@@ -342,7 +342,7 @@ public:
// return s_v;
//}
private:static void check_instantiation() {qrot<float> v;}
//private:static void check_instantiation() {qrot<float> v;}
};
}
+20 -21
View File
@@ -8,35 +8,29 @@
#include "qrot"
#include "vec3f"
#include "vec4f"
#include "mat4f"
namespace tools {
class rotf : public qrot<float> {
rotf(float a_q0,float a_q1,float a_q2,float a_q3)
:qrot<float>(a_q0,a_q1,a_q2,a_q3)
{}
class rotf : public qrot<vec3f,vec4f> {
typedef qrot<vec3f,vec4f> parent;
private:
rotf(float a_q0,float a_q1,float a_q2,float a_q3):parent(a_q0,a_q1,a_q2,a_q3) {}
public:
rotf()
:qrot<float>() //zero rotation around the positive Z axis.
{}
rotf(const vec3f& a_axis,float a_radians)
:qrot<float>(a_axis,a_radians)
{}
rotf(const vec3f& a_from,const vec3f& a_to)
:qrot<float>(a_from,a_to)
{}
rotf():parent() {} //zero rotation around the positive Z axis.
rotf(const vec3f& a_axis,float a_radians):parent(a_axis,a_radians,::sinf,::cosf) {}
rotf(const vec3f& a_from,const vec3f& a_to):parent(a_from,a_to,::sqrtf,::fabsf) {}
virtual ~rotf(){}
public:
rotf(const rotf& a_from)
:qrot<float>(a_from)
{}
rotf(const rotf& a_from):parent(a_from) {}
rotf& operator=(const rotf& a_from){
qrot<float>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
public:
rotf& operator*=(const rotf& a_q) {
qrot<float>::operator*=(a_q);
parent::operator*=(a_q);
return *this;
}
rotf operator*(const rotf& a_r) const {
@@ -46,11 +40,16 @@ public:
}
public:
bool set_value(const vec3f& a_from,const vec3f& a_to){
return qrot<float>::set_value(a_from,a_to);
return parent::set_value(a_from,a_to,::sqrtf,::fabsf);
}
bool set_value(const vec3f& a_from,float a_a){
return qrot<float>::set_value(a_from,a_a);
return parent::set_value(a_from,a_a,::sinf,::cosf);
}
bool value(vec3f& a_from,float a_a) const {
return parent::value(a_from,a_a,::sinf,::acosf); //WARNING acos and not cos
}
void set_value(const mat4f& a_m) {parent::set_value(a_m,::sqrtf);}
void value(mat4f& a_m) const {parent::value(a_m);}
//NOTE : don't handle a static object because of mem balance.
//static const rotf& identity() {
@@ -67,7 +66,7 @@ namespace tools {
inline bool tos(const rotf& a_v,std::string& a_s) {
vec3f axis;
float angle;
float angle = 0;
if(!a_v.value(axis,angle)) {a_s.clear();return false;}
std::ostringstream strm;
strm << axis[0] << " "
+15 -12
View File
@@ -4,10 +4,10 @@
#ifndef tools_vec2
#define tools_vec2
#include <cmath> //sqrt
#include <cstddef> //size_t
#ifdef TOOLS_MEM
#include "mem"
#include "../mem"
#endif
namespace tools {
@@ -21,6 +21,7 @@ class vec2 {
}
#endif
public:
typedef T elem_t;
unsigned int dimension() const {return 2;}
public:
vec2(){
@@ -63,14 +64,16 @@ public:
return *this;
}
public:
T v0() const { return m_data[0];}
T v1() const { return m_data[1];}
const T& v0() const { return m_data[0];}
const T& v1() const { return m_data[1];}
void v0(const T& a_value) { m_data[0] = a_value;}
void v1(const T& a_value) { m_data[1] = a_value;}
T x() const {return m_data[0];}
T y() const {return m_data[1];}
const T& x() const {return m_data[0];}
const T& y() const {return m_data[1];}
T& x() {return m_data[0];}
T& y() {return m_data[1];}
void set_value(const T& a0,const T& a1) {
m_data[0] = a0;
@@ -91,12 +94,12 @@ public:
// return true;
//}
T length() const {
return (T)::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
T length(T(*a_sqrt)(T)) const {
return a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
}
T normalize() {
T norme = length();
T normalize(T(*a_sqrt)(T)) {
T norme = length(a_sqrt);
if(norme==T()) return T();
divide(norme);
return norme;
@@ -145,11 +148,11 @@ public:
}
public: //operators
T& operator[](unsigned int a_index) {
T& operator[](size_t a_index) {
//WARNING : no check on a_index.
return m_data[a_index];
}
const T& operator[](unsigned int a_index) const {
const T& operator[](size_t a_index) const {
//WARNING : no check on a_index.
return m_data[a_index];
}
@@ -6,6 +6,7 @@
#include "vec2"
#include "../S_STRING"
#include <cmath>
namespace tools {
@@ -53,6 +54,22 @@ public: //operators
vec2f operator-() const {
return vec2f(-m_data[0],-m_data[1]);
}
public:
#define TOOLS_VEC2F_MORE_PREC
#ifdef TOOLS_VEC2F_MORE_PREC
float length() const {
return float(::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]));
}
float normalize() {
float norme = length();
if(!norme) return 0;
divide(norme);
return norme;
}
#else
float length() const {return parent::length(::sqrtf);}
float normalize() {return parent::normalize(::sqrtf);}
#endif
public: //iv2sg
bool equals(const vec2f& a_v,const float a_epsil) const {
//if(a_epsil<0.0f))
+102 -41
View File
@@ -4,10 +4,10 @@
#ifndef tools_vec3
#define tools_vec3
#include <cmath> //sqrt
#include <cstddef> //size_t
#ifdef TOOLS_MEM
#include "mem"
#include "../mem"
#endif
namespace tools {
@@ -71,17 +71,21 @@ public:
return *this;
}
public:
T v0() const { return m_data[0];}
T v1() const { return m_data[1];}
T v2() const { return m_data[2];}
const T& v0() const { return m_data[0];}
const T& v1() const { return m_data[1];}
const T& v2() const { return m_data[2];}
void v0(const T& a_value) { m_data[0] = a_value;}
void v1(const T& a_value) { m_data[1] = a_value;}
void v2(const T& a_value) { m_data[2] = a_value;}
T x() const {return m_data[0];}
T y() const {return m_data[1];}
T z() const {return m_data[2];}
const T& x() const {return m_data[0];}
const T& y() const {return m_data[1];}
const T& z() const {return m_data[2];}
T& x() {return m_data[0];}
T& y() {return m_data[1];}
T& z() {return m_data[2];}
void set_value(const T& a0,const T& a1,const T& a2) {
m_data[0] = a0;
@@ -105,14 +109,12 @@ public:
// return true;
//}
T length() const {
return (T)::sqrt(m_data[0]*m_data[0]
+m_data[1]*m_data[1]
+m_data[2]*m_data[2]);
T length(T(*a_sqrt)(T)) const {
return a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]);
}
T normalize() {
T norme = length();
T normalize(T(*a_sqrt)(T)) {
T norme = length(a_sqrt);
if(norme==T()) return T();
divide(norme);
return norme;
@@ -124,10 +126,10 @@ public:
m_data[2] * aV.m_data[2]);
}
vec3<T> cross(const vec3<T>& aV) const {
return vec3<T>(m_data[1] * aV.m_data[2] - m_data[2] * aV.m_data[1],
m_data[2] * aV.m_data[0] - m_data[0] * aV.m_data[2],
m_data[0] * aV.m_data[1] - m_data[1] * aV.m_data[0]);
void cross(const vec3<T>& aV,vec3<T>& a_value) const {
a_value.set_value(m_data[1] * aV.m_data[2] - m_data[2] * aV.m_data[1],
m_data[2] * aV.m_data[0] - m_data[0] * aV.m_data[2],
m_data[0] * aV.m_data[1] - m_data[1] * aV.m_data[0]);
}
bool equal(const vec3& aV) const {
@@ -137,6 +139,23 @@ public:
return true;
}
template <class PREC>
bool equal_prec(const vec3& a_v,PREC a_prec,PREC(*a_fabs)(const T&)) const {
if(&a_v==this) return true;
for(unsigned int index=0;index<3;index++) {
T diff = m_data[index]-a_v.m_data[index];
if(a_fabs(diff)>=a_prec) return false;
}
return true;
}
vec3<T> _cross(const vec3<T>& aV) const {
//not effective.
return vec3<T>(m_data[1] * aV.m_data[2] - m_data[2] * aV.m_data[1],
m_data[2] * aV.m_data[0] - m_data[0] * aV.m_data[2],
m_data[0] * aV.m_data[1] - m_data[1] * aV.m_data[0]);
}
bool divide(const T& a_T) {
if(a_T==T()) return false;
m_data[0] /= a_T;
@@ -175,6 +194,7 @@ public:
m_data[2] -= a2;
}
/*
bool cos_angle(const vec3& a_v,T& a_cos) const {
//WARNING : if ret false, a_cos is not set.
if(length()==T()) return false;
@@ -183,21 +203,22 @@ public:
return true;
}
bool theta_phi(T& a_theta,T& a_phi) const {
*/
bool theta_phi(T& a_theta,T& a_phi,T(*a_sqrt)(T),T(*a_atan2)(T,T)) const {
//WARNING : if ret false, a_theta, a_phi are not set.
if(length()==T()) return false;
a_phi = (T)::atan2(m_data[1],m_data[0]);
T xy = (T)::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
a_theta = (T)::atan2(xy,m_data[2]);
if(length(a_sqrt)==T()) return false;
a_phi = a_atan2(m_data[1],m_data[0]);
T xy = a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
a_theta = a_atan2(xy,m_data[2]);
return true;
}
public: //operators
T& operator[](unsigned int a_index) {
T& operator[](size_t a_index) {
//WARNING : no check on a_index.
return m_data[a_index];
}
const T& operator[](unsigned int a_index) const {
const T& operator[](size_t a_index) const {
//WARNING : no check on a_index.
return m_data[a_index];
}
@@ -241,6 +262,7 @@ public: //for inlib/sg/sf_vec
typedef unsigned int size_type;
size_type size() const {return 3;}
const T* data() const {return m_data;}
size_type data_size() const {return 3;} //for eqT.
public: //for iv2sg
const T* getValue() const {return m_data;}
void setValue(const T& a0,const T& a1,const T& a2) {
@@ -296,30 +318,69 @@ template <class T>
inline const T* get_data(const vec3<T>& a_v) {return a_v.data();}
template <class T>
inline void normal(const vec3<T>& a_p0,const vec3<T>& a_p1,const vec3<T>& a_p2,vec3<T>& a_nm) {
a_nm = (a_p1-a_p0).cross(a_p2-a_p1);
a_nm.normalize();
inline void normal(const vec3<T>& a_p0,const vec3<T>& a_p1,const vec3<T>& a_p2,vec3<T>& a_nm,
vec3<T>& a_tmp_1,vec3<T>& a_tmp_2,T(*a_sqrt)(T)) {
// Used to optimize sg::bin().
//(a_p1-a_p0).cross(a_p2-a_p1,a_nm);
a_tmp_1 = a_p1;
a_tmp_1.subtract(a_p0);
a_tmp_2 = a_p2;
a_tmp_2.subtract(a_p1);
a_tmp_1.cross(a_tmp_2,a_nm);
a_nm.normalize(a_sqrt);
}
template <class T>
inline vec3<T> direction(const vec3<T>& a_p0,
const vec3<T>& a_p1,
const vec3<T>& a_p2) {
/*
template <class VEC3>
inline void normal(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,VEC3& a_nm) {
VEC3 tmp1,tmp2;
normal(a_p0,a_p1,a_p2,a_nm,tmp1,tmp2);
}
*/
template <class VEC3>
inline void direction(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,VEC3& a_value) {
// Orientation is computed by taking (p1 - p0) x (p2 - p0)
vec3<T> P = a_p1;
VEC3 P = a_p1;
P.subtract(a_p0);
vec3<T> P2 = a_p2;
VEC3 P2 = a_p2;
P2.subtract(a_p0);
return P.cross(P2);
P.cross(P2,a_value);
}
template <class VEC3>
inline void area(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,typename VEC3::elem_t& a_value,
VEC3& a_tmp_1,VEC3& a_tmp_2,VEC3& a_tmp_3) {
// area of the triangle (a_p0,a_p1,a_p2)
typedef typename VEC3::elem_t T;
a_tmp_1 = a_p1;
a_tmp_1.subtract(a_p0);
a_tmp_2 = a_p2;
a_tmp_2.subtract(a_p1);
a_tmp_1.cross(a_tmp_2,a_tmp_3);
a_value = a_tmp_3.length()/T(2);
}
template <class VEC3>
inline void area(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,typename VEC3::elem_t& a_value) {
VEC3 tmp1,tmp2,tmp3;
area(a_p0,a_p1,a_p2,a_value,tmp1,tmp2,tmp3);
}
template <class T>
inline vec3<T> direction(const T& a_0_x,const T& a_0_y,const T& a_0_z,
const T& a_1_x,const T& a_1_y,const T& a_1_z,
const T& a_2_x,const T& a_2_y,const T& a_2_z) {
return direction(vec3<T>(a_0_x,a_0_y,a_0_z),
vec3<T>(a_1_x,a_1_y,a_1_z),
vec3<T>(a_2_x,a_2_y,a_2_z));
inline void direction(const T& a_0_x,const T& a_0_y,const T& a_0_z,
const T& a_1_x,const T& a_1_y,const T& a_1_z,
const T& a_2_x,const T& a_2_y,const T& a_2_z,vec3<T>& a_value) {
direction(vec3<T>(a_0_x,a_0_y,a_0_z),
vec3<T>(a_1_x,a_1_y,a_1_z),
vec3<T>(a_2_x,a_2_y,a_2_z),a_value);
}
}
@@ -6,25 +6,27 @@
#include "vec3"
#include "../S_STRING"
#include <cmath>
namespace tools {
class vec3d : public vec3<double> {
typedef vec3<double> parent;
public:
TOOLS_SCLASS(tools::vec3d) //for stype()
public:
vec3d():vec3<double>(){}
vec3d(const double a_vec[3]):vec3<double>(a_vec){}
vec3d(double a0,double a1,double a2):vec3<double>(a0,a1,a2){}
vec3d():parent(){}
vec3d(const double a_vec[3]):parent(a_vec){}
vec3d(double a0,double a1,double a2):parent(a0,a1,a2){}
virtual ~vec3d() {}
public:
vec3d(const vec3d& a_from):vec3<double>(a_from){}
vec3d(const vec3d& a_from):parent(a_from){}
vec3d& operator=(const vec3d& a_from){
vec3<double>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
vec3d(const vec3<double>& a_from):vec3<double>(a_from){}
vec3d(const parent& a_from):parent(a_from){}
public: //operators
vec3d operator*(double a_v) const {
@@ -63,6 +65,9 @@ public: //operators
vec3d operator-() const {
return vec3d(-m_data[0],-m_data[1],-m_data[2]);
}
public:
double length() const {return parent::length(::sqrt);}
double normalize() {return parent::normalize(::sqrt);}
private:static void check_instantiation() {vec3d v(0,0,0);v.set_value(1,1,1);}
};
@@ -6,25 +6,27 @@
#include "vec3"
#include "../S_STRING"
#include <cmath> //sqrt
namespace tools {
class vec3f : public vec3<float> {
typedef vec3<float> parent;
public:
TOOLS_SCLASS(tools::vec3f) //for stype()
public:
vec3f():vec3<float>(){}
vec3f(const float a_vec[3]):vec3<float>(a_vec){}
vec3f(float a0,float a1,float a2):vec3<float>(a0,a1,a2){}
vec3f():parent(){}
vec3f(const float a_vec[3]):parent(a_vec){}
vec3f(float a0,float a1,float a2):parent(a0,a1,a2){}
virtual ~vec3f() {}
public:
vec3f(const vec3f& a_from):vec3<float>(a_from){}
vec3f(const vec3f& a_from):parent(a_from){}
vec3f& operator=(const vec3f& a_from){
vec3<float>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
vec3f(const vec3<float>& a_from):vec3<float>(a_from){}
vec3f(const parent& a_from):parent(a_from){}
public: //operators
vec3f operator*(float a_v) const {
@@ -63,7 +65,26 @@ public: //operators
vec3f operator-() const {
return vec3f(-m_data[0],-m_data[1],-m_data[2]);
}
public:
#define TOOLS_VEC3F_MORE_PREC
#ifdef TOOLS_VEC3F_MORE_PREC
float length() const {
return float(::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]));
}
float normalize() {
float norme = length();
if(!norme) return 0;
divide(norme);
return norme;
}
#else
float length() const {return parent::length(::sqrtf);}
float normalize() {return parent::normalize(::sqrtf);}
#endif
bool theta_phi(float& a_theta,float& a_phi) const {
return parent::theta_phi(a_theta,a_phi,::sqrtf,::atan2f);
}
public: //iv2sg
bool equals(const vec3f& a_v,const float a_epsil) const {
//if(a_epsil<0.0f))
@@ -87,6 +108,30 @@ inline vec3f operator*(float a_f,const vec3f& a_v) {
return res;
}
#define TOOLS_VEC3F_MORE_PREC
#ifdef TOOLS_VEC3F_MORE_PREC
inline void normal(const vec3f& a_p0,const vec3f& a_p1,const vec3f& a_p2,vec3f& a_nm,
vec3f& a_tmp_1,vec3f& a_tmp_2) {
// Used to optimize sg::bin().
//(a_p1-a_p0).cross(a_p2-a_p1,a_nm);
a_tmp_1 = a_p1;
a_tmp_1.subtract(a_p0);
a_tmp_2 = a_p2;
a_tmp_2.subtract(a_p1);
a_tmp_1.cross(a_tmp_2,a_nm);
a_nm.normalize();
}
#else
inline void normal(const vec3f& a_p0,const vec3f& a_p1,const vec3f& a_p2,vec3f& a_nm,
vec3f& a_tmp_1,vec3f& a_tmp_2) {
normal<float>(a_p0,a_p1,a_p2,a_nm,a_tmp_1,a_tmp_2,::sqrtf);
}
#endif
}
#include <vector>
+14 -15
View File
@@ -4,10 +4,10 @@
#ifndef tools_vec4
#define tools_vec4
#include <cmath> //sqrt
#include <cstddef> //size_t
#ifdef TOOLS_MEM
#include "mem"
#include "../mem"
#endif
namespace tools {
@@ -15,6 +15,7 @@ namespace tools {
template <class T>
class vec4 {
#ifdef TOOLS_MEM
public:
static const std::string& s_class() {
static const std::string s_v("tools::vec4");
return s_v;
@@ -24,6 +25,7 @@ protected:
static T zero() {return T();}
static T minus_one() {return T(-1);}
public:
typedef T elem_t;
unsigned int dimension() const {return 4;}
public:
vec4(){
@@ -78,10 +80,10 @@ public:
return *this;
}
public:
T v0() const { return m_data[0];}
T v1() const { return m_data[1];}
T v2() const { return m_data[2];}
T v3() const { return m_data[3];}
const T& v0() const { return m_data[0];}
const T& v1() const { return m_data[1];}
const T& v2() const { return m_data[2];}
const T& v3() const { return m_data[3];}
void v0(const T& a_value) { m_data[0] = a_value;}
void v1(const T& a_value) { m_data[1] = a_value;}
@@ -117,15 +119,12 @@ public:
return true;
}
T length() const {
return (T)::sqrt(m_data[0]*m_data[0]
+m_data[1]*m_data[1]
+m_data[2]*m_data[2]
+m_data[3]*m_data[3]);
T length(T(*a_sqrt)(T)) const {
return a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]+m_data[3]*m_data[3]);
}
T normalize() {
T norme = length();
T normalize(T(*a_sqrt)(T)) {
T norme = length(a_sqrt);
if(norme==T()) return T();
divide(norme);
return norme;
@@ -219,11 +218,11 @@ public:
}
public: //operators
T& operator[](unsigned int a_index) {
T& operator[](size_t a_index) {
//WARNING : no check on a_index.
return m_data[a_index];
}
const T& operator[](unsigned int a_index) const {
const T& operator[](size_t a_index) const {
//WARNING : no check on a_index.
return m_data[a_index];
}
@@ -6,22 +6,24 @@
#include "vec4"
#include "../S_STRING"
#include <cmath>
namespace tools {
class vec4f : public vec4<float> {
typedef vec4<float> parent;
public:
TOOLS_SCLASS(tools::vec4f) //for stype()
public:
vec4f():vec4<float>() {}
vec4f(const float a_vec[4]):vec4<float>(a_vec) {}
vec4f(const float& a0,const float& a1,const float& a2,const float& a3)
:vec4<float>(a0,a1,a2,a3){}
vec4f():parent() {}
vec4f(const float a_vec[4]):parent(a_vec) {}
vec4f(const float& a0,const float& a1,const float& a2,const float& a3,bool a_inc = true)
:parent(a0,a1,a2,a3,a_inc){}
virtual ~vec4f() {}
public:
vec4f(const vec4f& a_from):vec4<float>(a_from){}
vec4f(const vec4f& a_from):parent(a_from){}
vec4f& operator=(const vec4f& a_from){
vec4<float>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
public: //operators
@@ -60,6 +62,22 @@ public: //operators
vec4f operator-() const {
return vec4f(-m_data[0],-m_data[1],-m_data[2],-m_data[3]);
}
public:
#define TOOLS_VEC4F_MORE_PREC
#ifdef TOOLS_VEC4F_MORE_PREC
float length() const {
return float(::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]+m_data[3]*m_data[3]));
}
float normalize() {
float norme = length();
if(!norme) return 0;
divide(norme);
return norme;
}
#else
float length() const {return parent::length(::sqrtf);}
float normalize() {return parent::normalize(::sqrtf);}
#endif
};
}
@@ -12,7 +12,7 @@ namespace tools {
class long_out : public std::string {
typedef std::string parent;
public:
long_out(const long& a_value) {
long_out(long a_value) {
char s[512];
snpf(s,sizeof(s),"%ld",a_value);
parent::operator+=(s);
+27 -2
View File
@@ -18,8 +18,14 @@ inline double pi() {return 3.1415926535897931160E0;}
inline double two_pi() {return 6.2831853071795862320E0;}
inline double half_pi() {return 1.5707963267948965580E0;}
inline double deg2rad() {return pi()/180.0;}
inline double rad2deg() {return 180.0/pi();}
inline double deg2rad() {
static const double s_v = pi()/180.0;
return s_v;
}
inline double rad2deg() {
static const double s_v = 180.0/pi();
return s_v;
}
// for Lib/ExpFunc.
inline bool in_domain_all(double){return true;}
@@ -34,8 +40,27 @@ inline bool in_domain_acos(double a_x){
return true;
}
/*
inline double angle_modulo(double a_angle) {
int64 div = a_angle/two_pi();
double rest = a_angle - div*two_pi();
if(rest<0) rest += two_pi();
return rest;
}
*/
}
//#include "power"
#include <cmath>
namespace tools {
inline double dconj(const double& a_x) {return a_x;}
inline double dfabs(const double& a_x) {return ::fabs(a_x);} //if passing a_fabs(const T&).
inline double dsqrt(const double& a_x) {return ::sqrt(a_x);}
}
#endif
+31 -12
View File
@@ -4,8 +4,6 @@
#ifndef tools_mathf
#define tools_mathf
#include <cmath>
namespace tools {
//have : static const fpi = (float)3.1415926535897931160E0; ???
@@ -14,6 +12,33 @@ inline float fpi() {return (float)3.1415926535897931160E0;}
inline float ftwo_pi() {return (float)6.2831853071795862320E0;}
inline float fhalf_pi() {return (float)1.5707963267948965580E0;}
//inline float fdeg2rad() {return fpi()/180.0f;} //0.0174f
//inline float frad2deg() {return 180.0f/fpi();}
inline float fdeg2rad() {
static const float s_v = fpi()/180.0f; //0.0174f
return s_v;
}
inline float frad2deg() {
static const float s_v = 180.0f/fpi();
return s_v;
}
inline int fround(float a_x) {
// From CoinGL/src/base/SbViewportRegion.cpp.
if (a_x == (float) (int(a_x))) return int(a_x);
else return (a_x>0.0f) ? int(a_x+0.5f) : -int(0.5f-a_x);
}
inline float fstep(float a_x) {return a_x<0.0f?0.0f:1.0f;}
}
#include <cmath>
namespace tools {
inline float fcos(float x) {return (float)::cos(double(x));}
inline float fsin(float x) {return (float)::sin(double(x));}
inline float facos(float x) {return (float)::acos(double(x));}
@@ -27,19 +52,13 @@ inline float fexp(float x) {return (float)::exp(double(x));}
inline float flog(float x) {return (float)::log(double(x));}
inline float flog10(float x) {return (float)::log10(double(x));}
inline float ffloor(float x) {return (float)::floor(double(x));}
inline float ffabs(float x) {return (float)::fabs(double(x));}
inline float fceil(float x) {return (float)::ceil(double(x));}
inline float fdeg2rad() {return fpi()/180.0f;} //0.0174f
inline float frad2deg() {return 180.0f/fpi();}
inline float fcosh(float x) {return (float)::cosh(double(x));}
inline float fsinh(float x) {return (float)::sinh(double(x));}
inline int fround(float a_x) {
// From CoinGL/src/base/SbViewportRegion.cpp.
if (a_x == (float) (int(a_x))) return int(a_x);
else return (a_x>0.0f) ? int(a_x+0.5f) : -int(0.5f-a_x);
}
inline float ffabs(float x) {return (float)::fabs(double(x));}
inline float fstep(float a_x) {return a_x<0.0f?0.0f:1.0f;}
inline float ffabsc(const float& x) {return (float)::fabs(double(x));}
}
+4 -4
View File
@@ -41,17 +41,17 @@ public:
}
}
static void decrement(const char* a_class){
counter()--;
static void decrement(const char* a_class,unsigned int a_num = 1){
counter() -= a_num;
if(check_by_class()) {
mem_list::iterator it;
for(it=list().begin();it!=list().end();++it) {
if(!::strcmp((*it).first.c_str(),a_class)) {
(*it).second--;
(*it).second -= a_num;
return;
}
}
list().push_back(std::pair<std::string,int>(std::string(a_class),-1));
list().push_back(std::pair<std::string,int>(std::string(a_class),-int(a_num)));
}
}
@@ -13,10 +13,17 @@ extern "C" {
typedef void* MPI_Comm;
typedef void* MPI_Datatype;
#define MPI_UNSIGNED 0
#define MPI_DOUBLE 0
#define MPI_UNSIGNED_CHAR 0
#define MPI_CHAR 0
#define MPI_UNSIGNED 0
#define MPI_DOUBLE 0
#define MPI_UNSIGNED_CHAR 0
#define MPI_CHAR 0
#define MPI_LONG 0
#define MPI_INT 0
#define MPI_UNSIGNED_LONG 0
#define MPI_LONG_LONG 0
#define MPI_UNSIGNED_LONG_LONG 0
#define MPI_ANY_SOURCE 0
#define MPI_SUCCESS 1
@@ -32,7 +39,11 @@ inline int MPI_Unpack(const void*,int,int*,void*,int,MPI_Datatype,MPI_Comm){retu
/// to pass h2mpi, hs2mpi /////////////////////////////////////
///////////////////////////////////////////////////////////////
typedef int MPI_Status;
struct _MPI_Status {
int MPI_SOURCE;
int MPI_TAG;
};
typedef _MPI_Status MPI_Status;
inline int MPI_Probe(int,int,MPI_Comm,MPI_Status*){return 0;}
inline int MPI_Get_count(const MPI_Status*,MPI_Datatype,int*){return 0;}
@@ -264,5 +264,3 @@ protected:
}}
#endif
//exlib_build_use inlib mpi
@@ -0,0 +1,198 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_mpi_pntuple
#define tools_mpi_pntuple
// pntuple = for parallel ntupling.
#include <tools/wroot/base_pntuple>
#include <tools/S_STRING>
#include <tools/impi>
namespace tools {
namespace mpi {
class pntuple : public tools::wroot::base_pntuple {
typedef tools::wroot::base_pntuple parent;
public:
static tools::uint32 protocol_basket() {return 1;}
static tools::uint32 protocol_end_fill() {return 2;}
public:
pntuple(std::ostream& a_out,
bool a_byte_swap,tools::uint32 a_compression,
const std::string& a_name,const std::string& a_title,bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_name,a_title,a_verbose)
{}
pntuple(std::ostream& a_out,bool a_byte_swap,tools::uint32 a_compression,tools::wroot::seek a_seek_directory,
const std::vector<tools::uint32>& a_basket_sizes,const tools::ntuple_booking& a_bkg,bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_basket_sizes,a_bkg,a_verbose)
{}
virtual ~pntuple() {}
protected:
pntuple(const pntuple& a_from):parent(a_from){}
pntuple& operator=(const pntuple& a_from){parent::operator=(a_from);return *this;}
protected:
class basket_add : public virtual tools::wroot::branch::iadd_basket {
typedef tools::wroot::branch::iadd_basket parent;
public:
virtual bool add_basket(tools::wroot::basket& a_basket) {
m_mpi.pack_reset();
if(!m_mpi.pack(protocol_basket())) return false;
if(!m_mpi.pack(m_icol)) return false;
if(!m_mpi.spack(a_basket.object_name())) return false;
if(!m_mpi.spack(a_basket.object_title())) return false;
if(!m_mpi.pack(a_basket.last())) return false;
if(!m_mpi.pack(a_basket.nev_buf_size())) return false;
if(!m_mpi.pack(a_basket.nev())) return false;
if(a_basket.entry_offset()) {
if(!m_mpi.bpack(true)) return false;
if(!m_mpi.pack(a_basket.nev_buf_size(),a_basket.entry_offset())) return false;
} else {
if(!m_mpi.bpack(false)) return false;
}
if(a_basket.displacement()) {
if(!m_mpi.bpack(true)) return false;
if(!m_mpi.pack(a_basket.nev_buf_size(),a_basket.displacement())) return false;
} else {
if(!m_mpi.bpack(false)) return false;
}
if(!m_mpi.pack(a_basket.datbuf().length(),a_basket.datbuf().buf())) return false;
if(!m_mpi.send_buffer(m_dest,m_tag)) return false;
return true;
}
public:
basket_add(file& a_file,tools::impi& a_mpi,int a_dest,int a_tag,tools::uint32 a_icol)
:m_file(a_file),m_mpi(a_mpi),m_dest(a_dest),m_tag(a_tag),m_icol(a_icol)
{}
protected:
basket_add(const basket_add& a_from):parent()
,m_file(a_from.m_file),m_mpi(a_from.m_mpi),m_dest(a_from.m_dest),m_tag(a_from.m_tag),m_icol(a_from.m_icol)
{}
basket_add& operator=(const basket_add& a_from){
m_file = a_from.m_file;
m_dest = a_from.m_dest;
m_tag = a_from.m_tag;
m_icol = a_from.m_icol;
return *this;
}
protected:
file m_file;
tools::impi& m_mpi;
int m_dest;
int m_tag;
tools::uint32 m_icol;
};
public:
bool add_row(tools::impi& a_mpi,int a_dest,int a_tag) {
if(m_cols.empty()) return false;
tools_vforit(tools::wroot::icol*,m_cols,it) (*it)->add();
tools::uint32 icol = 0;
tools_vforit(tools::wroot::icol*,m_cols,it) {
basket_add _badd(m_file,a_mpi,a_dest,a_tag,icol);icol++;
if(!(*it)->get_branch()->pfill(_badd)) return false;
}
tools_vforit(tools::wroot::icol*,m_cols,it) (*it)->set_def();
return true;
}
protected:
void end_leaves(std::vector<tools::uint32>& a_lengths,std::vector<int>& a_mxs) const {
a_lengths.clear();
a_mxs.clear();
tools_vforcit(tools::wroot::icol*,m_cols,it) {
tools::wroot::base_leaf* _leaf = (*it)->get_leaf();
tools::wroot::leaf_string* _leafs = _leaf?tools::id_cast<tools::wroot::base_leaf,tools::wroot::leaf_string>(*_leaf):0;
if(_leafs) {
a_lengths.push_back(_leafs->length());
a_mxs.push_back(_leafs->get_max());
}
}
}
public:
bool end_fill(tools::impi& a_mpi,int a_dest,int a_tag) {
tools::uint32 icol = 0;
tools_vforit(tools::wroot::icol*,m_cols,it) {
basket_add _badd(m_file,a_mpi,a_dest,a_tag,icol);icol++;
if(!(*it)->get_branch()->end_pfill(_badd)) return false;
}
std::vector<tools::uint32> lengths;
std::vector<int> mxs;
end_leaves(lengths,mxs);
a_mpi.pack_reset();
if(!a_mpi.pack(protocol_end_fill())) return false;
if(!a_mpi.vpack(lengths)) return false;
if(!a_mpi.vpack(mxs)) return false;
if(!a_mpi.send_buffer(a_dest,a_tag)) return false;
return true;
}
protected:
};
inline tools::wroot::basket* get_basket(std::ostream& a_out,tools::impi& a_mpi,
bool a_byte_swap,tools::wroot::seek a_seek_directory,
tools::uint32 a_basket_size) {
std::string oname;
if(!a_mpi.sunpack(oname)) return 0;
std::string otitle;
if(!a_mpi.sunpack(otitle)) return 0;
tools::uint32 last,nev_buf_size,nev;
if(!a_mpi.unpack(last)) return 0;
if(!a_mpi.unpack(nev_buf_size)) return 0;
if(!a_mpi.unpack(nev)) return 0;
int* entry_offset = 0;
{bool not_null;
if(!a_mpi.bunpack(not_null)) return 0;
if(not_null) {
tools::uint32 n;
if(!a_mpi.unpack(n,entry_offset)) return 0;
}}
int* displacement = 0;
{bool not_null;
if(!a_mpi.bunpack(not_null)) return 0;
if(not_null) {
tools::uint32 n;
if(!a_mpi.unpack(n,displacement)) return 0;
}}
tools::uint32 _size;
char* _buffer;
if(!a_mpi.unpack(_size,_buffer)) {a_out << "unpack(buffer) failed."<< std::endl;return 0;}
// wbasket fields set at file writing :
//m_buf_size,m_buffer,m_nbytes,m_object_size,m_date,m_cycle,m_seek_key
//::printf("debug : col = %d, %s, %s, %lu\n",
// icol,rbasket.object_class().c_str(),rbasket.object_name().c_str(),rbasket.seek_key());
tools::wroot::basket* basket = new tools::wroot::basket(a_out,a_byte_swap,a_seek_directory,
oname,otitle,"TBasket",a_basket_size,
false/*verbose*/);
basket->datbuf().write_fast_array(_buffer,_size);
basket->set_nev(last,nev_buf_size,nev,entry_offset,displacement);
delete [] _buffer;
return basket;
}
}}
#endif
@@ -0,0 +1,70 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_mpi_wait_buffer
#define tools_mpi_wait_buffer
#ifdef TOOLS_USE_NATIVE_MPI
#include <mpi.h>
#else
#include "dummy_mpi.h"
#endif
#include <ostream>
namespace tools {
namespace mpi {
inline bool wait_buffer(std::ostream& a_out,int a_rank,int a_src,int a_tag,const MPI_Comm& a_comm,
int& a_buffer_size,char*& a_buffer,int& a_probe_src,bool a_verbose = false) {
a_buffer = 0;
a_buffer_size = 0;
a_probe_src = -1;
MPI_Status status;
if(::MPI_Probe(a_src,a_tag,a_comm,&status)!=MPI_SUCCESS) {
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Probe : failed." << std::endl;
return false;
}
if(::MPI_Get_count(&status,MPI_CHAR,&a_buffer_size)!=MPI_SUCCESS) {
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Get_count : failed." << std::endl;
a_buffer_size = 0;
return false;
}
a_probe_src = status.MPI_SOURCE;
if(!a_buffer_size) {
a_out << "exlb::mpi::wait_buffer : MPI_Get_count returns zero data." << std::endl;
a_probe_src = -1;
return false;
}
if(a_verbose) a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : get_count " << a_buffer_size << std::endl;
a_buffer = new char[a_buffer_size];
if(!a_buffer) {
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : can't alloc buffer of size " << a_buffer_size << std::endl;
a_buffer_size = 0;
a_probe_src = -1;
return false;
}
if(::MPI_Recv(a_buffer,a_buffer_size,MPI_CHAR,status.MPI_SOURCE,status.MPI_TAG,a_comm,&status)!=MPI_SUCCESS) {
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Recv : failed." << std::endl;
a_buffer_size = 0;
delete [] a_buffer;
a_buffer = 0;
a_probe_src = -1;
return false;
}
if(a_verbose) a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : unpack data ..." << std::endl;
return true;
}
}}
#endif
@@ -72,6 +72,4 @@ protected:
}}
//exlib_build_use inlib mpi
#endif
+162 -16
View File
@@ -12,7 +12,6 @@
#include <tools/impi>
#include <tools/vdata>
#include <tools/typedefs>
#include <tools/realloc>
#include <tools/mnmx>
#include <ostream>
@@ -21,13 +20,34 @@
#include <tools/mem>
#endif
// the below must be in sync with inlib/typedefs
#ifdef _MSC_VER
//typedef __int64 int64;
//typedef unsigned __int64 uint64;
#define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG_LONG
#define TOOLS_MPI_INT64 MPI_LONG_LONG
#elif defined(_LP64)
// 64 Bit Platforms
//typedef long int64;
//typedef unsigned long uint64;
#define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG
#define TOOLS_MPI_INT64 MPI_LONG
#else
// 32-Bit Platforms
//typedef long long int64;
//typedef unsigned long long uint64;
#define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG_LONG
#define TOOLS_MPI_INT64 MPI_LONG_LONG
#endif
namespace tools {
namespace mpi {
class wrmpi : public virtual tools::impi {
typedef tools::impi parent;
protected:
public:
typedef unsigned int num_t;
protected:
static const std::string& s_class() {
static const std::string s_v("tools::mpi::wrmpi");
return s_v;
@@ -43,6 +63,26 @@ public: //inlib::mpi::impi
m_pos += sz;
return true;
}
virtual bool pack(tools::uint64 a_val) {
tools::uint32 sz = tools::uint32(sizeof(tools::uint64));
if(m_pos+sz>m_max) {if(!expand2(m_size+sz)) return false;}
if(::MPI_Pack(&a_val,1,TOOLS_MPI_UINT64,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Pack(uint64) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
virtual bool pack(tools::int64 a_val) {
tools::uint32 sz = tools::uint32(sizeof(tools::int64));
if(m_pos+sz>m_max) {if(!expand2(m_size+sz)) return false;}
if(::MPI_Pack(&a_val,1,TOOLS_MPI_INT64,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Pack(int64) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
virtual bool pack(double a_val) {
tools::uint32 sz = tools::uint32(sizeof(double));
if(m_pos+sz>m_max) {if(!expand2(m_size+sz)) return false;}
@@ -95,13 +135,27 @@ public: //inlib::mpi::impi
m_pos += sz;
return true;
}
virtual bool vpack(const std::vector<int>& a_v) {
if(!pack((num_t)a_v.size())) return false;
tools::uint32 sz = (tools::uint32)(a_v.size()*sizeof(int));
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
if(::MPI_Pack(const_cast<int*>(tools::vec_data(a_v)),a_v.size(),MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#else
if(::MPI_Pack(tools::vec_data(a_v),a_v.size(),MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#endif
m_out << "tools::mpi::wrmpi : MPI_Pack(std::vector<int>) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
virtual bool vpack(const std::vector<double>& a_v) {
if(!pack((num_t)a_v.size())) return false;
tools::uint32 sz = (tools::uint32)(a_v.size()*sizeof(double));
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
if(::MPI_Pack(const_cast<double*>(tools::vec_data(a_v)),a_v.size(),
MPI_DOUBLE,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
if(::MPI_Pack(const_cast<double*>(tools::vec_data(a_v)),a_v.size(),MPI_DOUBLE,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#else
if(::MPI_Pack(tools::vec_data(a_v),a_v.size(),MPI_DOUBLE,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#endif
@@ -111,6 +165,37 @@ public: //inlib::mpi::impi
m_pos += sz;
return true;
}
virtual bool pack(tools::uint32 a_size,const char* a_buffer) {
if(!pack((num_t)a_size)) return false;
tools::uint32 sz = (tools::uint32)(a_size*sizeof(char));
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
if(::MPI_Pack(const_cast<char*>(a_buffer),a_size,MPI_CHAR,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#else
if(::MPI_Pack(a_buffer,a_size,MPI_CHAR,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#endif
m_out << "tools::mpi::wrmpi : MPI_Pack(char*) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
virtual bool pack(tools::uint32 a_size,const int* a_buffer) {
if(!pack((num_t)a_size)) return false;
tools::uint32 sz = (tools::uint32)(a_size*sizeof(int));
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
if(::MPI_Pack(const_cast<int*>(a_buffer),a_size,MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#else
if(::MPI_Pack(a_buffer,a_size,MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#endif
m_out << "tools::mpi::wrmpi : MPI_Pack(int*) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
public: //inlib::mpi::impi
virtual bool unpack(unsigned int& a_val) {
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,MPI_UNSIGNED,m_comm)!=MPI_SUCCESS) {
@@ -120,6 +205,22 @@ public: //inlib::mpi::impi
}
return true;
}
virtual bool unpack(tools::uint64& a_val) {
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,TOOLS_MPI_UINT64,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(uint64) failed." << std::endl;
a_val = 0;
return false;
}
return true;
}
virtual bool unpack(tools::int64& a_val) {
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,TOOLS_MPI_INT64,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(int64) failed." << std::endl;
a_val = 0;
return false;
}
return true;
}
virtual bool unpack(double& a_val) {
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,MPI_DOUBLE,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(double) failed." << std::endl;
@@ -150,6 +251,17 @@ public: //inlib::mpi::impi
}
return true;
}
virtual bool vunpack(std::vector<int>& a_v) {
num_t num;
if(!unpack(num)) {a_v.clear();return false;}
a_v.resize(num);
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,tools::vec_data(a_v),a_v.size(),MPI_INT,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(std::vector<int>) failed." << std::endl;
a_v.clear();
return false;
}
return true;
}
virtual bool vunpack(std::vector<double>& a_v) {
num_t num;
if(!unpack(num)) {a_v.clear();return false;}
@@ -172,7 +284,52 @@ public: //inlib::mpi::impi
}
return true;
}
virtual bool unpack(tools::uint32& a_size,char*& a_buffer) {
num_t num;
if(!unpack(num)) {a_size = 0;a_buffer = 0;return false;}
a_buffer = new char[num];
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,a_buffer,num,MPI_CHAR,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(char*) failed." << std::endl;
delete [] a_buffer;
a_size = 0;
a_buffer = 0;
return false;
}
a_size = num;
return true;
}
virtual bool unpack(tools::uint32& a_size,int*& a_buffer) {
num_t num;
if(!unpack(num)) {a_size = 0;a_buffer = 0;return false;}
a_buffer = new int[num];
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,a_buffer,num,MPI_INT,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(int*) failed." << std::endl;
delete [] a_buffer;
a_size = 0;
a_buffer = 0;
return false;
}
a_size = num;
return true;
}
virtual void pack_reset() {
delete [] m_buffer;
m_size = 128;
m_buffer = new char[m_size];
//if(!m_buffer) {}
m_max = m_buffer+m_size;
m_pos = m_buffer;
m_ipos = 0; //IMPORTANT
}
virtual bool send_buffer(int a_dest,int a_tag) { // used in tools/mpi/pntuple.
if(::MPI_Send(m_buffer,m_ipos,MPI_CHAR,a_dest,a_tag,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi::send_buffer : MPI_Send() failed for rank destination " << a_dest << "." << std::endl;
return false;
}
return true;
}
public:
wrmpi(std::ostream& a_out,const MPI_Comm& a_comm,tools::uint32 a_size = 128) // we expect a_size!=0
:m_out(a_out)
@@ -236,15 +393,7 @@ public:
#else
const char* buffer() const {return m_buffer;}
#endif
void pack_reset() {
delete [] m_buffer;
m_size = 128;
m_buffer = new char[m_size];
//if(!m_buffer) {}
m_max = m_buffer+m_size;
m_pos = m_buffer;
m_ipos = 0; //IMPORTANT
}
protected:
bool expand2(tools::uint32 a_new_size) {return expand(tools::mx<tools::uint32>(2*m_size,a_new_size));} //CERN-ROOT logic.
@@ -280,6 +429,3 @@ protected:
}}
#endif
//exlib_build_use inlib mpi
@@ -36,6 +36,7 @@ public:
const std::string& name() const {return m_name;}
cid cls_id() const {return m_cid;}
void* user_obj() const {return m_user_obj;}
void set_user_obj(void* a_obj) {m_user_obj = a_obj;}
protected:
std::string m_name;
cid m_cid;
@@ -74,6 +75,7 @@ public:
const std::string& name() const {return m_name;}
const std::string& title() const {return m_title;}
const std::vector<column_booking>& columns() const {return m_columns;}
std::vector<column_booking>& columns() {return m_columns;}
void set_name(const std::string& a_s) {m_name = a_s;}
void set_title(const std::string& a_s) {m_title = a_s;}
+23 -8
View File
@@ -8,18 +8,18 @@
namespace tools {
inline std::string suffix(const std::string& a_string,bool a_back = true) {
inline void suffix(const std::string& a_string,std::string& a_value,bool a_back = true) {
// If a_string = dir0/dir1/dir2/dir3/name.xxx
// return xxx
// a_value = xxx
std::string::size_type pos = a_back?a_string.rfind('.'):a_string.find('.');
if(pos==std::string::npos) return "";
if(pos==std::string::npos) {a_value.clear();return;}
pos++;
return a_string.substr(pos,a_string.size()-pos);
a_value = a_string.substr(pos,a_string.size()-pos);
}
inline std::string nosuffix(const std::string& a_string,bool a_back = true){
inline void nosuffix(const std::string& a_string,std::string& a_value,bool a_back = true){
// If a_string = dir0/dir1/dir2/dir3/name.xxx
// return name
// a_value = name
// Start searching after the last / (or last \ for Windows).
std::string::size_type pos = a_string.rfind('/');
if(pos==std::string::npos) pos = a_string.rfind('\\');
@@ -27,8 +27,11 @@ inline std::string nosuffix(const std::string& a_string,bool a_back = true){
else pos++;
std::string s = a_string.substr(pos,a_string.size()-pos);
std::string::size_type dot_pos = a_back?s.rfind('.'):s.find('.');
if(dot_pos==std::string::npos) return s;
return s.substr(0,dot_pos);
if(dot_pos==std::string::npos) {
a_value = s;
} else {
a_value = s.substr(0,dot_pos);
}
}
inline void base_name(const std::string& a_path,std::string& a_value) {
@@ -57,6 +60,18 @@ inline void base_name(const std::string& a_path,std::string& a_value) {
a_value = a_path.substr(pos,a_path.size()-pos);
}
inline std::string suffix(const std::string& a_string,bool a_back = true) {
std::string value;
suffix(a_string,value,a_back);
return value;
}
inline std::string nosuffix(const std::string& a_string,bool a_back = true){
std::string value;
nosuffix(a_string,value,a_back);
return value;
}
inline std::string base_name(const std::string& a_path) { //deprecated.
std::string value;
base_name(a_path,value);
@@ -85,6 +85,125 @@ inline unsigned int tex_mem_limit() {
}}
///////////////////////////////////////////////////////////////////
/// backcomp : for OnX/source/Core/atat.cxx : /////////////////////
///////////////////////////////////////////////////////////////////
//NOTE : we avoid to have std includes here to be sure
// that in the below ifdef things come only from the compiler.
namespace tools {
inline const char* os() {
#if TARGET_OS_IPHONE
static const char s_s[] = "iOS";
#elif defined(ANDROID)
static const char s_s[] = "Android";
#elif defined(_WIN32)
static const char s_s[] = "Windows_NT";
#elif __APPLE__
static const char s_s[] = "Darwin";
#elif defined(__linux)
static const char s_s[] = "Linux";
#elif defined(__alpha)
static const char s_s[] = "OSF1";
#elif defined(__CYGWIN__)
static const char s_s[] = "CYGWIN";
#else
static const char s_s[] = "unknown";
#endif
return s_s;
}
inline const char* processor() {
#if defined(__GNUC__)
#if defined(__ppc__)
static const char s_s[] = "ppc";
#elif defined(__ppc64__)
static const char s_s[] = "ppc64";
#elif defined(__i386__)
static const char s_s[] = "i386";
#elif defined(__x86_64__)
static const char s_s[] = "x86_64";
#elif defined(__ia64__)
static const char s_s[] = "ia64";
#else
static const char s_s[] = "unknown";
#endif
#elif defined(_MSC_VER)
#if defined(_M_IX86)
static const char s_s[] = "ix86";
#elif defined(_M_X64)
static const char s_s[] = "x64";
#else
static const char s_s[] = "unknown";
#endif
#elif defined(__alpha)
static const char s_s[] = "alpha";
#else
static const char s_s[] = "unknown";
#endif
return s_s;
}
inline const char* compiler_name() {
#if defined(__clang__)
static const char s_s[] = "clang";
#elif defined(__GNUC__)
static const char s_s[] = "gcc";
#elif defined(_MSC_VER)
static const char s_s[] = "cl";
#elif defined(__alpha)
static const char s_s[] = "cxx";
#else
static const char s_s[] = "unknown";
#endif
return s_s;
}
}
#include "tosu" //does not bring any std include.
namespace tools {
inline char* compiler() {
static char s_s[128];
char* pos = s_s;
unsigned int l;
toss(compiler_name(),pos,l);pos += l;
#if defined(__clang__)
*pos++ = '_';
tosu<unsigned int>(__clang_major__,pos,l);pos += l;
tosu<unsigned int>(__clang_minor__,pos,l);pos += l;
tosu<unsigned int>(__clang_patchlevel__,pos,l);pos += l;
#elif defined(__GNUC__)
*pos++ = '_';
tosu<unsigned int>(__GNUC__,pos,l);pos += l;
tosu<unsigned int>(__GNUC_MINOR__,pos,l);pos += l;
tosu<unsigned int>(__GNUC_PATCHLEVEL__,pos,l);pos += l;
#elif defined(_MSC_VER)
*pos++ = '_';
tosu<unsigned int>(_MSC_VER,pos,l);pos += l;
//_mfc_
//tosu<unsigned int>(_MFC_VER,pos,l);pos += l;
#elif defined(__alpha)
#else
#endif
return s_s;
}
}
#endif
+59 -21
View File
@@ -4,14 +4,13 @@
#ifndef tools_randT
#define tools_randT
#include "cmathT"
#include "mathd"
namespace tools {
template <class FLAT,class REAL>
class rgauss {
typedef REAL(*math_func)(REAL); //for rootcint.
//public:
// typedef REAL value_t;
public:
rgauss(FLAT& a_flat,REAL a_mean = 0,REAL a_std_dev = 1)
:m_flat(a_flat),m_mean(a_mean),m_std_dev(a_std_dev){}
@@ -24,19 +23,18 @@ public:
return *this;
}
public:
REAL shoot() {
// Shoot random numbers according a
// rgaussian distribution of mean 0 and sigma 1.
REAL shoot(math_func a_sqrt,math_func a_log) const {
REAL v1,v2,r,fac;
do {
v1 = REAL(2) * m_flat.shoot() - REAL(1);
v2 = REAL(2) * m_flat.shoot() - REAL(1);
r = v1*v1 + v2*v2;
} while (r>REAL(1));
fac = _sqrt(-REAL(2)*_log(r)/r);
fac = a_sqrt(-REAL(2)*a_log(r)/r);
return (v2 * fac) * m_std_dev + m_mean;
}
FLAT& flat() {return m_flat;}
void set_seed(unsigned int a_seed) {m_flat.set_seed(a_seed);}
protected:
FLAT& m_flat;
REAL m_mean;
@@ -46,23 +44,19 @@ protected:
template <class FLAT,class REAL>
class rbw {
public:
rbw(FLAT& a_flat,REAL a_mean = 0,REAL a_gamma = 1)
:m_flat(a_flat),m_mean(a_mean),m_gamma(a_gamma){
_half_pi(m_half_pi);
}
rbw(FLAT& a_flat,REAL a_mean = 0,REAL a_gamma = 1):m_flat(a_flat),m_mean(a_mean),m_gamma(a_gamma){}
virtual ~rbw(){}
public:
rbw(const rbw& a_from):m_flat(a_from.m_flat),m_mean(a_from.m_mean),m_gamma(a_from.m_gamma),m_half_pi(a_from.m_half_pi){}
rbw(const rbw& a_from):m_flat(a_from.m_flat),m_mean(a_from.m_mean),m_gamma(a_from.m_gamma){}
rbw& operator=(const rbw& a_from) {
m_mean = a_from.m_mean;
m_gamma = a_from.m_gamma;
m_half_pi = a_from.m_half_pi;
return *this;
}
public:
REAL shoot() const {
REAL shoot(const REAL& a_half_pi,REAL(*a_tan)(REAL)) const {
REAL rval = REAL(2) * m_flat.shoot() - REAL(1);
REAL displ = (REAL(1)/REAL(2)) * m_gamma * _tan(rval * m_half_pi);
REAL displ = (REAL(1)/REAL(2)) * m_gamma * a_tan(rval * a_half_pi);
return m_mean + displ;
}
FLAT& flat() {return m_flat;}
@@ -70,11 +64,11 @@ protected:
FLAT& m_flat;
REAL m_mean;
REAL m_gamma;
REAL m_half_pi;
};
template <class FLAT,class REAL>
class rexp {
typedef REAL(*math_func)(REAL); //for rootcint.
public:
rexp(FLAT& a_flat,REAL a_rate = 1):m_flat(a_flat),m_rate(a_rate){}
virtual ~rexp(){}
@@ -82,12 +76,12 @@ public:
rexp(const rexp& a_from):m_flat(a_from.m_flat),m_rate(a_from.m_rate){}
rexp& operator=(const rexp& a_from) {m_rate = a_from.m_rate;return *this;}
public:
REAL shoot() const {
REAL shoot(math_func a_log) const {
REAL v;
do {
v = m_flat.shoot();
} while(v<=REAL(0));
return -_log(v)/m_rate;
return -a_log(v)/m_rate;
}
FLAT& flat() {return m_flat;}
protected:
@@ -130,7 +124,7 @@ public:
rdir3(const rdir3& a_from):m_flat(a_from.m_flat){}
rdir3& operator=(const rdir3&) {return *this;}
public:
void shoot(REAL& a_x,REAL& a_y,REAL& a_z) const {
void shoot(REAL& a_x,REAL& a_y,REAL& a_z,REAL(*a_sqrt)(REAL)) const {
// from gsl_ran_dir_3d.
REAL s;
do {
@@ -140,7 +134,7 @@ public:
}
while (s > REAL(1));
a_z = REAL(2) * s - REAL(1);
REAL a = REAL(2) * _sqrt(REAL(1) - s);
REAL a = REAL(2) * a_sqrt(REAL(1) - s);
a_x *= a;
a_y *= a;
}
@@ -149,6 +143,50 @@ protected:
FLAT& m_flat;
};
// from Geant4/G4Poisson.hh :
// NOTE : not used yet.
template <class FLAT,class REAL,class UINT>
class rpoiss {
public:
rpoiss(FLAT& a_flat,REAL a_mean = 1):m_flat(a_flat),m_mean(a_mean){}
virtual ~rpoiss(){}
public:
rpoiss(const rpoiss& a_from):m_flat(a_from.m_flat),m_mean(a_from.m_mean){}
rpoiss& operator=(const rpoiss& a_from) {
m_mean = a_from.m_mean;
return *this;
}
public:
UINT shoot(const REAL& a_two_pi,REAL(*a_sqrt)(REAL),REAL(*a_log)(REAL),REAL(*a_exp)(REAL),REAL(*a_cos)(REAL)) const {
UINT number = 0;
if(m_mean <= 16) {
REAL position = m_flat.shoot();
REAL poissonValue = a_exp(-m_mean);
REAL poissonSum = poissonValue;
while(poissonSum <= position) {
number++;
poissonValue *= m_mean/REAL(number);
poissonSum += poissonValue;
}
return number;
}
// m_mean > 16 :
REAL t = a_sqrt(-REAL(2)*a_log(m_flat.shoot()));
REAL y = a_two_pi*m_flat.shoot();
t *= a_cos(y);
REAL value = m_mean + t*a_sqrt(m_mean) + REAL(0.5);
if(value <= REAL(0)) return UINT(0);
static const REAL limit = REAL(2e9);
if(value >= limit) return UINT(limit);
return UINT(value);
}
FLAT& flat() {return m_flat;}
void set_seed(unsigned int a_seed) {m_flat.set_seed(a_seed);}
protected:
FLAT& m_flat;
REAL m_mean;
};
}
#endif
+56 -15
View File
@@ -21,22 +21,8 @@ public:
m_flat = a_from.m_flat;
return *this;
}
protected:
rtausmed m_flat;
};
class rbwd : public rbw<rtausmed,double> {
typedef rbw<rtausmed,double> parent;
public:
rbwd(double a_mean = 0,double a_gamma = 1):parent(m_flat,a_mean,a_gamma),m_flat(){}
virtual ~rbwd(){}
public:
rbwd(const rbwd& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rbwd& operator=(const rbwd& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
double shoot() const {return parent::shoot(::sqrt,::log);}
protected:
rtausmed m_flat;
};
@@ -53,6 +39,8 @@ public:
m_flat = a_from.m_flat;
return *this;
}
public:
double shoot() const {return parent::shoot(::log);}
protected:
rtausmed m_flat;
};
@@ -85,6 +73,59 @@ public:
m_flat = a_from.m_flat;
return *this;
}
public:
void shoot(double& a_x,double& a_y,double& a_z) const {
parent::shoot(a_x,a_y,a_z,::sqrt);
}
protected:
rtausmed m_flat;
};
}
#include "mathd"
namespace tools {
class rbwd : public rbw<rtausmed,double> {
typedef rbw<rtausmed,double> parent;
public:
rbwd(double a_mean = 0,double a_gamma = 1):parent(m_flat,a_mean,a_gamma),m_flat(){}
virtual ~rbwd(){}
public:
rbwd(const rbwd& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rbwd& operator=(const rbwd& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
public:
double shoot() const {return parent::shoot(half_pi(),::tan);}
protected:
rtausmed m_flat;
};
}
#include "typedefs"
namespace tools {
// NOTE : not used yet.
class rpoissd : public rpoiss<rtausmed,double,uint64> {
typedef rpoiss<rtausmed,double,uint64> parent;
public:
rpoissd(double a_mean = 1):parent(m_flat,a_mean),m_flat(){}
virtual ~rpoissd(){}
public:
rpoissd(const rpoissd& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rpoissd& operator=(const rpoissd& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
public:
uint64 shoot() const {return parent::shoot(two_pi(),::sqrt,::log,::exp,::cos);}
protected:
rtausmed m_flat;
};
+27 -15
View File
@@ -21,22 +21,8 @@ public:
m_flat = a_from.m_flat;
return *this;
}
protected:
rtausmef m_flat;
};
class rbwf : public rbw<rtausmef,float> {
typedef rbw<rtausmef,float> parent;
public:
rbwf(float a_mean = 0,float a_gamma = 1):parent(m_flat,a_mean,a_gamma),m_flat(){}
virtual ~rbwf(){}
public:
rbwf(const rbwf& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rbwf& operator=(const rbwf& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
float shoot() const {return parent::shoot(::sqrtf,::logf);}
protected:
rtausmef m_flat;
};
@@ -53,6 +39,32 @@ public:
m_flat = a_from.m_flat;
return *this;
}
public:
float shoot() const {return parent::shoot(::logf);}
protected:
rtausmef m_flat;
};
}
#include "mathf"
namespace tools {
class rbwf : public rbw<rtausmef,float> {
typedef rbw<rtausmef,float> parent;
public:
rbwf(float a_mean = 0,float a_gamma = 1):parent(m_flat,a_mean,a_gamma),m_flat(){}
virtual ~rbwf(){}
public:
rbwf(const rbwf& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rbwf& operator=(const rbwf& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
public:
float shoot() const {return parent::shoot(fhalf_pi(),::tanf);}
protected:
rtausmef m_flat;
};
File diff suppressed because it is too large Load Diff
@@ -69,9 +69,7 @@ public:
file_sz = m_reader.tellg();
m_reader.seekg(0,std::ios::beg);
if(!file_sz) {
a_out << "tools::rcsv::histo::read :"
<< " stream is empty."
<< std::endl;
a_out << "tools::rcsv::histo::read : stream is empty." << std::endl;
return false;
}
if(a_verbose) a_out << "file size is " << file_sz << std::endl;
@@ -94,24 +92,18 @@ public:
std::vector<std::string> _words;
tools::words(line," ",false,_words);
if(!_words.size()) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error : empty header line."
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error : empty header line." << std::endl;
return false;
}
if((_words[0]=="#class")) {
if(_words.size()!=2) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
_class = _words[1];
} else if(_words[0]=="#title") {
if(_words.size()<1) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
if(_words.size()==1) {
@@ -123,17 +115,13 @@ public:
}
} else if(_words[0]=="#dimension") {
if(_words.size()!=2) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
to(_words[1],hdata.m_dimension);
} else if(_words[0]=="#annotation") {
if(_words.size()<2) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
if(_words.size()==2) {
@@ -145,44 +133,32 @@ public:
}
} else if(_words[0]=="#axis") {
if(_words.size()<2) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
if(_words[1]=="fixed") {
if(_words.size()!=5) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
unsigned int number_of_bins;
if(!to(_words[2],number_of_bins)) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
double minimum_value;
if(!to(_words[3],minimum_value)) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
double maximum_value;
if(!to(_words[4],maximum_value)) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
axis_t axis;
if(!axis.configure(number_of_bins,minimum_value,maximum_value)) {
a_out << "tools::rcsv::histo::read :"
<< " bad axis values in line " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : bad axis values in line " << sout(line) << std::endl;
return false;
}
hdata.m_axes.push_back(axis);
@@ -191,25 +167,19 @@ public:
double value;
for(unsigned int index=2;index<_words.size();index++) {
if(!to(_words[index],value)) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
edges.push_back(value);
}
axis_t axis;
if(!axis.configure(edges)) {
a_out << "tools::rcsv::histo::read :"
<< " bad axis values in line " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : bad axis values in line " << sout(line) << std::endl;
return false;
}
hdata.m_axes.push_back(axis);
} else {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
@@ -218,9 +188,7 @@ public:
double value;
for(unsigned int index=1;index<_words.size();index++) {
if(!to(_words[index],value)) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
planes.push_back(value);
@@ -229,56 +197,40 @@ public:
} else if(_words[0]=="#bin_number") {
if(_words.size()!=2) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
to(_words[1],hdata.m_bin_number);
} else if(_words[0]=="#cut_v") {
if(_words.size()!=2) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
if(!to(_words[1],_cut_v)) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
is_profile = true;
} else if(_words[0]=="#min_v") {
if(_words.size()!=2) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
if(!to(_words[1],_min_v)) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
} else if(_words[0]=="#max_v") {
if(_words.size()!=2) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
if(!to(_words[1],_max_v)) {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
} else {
a_out << "tools::rcsv::histo::read :"
<< " syntax error in " << sout(line)
<< std::endl;
a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
return false;
}
}}
@@ -292,9 +244,7 @@ public:
}
if(!hdata.m_dimension) {
a_out << "tools::rcsv::histo::read :"
<< " null dimension."
<< std::endl;
a_out << "tools::rcsv::histo::read : null dimension." << std::endl;
return false;
}
@@ -359,16 +309,13 @@ public:
nline++;
}
if(nline!=hdata.m_bin_number) {
a_out << "tools::rcsv::histo::read :"
<< " bad data line number " << nline << ". Expected " << hdata.m_bin_number << "."
a_out << "tools::rcsv::histo::read : bad data line number " << nline << ". Expected " << hdata.m_bin_number << "."
<< std::endl;
return false;
}}
if(hdata.m_axes.size()!=hdata.m_dimension) {
a_out << "tools::rcsv::histo::read :"
<< " inconsistent axes data."
<< std::endl;
a_out << "tools::rcsv::histo::read : inconsistent axes data." << std::endl;
return false;
}
@@ -508,9 +455,7 @@ public:
*/
} else {
a_out << "tools::rcsv::histo::read :"
<< " unknown class " << sout(_class)
<< std::endl;
a_out << "tools::rcsv::histo::read : unknown class " << sout(_class) << std::endl;
return false;
}
@@ -548,9 +493,9 @@ protected:
return true;
}
static bool read_data_line(std::istream& a_reader,std::streampos a_sz,unsigned int a_number,std::vector<double>& a_vals) {
static bool read_data_line(std::istream& a_reader,std::streampos a_sz,size_t a_number,std::vector<double>& a_vals) {
a_vals.clear();
for(unsigned int index=0;index<a_number;index++) {
for(size_t index=0;index<a_number;index++) {
double v;
if(!_read(a_reader,v)) return false;
a_vals.push_back(v);
@@ -409,7 +409,7 @@ public:
}
*/
std::string name = a_suffix;
if(!numas<uint32>(m_cols.size(),name)){}
if(!numas<uint64>(m_cols.size(),name)){}
if(m_hippo) {
if(index>=labels.size()) {
a_out << "tools::rcsv::ntuple::initialize :"
@@ -438,7 +438,7 @@ public:
}
}
}
unsigned int num = m_cols.size();
size_t num = m_cols.size();
if(!num) {
a_out << "tools::rcsv::ntuple::initialize :"
<< " zero columns."
@@ -615,7 +615,7 @@ public:
}
unsigned int num = m_cols.size();
size_t num = m_cols.size();
if(!num) {
a_out << "tools::rcsv::ntuple::initialize(booking) :"
<< " zero columns."
@@ -915,8 +915,8 @@ protected:
std::istringstream iss;
std::vector<std::string> tmp;
unsigned int index = 0;
unsigned int num = m_cols.size();
size_t index = 0;
size_t num = m_cols.size();
std::vector<icol_t*>::const_iterator it;
for(it=m_cols.begin();it!=m_cols.end();++it,index++) {
@@ -6,9 +6,7 @@
namespace tools {
template <class T>
inline bool realloc(T*& a_pointer,
unsigned int a_new_size,unsigned int a_old_size,
bool a_init = false) {
inline bool realloc(T*& a_pointer,size_t a_new_size,size_t a_old_size,bool a_init = false) {
if(!a_new_size) {
delete [] a_pointer;
a_pointer = 0;
@@ -29,9 +27,9 @@ inline bool realloc(T*& a_pointer,
if(a_new_size>a_old_size) {
::memcpy(pointer,a_pointer,a_old_size*sizeof(T));
if(a_init){
unsigned int num = a_new_size-a_old_size;
size_t num = a_new_size-a_old_size;
T* pos = pointer+a_old_size;
for(unsigned int i=0;i<num;i++,pos++) *pos = T();
for(size_t i=0;i<num;i++,pos++) *pos = T();
}
} else {
::memcpy(pointer,a_pointer,a_new_size*sizeof(T));
@@ -10,11 +10,6 @@
#include "named"
namespace tools {
namespace rroot {
class branch;
}}
namespace tools {
namespace rroot {
@@ -63,7 +58,6 @@ public:
if(!a_buffer.read(fIsUnsigned)) return false;
{ifac::args args;
args[ifac::arg_branch()] = &m_branch;
iro* obj;
if(!a_buffer.read_object(m_fac,args,obj)) {
m_out << "tools::rroot::base_leaf::stream :"
@@ -97,13 +91,12 @@ public:
return true;
}
public:
virtual bool read_basket(buffer&) = 0;
virtual bool read_buffer(buffer&) = 0;
virtual bool print_value(std::ostream&,uint32) const = 0;
virtual uint32 num_elem() const = 0;
public:
base_leaf(std::ostream& a_out,rroot::branch& a_branch,ifac& a_fac)
base_leaf(std::ostream& a_out,ifac& a_fac)
:m_out(a_out)
,m_branch(a_branch)
,m_fac(a_fac)
,m_name("")
,m_title("")
@@ -134,7 +127,6 @@ protected:
base_leaf(const base_leaf& a_from)
:iro(a_from)
,m_out(a_from.m_out)
,m_branch(a_from.m_branch)
,m_fac(a_from.m_fac)
,m_ndata(0)
,m_length(0)
@@ -142,7 +134,6 @@ protected:
{}
base_leaf& operator=(const base_leaf&){return *this;}
public:
rroot::branch& branch() {return m_branch;}
const std::string& name() const {return m_name;}
const std::string& title() const {return m_title;}
/*
@@ -171,7 +162,6 @@ public:
*/
protected:
std::ostream& m_out;
rroot::branch& m_branch;
ifac& m_fac;
protected: //Named
std::string m_name;
@@ -15,6 +15,7 @@ namespace tools {
namespace rroot {
class basket : public virtual iro, public key {
typedef key parent;
static uint32 kDisplacementMask() {return 0xFF000000;}
public:
static const std::string& s_class() {
@@ -40,7 +41,7 @@ public:
uint32 startpos = a_buffer.length();
if(!key::from_buffer(a_buffer.eob(),a_buffer.pos())) return false;
if(!parent::from_buffer(a_buffer.byte_swap(),a_buffer.eob(),a_buffer.pos(),a_buffer.verbose())) return false;
uint32 fBufferSize;
@@ -56,7 +57,7 @@ public:
uint16 basket_key_length = a_buffer.length()-startpos;
if(basket_key_length!=m_key_length) {
//m_file.out() << "tools::rroot::basket::stream :"
//m_out << "tools::rroot::basket::stream :"
// << " key length not consistent."
// << " read " << m_key_length
// << ", expected " << basket_key_length
@@ -65,7 +66,7 @@ public:
m_key_length = basket_key_length;
}
if(!m_object_size) {
//m_file.out() << "tools::rroot::basket::stream :"
//m_out << "tools::rroot::basket::stream :"
// << " m_object_size is found to be zero."
// << " Continue with (m_nbytes-m_key_length) "
// << (m_nbytes-m_key_length)
@@ -80,7 +81,7 @@ public:
(flag!=11)&&(flag!=12) &&
(flag!=41)&&(flag!=42) &&
(flag!=51)&&(flag!=52) ) {
m_file.out() << "tools::rroot::basket::stream :"
m_out << "tools::rroot::basket::stream :"
<< " bad flag " << (int)flag
<< std::endl;
return false;
@@ -90,12 +91,12 @@ public:
//due to the upper "G.Barrand if", flag is here in {1,11,41,51}
if(!m_nev_buf_size) {
m_file.out() << "tools::rroot::basket::stream :"
m_out << "tools::rroot::basket::stream :"
<< " m_nev_buf_size is zero." << std::endl;
return false;
}
if(m_nev>m_nev_buf_size) {
m_file.out() << "tools::rroot::basket::stream :"
m_out << "tools::rroot::basket::stream :"
<< " m_nev>m_nev_buf_size !"
<< " m_nev " << m_nev
<< " m_nev_buf_size " << m_nev_buf_size
@@ -110,7 +111,7 @@ public:
return false;
}
if((n!=m_nev)&&(n!=(m_nev+1))) {
m_file.out() << "tools::rroot::basket::stream :"
m_out << "tools::rroot::basket::stream :"
<< " m_entry_offset read len mismatch."
<< " n " << n
<< " m_nev " << m_nev
@@ -134,7 +135,7 @@ public:
return false;
}
if((n!=m_nev)&&(n!=(m_nev+1))) {
m_file.out() << "tools::rroot::basket::stream :"
m_out << "tools::rroot::basket::stream :"
<< " m_displacement read len mismatch."
<< " n " << n
<< " m_nev " << m_nev
@@ -153,7 +154,7 @@ public:
if(fBufferSize) {
char* _buf = new char[fBufferSize];
if(!_buf) {
m_file.out() << "tools::rroot::basket::stream :"
m_out << "tools::rroot::basket::stream :"
<< " can't alloc " << fBufferSize << std::endl;
_clear();
return false;
@@ -182,8 +183,8 @@ public:
return true;
}
public:
basket(ifile& a_file)
:key(a_file)
basket(std::ostream& a_out)
:parent(a_out)
,m_nev_buf_size(0)
,m_nev(0)
,m_last(0)
@@ -194,8 +195,8 @@ public:
mem::increment(s_class().c_str());
#endif
}
basket(ifile& a_file,seek a_pos,uint32 a_nbytes)
:key(a_file,a_pos,a_nbytes)
basket(std::ostream& a_out,seek a_pos,uint32 a_nbytes)
:parent(a_out,a_pos,a_nbytes)
,m_nev_buf_size(0)
,m_nev(0)
,m_last(0)
@@ -215,7 +216,7 @@ public:
public:
basket(const basket& a_from)
:iro(a_from)
,key(a_from)
,parent(a_from)
,m_nev_buf_size(a_from.m_nev_buf_size)
,m_nev(a_from.m_nev)
,m_last(a_from.m_last)
@@ -228,7 +229,7 @@ public:
if(a_from.m_nev && a_from.m_entry_offset) {
m_entry_offset = new int[a_from.m_nev];
if(!m_entry_offset) {
m_file.out() << "tools::rroot::basket::basket(cpcstor) :"
m_out << "tools::rroot::basket::basket(cpcstor) :"
<< " can't alloc " << a_from.m_nev << "."
<< std::endl;
} else {
@@ -239,7 +240,7 @@ public:
if(a_from.m_nev && a_from.m_displacement) {
m_displacement = new int[a_from.m_nev];
if(!m_displacement) {
m_file.out() << "tools::rroot::basket::basket(cpcstor) :"
m_out << "tools::rroot::basket::basket(cpcstor) :"
<< " can't alloc " << a_from.m_nev << "."
<< std::endl;
} else {
@@ -249,7 +250,7 @@ public:
}
}
basket& operator=(const basket& a_from){
key::operator=(a_from);
parent::operator=(a_from);
if(&a_from==this) return *this;
@@ -265,7 +266,7 @@ public:
if(a_from.m_nev && a_from.m_entry_offset) {
m_entry_offset = new int[a_from.m_nev];
if(!m_entry_offset) {
m_file.out() << "tools::rroot::basket::operator=() :"
m_out << "tools::rroot::basket::operator=() :"
<< " can't alloc " << a_from.m_nev << "."
<< std::endl;
} else {
@@ -276,7 +277,7 @@ public:
if(a_from.m_nev && a_from.m_displacement) {
m_displacement = new int[a_from.m_nev];
if(!m_displacement) {
m_file.out() << "tools::rroot::basket::operator=() :"
m_out << "tools::rroot::basket::operator=() :"
<< " can't alloc " << a_from.m_nev << "."
<< std::endl;
} else {
@@ -292,27 +293,27 @@ public:
int* displacement() {return m_displacement;}
uint32 nev_buf_size() const {return m_nev_buf_size;}
uint32 nev() const {return m_nev;}
uint32 last() const {return m_last;}
bool read_offset_tables() {
bool read_offset_tables(bool a_byte_swap) {
if(!m_buffer) return false;
if(!m_last) return false;
delete [] m_entry_offset;
m_entry_offset = 0;
rroot::buffer buffer(m_file.out(),m_file.byte_swap(),
m_buf_size,m_buffer,0,false);
rroot::buffer buffer(m_out,a_byte_swap,m_buf_size,m_buffer,0,false);
buffer.set_offset(m_last);
{uint32 n;
if(!buffer.read_array<int>(0,m_entry_offset,n)) {
m_file.out() << "tools::rroot::basket::read_offset_tables :"
m_out << "tools::rroot::basket::read_offset_tables :"
<< " read_array failed."
<< std::endl;
return false;
}
if((n!=m_nev)&&(n!=(m_nev+1))) {
m_file.out() << "tools::rroot::basket::read_offset_tables :"
m_out << "tools::rroot::basket::read_offset_tables :"
<< " m_entry_offset read len mismatch."
<< " n " << n
<< " m_nev " << m_nev
@@ -327,13 +328,13 @@ public:
// array.
uint32 n;
if(!buffer.read_array<int>(0,m_displacement,n)) {
m_file.out() << "tools::rroot::basket::read_offset_tables :"
m_out << "tools::rroot::basket::read_offset_tables :"
<< " readArray(2) failed."
<< std::endl;
return false;
}
if((n!=m_nev)&&(n!=(m_nev+1))) {
m_file.out() << "tools::rroot::basket::read_offset_tables :"
m_out << "tools::rroot::basket::read_offset_tables :"
<< " m_displacement read len mismatch."
<< " n " << n
<< " m_nev " << m_nev
@@ -259,7 +259,7 @@ public:
//TObjArray
//::printf("debug : branch::stream : leaves : begin\n");
{ifac::args args;
args[ifac::arg_branch()] = this;
//args[ifac::arg_branch()] = this;
if(!m_leaves.stream(a_buffer,args)) {
m_out << "tools::rroot::branch::stream :"
<< " can't read leaves."
@@ -516,9 +516,9 @@ public:
virtual bool read_leaves(buffer& a_buffer){
tools_vforcit(base_leaf*,m_leaves,it) {
if(!(*it)->read_basket(a_buffer)) {
if(!(*it)->read_buffer(a_buffer)) {
m_out << "tools::rroot::branch::read_leaves :"
<< " read_basket failed."
<< " read_buffer failed."
<< std::endl;
return false;
}
@@ -526,7 +526,7 @@ public:
return true;
}
virtual bool find_entry(uint32 a_entry,uint32& a_nbytes){
virtual bool find_entry(ifile& a_file,uint32 a_entry,uint32& a_nbytes){
// Read all leaves of entry and return total number of bytes :
// The input argument entry is the entry serial number in the current tree.
a_nbytes = 0;
@@ -635,7 +635,7 @@ public:
return false;
}
bsk = get_basket(fBasketSeek[m_read_basket],fBasketBytes[m_read_basket]);
bsk = get_basket(a_file,fBasketSeek[m_read_basket],fBasketBytes[m_read_basket]);
if(!bsk) {
m_out << "tools::rroot::branch::find_entry :"
<< " can't read basket " << m_read_basket
@@ -706,7 +706,7 @@ public:
}
*/
rroot::buffer buffer(m_out,m_file.byte_swap(),m__read_basket->buf_size(),m__read_basket->buf(),0,false);
rroot::buffer buffer(m_out,a_file.byte_swap(),m__read_basket->buf_size(),m__read_basket->buf(),0,false);
buffer.set_offset(bufbegin);
if(!read_leaves(buffer)) {
@@ -727,10 +727,37 @@ public:
return true;
}
virtual bool show(std::ostream& a_out,ifile& a_file,uint32 a_entry) {
// Print values of all active leaves for entry :
// if entry==-1, print current entry (default)
uint32 n;
if(!find_entry(a_file,a_entry,n)) return false;
tools_vforcit(base_leaf*,m_leaves,it) {
base_leaf* bl = *it;
uint32 num = bl->num_elem();
num = mn<uint32>(num,10);
if(!num) continue;
{std::string s;
uint32 len = uint32(bl->name().size())+128;
sprintf(s,len," %-15s = ",bl->name().c_str());
a_out << s;}
for(uint32 i=0;i<num;i++) {
if(i) a_out << ", ";
bl->print_value(a_out,i);
}
a_out << std::endl;
}
return true;
}
public:
branch(ifile& a_file,ifac& a_fac)
:m_file(a_file)
,m_out(a_file.out())
branch(std::ostream& a_out,ifac& a_fac)
:m_out(a_out)
,m_fac(a_fac)
,m_streamed_baskets(m_fac,true)
@@ -765,7 +792,7 @@ public:
protected:
branch(const branch& a_from)
:iro(a_from)
,m_file(a_from.m_file),m_out(a_from.m_out),m_fac(a_from.m_fac)
,m_out(a_from.m_out),m_fac(a_from.m_fac)
,m_streamed_baskets(m_fac,false),m__read_basket(0)
,fAutoDelete(false)
,m_branches(m_fac,false),m_leaves(m_fac,false)
@@ -779,57 +806,25 @@ protected:
{}
branch& operator=(const branch&){return *this;}
public:
ifile& file() {return m_file;}
uint32 entry_number() const {return m_entry_number;}
const std::string& name() const {return m_name;}
const std::string& title() const {return m_title;}
const std::vector<base_leaf*>& leaves() const {return m_leaves;}
const std::vector<branch*>& branches() const {return m_branches;}
bool show(std::ostream& a_out,uint32 a_entry){
// Print values of all active leaves for entry :
// if entry==-1, print current entry (default)
uint32 n;
if(!find_entry(a_entry,n)) return false;
tools_vforcit(base_leaf*,m_leaves,it) {
base_leaf* bl = *it;
uint32 num = bl->num_elem();
num = mn<uint32>(num,10);
if(!num) continue;
{std::string s;
uint32 len = bl->name().size()+128;
sprintf(s,len," %-15s = ",bl->name().c_str());
a_out << s;}
for(uint32 i=0;i<num;i++) {
if(i) a_out << ", ";
bl->print_value(a_out,i);
}
a_out << std::endl;
}
return true;
}
protected:
basket* get_basket(seek a_pos,uint32 a_len) {
basket* get_basket(ifile& a_file,seek a_pos,uint32 a_len) {
//if(fBranch.tree().memoryFull(fBufferSize)) fBranch.dropBaskets();
if(!a_len) return 0;
rroot::basket* basket =
new rroot::basket(m_file,a_pos,a_len); //basket is a key.
if(!basket->read_file()) {
rroot::basket* basket = new rroot::basket(m_out,a_pos,a_len); //basket is a key.
if(!basket->read_file(a_file)) {
m_out << "tools::rroot::branch::get_basket :"
<< " read_file() failed."
<< std::endl;
delete basket;
return 0;
}
{rroot::buffer buffer(m_out,m_file.byte_swap(),
a_len,basket->buf(),0,false);
{rroot::buffer buffer(m_out,a_file.byte_swap(),a_len,basket->buf(),0,false);
if(!basket->stream(buffer)) {
m_out << "tools::rroot::branch::get_basket :"
<< " basket stream failed."
@@ -838,7 +833,7 @@ protected:
return 0;
}}
unsigned int sz;
char* buf = basket->get_object_buffer(sz); //basket owns buf.
char* buf = basket->get_object_buffer(a_file,sz); //basket owns buf.
if(!buf) {
m_out << "tools::rroot::branch::get_basket :"
<< " get_object_buffer() failed."
@@ -865,7 +860,7 @@ protected:
//}
if(fEntryOffsetLen) {
if(!basket->read_offset_tables()) {
if(!basket->read_offset_tables(a_file.byte_swap())) {
m_out << "tools::rroot::branch::get_basket :"
<< " read_offset_tables failed."
<< std::endl;
@@ -916,8 +911,6 @@ protected:
protected:
//Tree& fTree;
ifile& m_file;
std::ostream& m_out;
ifac& m_fac;
std::vector< std::pair<uint32,uint32> > m_first_last;
@@ -10,6 +10,7 @@ namespace tools {
namespace rroot {
class branch_element : public branch {
typedef branch parent;
public:
static const std::string& s_class() {
static const std::string s_v("tools::rroot::branch_element");
@@ -18,21 +19,21 @@ public:
public: //iro
virtual void* cast(const std::string& a_class) const {
if(void* p = cmp_cast<branch_element>(this,a_class)) return p;
return branch::cast(a_class);
return parent::cast(a_class);
}
virtual const std::string& s_cls() const {return s_class();}
public:
static cid id_class() {return branch_element_cid();}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<branch_element>(this,a_class)) {return p;}
return branch::cast(a_class);
return parent::cast(a_class);
}
public:
virtual bool stream(buffer& a_buffer) {
short v;
unsigned int s, c;
if(!a_buffer.read_version(v,s,c)) return false;
if(!branch::stream(a_buffer)) return false;
if(!parent::stream(a_buffer)) return false;
if(v<=7) {
if(!a_buffer.read(fClassName)) return false;
@@ -264,9 +265,9 @@ public: //branch
*/
}
virtual bool find_entry(uint32 a_entry,uint32& a_nbytes){
virtual bool find_entry(ifile& a_file,uint32 a_entry,uint32& a_nbytes){
//The below line will call the upper read_leaves.
if(!branch::find_entry(a_entry,a_nbytes)) return false;
if(!parent::find_entry(a_file,a_entry,a_nbytes)) return false;
if(m_branches.size()) {
//if(!m_obj) {
@@ -276,16 +277,31 @@ public: //branch
tools_vforcit(branch*,m_branches,it) {
uint32 n;
if(!(*it)->find_entry(a_entry,n)) return false;
if(!(*it)->find_entry(a_file,a_entry,n)) return false;
a_nbytes += n;
}
}
return true;
}
virtual bool show(std::ostream& a_out,ifile& a_file,uint32 a_entry){
uint32 n;
if(!find_entry(a_file,a_entry,n)) return false;
{std::string s;
uint32 len = uint32(name().size())+128;
sprintf(s,len," %-15s = ",name().c_str());
a_out << s;}
a_out << m_obj << std::endl;
return true;
//return parent::show(a_out,a_file,a_entry);
}
public:
branch_element(ifile& a_file,ifac& a_fac)
: branch(a_file,a_fac)
branch_element(std::ostream& a_out,ifac& a_fac)
:parent(a_out,a_fac)
,m_obj(0)
,fClassVersion(0)
,fID(0)
@@ -296,7 +312,7 @@ public:
virtual ~branch_element(){delete m_obj;}
protected:
branch_element(const branch_element& a_from)
:iro(a_from),branch(a_from){}
:iro(a_from),parent(a_from){}
branch_element& operator=(const branch_element&){return *this;}
public:
const std::string& class_name() const {return fClassName;}
@@ -18,7 +18,7 @@
// in TOOLS_STL, we don't have (yet) a performant map.
#ifdef inlib_stl_vector
#ifdef tools_stl_vector
#define TOOLS_RROOT_OBJ_MAP_HASH_TABLE
//#define TOOLS_RROOT_OBJ_MAP_OMAP
#else
@@ -40,6 +40,8 @@ namespace tools {
namespace rroot {
class buffer : public rbuf {
typedef rbuf parent;
static const std::string& s_class() {
static const std::string s_v("tools::rroot::buffer");
return s_v;
@@ -76,7 +78,7 @@ class buffer : public rbuf {
public:
buffer(std::ostream& a_out,bool a_byte_swap,
uint32 a_size,char* a_buffer,uint32 a_klen,bool a_verbose)
: rbuf(a_out,a_byte_swap,a_buffer+a_size,m_pos)
:parent(a_out,a_byte_swap,a_buffer+a_size,m_pos)
,m_byte_swap(a_byte_swap)
,m_verbose(a_verbose)
,m_size(a_size) //expect a not zero size.
@@ -97,7 +99,7 @@ public:
}
protected:
buffer(const buffer& a_from)
: rbuf(a_from.m_out,a_from.m_byte_swap,0,m_pos)
:parent(a_from.m_out,a_from.m_byte_swap,0,m_pos)
,m_byte_swap(a_from.m_byte_swap)
,m_map_objs(a_from.m_map_objs)
{
@@ -107,6 +109,9 @@ protected:
}
buffer& operator=(const buffer&){return *this;}
public:
bool byte_swap() const {return m_byte_swap;}
bool verbose() const {return m_verbose;}
void set_offset(unsigned int a_off) {m_pos = m_buffer+a_off;}
//char* buffer() const {return m_buffer;}
@@ -128,7 +133,7 @@ protected:
a_class.clear();
uint32 tag;
if(!rbuf::read(tag)) return false;
if(!parent::read(tag)) return false;
if(tag==kNewClassTag()) {
char s[80];
@@ -186,7 +191,7 @@ protected:
// read byte count and/or tag (older files don't have byte count)
uint32 first_int = 0;
if(!rbuf::read(first_int)) return false;
if(!parent::read(first_int)) return false;
if(m_verbose) {
std::ios::fmtflags old_flags = m_out.flags();
@@ -317,7 +322,7 @@ public:
m_pos = m_buffer + obj_offset;
uint32 first_int;
if(!rbuf::read(first_int)) return false;
if(!parent::read(first_int)) return false;
if(first_int & kByteCountMask()) {
std::string scls;
if(!read_class_tag(scls)) return false;
@@ -466,12 +471,12 @@ public:
a_version = 0;
short version = 0;
// not interested in byte count
if(!rbuf::read(version)) return false;
if(!parent::read(version)) return false;
// if this is a byte count, then skip next short and read version
if(version & kByteCountVMask()) {
if(!rbuf::read(version)) return false;
if(!rbuf::read(version)) return false;
if(!parent::read(version)) return false;
if(!parent::read(version)) return false;
}
a_version = version;
@@ -500,11 +505,11 @@ public:
} v;
if(m_byte_swap) {
if(!rbuf::read(v.vers[1])) return false;
if(!rbuf::read(v.vers[0])) return false;
if(!parent::read(v.vers[1])) return false;
if(!parent::read(v.vers[0])) return false;
} else {
if(!rbuf::read(v.vers[0])) return false;
if(!rbuf::read(v.vers[1])) return false;
if(!parent::read(v.vers[0])) return false;
if(!parent::read(v.vers[1])) return false;
}
// no bytecount, backup and read version
@@ -514,7 +519,7 @@ public:
} else {
m_pos -= sizeof(unsigned int);
}
if(!rbuf::read(version)) return false;
if(!parent::read(version)) return false;
//printf("Reading version=%d at pos=%d, bytecount=%d\n",
//version,*startpos,*bcnt);
@@ -567,7 +572,7 @@ protected:
int nr = 0;
while (nr < int(a_max-1)) {
char ch;
if(!rbuf::read(ch)) return false;
if(!parent::read(ch)) return false;
// stop when 0 read
if(ch == 0) break;
a_string[nr++] = ch;
@@ -4,6 +4,8 @@
#ifndef tools_rroot_cids
#define tools_rroot_cids
//NOTE : logic must be in sync with wroot/cids.
#include "../cid"
namespace tools {
@@ -34,6 +36,8 @@ inline cid streamer_element_cid() {return base_cid()+14;}
inline cid stl_vector_string_cid() {return base_cid()+16;}
inline cid Named_cid() {return base_cid()+17;}
//base for templates :
inline cid base_leaf_cid() {return base_cid()+20;} //+12=32
//NOTE : leaf<T> = base_leaf_cid()+_cid(T)
@@ -59,6 +59,11 @@ inline const std::string& TList_cls(){
return s_v;
}
inline const std::string& TNamed_cls(){
static const std::string s_v("TNamed");
return s_v;
}
}}
#endif
@@ -116,7 +116,7 @@ public:
{int v;
if(!rb.read(v)) return false;
m_nbytes_name = v;}
if(versiondir>1000) {
if(versiondir>(short)big_file_version_tag()) {
if(!rb.read(m_seek_directory)) return false;
if(!rb.read(m_seek_parent)) return false;
if(!rb.read(m_seek_keys)) return false;
@@ -150,10 +150,10 @@ public:
clear_keys();
key headerkey(m_file,m_seek_keys,m_nbytes_keys);
if(!headerkey.read_file()) return false;
key headerkey(m_file.out(),m_seek_keys,m_nbytes_keys);
if(!headerkey.read_file(m_file)) return false;
char* buffer = headerkey.data_buffer();
if(!headerkey.from_buffer(headerkey.eob(),buffer)) return false;
if(!headerkey.from_buffer(m_file.byte_swap(),headerkey.eob(),buffer,m_file.verbose())) return false;
int nkeys = 0;
rbuf rb(m_file.out(),m_file.byte_swap(),headerkey.eob(),buffer);
if(!rb.read(nkeys)) return false;
@@ -164,8 +164,8 @@ public:
<< std::endl;
}
for(int i=0;i<nkeys;i++) {
key* k = new key(m_file);
if(!k->from_buffer(headerkey.eob(),buffer)) {
key* k = new key(m_file.out());
if(!k->from_buffer(m_file.byte_swap(),headerkey.eob(),buffer,m_file.verbose())) {
delete k;
return false;
}
@@ -183,8 +183,8 @@ protected:
// Record (stored in file):
date m_date_C; //Date and time when directory is created
date m_date_M; //Date and time of last modification
uint32 m_nbytes_keys; //Number of bytes for the keys
uint32 m_nbytes_name; //Number of bytes in TNamed at creation time
uint32 m_nbytes_keys; //Number of bytes for the keys
uint32 m_nbytes_name; //Number of bytes in TNamed at creation time
seek m_seek_directory; //Location of directory on file
seek m_seek_parent; //Location of parent directory on file
seek m_seek_keys; //Location of Keys record on file
+20 -34
View File
@@ -23,57 +23,41 @@ public:
return s_v;
}
public: //ifac
virtual iro* create(const std::string& a_class,const args& a_args) {
//m_file.out() << "tools::rroot::fac::create :"
virtual iro* create(const std::string& a_class,const args&) {
//m_out << "tools::rroot::fac::create :"
// << " create object of class " << a_class << "..."
// << std::endl;
if(a_class=="TBranch") {
return new branch(m_file,*this);
return new branch(m_out,*this);
} else if(a_class=="TBranchElement") {
return new branch_element(m_file,*this);
return new branch_element(m_out,*this);
} else if(a_class=="TLeafB") {
branch* b = arg_branch(a_args);
if(!b) return 0;
return new leaf<char>(m_file.out(),*b,*this);
return new leaf<char>(m_out,*this);
} else if(a_class=="TLeafS") {
branch* b = arg_branch(a_args);
if(!b) return 0;
return new leaf<short>(m_file.out(),*b,*this);
return new leaf<short>(m_out,*this);
} else if(a_class=="TLeafI") {
branch* b = arg_branch(a_args);
if(!b) return 0;
return new leaf<int>(m_file.out(),*b,*this);
return new leaf<int>(m_out,*this);
} else if(a_class=="TLeafF") {
branch* b = arg_branch(a_args);
if(!b) return 0;
return new leaf<float>(m_file.out(),*b,*this);
return new leaf<float>(m_out,*this);
} else if(a_class=="TLeafD") {
branch* b = arg_branch(a_args);
if(!b) return 0;
return new leaf<double>(m_file.out(),*b,*this);
return new leaf<double>(m_out,*this);
} else if(a_class=="TLeafO") {
branch* b = arg_branch(a_args);
if(!b) return 0;
return new leaf<bool>(m_file.out(),*b,*this);
return new leaf<bool>(m_out,*this);
} else if(a_class=="TLeafC") {
branch* b = arg_branch(a_args);
if(!b) return 0;
return new leaf_string(m_file.out(),*b,*this);
return new leaf_string(m_out,*this);
} else if(a_class=="TLeafElement") {
branch* b = arg_branch(a_args);
if(!b) return 0;
return new leaf_element(m_file.out(),*b,*this);
return new leaf_element(m_out,*this);
} else if(a_class=="TBasket") {
return new basket(m_file);
return new basket(m_out);
// L.Duflot ATLAS file :
} else if(a_class=="TTreeIndex") {
@@ -118,7 +102,7 @@ public: //ifac
return new dummy();
} else {
m_file.out() << "tools::rroot::fac::create :"
m_out << "tools::rroot::fac::create :"
<< " unknown class " << sout(a_class) << "."
<< " Create a tools::rroot::dummy object."
<< std::endl;
@@ -127,24 +111,26 @@ public: //ifac
}
virtual void destroy(iro*& a_obj) {delete a_obj;a_obj = 0;}
public:
fac(ifile& a_file):m_file(a_file){}
fac(std::ostream& a_out):m_out(a_out){}
virtual ~fac(){}
public:
fac(const fac& a_from): ifac(a_from),m_file(a_from.m_file){}
fac(const fac& a_from):ifac(a_from),m_out(a_from.m_out){}
fac& operator=(const fac&){return *this;}
protected:
/*
branch* arg_branch(const args& a_args) {
void* p = ifac::find_args(a_args,ifac::arg_branch());
if(!p) {
m_file.out() << "tools::rroot::fac::arg_branch :"
m_out << "tools::rroot::fac::arg_branch :"
<< " branch not found in args."
<< std::endl;
return 0;
}
return (branch*)p;
}
*/
protected:
ifile& m_file;
std::ostream& m_out;
};
}}
@@ -33,6 +33,7 @@ public:
static const std::string s_v("tools::rroot::file");
return s_v;
}
virtual const std::string& s_cls() const {return s_class();}
public: //ifile
virtual const std::string& path() const {return m_path;}
@@ -115,7 +116,7 @@ public:
,m_file(not_open())
,m_bytes_read(0)
,m_root_directory(*this)
,m_streamer_info_key(*this)
,m_streamer_info_key(a_out)
// begin of record :
,m_version(0)
,m_BEGIN(0)
@@ -156,7 +157,7 @@ protected:
:ifile(a_from)
,m_out(a_from.m_out)
,m_root_directory(*this)
,m_streamer_info_key(*this)
,m_streamer_info_key(a_from.m_out)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
@@ -422,7 +423,7 @@ protected:
char* buffer = new char[m_nbytes_info+1];
if(!read_buffer(buffer,m_nbytes_info)) {delete [] buffer;return false;}
char* buf = buffer;
if(!m_streamer_info_key.from_buffer(buffer+m_nbytes_info,buf)) {
if(!m_streamer_info_key.from_buffer(byte_swap(),buffer+m_nbytes_info,buf,m_verbose)) {
delete [] buffer;
return false;
}
@@ -29,7 +29,7 @@ public:
if(it==a_args.end()) return 0;
return (*it).second;
}
static char arg_branch() {return 'B';}
//static char arg_branch() {return 'B';}
static char arg_class() {return 'C';}
static std::string* arg_class(const args& a_args) {
@@ -189,7 +189,7 @@ public: //iro
<< std::endl;
return false;
}
m_elements.operator=(*obj);
if(obj) m_elements.operator=(*obj);
delete obj;}
return a_buffer.check_byte_count(s,c,s_store_class());
+41 -40
View File
@@ -40,14 +40,14 @@ public:
static uint32 std_string_record_size(const std::string& x) {
// Returns size string will occupy on I/O buffer.
if (x.size() > 254)
return x.size()+sizeof(unsigned char)+sizeof(int);
return uint32(x.size()+sizeof(unsigned char)+sizeof(int));
else
return x.size()+sizeof(unsigned char);
return uint32(x.size()+sizeof(unsigned char));
}
public:
key(ifile& a_file)
:m_file(a_file)
key(std::ostream& a_out)
:m_out(a_out)
,m_buf_size(0)
,m_buffer(0)
// Record :
@@ -70,8 +70,8 @@ public:
//fDate.setDate(0);
}
key(ifile& a_file,seek a_pos,uint32 a_nbytes)
:m_file(a_file)
key(std::ostream& a_out,seek a_pos,uint32 a_nbytes)
:m_out(a_out)
,m_buf_size(0)
,m_buffer(0)
// Record :
@@ -90,10 +90,10 @@ public:
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
if(a_pos>START_BIG_FILE) m_version += 1000;
if(a_pos>START_BIG_FILE) m_version += big_file_version_tag();
m_buffer = new char[a_nbytes];
if(!m_buffer) {
m_file.out() << "tools::rroot::key::key(cpcstor) :"
m_out << "tools::rroot::key::key(cpcstor) :"
<< " can't alloc " << a_nbytes << "."
<< std::endl;
} else {
@@ -108,7 +108,7 @@ public:
}
protected:
key(const key& a_from)
:m_file(a_from.m_file)
:m_out(a_from.m_out)
,m_buf_size(0)
,m_buffer(0)
,m_nbytes(a_from.m_nbytes)
@@ -129,7 +129,7 @@ protected:
if(a_from.m_buf_size && a_from.m_buffer) {
m_buffer = new char[a_from.m_buf_size];
if(!m_buffer) {
m_file.out() << "tools::rroot::key::key(cpcstor) :"
m_out << "tools::rroot::key::key(cpcstor) :"
<< " can't alloc " << a_from.m_buf_size << "."
<< std::endl;
} else {
@@ -160,7 +160,7 @@ public:
if(a_from.m_buf_size && a_from.m_buffer) {
m_buffer = new char[a_from.m_buf_size];
if(!m_buffer) {
m_file.out() << "tools::rroot::key::operator=() :"
m_out << "tools::rroot::key::operator=() :"
<< " can't alloc " << a_from.m_buf_size << "."
<< std::endl;
} else {
@@ -173,7 +173,7 @@ public:
}
public:
ifile& file() {return m_file;}
std::ostream& out() const {return m_out;}
uint32 nbytes() const {return m_nbytes;}
seek seek_key() const {return m_seek_key;}
@@ -183,12 +183,12 @@ public:
const std::string& object_title() const {return m_object_title;}
const std::string& object_class() const {return m_object_class;}
bool read_file(){
bool read_file(ifile& a_file){
// Read the key structure from the file.
if(!m_file.set_pos(m_seek_key)) return false;
if(!m_file.read_buffer(m_buffer,m_nbytes)) return false;
if(m_file.verbose()) {
m_file.out() << "tools::rroot::key::read_file :"
if(!a_file.set_pos(m_seek_key)) return false;
if(!a_file.read_buffer(m_buffer,m_nbytes)) return false;
if(a_file.verbose()) {
m_out << "tools::rroot::key::read_file :"
<< " reading " << m_nbytes << " bytes"
<< " at position " << m_seek_key
<< "."
@@ -203,8 +203,8 @@ public:
uint32 buf_size() const {return m_buf_size;}
uint32 key_length() const {return m_key_length;}
bool from_buffer(const char* aEOB,char*& a_pos) {
rbuf rb(m_file.out(),m_file.byte_swap(),aEOB,a_pos);
bool from_buffer(bool a_byte_swap,const char* aEOB,char*& a_pos,bool a_verbose) {
rbuf rb(m_out,a_byte_swap,aEOB,a_pos);
int _nbytes;
if(!rb.read(_nbytes)) return false;
/*
@@ -237,7 +237,7 @@ public:
{short v;
if(!rb.read(v)) return false;
m_cycle = v;}
if(version>1000) {
if(version>(short)big_file_version_tag()) {
if(!rb.read(m_seek_key)) return false;
if(!rb.read(m_seek_parent_dir)) return false;
} else {
@@ -251,8 +251,8 @@ public:
if(!rb.read(m_object_class)) return false;
if(!rb.read(m_object_name)) return false;
if(!rb.read(m_object_title)) return false;
if(m_file.verbose()) {
m_file.out() << "tools::rroot::key::from_buffer :"
if(a_verbose) {
m_out << "tools::rroot::key::from_buffer :"
<< " nbytes : " << m_nbytes
<< ", object class : " << sout(m_object_class)
<< ", object name : " << sout(m_object_name)
@@ -264,9 +264,9 @@ public:
return true;
}
char* get_object_buffer(uint32& a_size) {
char* get_object_buffer(ifile& a_file,uint32& a_size) {
if(!m_key_length) {
m_file.out() << "tools::rroot::key::get_object_buffer :"
m_out << "tools::rroot::key::get_object_buffer :"
<< " WARNING : m_key_length is zero."
<< std::endl;
//delete [] m_buffer;
@@ -276,7 +276,7 @@ public:
//return 0;
}
if(!m_nbytes) {
m_file.out() << "tools::rroot::key::get_object_buffer :"
m_out << "tools::rroot::key::get_object_buffer :"
<< " m_nbytes is zero."
<< std::endl;
delete [] m_buffer;
@@ -286,13 +286,13 @@ public:
return 0;
}
if(!m_object_size) {
m_file.out() << "tools::rroot::key::get_object_buffer :"
m_out << "tools::rroot::key::get_object_buffer :"
<< " WARNING : m_object_size is zero."
<< std::endl;
}
if(m_file.verbose()) {
m_file.out() << "tools::rroot::key::get_object_buffer :"
if(a_file.verbose()) {
m_out << "tools::rroot::key::get_object_buffer :"
<< " m_nbytes : " << m_nbytes
<< " m_key_length : " << m_key_length
<< " m_object_size : " << m_object_size << "."
@@ -304,7 +304,7 @@ public:
delete [] m_buffer;
m_buf_size = m_key_length+m_object_size;
if(m_buf_size<m_nbytes) {
m_file.out() << "tools::rroot::key::get_object_buffer :"
m_out << "tools::rroot::key::get_object_buffer :"
<< " WARNING : m_buf_size<m_nbytes."
<< " m_buf_size " << m_buf_size
<< " m_nbytes " << m_nbytes
@@ -314,7 +314,7 @@ public:
}
m_buffer = new char[m_buf_size];
if(!m_buffer) {
m_file.out() << "tools::rroot::key::get_object_buffer :"
m_out << "tools::rroot::key::get_object_buffer :"
<< " can't alloc " << m_buf_size
<< std::endl;
m_buffer = 0;
@@ -323,7 +323,7 @@ public:
return 0;
}
if(!read_file()) {
if(!read_file(a_file)) {
delete [] m_buffer;
m_buffer = 0;
m_buf_size = 0;
@@ -337,7 +337,7 @@ public:
uint32 decsiz = m_key_length+m_object_size;
char* decbuf = new char[decsiz];
if(!decbuf) {
m_file.out() << "tools::rroot::key::get_object_buffer :"
m_out << "tools::rroot::key::get_object_buffer :"
<< " can't alloc " << decsiz
<< std::endl;
a_size = 0;
@@ -347,7 +347,7 @@ public:
delete [] m_buffer;
m_buffer = new char[m_nbytes];
m_buf_size = m_nbytes;
if(!read_file()) {
if(!read_file(a_file)) {
delete [] decbuf;
decbuf = 0;
delete [] m_buffer;
@@ -367,7 +367,7 @@ public:
while(true) {
int nin = 9 + ((int)bufcur[3] | ((int)bufcur[4] << 8) | ((int)bufcur[5] << 16));
int nbuf = (int)bufcur[6] | ((int)bufcur[7] << 8) | ((int)bufcur[8] << 16);
if(!unzip(m_file.out(),nin,bufcur,nbuf,objbuf,nout)) break;
if(!unzip(m_out,a_file,nin,bufcur,nbuf,objbuf,nout)) break;
if(!nout) break;
noutot += nout;
if(noutot >= m_object_size) break;
@@ -380,7 +380,7 @@ public:
m_buf_size = 0;
if(!noutot) {
m_file.out() << "tools::rroot::key::get_object_buffer :"
m_out << "tools::rroot::key::get_object_buffer :"
<< " nothing from decompression."
<< std::endl;
delete [] decbuf;
@@ -389,7 +389,7 @@ public:
return 0;
}
if(noutot!=m_object_size) {
m_file.out() << "tools::rroot::key::get_object_buffer :"
m_out << "tools::rroot::key::get_object_buffer :"
<< " decompression mismatch."
<< " noutot " << noutot
<< " m_object_size " << m_object_size
@@ -428,7 +428,7 @@ protected:
_nbytes += sizeof(date);
_nbytes += sizeof(m_key_length);
_nbytes += sizeof(m_cycle); //2+4*4=18
if(a_version>1000) {
if(a_version>big_file_version_tag()) {
_nbytes += sizeof(seek);
_nbytes += sizeof(seek); //18+2*8=34
} else {
@@ -442,7 +442,8 @@ protected:
return _nbytes;
}
bool unzip(std::ostream& a_out,int a_srcsize,unsigned char* a_src,int a_tgtsize,unsigned char* a_tgt,int& a_irep) {
bool unzip(std::ostream& a_out,ifile& a_file,
int a_srcsize,unsigned char* a_src,int a_tgtsize,unsigned char* a_tgt,int& a_irep) {
// Author: E.Chernyaev (IHEP/Protvino)
// Input: scrsize - size of input buffer
@@ -490,7 +491,7 @@ protected:
if (a_src[0] == 'Z' && a_src[1] == 'L') { //compressed with zlib.
tools::decompress_func func;
if(!m_file.unziper('Z',func)) {
if(!a_file.unziper('Z',func)) {
a_out << "tools::rroot::key::unzip : "
<< " zlib unziper not found." << std::endl;
return false;
@@ -553,7 +554,7 @@ protected:
return s_v;
}
protected:
ifile& m_file;
std::ostream& m_out;
uint32 m_buf_size;
char* m_buffer;
// Record (stored in file) :
@@ -91,41 +91,38 @@ public:
return true;
}
public: //base_leaf
virtual bool read_basket(buffer& a_buffer) {
virtual bool read_buffer(buffer& a_buffer) {
if(!m_leaf_count && (m_ndata == 1)) {
/*
if(!aBuffer.read(m_value[0])) {
std::ostream& out = base_leaf::branch().out();
out << "Rio::Leaf::readBasket : \"" << name() << "\" :"
m_out << "Rio::Leaf::readBasket : \"" << name() << "\" :"
<< " read value failed."
<< std::endl;
return false;
}
return true;
*/
m_out << "tools::rroot::leaf::read_basket :"
m_out << "tools::rroot::leaf::read_buffer :"
<< " case(1) not yet handled."
<< std::endl;
return false;
}else {
if(m_leaf_count) {
m_out << "tools::rroot::leaf::read_basket :"
m_out << "tools::rroot::leaf::read_buffer :"
<< " case(2) not yet handled."
<< std::endl;
return false;
/*
int len = m_leaf_count->number();
if (len > m_leaf_count->maximum()) {
std::ostream& out = base_leaf::branch().out();
out << "Rio::Leaf::readBasket : \""
m_out << "Rio::Leaf::readBasket : \""
<< name() << "\", len = " << len << " and max = "
<< m_leaf_count->maximum() << std::endl;
len = m_leaf_count->maximum();
}
m_ndata = len * fLength;
if(!aBuffer.readFastArray(m_value,len * fLength)) {
std::ostream& out = base_leaf::branch().out();
out << "Rio::Leaf::readBasket : \"" << name() << "\" :"
m_out << "Rio::Leaf::readBasket : \"" << name() << "\" :"
<< " readFastArray failed."
<< std::endl;
return false;
@@ -139,14 +136,14 @@ public: //base_leaf
m_value = new T[m_length]; //we assume m_length is constant.
}
if(!a_buffer.read_fast_array<T>(m_value,m_length)) {
m_out << "tools::rroot::leaf::read_basket :"
m_out << "tools::rroot::leaf::read_buffer :"
<< " read_fast_array failed. m_length " << m_length
<< std::endl;
return false;
}
return true;
} else {
m_out << "tools::rroot::leaf::read_basket :"
m_out << "tools::rroot::leaf::read_buffer :"
<< " read_fast_array failed. m_length is zero."
<< std::endl;
return false;
@@ -163,8 +160,8 @@ public: //base_leaf
}
virtual uint32 num_elem() const {return m_length;}
public:
leaf(std::ostream& a_out,rroot::branch& a_branch,ifac& a_fac)
:base_leaf(a_out,a_branch,a_fac)
leaf(std::ostream& a_out,ifac& a_fac)
:base_leaf(a_out,a_fac)
,m_min(T()),m_max(T())
,m_value(0)
{}
@@ -221,13 +218,13 @@ public:
return true;
}
public: //base_leaf
virtual bool read_basket(buffer& a_buffer) {
virtual bool read_buffer(buffer& a_buffer) {
delete [] m_value;
m_value = 0;
unsigned char lenchar;
if(!a_buffer.read(lenchar)) {
m_out << "tools::rroot::leaf_string::read_basket :"
m_out << "tools::rroot::leaf_string::read_buffer :"
<< " read(uchar) failed."
<< std::endl;
return false;
@@ -237,7 +234,7 @@ public: //base_leaf
len = lenchar;
} else {
if(!a_buffer.read(len)) {
m_out << "tools::rroot::leaf_string::read_basket :"
m_out << "tools::rroot::leaf_string::read_buffer :"
<< " read(int) failed."
<< std::endl;
return false;
@@ -246,7 +243,7 @@ public: //base_leaf
if(len) {
if(!m_length) {
m_out << "tools::rroot::leaf_string::read_basket :"
m_out << "tools::rroot::leaf_string::read_buffer :"
<< " m_length is zero."
<< std::endl;
return false;
@@ -257,7 +254,7 @@ public: //base_leaf
m_value = new char[len+1];
if(!a_buffer.read_fast_array(m_value,len)) {
m_out << "tools::rroot::leaf_string::read_basket :"
m_out << "tools::rroot::leaf_string::read_buffer :"
<< " read_fast_array failed."
<< std::endl;
delete [] m_value;
@@ -276,8 +273,8 @@ public: //base_leaf
}
virtual uint32 num_elem() const {return 1;}
public:
leaf_string(std::ostream& a_out,rroot::branch& a_branch,ifac& a_fac)
:base_leaf(a_out,a_branch,a_fac)
leaf_string(std::ostream& a_out,ifac& a_fac)
:base_leaf(a_out,a_fac)
,m_min(0),m_max(0),m_value(0){}
virtual ~leaf_string(){
delete [] m_value;
@@ -330,8 +327,8 @@ public:
return true;
}
public: //base_leaf
virtual bool read_basket(buffer&) {
m_out << "tools::rroot::leaf_element::read_basket :"
virtual bool read_buffer(buffer&) {
m_out << "tools::rroot::leaf_element::read_buffer :"
<< " dummy."
<< std::endl;
return false;
@@ -339,8 +336,8 @@ public: //base_leaf
virtual bool print_value(std::ostream&,uint32) const {return true;}
virtual uint32 num_elem() const {return 0;}
public:
leaf_element(std::ostream& a_out,rroot::branch& a_branch,ifac& a_fac)
:base_leaf(a_out,a_branch,a_fac),fID(0),fType(0){}
leaf_element(std::ostream& a_out,ifac& a_fac)
:base_leaf(a_out,a_fac),fID(0),fType(0){}
virtual ~leaf_element(){}
protected:
leaf_element(const leaf_element& a_from)
@@ -354,6 +351,10 @@ protected:
int fType; //leaf type
};
// for SWIG :
inline leaf<float>* cast_leaf_float(base_leaf& a_leaf) {return safe_cast<base_leaf, leaf<float> >(a_leaf);}
inline leaf<int>* cast_leaf_int(base_leaf& a_leaf) {return safe_cast<base_leaf, leaf<int> >(a_leaf);}
}}
#endif
@@ -46,9 +46,9 @@ public:
virtual bool visit(std::vector<bool>& a_v){
std::vector<unsigned char> data;
if(!m_buf.read_array(data)) {a_v.clear();return false;}
unsigned int number = data.size();
size_t number = data.size();
a_v.resize(number);
for(unsigned int index=0;index<number;index++) {
for(size_t index=0;index<number;index++) {
a_v[index] = (data[index]==1?true:false);
}
return true;

Some files were not shown because too many files have changed in this diff Show More