Import Geant4 10.1.0 source tree
This commit is contained in:
@@ -10,7 +10,9 @@
|
||||
#include "../vfind"
|
||||
#include "../vmanip"
|
||||
#include "../sout"
|
||||
#include "../srep"
|
||||
#include "../tos"
|
||||
#include "../forit"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
@@ -31,6 +33,8 @@ protected:
|
||||
virtual ~iobj(){}
|
||||
public:
|
||||
virtual void* cast(cid) const = 0;
|
||||
virtual cid id_cls() const = 0;
|
||||
public:
|
||||
virtual const std::string& name() const = 0;
|
||||
virtual std::string aida_type() const = 0;
|
||||
};
|
||||
@@ -43,6 +47,7 @@ protected:
|
||||
if(void* p = cmp_cast<leaf>(this,a_class)) {return p;}
|
||||
return 0;
|
||||
}
|
||||
virtual cid id_cls() const {return id_class();}
|
||||
public:
|
||||
virtual std::string s_def() const = 0;
|
||||
virtual std::string s_value() const = 0;
|
||||
@@ -65,6 +70,10 @@ protected:
|
||||
static const std::string s_v("double");
|
||||
return s_v;
|
||||
}
|
||||
static const std::string& s_aida_type(const std::string&) {
|
||||
static const std::string s_v("string");
|
||||
return s_v;
|
||||
}
|
||||
|
||||
public:
|
||||
template <class T>
|
||||
@@ -76,6 +85,8 @@ public:
|
||||
if(void* p = cmp_cast< column<T> >(this,a_class)) {return p;}
|
||||
return leaf::cast(a_class);
|
||||
}
|
||||
virtual cid id_cls() const {return id_class();}
|
||||
public:
|
||||
virtual const std::string& name() const {return m_name;}
|
||||
virtual std::string aida_type() const {return s_aida_type(T());}
|
||||
public: //leaf
|
||||
@@ -116,11 +127,12 @@ public:
|
||||
if(void* p = cmp_cast<sub_ntuple>(this,a_class)) {return p;}
|
||||
return 0;
|
||||
}
|
||||
virtual cid id_cls() const {return id_class();}
|
||||
public:
|
||||
virtual const std::string& name() const {return m_name;}
|
||||
virtual std::string aida_type() const {return "ITuple";}
|
||||
public:
|
||||
sub_ntuple(const std::string& a_name,
|
||||
const std::string& a_spaces)
|
||||
sub_ntuple(const std::string& a_name,const std::string& a_spaces)
|
||||
:m_name(a_name),m_spaces(a_spaces){}
|
||||
virtual ~sub_ntuple(){}
|
||||
protected:
|
||||
@@ -129,8 +141,7 @@ public:
|
||||
sub_ntuple& operator=(const sub_ntuple&){return *this;}
|
||||
public:
|
||||
template <class T>
|
||||
column<T>* create_column(const std::string& a_name,
|
||||
const T& a_def = T()) {
|
||||
column<T>* create_column(const std::string& a_name,const T& a_def = T()) {
|
||||
if(find_named<iobj>(m_cols,a_name)) return 0;
|
||||
column<T>* col = new column<T>(a_name,a_def);
|
||||
if(!col) return 0;
|
||||
@@ -151,9 +162,9 @@ public:
|
||||
|
||||
const std::vector<iobj*>& columns() const {return m_cols;}
|
||||
|
||||
std::string booking() const {
|
||||
std::string booking(bool a_xml_esc) const {
|
||||
std::string s;
|
||||
get_booking(m_cols,s);
|
||||
get_booking(m_cols,a_xml_esc,s);
|
||||
return s;
|
||||
}
|
||||
void reset() {m_tmp.clear();}
|
||||
@@ -163,8 +174,7 @@ public:
|
||||
if(m_cols.empty()) return false;
|
||||
std::ostringstream sout;
|
||||
sout << m_spaces << "<row>" << std::endl;
|
||||
std::vector<iobj*>::const_iterator it;
|
||||
for(it=m_cols.begin();it!=m_cols.end();++it) {
|
||||
tools_vforcit(iobj*,m_cols,it) {
|
||||
if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))) {
|
||||
sout << m_spaces << " <entryITuple>" << std::endl;
|
||||
sout << sub->value();
|
||||
@@ -189,6 +199,63 @@ public:
|
||||
std::string m_tmp;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class std_vector_column : public leaf {
|
||||
public:
|
||||
static cid id_class() {return 200+_cid_std_vector<T>();}
|
||||
public: //iobj
|
||||
virtual void* cast(cid a_class) const {
|
||||
if(void* p = cmp_cast<std_vector_column>(this,a_class)) {return p;}
|
||||
return leaf::cast(a_class);
|
||||
}
|
||||
virtual cid id_cls() const {return id_class();}
|
||||
public:
|
||||
virtual const std::string& name() const {return m_name;}
|
||||
virtual std::string aida_type() const {return s_aida_type(T());}
|
||||
public: //leaf
|
||||
virtual std::string s_def() const {return "";} //not used.
|
||||
virtual std::string s_value() const {
|
||||
std::ostringstream sout;
|
||||
sout << m_spaces << "<entryITuple>" << std::endl;
|
||||
typedef typename std::vector<T>::const_iterator it_t;
|
||||
for(it_t it=m_user_vec.begin();it!=m_user_vec.end();++it) {
|
||||
sout << m_spaces << " <row><entry" << " value=\"" << tos(*it) << "\"/></row>" << std::endl;
|
||||
}
|
||||
sout << m_spaces << "</entryITuple>" << std::endl;
|
||||
return sout.str();
|
||||
}
|
||||
public:
|
||||
std_vector_column(const std::string& a_name,std::vector<T>& a_user_vec,const std::string& a_spaces)
|
||||
:m_name(a_name)
|
||||
,m_user_vec(a_user_vec)
|
||||
,m_spaces(a_spaces)
|
||||
{}
|
||||
virtual ~std_vector_column(){}
|
||||
protected:
|
||||
std_vector_column(const std_vector_column& a_from)
|
||||
:leaf(a_from)
|
||||
,m_name(a_from.m_name)
|
||||
,m_user_vec(a_from.m_user_vec)
|
||||
,m_spaces(a_from.m_spaces)
|
||||
{}
|
||||
std_vector_column& operator=(const std_vector_column& a_from){
|
||||
m_name = a_from.m_name;
|
||||
m_spaces = a_from.m_spaces;
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
std::string m_name;
|
||||
std::vector<T>& m_user_vec;
|
||||
std::string m_spaces;
|
||||
};
|
||||
|
||||
static leaf* is_std_vector_column(iobj& a_obj) {
|
||||
//200+20+id(basic type) ?
|
||||
int _id = (int)a_obj.id_cls()-220;
|
||||
if((_id<=0)||(_id>=20)) return 0;
|
||||
return id_cast<iobj,leaf>(a_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
ntuple(std::ostream& a_writer,unsigned int a_spaces = 0)
|
||||
:m_writer(a_writer){
|
||||
@@ -201,21 +268,59 @@ public:
|
||||
:m_writer(a_writer){
|
||||
for(unsigned int i=0;i<a_spaces;i++) m_spaces += " ";
|
||||
|
||||
const std::vector<ntuple_booking::col_t>& cols = a_bkg.m_columns;
|
||||
std::vector<ntuple_booking::col_t>::const_iterator it;
|
||||
for(it=cols.begin();it!=cols.end();++it){
|
||||
const std::vector<column_booking>& cols = a_bkg.columns();
|
||||
tools_vforcit(column_booking,cols,it){
|
||||
|
||||
if((*it).second==_cid(int(0))) {
|
||||
create_column<int>((*it).first);
|
||||
} else if((*it).second==_cid(float(0))) {
|
||||
create_column<float>((*it).first);
|
||||
} else if((*it).second==_cid(double(0))) {
|
||||
create_column<double>((*it).first);
|
||||
if((*it).cls_id()==_cid(int(0))) {
|
||||
create_column<int>((*it).name());
|
||||
} else if((*it).cls_id()==_cid(float(0))) {
|
||||
create_column<float>((*it).name());
|
||||
} else if((*it).cls_id()==_cid(double(0))) {
|
||||
create_column<double>((*it).name());
|
||||
} else if((*it).cls_id()==_cid(std::string())) {
|
||||
create_column<std::string>((*it).name());
|
||||
|
||||
} else if((*it).cls_id()==_cid_std_vector<int>()) {
|
||||
std::vector<int>* vec = (std::vector<int>*)(*it).user_obj();
|
||||
if(vec) {
|
||||
create_column<int>((*it).name(),*vec);
|
||||
} else {
|
||||
a_out << "tools::waxml::ntuple :"
|
||||
<< " for std::vector column " << sout((*it).name())
|
||||
<< ", the user vector pointer is null."
|
||||
<< std::endl;
|
||||
tools::clear<iobj>(m_cols);
|
||||
return;
|
||||
}
|
||||
} else if((*it).cls_id()==_cid_std_vector<float>()) {
|
||||
std::vector<float>* vec = (std::vector<float>*)(*it).user_obj();
|
||||
if(vec) {
|
||||
create_column<float>((*it).name(),*vec);
|
||||
} else {
|
||||
a_out << "tools::waxml::ntuple :"
|
||||
<< " for std::vector column " << sout((*it).name())
|
||||
<< ", the user vector pointer is null."
|
||||
<< std::endl;
|
||||
tools::clear<iobj>(m_cols);
|
||||
return;
|
||||
}
|
||||
} else if((*it).cls_id()==_cid_std_vector<double>()) {
|
||||
std::vector<double>* vec = (std::vector<double>*)(*it).user_obj();
|
||||
if(vec) {
|
||||
create_column<double>((*it).name(),*vec);
|
||||
} else {
|
||||
a_out << "tools::waxml::ntuple :"
|
||||
<< " for std::vector column " << sout((*it).name())
|
||||
<< ", the user vector pointer is null."
|
||||
<< std::endl;
|
||||
tools::clear<iobj>(m_cols);
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
a_out << "tools::waxml::ntuple :"
|
||||
<< " for column " << sout((*it).first)
|
||||
<< ", type with cid " << (*it).second << " not yet handled."
|
||||
<< " for column " << sout((*it).name())
|
||||
<< ", type with cid " << (*it).cls_id() << " not yet handled."
|
||||
<< std::endl;
|
||||
//throw
|
||||
tools::clear<iobj>(m_cols);
|
||||
@@ -247,6 +352,17 @@ public:
|
||||
return col;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std_vector_column<T>* create_column(const std::string& a_name,std::vector<T>& a_user_vec) {
|
||||
if(find_named<iobj>(m_cols,a_name)) return 0;
|
||||
std::string spaces;
|
||||
for(unsigned int i=0;i<8;i++) spaces += " ";
|
||||
std_vector_column<T>* col = new std_vector_column<T>(a_name,a_user_vec,m_spaces+spaces);
|
||||
if(!col) return 0;
|
||||
m_cols.push_back(col);
|
||||
return col;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
column<T>* find_column(const std::string& a_name) {
|
||||
iobj* col = find_named<iobj>(m_cols,a_name);
|
||||
@@ -270,25 +386,31 @@ public:
|
||||
|
||||
// <tuple> :
|
||||
m_writer << m_spaces << " <tuple"
|
||||
<< " path=" << sout(a_path)
|
||||
<< " name=" << sout(a_name)
|
||||
<< " title=" << sout(a_title)
|
||||
<< " path=" << sout(to_xml(a_path))
|
||||
<< " name=" << sout(to_xml(a_name))
|
||||
<< " title=" << sout(to_xml(a_title))
|
||||
<< ">" << std::endl;
|
||||
|
||||
// <columns> :
|
||||
m_writer << m_spaces << " <columns>" << std::endl;
|
||||
|
||||
std::vector<iobj*>::iterator it;
|
||||
for(it=m_cols.begin();it!=m_cols.end();++it) {
|
||||
if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
|
||||
tools_vforcit(iobj*,m_cols,it) {
|
||||
if(leaf* vlf = is_std_vector_column(*(*it))) {
|
||||
m_writer << m_spaces << " <column"
|
||||
<< " name=" << sout((*it)->name())
|
||||
<< " name=" << sout(to_xml((*it)->name()))
|
||||
<< " type=" << sout("ITuple")
|
||||
<< " booking=" << sout(sub->booking())
|
||||
<< " booking=\"{" << vlf->aida_type() << " " << to_xml((*it)->name())
|
||||
<< "}\""
|
||||
<< "/>" << std::endl;
|
||||
} else if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
|
||||
m_writer << m_spaces << " <column"
|
||||
<< " name=" << sout(to_xml((*it)->name()))
|
||||
<< " type=" << sout("ITuple")
|
||||
<< " booking=" << sout(sub->booking(true))
|
||||
<< "/>" << std::endl;
|
||||
} else if(/*leaf* lf =*/ id_cast<iobj,leaf>(*(*it))){
|
||||
m_writer << m_spaces << " <column"
|
||||
<< " name=" << sout((*it)->name())
|
||||
<< " name=" << sout(to_xml((*it)->name()))
|
||||
<< " type=" << sout((*it)->aida_type())
|
||||
//<< " default=" << sout(lf->s_def()) //not understood by jas3
|
||||
<< "/>" << std::endl;
|
||||
@@ -304,9 +426,10 @@ public:
|
||||
bool add_row() {
|
||||
if(m_cols.empty()) return false;
|
||||
m_writer << m_spaces << " <row>" << std::endl;
|
||||
std::vector<iobj*>::const_iterator it;
|
||||
for(it=m_cols.begin();it!=m_cols.end();++it) {
|
||||
if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
|
||||
tools_vforcit(iobj*,m_cols,it) {
|
||||
if(leaf* vlf = is_std_vector_column(*(*it))) {
|
||||
m_writer << vlf->s_value();
|
||||
} else if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
|
||||
m_writer << m_spaces << " <entryITuple>" << std::endl;
|
||||
m_writer << sub->value();
|
||||
m_writer << m_spaces << " </entryITuple>" << std::endl;
|
||||
@@ -326,24 +449,32 @@ public:
|
||||
m_writer << m_spaces << " </tuple>" << std::endl;
|
||||
}
|
||||
|
||||
std::string booking(bool a_xml_esc) const {
|
||||
std::string s;
|
||||
get_booking(m_cols,a_xml_esc,s);
|
||||
return s;
|
||||
}
|
||||
|
||||
protected:
|
||||
static void get_booking(const std::vector<iobj*>& a_cols,
|
||||
std::string& a_string) {
|
||||
static void get_booking(const std::vector<iobj*>& a_cols,bool a_xml_esc,
|
||||
std::string& a_string) {
|
||||
a_string += "{"; //we need the + because of the tuple in tuple.
|
||||
|
||||
std::vector<iobj*>::const_iterator it;
|
||||
for(it=a_cols.begin();it!=a_cols.end();++it) {
|
||||
tools_vforcit(iobj*,a_cols,it) {
|
||||
if(it!=a_cols.begin()) a_string += ",";
|
||||
|
||||
std::string type = (*it)->aida_type();
|
||||
a_string += type + " ";
|
||||
std::string name = (*it)->name();
|
||||
a_string += name + " = ";
|
||||
std::string sname = (*it)->name();
|
||||
if(a_xml_esc) sname = to_xml(sname);
|
||||
|
||||
if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
|
||||
get_booking(sub->columns(),a_string);
|
||||
if(leaf* vlf = is_std_vector_column(*(*it))) {
|
||||
a_string += "ITuple " + (*it)->name() + " = {" + vlf->aida_type() + " " + sname + "}";
|
||||
|
||||
} else if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
|
||||
a_string += (*it)->aida_type() + " " + sname + " = ";
|
||||
|
||||
get_booking(sub->columns(),a_xml_esc,a_string);
|
||||
} else if(leaf* lf = id_cast<iobj,leaf>(*(*it))){
|
||||
a_string += lf->s_def();
|
||||
a_string += (*it)->aida_type() + " " + sname + " = " + lf->s_def();
|
||||
}
|
||||
}
|
||||
a_string += "}";
|
||||
|
||||
Reference in New Issue
Block a user