Import Geant4 10.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2017-12-08 12:52:30 +01:00
parent 98e455a940
commit fc6af9e721
2166 changed files with 276760 additions and 100873 deletions
+112 -68
View File
@@ -7,6 +7,7 @@
#include "streamers"
#include "fac"
#include "tree"
#include "../words" //for annotations.
#define TOOLS_RROOT_NOT_OSC
@@ -53,13 +54,26 @@ inline TDirectory* find_dir(directory& a_dir,const std::string& a_name) {
return tdir;
}
inline directory* find_path_dir(directory& a_from,const std::string& a_path) {
if(a_path.empty()) return 0;
std::vector<std::string> ws;
words(a_path,"/",false,ws);
directory* cur_dir = &a_from;
for(unsigned int index=0;index<ws.size();index++) {
TDirectory* _dir = find_dir(*cur_dir,ws[index]);
if(!_dir) return 0;
if(index==(ws.size()-1)) return _dir;
if(index) delete cur_dir;
cur_dir = _dir;
}
return 0;
}
inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
unsigned int sz;
char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
if(!buf) {
a_out << "tools::rroot::read_key :"
<< " can't get data buffer of " << a_key.object_name() << "."
<< std::endl;
a_out << "tools::rroot::read_key : can't get data buffer of " << a_key.object_name() << "." << std::endl;
return false;
}
@@ -69,19 +83,27 @@ inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
buffer b(a_out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
if(a_key.object_class()==TH1F_cls()) {
tools::histo::h1d* h = TH1F_stream(b);
if(a_key.object_class()==TNamed_cls()) {
std::string name,title;
if(!Named_stream(b,name,title)) {
a_out << "tools::rroot::read_key : TNamed streaming failed" << std::endl;
} else {
if(a_dump) {
a_out << "Named : name = " << sout(name) << ", title = " << sout(title) << std::endl;
}
}
} else if(a_key.object_class()==TH1F_cls()) {
histo::h1d* h = TH1F_stream(b);
if(!h) {
a_out << "tools::rroot::read_key :"
<< " TH1F streaming failed"
<< std::endl;
a_out << "tools::rroot::read_key : TH1F streaming failed" << std::endl;
} else {
if(a_dump) h->hprint(a_out);
}
delete h;
} else if(a_key.object_class()==TH1D_cls()) {
tools::histo::h1d* h = TH1D_stream(b);
histo::h1d* h = TH1D_stream(b);
if(!h) {
a_out << "tools::rroot::read_key :"
<< " TH1D streaming failed"
@@ -92,7 +114,7 @@ inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
delete h;
} else if(a_key.object_class()==TH2F_cls()) {
tools::histo::h2d* h = TH2F_stream(b);
histo::h2d* h = TH2F_stream(b);
if(!h) {
a_out << "tools::rroot::read_key :"
<< " TH2F streaming failed"
@@ -103,7 +125,7 @@ inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
delete h;
} else if(a_key.object_class()==TH2D_cls()) {
tools::histo::h2d* h = TH2D_stream(b); //we get ownership of h.
histo::h2d* h = TH2D_stream(b); //we get ownership of h.
if(!h) {
a_out << "tools::rroot::read_key :"
<< " TH2D streaming failed"
@@ -114,7 +136,7 @@ inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
delete h;
} else if(a_key.object_class()==TH3D_cls()) {
tools::histo::h3d* h = TH3D_stream(b); //we get ownership of h.
histo::h3d* h = TH3D_stream(b); //we get ownership of h.
if(!h) {
a_out << "tools::rroot::read_key :"
<< " TH3D streaming failed"
@@ -125,7 +147,7 @@ inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
delete h;
} else if(a_key.object_class()==TProfile_cls()) {
tools::histo::p1d* p = TProfile_stream(b);
histo::p1d* p = TProfile_stream(b);
if(!p) {
a_out << "tools::rroot::read_key :"
<< " TProfile streaming failed"
@@ -136,7 +158,7 @@ inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
delete p;
} else if(a_key.object_class()==TProfile2D_cls()) {
tools::histo::p2d* p = TProfile2D_stream(b);
histo::p2d* p = TProfile2D_stream(b);
if(!p) {
a_out << "tools::rroot::read_key :"
<< " TProfile2D streaming failed"
@@ -190,56 +212,56 @@ inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
}
#ifndef TOOLS_RROOT_NOT_OSC
} else if(a_key.object_class()==tools::osc::s_h1d()) {
} else if(a_key.object_class()==osc::s_h1d()) {
tools::histo::h1d h("",10,0,1);
if(!from_osc(b,tools::osc::s_h1d(),h)) {
histo::h1d h("",10,0,1);
if(!from_osc(b,osc::s_h1d(),h)) {
a_out << "tools::rroot::read_key :"
<< " " << tools::osc::s_h1d() << " streaming failed"
<< " " << osc::s_h1d() << " streaming failed"
<< std::endl;
} else {
if(a_dump) h.hprint(a_out);
}
} else if(a_key.object_class()==tools::osc::s_h2d()) {
} else if(a_key.object_class()==osc::s_h2d()) {
tools::histo::h2d h("",10,0,1,10,0,1);
if(!from_osc(b,tools::osc::s_h2d(),h)) {
histo::h2d h("",10,0,1,10,0,1);
if(!from_osc(b,osc::s_h2d(),h)) {
a_out << "tools::rroot::read_key :"
<< " " << tools::osc::s_h2d() << " streaming failed"
<< " " << osc::s_h2d() << " streaming failed"
<< std::endl;
} else {
if(a_dump) h.hprint(a_out);
}
} else if(a_key.object_class()==tools::osc::s_h3d()) {
} else if(a_key.object_class()==osc::s_h3d()) {
tools::histo::h3d h("",10,0,1,10,0,1,10,0,1);
if(!from_osc(b,tools::osc::s_h3d(),h)) {
histo::h3d h("",10,0,1,10,0,1,10,0,1);
if(!from_osc(b,osc::s_h3d(),h)) {
a_out << "tools::rroot::read_key :"
<< " " << tools::osc::s_h3d() << " streaming failed"
<< " " << osc::s_h3d() << " streaming failed"
<< std::endl;
} else {
if(a_dump) h.hprint(a_out);
}
} else if(a_key.object_class()==tools::osc::s_p1d()) {
} else if(a_key.object_class()==osc::s_p1d()) {
tools::histo::p1d h("",10,0,1);
if(!from_osc(b,tools::osc::s_p1d(),h)) {
histo::p1d h("",10,0,1);
if(!from_osc(b,osc::s_p1d(),h)) {
a_out << "tools::rroot::read_key :"
<< " " << tools::osc::s_p1d() << " streaming failed"
<< " " << osc::s_p1d() << " streaming failed"
<< std::endl;
} else {
if(a_dump) h.hprint(a_out);
}
} else if(a_key.object_class()==tools::osc::s_p2d()) {
} else if(a_key.object_class()==osc::s_p2d()) {
tools::histo::p2d h("",10,0,1,10,0,1);
if(!from_osc(b,tools::osc::s_p2d(),h)) {
histo::p2d h("",10,0,1,10,0,1);
if(!from_osc(b,osc::s_p2d(),h)) {
a_out << "tools::rroot::read_key :"
<< " " << tools::osc::s_p2d() << " streaming failed"
<< " " << osc::s_p2d() << " streaming failed"
<< std::endl;
} else {
if(a_dump) h.hprint(a_out);
@@ -253,28 +275,56 @@ inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
} else {
a_out << "tools::rroot::read_key :"
<< " dont't know how to read key with object class "
<< tools::sout(a_key.object_class())
<< sout(a_key.object_class())
<< std::endl;
}
return true;
}
inline tools::histo::h1d* key_to_h1d(ifile& a_file,key& a_key){
//typedef std::map<std::string,std::string> annotations_t;
inline bool key_to_annotations(ifile& a_file,key& a_key,std::map<std::string,std::string>& a_annotations,bool a_warn = true) {
a_annotations.clear();
std::ostream& out = a_key.out();
if((a_key.object_class()!=TH1D_cls())&&
(a_key.object_class()!=TH1F_cls())
) {
out << "tools::rroot::key_to_h1d :"
<< " key not a TH1D and not a TH1F."
<< std::endl;
if(a_key.object_class()!=TNamed_cls()) {
if(a_warn) out << "tools::rroot::key_to_annotations : key not a TNamed." << std::endl;
return false;
}
unsigned int sz;
char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
if(!buf) {
out << "tools::rroot::key_to_annotations : can't get data buffer of " << a_key.object_name() << "." << std::endl;
return false;
}
buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
std::string histo_name;
std::string sas;
if(!Named_stream(b,histo_name,sas)) return false;
std::vector<std::string> ws;
words(sas,"\n",true,ws);
size_t wordn = ws.size();
if(2*(wordn/2)!=wordn) {
out << "tools::rroot::key_to_annotations : wordn should be even in " << sout(sas) << "." << std::endl;
return false;
}
std::vector<std::string>::const_iterator it;
for(it=ws.begin();it!=ws.end();) {
const std::string& key = *it;it++;
const std::string& value = *it;it++;
a_annotations[key] = value;
}
return true;
}
inline histo::h1d* key_to_h1d(ifile& a_file,key& a_key,bool a_warn = true) {
std::ostream& out = a_key.out();
if( (a_key.object_class()!=TH1D_cls()) && (a_key.object_class()!=TH1F_cls()) ) {
if(a_warn) out << "tools::rroot::key_to_h1d : key not a TH1D and not a TH1F." << std::endl;
return 0;
}
unsigned int sz;
char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
if(!buf) {
out << "tools::rroot::key_to_h1d :"
<< " can't get data buffer of " << a_key.object_name() << "."
<< std::endl;
out << "tools::rroot::key_to_h1d : can't get data buffer of " << a_key.object_name() << "." << std::endl;
return 0;
}
buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
@@ -285,27 +335,27 @@ inline tools::histo::h1d* key_to_h1d(ifile& a_file,key& a_key){
}
}
inline tools::histo::h2d* key_to_h2d(ifile& a_file,key& a_key){
inline histo::h2d* key_to_h2d(ifile& a_file,key& a_key,bool a_warn = true){
std::ostream& out = a_key.out();
if(a_key.object_class()!=TH2D_cls()) {
out << "tools::rroot::key_to_h2d :"
<< " key not a TH2D."
<< std::endl;
if( (a_key.object_class()!=TH2D_cls()) && (a_key.object_class()!=TH2F_cls()) ) {
if(a_warn) out << "tools::rroot::key_to_h2d : key not a TH2D and not a TH2F." << std::endl;
return 0;
}
unsigned int sz;
char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
if(!buf) {
out << "tools::rroot::key_to_h2d :"
<< " can't get data buffer of " << a_key.object_name() << "."
<< std::endl;
out << "tools::rroot::key_to_h2d : can't get data buffer of " << a_key.object_name() << "." << std::endl;
return 0;
}
buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
return TH2D_stream(b);
if(a_key.object_class()==TH2D_cls()) {
return TH2D_stream(b);
} else {
return TH2F_stream(b);
}
}
inline tools::histo::h3d* key_to_h3d(ifile& a_file,key& a_key){
inline histo::h3d* key_to_h3d(ifile& a_file,key& a_key){
std::ostream& out = a_key.out();
if(a_key.object_class()!=TH3D_cls()) {
out << "tools::rroot::key_to_h3d :"
@@ -325,7 +375,7 @@ inline tools::histo::h3d* key_to_h3d(ifile& a_file,key& a_key){
return TH3D_stream(b);
}
inline tools::histo::p1d* key_to_p1d(ifile& a_file,key& a_key){
inline histo::p1d* key_to_p1d(ifile& a_file,key& a_key){
std::ostream& out = a_key.out();
if(a_key.object_class()!=TProfile_cls()) {
out << "tools::rroot::key_to_p1d :"
@@ -345,7 +395,7 @@ inline tools::histo::p1d* key_to_p1d(ifile& a_file,key& a_key){
return TProfile_stream(b);
}
inline tools::histo::p2d* key_to_p2d(ifile& a_file,key& a_key){
inline histo::p2d* key_to_p2d(ifile& a_file,key& a_key){
std::ostream& out = a_key.out();
if(a_key.object_class()!=TProfile2D_cls()) {
out << "tools::rroot::key_to_p2d :"
@@ -365,28 +415,22 @@ inline tools::histo::p2d* key_to_p2d(ifile& a_file,key& a_key){
return TProfile2D_stream(b);
}
inline tree* key_to_tree(ifile& a_file,ifac& a_fac,key& a_key) {
inline tree* key_to_tree(ifile& a_file,ifac& a_fac,key& a_key,bool a_warn = true) {
std::ostream& out = a_key.out();
if(a_key.object_class()!=TTree_cls()) {
out << "tools::rroot::key_to_tree :"
<< " key not a TTree."
<< std::endl;
if(a_warn) out << "tools::rroot::key_to_tree : key not a TTree." << std::endl;
return 0;
}
unsigned int sz;
char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
if(!buf) {
out << "tools::rroot::key_to_tree :"
<< " can't get data buffer of " << a_key.object_name() << "."
<< std::endl;
out << "tools::rroot::key_to_tree : can't get data buffer of " << a_key.object_name() << "." << std::endl;
return 0;
}
buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
tree* _tree = new tree(a_file,a_fac);
if(!_tree->stream(b)) {
out << "tools::rroot::key_to_tree :"
<< " TTree streaming failed"
<< std::endl;
out << "tools::rroot::key_to_tree : TTree streaming failed" << std::endl;
delete _tree;
return 0;
}
@@ -430,7 +474,7 @@ inline void read(std::ostream& a_out,
if(!a_recursive) continue;
tools::uint32 sz;
uint32 sz;
char* buf = k.get_object_buffer(a_file,sz);
if(!buf) {
a_out << "read :"