Import Geant4 11.4.0 source tree
This commit is contained in:
+5
-419
@@ -7,12 +7,7 @@
|
||||
// An in memory ntuple able to have "sub ntuple" on a column.
|
||||
// It is used in ioda to read ntuples in XML/AIDA files.
|
||||
|
||||
#ifdef TOOLS_MEM
|
||||
#include "mem"
|
||||
#endif
|
||||
|
||||
#include "vmanip"
|
||||
#include "vfind"
|
||||
#include "typedefs"
|
||||
#include "scast"
|
||||
#include "forit"
|
||||
@@ -48,24 +43,15 @@ protected:
|
||||
base_col(std::ostream& a_out,const std::string& a_name)
|
||||
:m_out(a_out)
|
||||
,m_name(a_name),m_index(0){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
public:
|
||||
virtual ~base_col(){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
protected:
|
||||
base_col(const base_col& a_from)
|
||||
:m_out(a_from.m_out)
|
||||
,m_name(a_from.m_name)
|
||||
,m_index(a_from.m_index){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
base_col& operator=(const base_col& a_from){
|
||||
m_name = a_from.m_name;
|
||||
@@ -95,24 +81,15 @@ public:
|
||||
protected:
|
||||
base_ntu(std::ostream& a_out,const std::string& a_title)
|
||||
:m_out(a_out),m_title(a_title),m_index(-1){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
virtual ~base_ntu() {
|
||||
clear();
|
||||
#ifdef TOOLS_MEM
|
||||
mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
protected:
|
||||
base_ntu(const base_ntu& a_from)
|
||||
:m_out(a_from.m_out)
|
||||
,m_title(a_from.m_title),m_index(a_from.m_index)
|
||||
{
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
tools_vforcit(base_col*,a_from.m_cols,it) {
|
||||
base_col* column = (*it)->copy();
|
||||
if(!column) {
|
||||
@@ -153,10 +130,6 @@ public:
|
||||
const std::vector<base_col*>& columns() const {return m_cols;}
|
||||
size_t number_of_columns() const {return m_cols.size();}
|
||||
|
||||
#ifdef tools_aida_ntuple
|
||||
const std::vector<base_col*>& cols() const {return m_cols;} //deprecated : use columns().
|
||||
#endif
|
||||
|
||||
void column_names(std::vector<std::string>& a_names) const {
|
||||
a_names.clear();
|
||||
tools_vforcit(base_col*,m_cols,it) a_names.push_back((*it)->name());
|
||||
@@ -247,10 +220,6 @@ protected:
|
||||
namespace tools {
|
||||
namespace aida {
|
||||
|
||||
//inline const std::string& s_aida_type(char) {
|
||||
// static const std::string s_v("char");
|
||||
// return s_v;
|
||||
//}
|
||||
inline const std::string& s_aida_type(short) {
|
||||
static const std::string s_v("short");
|
||||
return s_v;
|
||||
@@ -268,13 +237,6 @@ inline const std::string& s_aida_type(double) {
|
||||
return s_v;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
/////////////////////////////////////////
|
||||
//inline const std::string& s_aida_type(unsigned char) {
|
||||
// static const std::string s_v("byte");
|
||||
// return s_v;
|
||||
//}
|
||||
|
||||
inline const std::string& s_aida_type(bool) {
|
||||
static const std::string s_v("boolean");
|
||||
return s_v;
|
||||
@@ -287,12 +249,7 @@ inline const std::string& s_aida_type(int64) {
|
||||
static const std::string s_v("long");
|
||||
return s_v;
|
||||
}
|
||||
/*
|
||||
inline const std::string& s_aida_type(const std::vector<double>&) {
|
||||
static const std::string s_v("double[]");
|
||||
return s_v;
|
||||
}
|
||||
*/
|
||||
|
||||
inline const std::string& s_aida_type_ituple() {
|
||||
static const std::string s_v("ITuple");
|
||||
return s_v;
|
||||
@@ -609,7 +566,7 @@ public:
|
||||
if(!row) {
|
||||
a_value = v;
|
||||
} else {
|
||||
a_value = mn<T>(a_value,v);
|
||||
a_value = min_of<T>(a_value,v);
|
||||
}
|
||||
}}
|
||||
return true;
|
||||
@@ -632,7 +589,7 @@ public:
|
||||
if(!row) {
|
||||
a_value = v;
|
||||
} else {
|
||||
a_value = mx<T>(a_value,v);
|
||||
a_value = max_of<T>(a_value,v);
|
||||
}
|
||||
}}
|
||||
return true;
|
||||
@@ -771,9 +728,7 @@ inline bool create_cols_from_vals(ntuple& a_ntu,
|
||||
// double[]
|
||||
|
||||
base_col* col = 0;
|
||||
/*if((*it).type()==value::CHAR) {
|
||||
col = a_ntu.create_col<char>((*it).label(),(*it).get_char());
|
||||
} else*/ if((*it).type()==value::SHORT) {
|
||||
if((*it).type()==value::SHORT) {
|
||||
col = a_ntu.create_col<short>((*it).label(),(*it).get_short());
|
||||
} else if((*it).type()==value::INT) {
|
||||
col = a_ntu.create_col<int>((*it).label(),(*it).get_int());
|
||||
@@ -783,9 +738,6 @@ inline bool create_cols_from_vals(ntuple& a_ntu,
|
||||
col = a_ntu.create_col<float>((*it).label(),(*it).get_float());
|
||||
} else if((*it).type()==value::DOUBLE) {
|
||||
col = a_ntu.create_col<double>((*it).label(),(*it).get_double());
|
||||
|
||||
//} else if((*it).type()==value::UNSIGNED_CHAR) {
|
||||
// col = a_ntu.create_col<unsigned char>((*it).label(),(*it).get_unsigned_char());
|
||||
} else if((*it).type()==value::UNSIGNED_SHORT) {
|
||||
col = a_ntu.create_col<unsigned short>((*it).label(),(*it).get_unsigned_short());
|
||||
} else if((*it).type()==value::UNSIGNED_INT) {
|
||||
@@ -824,24 +776,7 @@ inline bool create_col(ntuple& a_ntu,
|
||||
const std::string& a_name,
|
||||
const std::string& a_s, //def or booking.
|
||||
bool a_is_ntu){
|
||||
/*
|
||||
if(a_type==s_aida_type((char)0)) {
|
||||
char v = 0;
|
||||
if(a_s.size()&&!to<char>(a_s,v)) {
|
||||
a_ntu.out() << "tools::aida::create_col :"
|
||||
<< " can't convert def " << sout(a_s)
|
||||
<< " to a " << a_type
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if(!a_ntu.create_col<char>(a_name,v)) {
|
||||
a_ntu.out() << "tools::aida::create_col :"
|
||||
<< " can't create column of type " << sout(a_type)
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
} else*/ if(a_type==s_aida_type((short)0)) {
|
||||
if(a_type==s_aida_type((short)0)) {
|
||||
short v = 0;
|
||||
if(a_s.size()&&!to<short>(a_s,v)) {
|
||||
a_ntu.out() << "tools::aida::create_col :"
|
||||
@@ -921,30 +856,6 @@ inline bool create_col(ntuple& a_ntu,
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* } else if(a_type==s_aida_type((unsigned char)0)) { //byte
|
||||
unsigned int v = 0;
|
||||
if(a_s.size()&&!to<unsigned int>(a_s,v)) {
|
||||
a_ntu.out() << "tools::aida::create_col :"
|
||||
<< " can't convert def " << sout(a_s)
|
||||
<< " to a " << a_type
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if(v>=256) {
|
||||
a_ntu.out() << "tools::aida::create_col :"
|
||||
<< " can't convert def " << sout(a_s)
|
||||
<< " to byte."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if(!a_ntu.create_col<unsigned char>(a_name,v)) {
|
||||
a_ntu.out() << "tools::aida::create_col :"
|
||||
<< " can't create column of type " << sout(a_type)
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
} else if(a_type==s_aida_type((unsigned short)0)) {
|
||||
unsigned short v = 0;
|
||||
if(a_s.size()&&!to<unsigned short>(a_s,v)) {
|
||||
@@ -1088,331 +999,6 @@ inline bool create_col(ntuple& a_ntu,
|
||||
return true;
|
||||
}
|
||||
|
||||
// for waxml :
|
||||
inline bool create_cols_from_string(ntuple& a_ntu,
|
||||
const std::string& a_booking,
|
||||
bool a_verbose = false){
|
||||
a_ntu.clear();
|
||||
if(a_booking.empty()) {
|
||||
a_ntu.out() << "tools::aida::create_cols_from_string :"
|
||||
<< " empty booking string."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
columns::finder f(a_ntu.out(),a_booking);
|
||||
if(!f.find_variables()) {
|
||||
a_ntu.out() << "tools::aida::create_cols_from_string :"
|
||||
<< " find_variables() failed."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
std::vector<value> vars;f.result(vars);
|
||||
if(a_verbose) columns::dump_columns(a_ntu.out(),vars);
|
||||
|
||||
if(!create_cols_from_vals(a_ntu,vars)) {
|
||||
columns::delete_columns(vars);
|
||||
a_ntu.clear();
|
||||
return false;
|
||||
}
|
||||
columns::delete_columns(vars);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline aida_col_ntu* find_col_ntu(ntuple& a_ntu,const std::string& a_name){
|
||||
base_col* col = find_named<base_col>(a_ntu.columns(),a_name);
|
||||
if(!col) return 0;
|
||||
return safe_cast<base_col, aida_col_ntu >(*col);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class base_looper {
|
||||
public:
|
||||
static const std::string& s_class() {
|
||||
static const std::string s_v("tools::aida::base_looper<"+stype(T())+">");
|
||||
return s_v;
|
||||
}
|
||||
protected:
|
||||
virtual bool action(const T& a_value) = 0; //return false to stop processing.
|
||||
public:
|
||||
base_looper(base_ntu& a_ntu,const base_col& a_col)
|
||||
:m_ntu(a_ntu),m_col(a_col){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
virtual ~base_looper(){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
public:
|
||||
base_looper(const base_looper& a_from)
|
||||
:m_ntu(a_from.m_ntu),m_col(a_from.m_col){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
base_looper& operator=(const base_looper&){return *this;}
|
||||
public:
|
||||
bool process() {
|
||||
std::vector<unsigned int> is;
|
||||
bool found = false;
|
||||
if(!find_is(m_ntu,&m_col,is,found)) {
|
||||
m_ntu.out() << s_class() << "::process :"
|
||||
<< " find_is failed."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if(!found) {
|
||||
m_ntu.out() << s_class() << "::process :"
|
||||
<< " find_is : col not found."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if(is.empty()) {
|
||||
m_ntu.out() << s_class() << "::process :"
|
||||
<< " is vec empty."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stop = false;
|
||||
if(!_looper(m_ntu,is,0,stop)) {
|
||||
m_ntu.out() << s_class() << "::process :"
|
||||
<< " _looper failed."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
protected:
|
||||
static bool find_is(const base_ntu& a_ntu,const base_col* a_col,
|
||||
std::vector<unsigned int>& a_is,
|
||||
bool& a_found){
|
||||
// search the indices to reach the sub leaf a_col from the main a_ntu.
|
||||
// Note : it is assumed that a_is is empty and a_found = false before
|
||||
// calling with function.
|
||||
|
||||
const std::vector<base_col*>& cols = a_ntu.columns();
|
||||
|
||||
// look if a_col is a leaf col of a_ntu :
|
||||
{unsigned int index = 0;
|
||||
tools_vforcit(base_col*,cols,it) {
|
||||
if(*it==a_col) {
|
||||
a_is.push_back(index); //leaf index is the last one in a_is.
|
||||
a_found = true;
|
||||
return true;
|
||||
}
|
||||
index++;
|
||||
}}
|
||||
|
||||
// go down sub ntu :
|
||||
{unsigned int index = 0;
|
||||
tools_vforcit(base_col*,cols,it) {
|
||||
aida_col_ntu* col = safe_cast<base_col,aida_col_ntu>(*(*it));
|
||||
if(col) {
|
||||
base_ntu* sub = col->get_to_fill(); //it holds the "sub" cols schema.
|
||||
if(!sub) {a_is.clear();return false;}
|
||||
a_is.push_back(index);
|
||||
if(!find_is(*sub,a_col,a_is,a_found)) {a_is.clear();return false;}
|
||||
if(a_found) return true;
|
||||
a_is.pop_back();
|
||||
}
|
||||
index++;
|
||||
}}
|
||||
return true;
|
||||
}
|
||||
protected:
|
||||
bool _looper(base_ntu& a_sub,
|
||||
const std::vector<unsigned int>& a_is,
|
||||
unsigned int a_depth,
|
||||
bool& a_stop) {
|
||||
if(a_depth>=a_is.size()) return false;
|
||||
|
||||
unsigned int coli = a_is[a_depth];
|
||||
const std::vector<base_col*>& cols = a_sub.columns();
|
||||
if(coli>=cols.size()) return false;
|
||||
|
||||
if(a_depth==(a_is.size()-1)) { //we reach the leaf.
|
||||
aida_col<T>* col = safe_cast<base_col, aida_col<T> >(*(cols[coli]));
|
||||
if(!col) return false;
|
||||
a_sub.start();
|
||||
while(a_sub.next()) {
|
||||
T v;
|
||||
if(!col->get_entry(v)) return false;
|
||||
if(!action(v)) {a_stop = true;break;}
|
||||
}
|
||||
} else {
|
||||
aida_col_ntu* col = safe_cast<base_col,aida_col_ntu>(*(cols[coli]));
|
||||
if(!col) return false;
|
||||
a_sub.start();
|
||||
while(a_sub.next()) {
|
||||
base_ntu* ntu = col->get_entry(); //not const.
|
||||
if(!ntu) return false;
|
||||
ntu->start();
|
||||
while(ntu->next()) {
|
||||
if(!_looper(*ntu,a_is,a_depth+1,a_stop)) return false;
|
||||
if(a_stop) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
protected:
|
||||
base_ntu& m_ntu;
|
||||
const base_col& m_col;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#include "mnmx"
|
||||
|
||||
namespace tools {
|
||||
namespace aida {
|
||||
|
||||
template <class T>
|
||||
class stat_looper : public base_looper<T> {
|
||||
protected:
|
||||
virtual bool action(const T& a_v) {
|
||||
if(m_first) {
|
||||
m_mn = a_v;
|
||||
m_mx = a_v;
|
||||
m_S = a_v;
|
||||
m_S2 = a_v*a_v;
|
||||
|
||||
m_first = false;
|
||||
} else {
|
||||
m_mn = min_of<T>(m_mn,a_v);
|
||||
m_mx = max_of<T>(m_mx,a_v);
|
||||
m_S += a_v;
|
||||
m_S2 += a_v*a_v;
|
||||
}
|
||||
m_counter++;
|
||||
return true; //continue looping.
|
||||
}
|
||||
public:
|
||||
stat_looper(base_ntu& a_ntu,const base_col& a_col)
|
||||
:base_looper<T>(a_ntu,a_col)
|
||||
,m_first(true)
|
||||
,m_mn(T())
|
||||
,m_mx(T())
|
||||
,m_S(T())
|
||||
,m_S2(T())
|
||||
,m_counter(0)
|
||||
{}
|
||||
virtual ~stat_looper(){}
|
||||
public:
|
||||
stat_looper(const stat_looper& a_from)
|
||||
:base_looper<T>(a_from)
|
||||
,m_first(true)
|
||||
,m_mn(T())
|
||||
,m_mx(T())
|
||||
,m_S(T())
|
||||
,m_S2(T())
|
||||
,m_counter(0)
|
||||
{}
|
||||
stat_looper& operator=(const stat_looper& a_from){
|
||||
base_looper<T>::operator=(a_from);
|
||||
if(&a_from==this) return *this;
|
||||
m_first = true;
|
||||
m_mn = T();
|
||||
m_mx = T();
|
||||
m_S = T();
|
||||
m_S2 = T();
|
||||
m_counter = 0;
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
bool process() {
|
||||
m_counter = 0;
|
||||
if(!base_looper<T>::process()) {
|
||||
m_mn = T();
|
||||
m_mx = T();
|
||||
m_S = T();
|
||||
m_S2 = T();
|
||||
m_counter = 0;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
T mn() const {return m_mn;}
|
||||
T mx() const {return m_mx;}
|
||||
T S() const {return m_S;}
|
||||
T S2() const {return m_S2;}
|
||||
uint64 counter() const {return m_counter;}
|
||||
protected:
|
||||
bool m_first;
|
||||
T m_mn;
|
||||
T m_mx;
|
||||
T m_S;
|
||||
T m_S2;
|
||||
uint64 m_counter;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline bool column_infos(base_ntu& a_ntu,
|
||||
base_col& a_col,
|
||||
T& a_mn,T& a_mx,T& a_S,T& a_S2,
|
||||
uint64& a_count){
|
||||
stat_looper<T> lpr(a_ntu,a_col);
|
||||
bool status = lpr.process();
|
||||
a_mn = lpr.mn();
|
||||
a_mx = lpr.mx();
|
||||
a_S = lpr.S();
|
||||
a_S2 = lpr.S2();
|
||||
a_count = lpr.counter();
|
||||
if(!status) return false;
|
||||
if(!a_count) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline base_col* find_leaf_column(const base_ntu& a_ntu,const std::string& a_name){
|
||||
const std::vector<base_col*>& cols = a_ntu.columns();
|
||||
tools_vforcit(base_col*,cols,it) {
|
||||
aida_col_ntu* col = safe_cast<base_col,aida_col_ntu>(*(*it));
|
||||
if(col) {
|
||||
base_ntu* sub = col->get_to_fill(); //it holds the "sub" cols schema.
|
||||
if(!sub) return 0;
|
||||
base_col* fcol = find_leaf_column(*sub,a_name);
|
||||
if(fcol) return fcol;
|
||||
} else {
|
||||
if((*it)->name()==a_name) return *it;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool to_vector(base_ntu& a_ntu,std::vector<double>& a_vec,unsigned int a_col = 0) {
|
||||
a_vec.clear();
|
||||
const std::vector<base_col*>& cols = a_ntu.columns();
|
||||
if(cols.empty()) return false;
|
||||
if(a_col>=cols.size()) return false;
|
||||
base_col* _base_col = cols[a_col];
|
||||
aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
|
||||
if(!_col) return false;
|
||||
a_ntu.start();
|
||||
uint64 _rows = a_ntu.rows();
|
||||
a_vec.resize(_rows);
|
||||
T v;
|
||||
{for(uint64 row=0;row<_rows;row++) {
|
||||
if(!a_ntu.next()) {a_vec.clear();return false;}
|
||||
if(!_col->get_entry(v)) {}
|
||||
a_vec[row] = v;
|
||||
}}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool column_min(ntuple& a_ntu,unsigned int a_col,T& a_value) {
|
||||
return a_ntu.column_min(a_col,a_value);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool column_max(ntuple& a_ntu,unsigned int a_col,T& a_value) {
|
||||
return a_ntu.column_max(a_col,a_value);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user