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
@@ -0,0 +1,25 @@
#define TOOLS_WROOT_MPI_NTUPLE_LEAF_SET_LENGTH_MAX(a__type) \
{leaf_ref<a__type>* _pleaf_ = _pleaf?id_cast<base_leaf, leaf_ref<a__type> >(*_pleaf):0;\
if(_pleaf_) {\
if(!a_mpi.pack(_pleaf_->length())) return false;\
if(!a_mpi.pack(_pleaf_->get_max())) return false;\
set_done = true;\
}}
#define TOOLS_WROOT_MPI_NTUPLE_LEAF_STD_VECTOR_SET_LENGTH_MAX(a__type) \
{leaf_std_vector_ref<a__type>* _pleaf_ = _pleaf?id_cast<base_leaf, leaf_std_vector_ref<a__type> >(*_pleaf):0;\
if(_pleaf_) {\
if(!a_mpi.pack(_pleaf_->length())) return false;\
if(!a_mpi.pack(_pleaf_->get_max())) return false;\
set_done = true;\
}}
#define TOOLS_WROOT_MPI_NTUPLE_LEAF_STRING_SET_LENGTH_MAX \
{leaf_string_ref* _pleaf_ = _pleaf?id_cast<base_leaf,leaf_string_ref>(*_pleaf):0;\
if(_pleaf_) {\
if(!a_mpi.pack(_pleaf_->length())) return false;\
if(!a_mpi.pack(_pleaf_->get_max())) return false;\
set_done = true;\
}}
@@ -0,0 +1,46 @@
#define TOOLS_WROOT_MT_NTUPLE_SET_MAX(a__type) \
{leaf_ref<a__type>* _mleaf_ = _mleaf?id_cast<base_leaf, leaf_ref<a__type> >(*_mleaf):0;\
leaf_ref<a__type>* _pleaf_ = _pleaf?id_cast<base_leaf, leaf_ref<a__type> >(*_pleaf):0;\
if(_mleaf_&&!_pleaf_) {\
m_out << "tools::wroot::mt_ntuple::end_leaves : merge leaves problem (1)." << std::endl;\
if(_mleaf) m_out << "main leaf name " << _mleaf->name() << ", cid " << _mleaf->id_cls() << std::endl;\
return false;\
}\
if(!_mleaf_&&_pleaf_) {\
m_out << "tools::wroot::mt_ntuple::end_leaves : merge leaves problem (2)." << std::endl;\
if(_pleaf) m_out << "to compare with parallel leaf name " << _pleaf->name() << ", cid " << _pleaf->id_cls() << std::endl;\
return false;\
}\
if(_mleaf_ && _pleaf_) {\
/*uint32 _length = _pleaf_->length();*/\
a__type _mx = _pleaf_->get_max();\
a_mutex.lock(); /*do it here (and not outside loop) because of upper m_out.*/\
/*_mleaf_->set_length(max_of(_length,_mleaf_->length()));*/\
_mleaf_->set_max(max_of<a__type>(_mx,_mleaf_->get_max()));\
a_mutex.unlock();\
}}
#define TOOLS_WROOT_MT_NTUPLE_STRING_SET_MAX \
{leaf_string_ref* _mleaf_ = _mleaf?id_cast<base_leaf,leaf_string_ref>(*_mleaf):0;\
leaf_string_ref* _pleaf_ = _pleaf?id_cast<base_leaf,leaf_string_ref>(*_pleaf):0;\
if(_mleaf_&&!_pleaf_) {\
m_out << "tools::wroot::mt_ntuple::end_leaves : merge string leaves problem (1)." << std::endl;\
if(_mleaf) m_out << "main leaf name " << _mleaf->name() << ", cid " << _mleaf->id_cls() << std::endl;\
return false;\
}\
if(!_mleaf_&&_pleaf_) {\
m_out << "tools::wroot::mt_ntuple::end_leaves : merge string leaves problem (2)." << std::endl;\
if(_pleaf) m_out << "to compare with parallel leaf name " << _pleaf->name() << ", cid " << _pleaf->id_cls() << std::endl;\
return false;\
}\
if(_mleaf_ && _pleaf_) {\
/*m_out << "tools::wroot::mt_ntuple::end_leaves : merge string leaves ok." << std::endl;*/\
uint32 _length = _pleaf_->length();\
int _mx = _pleaf_->get_max();\
a_mutex.lock(); /*do it here (and not outside loop) because of upper m_out.*/\
_mleaf_->set_length(max_of(_length,_mleaf_->length()));\
_mleaf_->set_max(max_of(_mx,_mleaf_->get_max()));\
a_mutex.unlock();\
}}
@@ -31,8 +31,13 @@ public:
if(void* p = cmp_cast<base_leaf>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //ibo
virtual bool stream(buffer& a_buffer) const {
//::printf("debug : base_leaf::stream %s\n",m_name.c_str());
//::printf("debug : m_length %d\n",m_length);
//::printf("debug : m_is_range %d\n",m_is_range);
//::printf("debug : m_leaf_count %lu\n",m_leaf_count);
unsigned int c;
if(!a_buffer.write_version(2,c)) return false;
if(!Named_stream(a_buffer,m_name,m_title)) return false;
@@ -40,13 +45,15 @@ public: //ibo
if(!a_buffer.write(m_length_type)) return false;
uint32 fOffset = 0;
if(!a_buffer.write(fOffset)) return false;
bool fIsRange = false;
if(!a_buffer.write(fIsRange)) return false;
if(!a_buffer.write(m_is_range)) return false;
bool fIsUnsigned = false;
if(!a_buffer.write(fIsUnsigned)) return false;
//if(!a_buffer.write_object(m_leaf_count)) return false;
if(!a_buffer.write(kNullTag())) return false;
if(m_leaf_count) {
if(!a_buffer.write_object(*m_leaf_count)) return false;
} else {
if(!a_buffer.write(kNullTag())) return false;
}
if(!a_buffer.set_byte_count(c)) return false;
return true;
@@ -61,6 +68,8 @@ public:
,m_length(0)
,m_length_type(0)
,m_leaf_count(0)
,m_is_range(false)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
@@ -75,13 +84,19 @@ protected:
base_leaf(const base_leaf& a_from)
:ibo(a_from)
,m_out(a_from.m_out)
,m_length(0)
,m_length_type(0)
,m_leaf_count(0)
,m_is_range(false)
{}
base_leaf& operator=(const base_leaf&){return *this;}
public:
const std::string& name() const {return m_name;}
//const std::string& title() const {return m_title;}
void set_title(const std::string& a_value) {m_title = a_value;}
uint32 length() const {return m_length;}
void set_length(uint32 a_value) {m_length = a_value;}
void set_is_range(bool a_value) {m_is_range = a_value;}
protected:
std::ostream& m_out;
protected: //Named
@@ -89,6 +104,8 @@ protected: //Named
std::string m_title;
uint32 m_length; // Number of fixed length elements
uint32 m_length_type; // Number of bytes for this data type
ibo* m_leaf_count;
bool m_is_range;
};
}}
@@ -10,11 +10,6 @@
#include "icol"
#include "../vfind"
#include "../vmanip"
#include "../ntuple_booking"
#include "../sout"
#include "../scast"
#include "../forit"
#ifdef TOOLS_MEM
#include "../mem"
@@ -25,396 +20,31 @@ namespace wroot {
class base_pntuple {
public:
class file {
public:
file(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,bool a_verbose)
:m_out(a_out)
,m_byte_swap(a_byte_swap),m_compression(a_compression),m_verbose(a_verbose)
{}
virtual ~file(){}
public:
file(const file& a_from)
:m_out(a_from.m_out)
,m_byte_swap(a_from.m_byte_swap),m_compression(a_from.m_compression),m_verbose(a_from.m_verbose)
{}
file& operator=(const file& a_from) {
m_byte_swap = a_from.m_byte_swap;
m_verbose = a_from.m_verbose;
return *this;
}
public:
bool verbose() const {return m_verbose;}
std::ostream& out() const {return m_out;}
bool byte_swap() const {return m_byte_swap;}
uint32 compression() const {return m_compression;}
protected:
std::ostream& m_out;
bool m_byte_swap;
uint32 m_compression;
bool m_verbose;
};
#include "columns.icc"
public:
template <class T>
class column : public virtual icol {
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column<"+stype(T())+">");
return s_v;
}
#endif
public:
static cid id_class() {
static const T s_v = T(); //do that for T = std::string.
return _cid(s_v);
}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {m_leaf->fill(m_tmp);}
virtual void set_def() {m_tmp = m_def;}
virtual const std::string& name() const {return m_leaf->name();}
virtual void set_basket_size(uint32 a_size) {m_branch->set_basket_size(a_size);}
virtual branch* get_branch() const {return m_branch;}
virtual base_leaf* get_leaf() const {return m_leaf;}
public:
column(file& a_file,seek a_seek_directory,uint32 a_basket_size,
const std::string& a_name,const std::string& a_title,const T& a_def)
:m_branch(0),m_leaf(0)
,m_def(a_def),m_tmp(a_def)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
m_branch = new branch(a_file.out(),a_file.byte_swap(),a_file.compression(),
a_seek_directory,a_name,a_title,a_file.verbose());
m_branch->set_basket_size(a_basket_size);
m_leaf = m_branch->create_leaf<T>(a_name,a_name);
}
virtual ~column() {
delete m_branch;
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column(const column& a_from)
:icol(a_from)
,m_branch(0)
,m_leaf(0)
,m_def(a_from.m_def)
,m_tmp(a_from.m_tmp)
{}
column& operator=(const column& a_from){
if(&a_from==this) return *this;
m_branch = 0;
m_leaf = 0;
m_def = a_from.m_def;
m_tmp = a_from.m_tmp;
return *this;
}
public:
bool fill(const T& a_value) {m_tmp = a_value;return true;}
protected:
branch* m_branch;
leaf<T>* m_leaf;
T m_def;
T m_tmp;
};
class column_string : public virtual icol {
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column_string");
return s_v;
}
#endif
public:
static cid id_class() {
static const std::string s_v;
return _cid(s_v);
}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column_string>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {m_leaf->fill(m_tmp);}
virtual void set_def() {m_tmp = m_def;}
virtual const std::string& name() const {return m_leaf->name();}
virtual void set_basket_size(uint32 a_size) {m_branch->set_basket_size(a_size);}
virtual branch* get_branch() const {return m_branch;}
virtual base_leaf* get_leaf() const {return m_leaf;}
public:
column_string(file& a_file,seek a_seek_directory,uint32 a_basket_size,
const std::string& a_name,const std::string& a_title,const std::string& a_def)
:m_branch(0),m_leaf(0)
,m_def(a_def),m_tmp(a_def)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
m_branch = new branch(a_file.out(),a_file.byte_swap(),a_file.compression(),
a_seek_directory,a_name,a_title,a_file.verbose());
m_branch->set_basket_size(a_basket_size);
m_leaf = m_branch->create_leaf_string(a_name,a_name);
}
virtual ~column_string() {
delete m_branch;
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column_string(const column_string& a_from)
:icol(a_from)
,m_branch(0)
,m_leaf(0)
,m_def(a_from.m_def)
,m_tmp(a_from.m_tmp)
{}
column_string& operator=(const column_string& a_from){
if(&a_from==this) return *this;
m_branch = 0;
m_leaf = 0;
m_def = a_from.m_def;
m_tmp = a_from.m_tmp;
return *this;
}
public:
bool fill(const std::string& a_value) {m_tmp = a_value;return true;}
leaf_string* leaf() const {return m_leaf;}
protected:
branch* m_branch;
leaf_string* m_leaf;
std::string m_def;
std::string m_tmp;
};
template <class T>
class std_vector_column : public virtual icol {
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::std_vector_column<"+stype(T())+">");
return s_v;
}
#endif
public:
static cid id_class() {return _cid_std_vector<T>();}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<std_vector_column>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {}
virtual void set_def() {}
virtual const std::string& name() const {return m_leaf->name();}
virtual void set_basket_size(uint32 a_size) {m_branch->set_basket_size(a_size);}
virtual branch* get_branch() const {return m_branch;}
virtual base_leaf* get_leaf() const {return m_leaf;}
public:
std_vector_column(file& a_file,seek a_seek_directory,uint32 a_basket_size,
const std::string& a_name,const std::string& a_title,std::vector<T>& a_user_vec)
:m_branch(0)
,m_leaf(0)
,m_user_vec(a_user_vec)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
std_vector_be<T>* br = new std_vector_be<T>(a_file.out(),a_file.byte_swap(),a_file.compression(),
a_seek_directory,a_name,a_title,m_user_vec,a_file.verbose());
m_leaf = br->create_leaf_element(a_name,a_name);
m_branch = br;
m_branch->set_basket_size(a_basket_size);
}
virtual ~std_vector_column() {
delete m_branch;
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
std_vector_column(const std_vector_column& a_from)
:icol(a_from)
,m_branch(0)
,m_leaf(0)
,m_user_vec(a_from.m_user_vec)
{}
std_vector_column& operator=(const std_vector_column& a_from){
if(&a_from==this) return *this;
m_branch = 0;
m_leaf = 0;
return *this;
}
protected:
branch* m_branch;
leaf_element* m_leaf;
std::vector<T>& m_user_vec;
};
public:
base_pntuple(std::ostream& a_out,
bool a_byte_swap,uint32 a_compression,
const std::string& a_name,const std::string& a_title,bool a_verbose)
:m_file(a_out,a_byte_swap,a_compression,a_verbose)
,m_seek_directory(0)
,m_name(a_name),m_title(a_title)
//,m_entries(0)
//,m_tot_bytes(0)
//,m_zip_bytes(0)
base_pntuple(std::ostream& a_out,seek a_seek_directory,const std::string& a_name,const std::string& a_title)
:m_out(a_out)
,m_seek_directory(a_seek_directory)
,m_name(a_name)
,m_title(a_title)
{}
base_pntuple(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
const std::vector<uint32>& a_basket_sizes,const ntuple_booking& a_bkg,bool a_verbose)
:m_file(a_out,a_byte_swap,a_compression,a_verbose)
,m_seek_directory(a_seek_directory),
m_name(a_bkg.name()),m_title(a_bkg.title())
//,m_entries(0)
//,m_tot_bytes(0)
//,m_zip_bytes(0)
{
std::ostream& out = a_out;
const std::vector<column_booking>& cols = a_bkg.columns();
std::vector<uint32>::const_iterator itb = a_basket_sizes.begin();
tools_vforcit(column_booking,cols,it){
if((*it).cls_id()==_cid(char(0))) {
//if((*it).cls_id()!=(*itb)->cls_id()) {
//}
//column title is the ntuple name.
create_column<char>(*itb,(*it).name(),m_name);itb++;
} else if((*it).cls_id()==_cid(short(0))) {
create_column<short>(*itb,(*it).name(),m_name);itb++;
} else if((*it).cls_id()==_cid(int(0))) {
create_column<int>(*itb,(*it).name(),m_name);itb++;
} else if((*it).cls_id()==_cid(float(0))) {
create_column<float>(*itb,(*it).name(),m_name);itb++;
} else if((*it).cls_id()==_cid(double(0))) {
create_column<double>(*itb,(*it).name(),m_name);itb++;
} else if((*it).cls_id()==_cid(std::string())) {
create_column_string(*itb,(*it).name(),m_name);itb++;
} else if((*it).cls_id()==_cid_std_vector<char>()) {
std::vector<char>* vec = (std::vector<char>*)(*it).user_obj();
if(vec) {
create_column<char>(*itb,(*it).name(),m_name,*vec);itb++;
} else {
out << "tools::wroot::base_pntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(m_cols);
return;
}
} else if((*it).cls_id()==_cid_std_vector<short>()) {
std::vector<short>* vec = (std::vector<short>*)(*it).user_obj();
if(vec) {
create_column<short>(*itb,(*it).name(),m_name,*vec);itb++;
} else {
out << "tools::wroot::base_pntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(m_cols);
return;
}
} else if((*it).cls_id()==_cid_std_vector<int>()) {
std::vector<int>* vec = (std::vector<int>*)(*it).user_obj();
if(vec) {
create_column<int>(*itb,(*it).name(),m_name,*vec);itb++;
} else {
out << "tools::wroot::base_pntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(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>(*itb,(*it).name(),m_name,*vec);itb++;
} else {
out << "tools::wroot::base_pntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(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>(*itb,(*it).name(),m_name,*vec);itb++;
} else {
out << "tools::wroot::base_pntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(m_cols);
return;
}
// no leaf_store_class() defined for the other types.
} else {
out << "tools::wroot::base_pntuple :"
<< " for column " << sout((*it).name())
<< ", type with cid " << (*it).cls_id() << " not yet handled."
<< std::endl;
//throw
tools::clear<icol>(m_cols);
return;
}
}
}
virtual ~base_pntuple() {
tools::clear<icol>(m_cols);
safe_clear<icol>(m_cols);
}
protected:
base_pntuple(const base_pntuple& a_from)
:m_file(a_from.m_file)
{}
base_pntuple(const base_pntuple& a_from):m_out(a_from.m_out){}
base_pntuple& operator=(const base_pntuple&){return *this;}
public:
const std::vector<icol*>& columns() const {return m_cols;}
template <class T>
column<T>* create_column(uint32 a_basket_size,const std::string& a_name,const std::string& a_title,const T& a_def = T()) {
if(find_named<icol>(m_cols,a_name)) return 0;
column<T>* col = new column<T>(m_file,m_seek_directory,a_basket_size,a_name,a_title,a_def);
column_ref<T>* find_column_ref(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
column_string* create_column_string(uint32 a_basket_size,const std::string& a_name,const std::string& a_title,
const std::string& a_def = std::string()) {
if(find_named<icol>(m_cols,a_name)) return 0;
column_string* col = new column_string(m_file,m_seek_directory,a_basket_size,a_name,a_title,a_def);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
template <class T>
std_vector_column<T>* create_column(uint32 a_basket_size,
const std::string& a_name,const std::string& a_title,
std::vector<T>& a_user_vec) {
//NOTE : to optimize, we do not handle a default std::vector value logic.
if(find_named<icol>(m_cols,a_name)) return 0;
std_vector_column<T>* col =
new std_vector_column<T>(m_file,m_seek_directory,a_basket_size,a_name,a_title,a_user_vec);
if(!col) return 0;
m_cols.push_back(col);
return col;
return id_cast<icol, column_ref<T> >(*col);
}
template <class T>
@@ -424,23 +54,59 @@ public:
return id_cast<icol, column<T> >(*col);
}
column_string_ref* find_column_string_ref(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, column_string_ref >(*col);
}
column_string* find_column_string(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, column_string >(*col);
}
void set_basket_size(uint32 a_size) {tools_vforit(icol*,m_cols,it) (*it)->set_basket_size(a_size);}
template <class T>
std_vector_column_ref<T>* find_column_vector_ref(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, std_vector_column_ref<T> >(*col);
}
template <class T>
std_vector_column<T>* find_column_vector(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, std_vector_column<T> >(*col);
}
column_vector_string_ref* find_column_vector_string_ref(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, column_vector_string_ref >(*col);
}
column_vector_string* find_column_vector_string(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, column_vector_string >(*col);
}
void print_columns(std::ostream& a_out) {
a_out << "for ntuple named " << sout(m_name) << ", number of columns " << m_cols.size() << " :" << std::endl;
tools_vforit(icol*,m_cols,it) {
a_out << " " << (*it)->name() << std::endl;
}
}
//void set_basket_size(uint32 a_size) {tools_vforit(icol*,m_cols,it) (*it)->set_basket_size(a_size);}
protected:
file m_file;
std::ostream& m_out;
seek m_seek_directory;
std::string m_name;
std::string m_title;
std::vector<icol*> m_cols;
//uint64 m_entries; // Number of entries
//uint64 m_tot_bytes; // Total number of bytes in branches before compression
//uint64 m_zip_bytes; // Total number of bytes in branches after compression
};
}}
@@ -0,0 +1,320 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_base_pntuple_column_wise
#define tools_wroot_base_pntuple_column_wise
// pntuple = for parallel ntupling.
#include "base_pntuple"
#include "../ntuple_booking"
#ifdef TOOLS_MEM
#include "../mem"
#endif
namespace tools {
namespace wroot {
class base_pntuple_column_wise : public base_pntuple {
typedef base_pntuple parent;
public:
class file {
public:
file(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,bool a_verbose)
:m_out(a_out)
,m_byte_swap(a_byte_swap),m_compression(a_compression),m_verbose(a_verbose)
{}
virtual ~file(){}
public:
file(const file& a_from)
:m_out(a_from.m_out)
,m_byte_swap(a_from.m_byte_swap),m_compression(a_from.m_compression),m_verbose(a_from.m_verbose)
{}
file& operator=(const file& a_from) {
m_byte_swap = a_from.m_byte_swap;
m_verbose = a_from.m_verbose;
return *this;
}
public:
bool verbose() const {return m_verbose;}
std::ostream& out() const {return m_out;}
bool byte_swap() const {return m_byte_swap;}
uint32 compression() const {return m_compression;}
protected:
std::ostream& m_out;
bool m_byte_swap;
uint32 m_compression;
bool m_verbose;
};
public:
base_pntuple_column_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
const std::string& a_name,const std::string& a_title,bool a_verbose)
:parent(a_out,a_seek_directory,a_name,a_title)
,m_file(a_out,a_byte_swap,a_compression,a_verbose)
{}
base_pntuple_column_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
const std::vector<uint32>& a_basket_sizes,
const ntuple_booking& a_bkg,bool a_verbose)
:parent(a_out,a_seek_directory,a_bkg.name(),a_bkg.title())
,m_file(a_out,a_byte_swap,a_compression,a_verbose)
{
const std::vector<column_booking>& cols = a_bkg.columns();
if(a_basket_sizes.size()!=cols.size()) {
a_out << "tools::wroot::base_pntuple_column_wise :"
<< " a_basket_sizes.size() (" << a_basket_sizes.size() << ") != "
<< "a_bkg.columns().size() (" << a_bkg.columns().size() << ")."
<< std::endl;
return;
}
std::vector<uint32>::const_iterator itb = a_basket_sizes.begin();
tools_vforcit(column_booking,cols,it){
#define TOOLS_WROOT_PNTUPLE_CREATE_COL(a__type) \
if((*it).cls_id()==_cid(a__type())) {\
a__type* user = (a__type*)(*it).user_obj();\
if(user) {\
if(!create_column_ref<a__type>(*itb,(*it).name(),*user)) {\
a_out << "tools::wroot::base_pntuple_column_wise : create_column_ref(" << (*it).name() << ") failed." << std::endl;\
safe_clear<icol>(m_cols);\
safe_clear<branch>(m_branches);\
return;\
}\
itb++;\
} else {\
if(!create_column<a__type>(*itb,(*it).name())) {\
a_out << "tools::wroot::base_pntuple_column_wise : create_column(" << (*it).name() << ") failed." << std::endl;\
safe_clear<icol>(m_cols);\
safe_clear<branch>(m_branches);\
return;\
}\
itb++;\
}\
}
#define TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(a__type) \
if((*it).cls_id()==_cid_std_vector<a__type>()) {\
std::vector<a__type>* vec = (std::vector<a__type>*)(*it).user_obj();\
if(vec) {\
if(!create_column_vector_ref<a__type>(*itb,(*it).name(),*vec)) {\
a_out << "tools::wroot::base_pntuple_column_wise :"\
<< " create_column failed for std::vector column_ref " << sout((*it).name()) << "."\
<< std::endl;\
safe_clear<icol>(m_cols);\
safe_clear<branch>(m_branches);\
return;\
}\
itb++;\
} else {\
if(!create_column_vector<a__type>(*itb,(*it).name())) {\
a_out << "tools::wroot::base_pntuple_column_wise :"\
<< " create_column failed for std::vector column " << sout((*it).name()) << "."\
<< std::endl;\
safe_clear<icol>(m_cols);\
safe_clear<branch>(m_branches);\
return;\
}\
itb++;\
}\
}
TOOLS_WROOT_PNTUPLE_CREATE_COL(char)
else TOOLS_WROOT_PNTUPLE_CREATE_COL(short)
else TOOLS_WROOT_PNTUPLE_CREATE_COL(int)
else TOOLS_WROOT_PNTUPLE_CREATE_COL(float)
else TOOLS_WROOT_PNTUPLE_CREATE_COL(double)
else if((*it).cls_id()==_cid(std::string())) {
std::string* user = (std::string*)(*it).user_obj();
if(user) {
if(!create_column_string_ref(*itb,(*it).name(),*user)) {
a_out << "tools::wroot::base_pntuple_column_wise : create_column_string_ref(" << (*it).name() << ") failed."
<< std::endl;
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
itb++;
} else {
if(!create_column_string(*itb,(*it).name())) {
a_out << "tools::wroot::base_pntuple_column_wise : create_column_string(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
itb++;
}
}
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(char)
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(short)
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(int)
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(float)
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(double)
else if((*it).cls_id()==_cid_std_vector<std::string>()) {\
std::vector<std::string>* user = (std::vector<std::string>*)(*it).user_obj();
char sep = '\n';
if(user) {
if(!create_column_vector_string_ref(*itb,(*it).name(),*user,sep)) {
a_out << "tools::wroot::base_pntuple_column_wise :"
<< " create_column_vector_string_ref(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
itb++;
} else {
if(!create_column_vector_string(*itb,(*it).name(),std::vector<std::string>(),sep)) {
a_out << "tools::wroot::base_pntuple_column_wise :"
<< " create_column_vector_string(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
itb++;
}
}
// no leaf_store_class() defined for the other types.
else {
a_out << "tools::wroot::base_pntuple_column_wise :"
<< " for column " << sout((*it).name())
<< ", type with cid " << (*it).cls_id() << " not yet handled."
<< std::endl;
//throw
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
#undef TOOLS_WROOT_PNTUPLE_CREATE_COL
#undef TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL
}
}
virtual ~base_pntuple_column_wise() {safe_clear<branch>(m_branches);}
protected:
base_pntuple_column_wise(const base_pntuple_column_wise& a_from):parent(a_from),m_file(a_from.m_file){}
base_pntuple_column_wise& operator=(const base_pntuple_column_wise&){return *this;}
public:
template <class T>
column_ref<T>* create_column_ref(uint32 a_basket_size,const std::string& a_name,const T& a_ref) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
m_seek_directory,a_name,m_name,m_file.verbose());
_branch->set_basket_size(a_basket_size);
column_ref<T>* col = new column_ref<T>(*_branch,a_name,a_ref);
if(!col) {delete _branch;return 0;}
m_branches.push_back(_branch);
m_cols.push_back(col);
return col;
}
template <class T>
column<T>* create_column(uint32 a_basket_size,const std::string& a_name,const T& a_def = T()) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
m_seek_directory,a_name,m_name,m_file.verbose());
_branch->set_basket_size(a_basket_size);
column<T>* col = new column<T>(*_branch,a_name,a_def);
if(!col) {delete _branch;return 0;}
m_branches.push_back(_branch);
m_cols.push_back(col);
return col;
}
column_string_ref* create_column_string_ref(uint32 a_basket_size,const std::string& a_name,const std::string& a_ref) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
m_seek_directory,a_name,m_name,m_file.verbose());
_branch->set_basket_size(a_basket_size);
column_string_ref* col = new column_string_ref(*_branch,a_name,a_ref);
if(!col) {delete _branch;return 0;}
m_branches.push_back(_branch);
m_cols.push_back(col);
return col;
}
column_string* create_column_string(uint32 a_basket_size,
const std::string& a_name,
const std::string& a_def = std::string()) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
m_seek_directory,a_name,m_name,m_file.verbose());
_branch->set_basket_size(a_basket_size);
column_string* col = new column_string(*_branch,a_name,a_def);
if(!col) {delete _branch;return 0;}
m_branches.push_back(_branch);
m_cols.push_back(col);
return col;
}
column_vector_string_ref* create_column_vector_string_ref(uint32 a_basket_size,const std::string& a_name,
const std::vector<std::string>& a_ref,char a_sep) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
m_seek_directory,a_name,m_name,m_file.verbose());
_branch->set_basket_size(a_basket_size);
column_vector_string_ref* col = new column_vector_string_ref(*_branch,a_name,a_ref,a_sep);
if(!col) {delete _branch;return 0;}
m_branches.push_back(_branch);
m_cols.push_back(col);
return col;
}
column_vector_string* create_column_vector_string(uint32 a_basket_size,
const std::string& a_name,
const std::vector<std::string>& a_def,char a_sep) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
m_seek_directory,a_name,m_name,m_file.verbose());
_branch->set_basket_size(a_basket_size);
column_vector_string* col = new column_vector_string(*_branch,a_name,a_def,a_sep);
if(!col) {delete _branch;return 0;}
m_branches.push_back(_branch);
m_cols.push_back(col);
return col;
}
template <class T>
std_vector_column_ref<T>* create_column_vector_ref(uint32 a_basket_size,const std::string& a_name,const std::vector<T>& a_ref) {
if(find_named<icol>(m_cols,a_name)) return 0;
std_vector_be_ref<T>* _branch = new std_vector_be_ref<T>(m_file.out(),m_file.byte_swap(),m_file.compression(),
m_seek_directory,a_name,m_name,a_ref,m_file.verbose());
_branch->set_basket_size(a_basket_size);
std_vector_column_ref<T>* col = new std_vector_column_ref<T>(*_branch,a_name,a_ref);
if(!col) {delete _branch;return 0;}
m_branches.push_back(_branch);
m_cols.push_back(col);
return col;
}
template <class T>
std_vector_column<T>* create_column_vector(uint32 a_basket_size,const std::string& a_name,const std::vector<T>& a_def = std::vector<T>()) {
if(find_named<icol>(m_cols,a_name)) return 0;
std_vector_be_pointer<T>* _branch = new std_vector_be_pointer<T>(m_file.out(),m_file.byte_swap(),m_file.compression(),
m_seek_directory,a_name,m_name,0,m_file.verbose());
_branch->set_basket_size(a_basket_size);
std_vector_column<T>* col = new std_vector_column<T>(*_branch,a_name,a_def);
if(!col) {delete _branch;return 0;}
_branch->set_pointer(&(col->variable()));
m_branches.push_back(_branch);
m_cols.push_back(col);
return col;
}
protected:
file m_file;
std::vector<branch*> m_branches;
};
}}
#endif
@@ -0,0 +1,233 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_base_pntuple_row_wise
#define tools_wroot_base_pntuple_row_wise
// pntuple = for parallel ntupling.
#include "base_pntuple"
#include "../ntuple_booking"
#ifdef TOOLS_MEM
#include "../mem"
#endif
namespace tools {
namespace wroot {
class base_pntuple_row_wise : public base_pntuple {
typedef base_pntuple parent;
public:
base_pntuple_row_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
const std::string& a_name,const std::string& a_title,
uint32 a_basket_size,bool a_verbose)
:parent(a_out,a_seek_directory,a_name,a_title)
,m_row_wise_branch(a_out,a_byte_swap,a_compression,a_seek_directory,"row_wise_branch","row_wise_branch",a_verbose)
{
m_row_wise_branch.set_basket_size(a_basket_size);
}
base_pntuple_row_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
uint32 a_basket_size,
const ntuple_booking& a_bkg,bool a_verbose)
:parent(a_out,a_seek_directory,a_bkg.name(),a_bkg.title())
,m_row_wise_branch(a_out,a_byte_swap,a_compression,a_seek_directory,"row_wise_branch","row_wise_branch",a_verbose)
{
m_row_wise_branch.set_basket_size(a_basket_size);
const std::vector<column_booking>& cols = a_bkg.columns();
tools_vforcit(column_booking,cols,it){
#define TOOLS_WROOT_PNTUPLE_CREATE_COL(a__type) \
if((*it).cls_id()==_cid(a__type())) {\
a__type* user = (a__type*)(*it).user_obj();\
if(user) {\
if(!create_column_ref<a__type>((*it).name(),*user)) {\
a_out << "tools::wroot::base_pntuple_row_wise : create_column_ref(" << (*it).name() << ") failed." << std::endl;\
safe_clear<icol>(m_cols);\
return;\
}\
} else {\
if(!create_column<a__type>((*it).name())) {\
a_out << "tools::wroot::base_pntuple_row_wise : create_column(" << (*it).name() << ") failed." << std::endl;\
safe_clear<icol>(m_cols);\
return;\
}\
}\
}
#define TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(a__type) \
if((*it).cls_id()==_cid_std_vector<a__type>()) {\
std::vector<a__type>* vec = (std::vector<a__type>*)(*it).user_obj();\
if(vec) {\
if(!create_column_vector_ref<a__type>((*it).name(),*vec)) {\
a_out << "tools::wroot::base_pntuple_row_wise :"\
<< " create_column_vector_ref failed for std::vector column " << sout((*it).name()) << "."\
<< std::endl;\
safe_clear<icol>(m_cols);\
return;\
}\
} else {\
if(!create_column_vector<a__type>((*it).name())) {\
a_out << "tools::wroot::base_pntuple_row_wise :"\
<< " create_column_vector failed for std::vector column " << sout((*it).name()) << "."\
<< std::endl;\
safe_clear<icol>(m_cols);\
return;\
}\
}\
}
TOOLS_WROOT_PNTUPLE_CREATE_COL(char)
else TOOLS_WROOT_PNTUPLE_CREATE_COL(short)
else TOOLS_WROOT_PNTUPLE_CREATE_COL(int)
else TOOLS_WROOT_PNTUPLE_CREATE_COL(float)
else TOOLS_WROOT_PNTUPLE_CREATE_COL(double)
else if((*it).cls_id()==_cid(std::string())) {
std::string* user = (std::string*)(*it).user_obj();
if(user) {
if(!create_column_string_ref((*it).name(),*user)) {
a_out << "tools::wroot::base_pntuple_row_wise : create_column_string_ref(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
return;
}
} else {
if(!create_column_string((*it).name())) {
a_out << "tools::wroot::base_pntuple_row_wise : create_column_string(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
return;
}
}
}
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(char)
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(short)
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(int)
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(float)
else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(double)
else if((*it).cls_id()==_cid_std_vector<std::string>()) {\
std::vector<std::string>* user = (std::vector<std::string>*)(*it).user_obj();
char sep = '\n';
if(user) {
if(!create_column_vector_string_ref((*it).name(),*user,sep)) {
a_out << "tools::wroot::base_pntuple_row_wise :"
<< " create_column_vector_string_ref(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
return;
}
} else {
if(!create_column_vector_string((*it).name(),std::vector<std::string>(),sep)) {
a_out << "tools::wroot::base_pntuple_row_wise :"
<< " create_column_vector_string(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
return;
}
}
}
// no leaf_store_class() defined for the other types.
else {
a_out << "tools::wroot::base_pntuple_row_wise :"
<< " for column " << sout((*it).name())
<< ", type with cid " << (*it).cls_id() << " not yet handled."
<< std::endl;
//throw
safe_clear<icol>(m_cols);
return;
}
#undef TOOLS_WROOT_PNTUPLE_CREATE_COL
#undef TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL
}
}
virtual ~base_pntuple_row_wise() {}
protected:
base_pntuple_row_wise(const base_pntuple_row_wise& a_from)
:parent(a_from)
,m_row_wise_branch(m_out,false,0,0,"row_wise_branch","row_wise_branch",false)
{}
base_pntuple_row_wise& operator=(const base_pntuple_row_wise&){return *this;}
public:
template <class T>
column_ref<T>* create_column_ref(const std::string& a_name,const T& a_ref) {
if(find_named<icol>(m_cols,a_name)) return 0;
column_ref<T>* col = new column_ref<T>(m_row_wise_branch,a_name,a_ref);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
template <class T>
column<T>* create_column(const std::string& a_name,const T& a_def = T()) {
if(find_named<icol>(m_cols,a_name)) return 0;
column<T>* col = new column<T>(m_row_wise_branch,a_name,a_def);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
column_string_ref* create_column_string_ref(const std::string& a_name,const std::string& a_ref) {
if(find_named<icol>(m_cols,a_name)) return 0;
column_string_ref* col = new column_string_ref(m_row_wise_branch,a_name,a_ref);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
column_string* create_column_string(const std::string& a_name,const std::string& a_def = std::string()) {
if(find_named<icol>(m_cols,a_name)) return 0;
column_string* col = new column_string(m_row_wise_branch,a_name,a_def);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
column_vector_string_ref* create_column_vector_string_ref(const std::string& a_name,
const std::vector<std::string>& a_ref,char a_sep) {
if(find_named<icol>(m_cols,a_name)) return 0;
column_vector_string_ref* col = new column_vector_string_ref(m_row_wise_branch,a_name,a_ref,a_sep);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
column_vector_string* create_column_vector_string(const std::string& a_name,const std::vector<std::string>& a_def,char a_sep) {
if(find_named<icol>(m_cols,a_name)) return 0;
column_vector_string* col = new column_vector_string(m_row_wise_branch,a_name,a_def,a_sep);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
template <class T>
std_vector_column_ref<T>* create_column_vector_ref(const std::string& a_name,const std::vector<T>& a_ref) {
if(find_named<icol>(m_cols,a_name)) return 0;
std_vector_column_ref<T>* col = new std_vector_column_ref<T>(m_row_wise_branch,a_name,a_ref);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
template <class T>
std_vector_column<T>* create_column_vector(const std::string& a_name,const std::vector<T>& a_def = std::vector<T>()) {
if(find_named<icol>(m_cols,a_name)) return 0;
std_vector_column<T>* col = new std_vector_column<T>(m_row_wise_branch,a_name,a_def);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
protected:
branch m_row_wise_branch;
};
}}
#endif
@@ -27,6 +27,8 @@ public: //ibo
// in principle we pass here only for the last basket
// of a branch when it is streamed from branch::stream().
// We pass also here in the case of filling "tree in a tree" (MEMPHYS sim).
// some consitency checks :
//G.Barrand : the below test is "too much". Someone
// may have to write a tree (and then a basket)
@@ -82,12 +84,12 @@ public: //ibo
}
if(m_data.to_displace()) {
//NOTE : how / when handle the displacements ?
m_out << "tools::wroot::basket::stream :"
<< " WARNING : m_data buffer has offsets to displace."
<< std::endl;
//if(!const_cast<basket&>(*this).m_data.displace_mapped(m_key_length))
// return false; //???
if(!const_cast<basket&>(*this).m_data.displace_mapped(m_key_length)) {
m_out << "tools::wroot::basket::stream :"
<< " m_data.displace_mapped() failed."
<< std::endl;
return false;
}
}
buffer bref(m_out,a_buffer.byte_swap(),256);
@@ -0,0 +1,48 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_basket_add
#define tools_wroot_basket_add
// used in pntuple.
#include "branch"
namespace tools {
namespace wroot {
class basket_add : public virtual branch::iadd_basket {
typedef branch::iadd_basket parent;
public:
virtual bool add_basket(basket& a_basket) {
m_mutex.lock();
uint32 add_bytes,nout;
if(!m_main_branch->add_basket(m_main_file,a_basket,add_bytes,nout)) {
m_mutex.unlock();
return false;
}
m_main_branch->set_tot_bytes(m_main_branch->tot_bytes()+add_bytes);
m_main_branch->set_zip_bytes(m_main_branch->zip_bytes()+nout);
m_mutex.unlock();
return true;
}
public:
basket_add(imutex& a_mutex,ifile& a_main_file)
:m_mutex(a_mutex),m_main_file(a_main_file),m_main_branch(0)
{}
protected:
basket_add(const basket_add& a_from):parent()
,m_mutex(a_from.m_mutex),m_main_file(a_from.m_main_file),m_main_branch(0)
{}
basket_add& operator=(const basket_add&){return *this;}
public:
void set_main_branch(branch* a_main_branch) {m_main_branch = a_main_branch;}
protected:
imutex& m_mutex;
ifile& m_main_file;
branch* m_main_branch;
};
}}
#endif
@@ -152,8 +152,7 @@ public:
fBasketEntry[i] = 0;
fBasketSeek[i] = 0;
}}
m_baskets[m_write_basket] = new basket(m_out,m_byte_swap,a_seek_directory,
m_name,m_title,"TBasket",m_basket_size,m_verbose);
m_baskets[m_write_basket] = new basket(m_out,m_byte_swap,a_seek_directory,m_name,m_title,"TBasket",m_basket_size,m_verbose);
fBasketEntry[m_write_basket] = (uint32)m_entry_number;
}
virtual ~branch(){
@@ -180,6 +179,9 @@ protected:
{}
branch& operator=(const branch&){return *this;}
public:
const std::string& name() const {return m_name;}
const std::string& title() const {return m_title;}
uint64 entries() const {return m_entries;}
uint64 tot_bytes() const {return m_tot_bytes;}
@@ -191,26 +193,101 @@ public:
void set_basket_size(uint32 a_size) {m_basket_size = a_size;}
uint32 basket_size() const {return m_basket_size;}
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
template <class T>
leaf<T>* create_leaf(const std::string& a_name,const std::string& a_title){
leaf<T>* lf = new leaf<T>(m_out,a_name,a_title);
leaf_ref<T>* create_leaf_ref(const std::string& a_name,const T& a_ref){
leaf_ref<T>* lf = new leaf_ref<T>(m_out,a_name,a_ref);
m_leaves.push_back(lf);
return lf;
}
leaf_string* create_leaf_string(const std::string& a_name,const std::string& a_title){
leaf_string* lf = new leaf_string(m_out,a_name,a_title);
leaf_string_ref* create_leaf_string_ref(const std::string& a_name,const std::string& a_ref){
leaf_string_ref* lf = new leaf_string_ref(m_out,a_name,a_ref);
m_leaves.push_back(lf);
return lf;
}
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
template <class T>
leaf<T>* create_leaf(const std::string& a_name){
leaf<T>* lf = new leaf<T>(m_out,a_name);
m_leaves.push_back(lf);
return lf;
}
leaf_string* create_leaf_string(const std::string& a_name){
leaf_string* lf = new leaf_string(m_out,a_name);
m_leaves.push_back(lf);
return lf;
}
leaf_element* create_leaf_element(const std::string& a_name,int a_id,int a_type){
leaf_element* lf = new leaf_element(m_out,a_name,a_id,a_type);
m_leaves.push_back(lf);
return lf;
}
// for row_wise ntuple :
template <class T>
leaf_std_vector_ref<T>* create_leaf_std_vector_ref(const std::string& a_name,
base_leaf& a_leaf_count,const std::vector<T>& a_ref) {
leaf_std_vector_ref<T>* lf = new leaf_std_vector_ref<T>(m_out,a_name,a_leaf_count,a_ref);
m_leaves.push_back(lf);
return lf;
}
const std::vector<base_leaf*>& leaves() const {return m_leaves;}
void reset() {
m_baskets.clear_objs();
delete [] fBasketBytes;
delete [] fBasketEntry;
delete [] fBasketSeek;
fBasketBytes = 0;
fBasketEntry = 0;
fBasketSeek = 0;
m_max_baskets = 10;
m_write_basket = 0;
m_entry_number = 0;
m_entries = 0;
m_tot_bytes = 0;
m_zip_bytes = 0;
m_baskets.resize(m_max_baskets,0);
fBasketBytes = new uint32[m_max_baskets];
fBasketEntry = new uint32[m_max_baskets];
fBasketSeek = new seek[m_max_baskets];
{for(uint32 i=0;i<m_max_baskets;i++) {
m_baskets[i] = 0;
fBasketBytes[i] = 0;
fBasketEntry[i] = 0;
fBasketSeek[i] = 0;
}}
fBasketEntry[m_write_basket] = (uint32)m_entry_number;
m_baskets[m_write_basket] = new basket(m_out,m_byte_swap,m_seek_directory,m_name,m_title,"TBasket",m_basket_size,m_verbose);
{tools_vforit(branch*,m_branches,it) (*it)->reset();}
}
bool fill(ifile& a_file,uint32& a_nbytes,uint32& a_add_bytes,uint32& a_nout) {
a_nbytes = 0;
a_add_bytes = 0;
a_nout = 0;
if(m_write_basket>=m_max_baskets) {
m_out << "tools::wroot::branch::fill :"
<< " potential overflow : m_write_basket (" << m_write_basket << ")"
<< " >= m_max_baskets (" << m_max_baskets << ")."
<< std::endl;
return false;
}
//FIXME if (TestBit(kDoNotProcess)) return 0;
basket* bk = m_baskets[m_write_basket];
@@ -222,15 +299,22 @@ public:
}
buffer& buf = bk->datbuf();
buf.reset_objs_map();
uint32 lold = buf.length();
bk->update(bk->key_length()+lold);
m_entries++;
m_entry_number++;
if(!fill_leaves(buf)) return false;
if(!fill_leaves(buf)) {
m_out << "tools::wroot::branch::fill :"
<< " fill_leaves() failed."
<< std::endl;
return false;
}
uint32 lnew = buf.length();
uint32 nbytes = lnew - lold;
uint32 nsize = 0;
@@ -280,6 +364,14 @@ public:
bool add_basket(ifile& a_file,basket& a_basket,uint32& a_add_bytes,uint32& a_nout) {
//done on a (main) ntuple/branch.
if(m_write_basket>=m_max_baskets) {
m_out << "tools::wroot::branch::add_basket :"
<< " potential overflow : m_write_basket (" << m_write_basket << ")"
<< " >= m_max_baskets (" << m_max_baskets << ")."
<< std::endl;
return false;
}
uint32 nout;
if(!a_basket.write_on_file(a_file,m_write_basket,nout)) { //a_file is the main file (a true file).
//the upper set a_basket.m_seek_key, set a_file.m_END. Does a a_file.set_END().
@@ -347,7 +439,12 @@ public:
//m_entries++; //not used by parallel branches.
//m_entry_number++; //idem.
if(!fill_leaves(buf)) return false;
if(!fill_leaves(buf)) {
m_out << "tools::wroot::branch::parallel_fill :"
<< " fill_leaves() failed."
<< std::endl;
return false;
}
uint32 lnew = buf.length();
uint32 nbytes = lnew - lold;
@@ -388,13 +485,19 @@ public:
<< std::endl;
return false;
}
buffer& buf = bk->datbuf();
uint32 lold = buf.length();
if(!a_badd.add_basket(*bk)) {
m_out << "tools::wroot::branch::parallel_fill :"
<< " main_branch.add_basket() failed."
<< std::endl;
return false;
if(lold) {
if(!a_badd.add_basket(*bk)) {
m_out << "tools::wroot::branch::parallel_fill :"
<< " main_branch.add_basket() failed."
<< std::endl;
return false;
}
}
delete bk;
m_baskets[m_write_basket] = 0; // no need to recreate a basket since it is end of fill.
@@ -458,7 +561,7 @@ protected:
bool m_byte_swap;
bool m_verbose;
seek m_seek_directory;
ObjArray<basket> m_baskets;
obj_array<basket> m_baskets;
protected:
//Object
//uint32 m_bits;
@@ -467,8 +570,10 @@ protected:
std::string m_title;
bool fAutoDelete;
ObjArray<branch> m_branches;
ObjArray<base_leaf> m_leaves;
private: //be sure that sub branches are not used for the moment.
obj_array<branch> m_branches;
protected:
obj_array<base_leaf> m_leaves;
uint32 fCompress; // Compression level and algorithm
uint32 m_basket_size; // Initial Size of Basket Buffer
uint32 m_write_basket; // Last basket number written
@@ -9,6 +9,11 @@
namespace tools {
namespace wroot {
inline const std::string& branch_element_store_class() {
static const std::string s_v("TBranchElement");
return s_v;
}
class branch_element : public branch {
typedef branch parent;
#ifdef TOOLS_MEM
@@ -18,10 +23,7 @@ class branch_element : public branch {
}
#endif
public: //ibo
virtual const std::string& store_cls() const {
static const std::string s_v("TBranchElement");
return s_v;
}
virtual const std::string& store_cls() const {return branch_element_store_class();}
virtual bool stream(buffer& a_buffer) const {
unsigned int c;
if(!a_buffer.write_version(1,c)) return false;
@@ -59,8 +61,8 @@ protected:
branch_element(const branch_element& a_from):ibo(a_from),parent(a_from) {}
branch_element& operator=(const branch_element& a_from){parent::operator=(a_from);return *this;}
public:
leaf_element* create_leaf_element(const std::string& a_name,const std::string& a_title){
leaf_element* lf = new leaf_element(m_out,a_name,a_title,fID,fType);
leaf_element* create_leaf_element(const std::string& a_name){
leaf_element* lf = new leaf_element(m_out,a_name,fID,fType);
m_leaves.push_back(lf);
return lf;
}
@@ -75,20 +77,20 @@ protected:
};
template <class T>
class std_vector_be : public branch_element {
class std_vector_be_ref : public branch_element {
typedef branch_element parent;
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::std_vector_be");
static const std::string s_v("tools::wroot::std_vector_be_ref");
return s_v;
}
#endif
public:
std_vector_be(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
seek a_seek_directory,
const std::string& a_name,const std::string& a_title,std::vector<T>& a_vec,bool a_verbose)
std_vector_be_ref(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
seek a_seek_directory,
const std::string& a_name,const std::string& a_title,const std::vector<T>& a_ref,bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
,m_vec(a_vec)
,m_ref(a_ref)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
@@ -99,6 +101,61 @@ public:
fType = 0;
fStreamerType = -1; // TStreamerInfo::kSTLp;
}
virtual ~std_vector_be_ref(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
std_vector_be_ref(const std_vector_be_ref& a_from)
:ibo(a_from)
,parent(a_from)
,m_ref(a_from.m_ref)
{}
std_vector_be_ref& operator=(const std_vector_be_ref& a_from){
parent::operator=(a_from);
return *this;
}
protected:
virtual bool fill_leaves(buffer& a_buffer) {
unsigned int c;
if(!a_buffer.write_version(4,c)) return false;
if(!a_buffer.write((int)m_ref.size())) return false;
if(m_ref.size()) {
// The awfull below is to pass T=bool :
const T& vr = m_ref[0];
if(!a_buffer.write_fast_array(&vr,(int)m_ref.size())) return false;
}
if(!a_buffer.set_byte_count(c)) return false;
return true;
}
public:
const std::vector<T>& variable() const {return m_ref;}
std::vector<T>& variable() {return const_cast< std::vector<T>& >(m_ref);}
protected:
const std::vector<T>& m_ref;
};
template <class T>
class std_vector_be : public std_vector_be_ref<T> {
typedef std_vector_be_ref<T> parent;
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::std_vector_be");
return s_v;
}
#endif
public:
std_vector_be(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
seek a_seek_directory,
const std::string& a_name,const std::string& a_title,const std::vector<T>& a_def,bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,m_value,a_verbose)
,m_def(a_def),m_value(a_def)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
virtual ~std_vector_be(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
@@ -108,27 +165,80 @@ protected:
std_vector_be(const std_vector_be& a_from)
:ibo(a_from)
,parent(a_from)
,m_vec(a_from.m_vec)
,m_def(a_from.m_def)
,m_value(a_from.m_value)
{}
std_vector_be& operator=(const std_vector_be& a_from){
parent::operator=(a_from);
m_def = a_from.m_def;
m_value = a_from.m_value;
return *this;
}
protected:
std::vector<T> m_def;
std::vector<T> m_value;
};
template <class T>
class std_vector_be_pointer : public branch_element {
typedef branch_element parent;
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::std_vector_be_pointer");
return s_v;
}
#endif
public:
std_vector_be_pointer(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
seek a_seek_directory,
const std::string& a_name,const std::string& a_title,std::vector<T>* a_pointer,bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
,m_pointer(a_pointer)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
fClassName = "vector<"+stype(T())+">";
fClassVersion = 0;
fID = -1;
fType = 0;
fStreamerType = -1; // TStreamerInfo::kSTLp;
}
virtual ~std_vector_be_pointer(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
std_vector_be_pointer(const std_vector_be_pointer& a_from)
:ibo(a_from)
,parent(a_from)
,m_pointer(a_from.m_pointer)
{}
std_vector_be_pointer& operator=(const std_vector_be_pointer& a_from){
parent::operator=(a_from);
return *this;
}
protected:
virtual bool fill_leaves(buffer& a_buffer) {
if(!m_pointer) return false;
unsigned int c;
if(!a_buffer.write_version(4,c)) return false;
if(!a_buffer.write((int)m_vec.size())) return false;
if(m_vec.size()) {
if(!a_buffer.write((int)m_pointer->size())) return false;
if(m_pointer->size()) {
// The awfull below is to pass T=bool :
const T& vr = m_vec[0];
if(!a_buffer.write_fast_array(&vr,(int)m_vec.size())) return false;
T& vr = (*m_pointer)[0];
if(!a_buffer.write_fast_array(&vr,(int)m_pointer->size())) return false;
}
if(!a_buffer.set_byte_count(c)) return false;
return true;
}
public:
void set_pointer(std::vector<T>* a_pointer) {m_pointer = a_pointer;}
const std::vector<T>* get_pointer() const {return m_pointer;}
std::vector<T>* get_pointer() {return m_pointer;}
protected:
std::vector<T>& m_vec;
std::vector<T>* m_pointer;
};
}}
@@ -0,0 +1,70 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_branch_object
#define tools_wroot_branch_object
#include "branch"
namespace tools {
namespace wroot {
class branch_object : public branch {
typedef branch parent;
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::branch_object");
return s_v;
}
#endif
public: //ibo
virtual const std::string& store_cls() const {
static const std::string s_v("TBranchObject");
return s_v;
}
virtual bool stream(buffer& a_buffer) const {
if(fClassName.empty()) {
m_out << "tools::wroot::branch_object::stream : fClassName is empty." << std::endl;
return false;
}
unsigned int c;
if(!a_buffer.write_version(1,c)) return false;
if(!parent::stream(a_buffer)) return false;
if(!a_buffer.write(fClassName)) return false;
if(!a_buffer.set_byte_count(c)) return false;
return true;
}
public:
branch_object(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
seek a_seek_directory,const std::string& a_name,const std::string& a_title,
bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
,fClassName()
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
virtual ~branch_object(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
branch_object(const branch_object& a_from):ibo(a_from),parent(a_from) {}
branch_object& operator=(const branch_object& a_from){parent::operator=(a_from);return *this;}
public:
leaf_object* create_leaf(const std::string& a_name,const iobject& a_obj){
fClassName = a_obj.store_class_name();
leaf_object* lf = new leaf_object(m_out,a_name,a_obj);
m_leaves.push_back(lf);
return lf;
}
protected:
std::string fClassName; //Class name of referenced object
};
}}
#endif
@@ -234,6 +234,7 @@ public:
std::map<ibo*,uint32>::const_iterator it = m_objs.find((ibo*)&a_obj);
if(it!=m_objs.end()) {
uint32 objIdx = (*it).second;
unsigned int offset = (unsigned int)(m_pos-m_buffer);
@@ -331,6 +332,10 @@ public:
return true;
}
void reset_objs_map() {
m_objs.clear();
//m_clss.clear();
}
protected:
static short kMaxVersion() {return 0x3FFF;}
static uint32 kMaxMapCount() {return 0x3FFFFFFE;}
@@ -15,6 +15,7 @@ inline cid base_cid() {return 100;} //must be > cids in ../cids.
inline cid leaf_string_cid() {return base_cid()+11;}
inline cid leaf_element_cid() {return base_cid()+12;}
inline cid leaf_object_cid() {return base_cid()+13;}
inline cid base_leaf_cid() {return base_cid()+20;} //+12=32
@@ -0,0 +1,475 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
// common columns code for ntuple and base_pntuple.
template <class T>
class column_ref : public virtual icol {
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column_ref<"+stype(T())+">");
return s_v;
}
#endif
public:
static cid id_class() {
static const T s_v = T(); //do that for T = std::string.
return _cid(s_v)+10000;
}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column_ref>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {}
virtual void set_def() {}
virtual const std::string& name() const {return m_leaf->name();}
virtual void set_basket_size(uint32 a_size) {m_branch.set_basket_size(a_size);}
virtual branch& get_branch() const {return m_branch;}
virtual base_leaf* get_leaf() const {return m_leaf;}
public:
column_ref(branch& a_branch,const std::string& a_name,const T& a_ref)
:m_branch(a_branch),m_leaf(0)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
m_leaf = m_branch.create_leaf_ref<T>(a_name,a_ref);
}
virtual ~column_ref(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column_ref(const column_ref& a_from)
:icol(a_from)
,m_branch(a_from.m_branch)
,m_leaf(0)
{}
column_ref& operator=(const column_ref& a_from){
if(&a_from==this) return *this;
m_leaf = 0;
return *this;
}
public:
const T& variable() const {return m_leaf->variable();}
T& variable() {return m_leaf->variable();}
protected:
branch& m_branch;
leaf_ref<T>* m_leaf;
};
template <class T>
class column : public column_ref<T> {
typedef column_ref<T> parent;
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column<"+stype(T())+">");
return s_v;
}
#endif
public:
static cid id_class() {
static const T s_v = T(); //do that for T = std::string.
return _cid(s_v);
}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void set_def() {m_value = m_def;}
public:
column(branch& a_branch,const std::string& a_name,const T& a_def)
:parent(a_branch,a_name,m_value)
,m_def(a_def),m_value(a_def)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
virtual ~column(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column(const column& a_from)
:icol(a_from)
,parent(a_from)
,m_def(a_from.m_def)
,m_value(a_from.m_value)
{}
column& operator=(const column& a_from){
if(&a_from==this) return *this;
parent::operator=(a_from);
m_def = a_from.m_def;
m_value = a_from.m_value;
return *this;
}
public:
column& operator=(const T& a_value){m_value = a_value;return *this;}
bool fill(const T& a_value) {m_value = a_value;return true;}
protected:
T m_def;
T m_value;
};
class column_string_ref : public virtual icol {
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column_string_ref");
return s_v;
}
#endif
public:
static cid id_class() {
static const std::string s_v;
return _cid(s_v)+10000;
}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column_string_ref>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {}
virtual void set_def() {}
virtual const std::string& name() const {return m_leaf->name();}
virtual void set_basket_size(uint32 a_size) {m_branch.set_basket_size(a_size);}
virtual branch& get_branch() const {return m_branch;}
virtual base_leaf* get_leaf() const {return m_leaf;}
public:
column_string_ref(branch& a_branch,const std::string& a_name,const std::string& a_ref)
:m_branch(a_branch),m_leaf(0)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
m_leaf = m_branch.create_leaf_string_ref(a_name,a_ref);
}
virtual ~column_string_ref(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column_string_ref(const column_string_ref& a_from)
:icol(a_from)
,m_branch(a_from.m_branch)
,m_leaf(0)
{}
column_string_ref& operator=(const column_string_ref& a_from){
if(&a_from==this) return *this;
m_leaf = 0;
return *this;
}
public:
const std::string& variable() const {return m_leaf->variable();}
std::string& variable() {return m_leaf->variable();}
protected:
branch& m_branch;
leaf_string_ref* m_leaf;
};
class column_string : public column_string_ref {
typedef column_string_ref parent;
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column_string");
return s_v;
}
#endif
public:
static cid id_class() {
static const std::string s_v;
return _cid(s_v);
}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column_string>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void set_def() {m_value = m_def;}
public:
column_string(branch& a_branch,const std::string& a_name,const std::string& a_def)
:parent(a_branch,a_name,m_value)
,m_def(a_def),m_value(a_def)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
virtual ~column_string(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column_string(const column_string& a_from)
:icol(a_from)
,parent(a_from)
,m_def(a_from.m_def)
,m_value(a_from.m_value)
{}
column_string& operator=(const column_string& a_from){
if(&a_from==this) return *this;
parent::operator=(a_from);
m_def = a_from.m_def;
m_value = a_from.m_value;
return *this;
}
public:
column_string& operator=(const std::string& a_value){m_value = a_value;return *this;}
bool fill(const std::string& a_value) {m_value = a_value;return true;}
protected:
std::string m_def;
std::string m_value;
};
class column_vector_string_ref : public column_string_ref {
typedef column_string_ref parent;
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column_vector_string_ref");
return s_v;
}
#endif
public:
static cid id_class() {return _cid_std_vector<std::string>()+10000;}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column_vector_string_ref>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {
m_string.clear();
tools_vforcit(std::string,m_ref,it) {
if(it!=m_ref.begin()) m_string += m_sep;
m_string += *it;
}
parent::add();
}
public:
column_vector_string_ref(branch& a_branch,const std::string& a_name,const std::vector<std::string>& a_ref,char a_sep)
:parent(a_branch,a_name,m_string)
,m_ref(a_ref)
,m_sep(a_sep)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
virtual ~column_vector_string_ref(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column_vector_string_ref(const column_vector_string_ref& a_from)
:icol(a_from)
,parent(a_from)
,m_ref(a_from.m_ref)
,m_sep(a_from.m_sep)
{}
column_vector_string_ref& operator=(const column_vector_string_ref& a_from){
if(&a_from==this) return *this;
m_sep = a_from.m_sep;
return *this;
}
public:
const std::vector<std::string>& variable() const {return m_ref;}
std::vector<std::string>& variable() {return const_cast< std::vector<std::string>& >(m_ref);}
protected:
const std::vector<std::string>& m_ref;
char m_sep;
std::string m_string;
};
class column_vector_string : public column_vector_string_ref {
typedef column_vector_string_ref parent;
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column_vector_string");
return s_v;
}
#endif
public:
static cid id_class() {return _cid_std_vector<std::string>();}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column_vector_string>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void set_def() {m_value = m_def;}
public:
column_vector_string(branch& a_branch,const std::string& a_name,const std::vector<std::string>& a_def,char a_sep)
:parent(a_branch,a_name,m_value,a_sep)
,m_def(a_def),m_value(a_def)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
virtual ~column_vector_string(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column_vector_string(const column_vector_string& a_from)
:icol(a_from)
,parent(a_from)
,m_def(a_from.m_def)
,m_value(a_from.m_value)
{}
column_vector_string& operator=(const column_vector_string& a_from){
if(&a_from==this) return *this;
parent::operator=(a_from);
m_def = a_from.m_def;
m_value = a_from.m_value;
return *this;
}
public:
column_vector_string& operator=(const std::vector<std::string>& a_value){m_value = a_value;return *this;}
bool fill(const std::vector<std::string>& a_value) {m_value = a_value;return true;}
protected:
std::vector<std::string> m_def;
std::vector<std::string> m_value;
};
template <class T>
class std_vector_column_ref : public virtual icol {
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::std_vector_column_ref<"+stype(T())+">");
return s_v;
}
#endif
public:
static cid id_class() {return _cid_std_vector<T>()+10000;}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<std_vector_column_ref>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {
if(m_leaf_count) m_leaf_count->fill((int)m_ref.size()); //row_wise
}
virtual void set_def() {}
virtual const std::string& name() const {return m_leaf->name();}
virtual void set_basket_size(uint32 a_size) {m_branch.set_basket_size(a_size);}
virtual branch& get_branch() const {return m_branch;}
virtual base_leaf* get_leaf() const {return m_leaf;}
public:
std_vector_column_ref(branch& a_branch,const std::string& a_name,const std::vector<T>& a_ref)
:m_branch(a_branch)
,m_ref(a_ref)
,m_leaf(0)
,m_leaf_count(0) //row_wise
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
if(a_branch.store_cls()==branch_element_store_class()) {
//::printf("debug : std_vector_column_ref : column_wise\n");
int id = -1; //same as in std_vector_be.
int type = 0;
m_leaf = m_branch.create_leaf_element(a_name,id,type);
} else { //row_wise.
//::printf("debug : std_vector_column_ref : row_wise\n");
std::string leaf_count_name = a_name+"_count";
m_leaf_count = m_branch.create_leaf<int>(leaf_count_name);
m_leaf = m_branch.create_leaf_std_vector_ref<T>(a_name,*m_leaf_count,a_ref);
m_leaf->set_title(a_name+"["+leaf_count_name+"]"); //for TTreeFormula::RegisterDimensions.
}
}
virtual ~std_vector_column_ref(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
std_vector_column_ref(const std_vector_column_ref& a_from)
:icol(a_from)
,m_branch(a_from.m_barnch)
,m_ref(a_from.m_ref)
,m_leaf(0)
,m_leaf_count(0)
{}
std_vector_column_ref& operator=(const std_vector_column_ref& a_from){
if(&a_from==this) return *this;
m_leaf = 0;
m_leaf_count = 0;
return *this;
}
public:
const std::vector<T>& variable() const {return m_ref;}
std::vector<T>& variable() {return const_cast< std::vector<T>& >(m_ref);}
protected:
branch& m_branch;
const std::vector<T>& m_ref;
base_leaf* m_leaf;
leaf<int>* m_leaf_count; //row_wise.
};
template <class T>
class std_vector_column : public std_vector_column_ref<T> {
typedef std_vector_column_ref<T> parent;
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::std_vector_column<"+stype(T())+">");
return s_v;
}
#endif
public:
static cid id_class() {return _cid_std_vector<T>();}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<std_vector_column>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void set_def() {m_value = m_def;}
public:
std_vector_column(branch& a_branch,const std::string& a_name,const std::vector<T>& a_def)
:parent(a_branch,a_name,m_value)
,m_def(a_def),m_value(a_def)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
virtual ~std_vector_column(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
std_vector_column(const std_vector_column& a_from)
:icol(a_from)
,parent(a_from)
,m_def(a_from.m_def)
,m_value(a_from.m_value)
{}
std_vector_column& operator=(const std_vector_column& a_from){
if(&a_from==this) return *this;
parent::operator=(a_from);
m_def = a_from.m_def;
m_value = a_from.m_value;
return *this;
}
public:
std_vector_column& operator=(const std::vector<T>& a_value){m_value = a_value;return *this;}
bool fill(const std::vector<T>& a_value) {m_value = a_value;return true;}
protected:
std::vector<T> m_def;
std::vector<T> m_value;
};
@@ -324,8 +324,8 @@ public:
return true;
}
void clear_dirs() {clear<directory>(m_dirs);}
void clear_objs() {clear<iobject>(m_objs);}
void clear_dirs() {safe_clear<directory>(m_dirs);}
void clear_objs() {safe_clear<iobject>(m_objs);}
protected:
void clear_keys() {
@@ -24,8 +24,6 @@
#ifdef _MSC_VER
#include <direct.h>
#include <io.h>
// disable the warning about the usage of "this" in the constructor.
#pragma warning(disable:4355)
#else
#include <unistd.h>
#endif
@@ -34,6 +32,7 @@ namespace tools {
namespace wroot {
class file : public virtual ifile {
file& get_me() {return *this;} //_MSC_VER : to avoid warning about the usage of "this" in the constructor.
static int not_open() {return -1;}
static uint32 kBegin() {return 64;}
public:
@@ -177,7 +176,7 @@ public: //ifile
uint32 nbytes = a_buffer.length();
uint32 cxlevel = m_compress;
if(cxlevel && (nbytes>256)) {
tools::compress_func func;
compress_func func;
if(!ziper('Z',func)) {
//m_out << "tools::wroot::directory::write_object :"
// << " zlib ziper not found."
@@ -225,7 +224,7 @@ public:
,m_verbose(a_verbose)
,m_file(not_open())
//,m_bytes_write(0)
,m_root_directory(*this,nosuffix(a_path),m_title)
,m_root_directory(get_me(),nosuffix(a_path),m_title)
// begin of record :
,m_version(0)
,m_BEGIN(0)
@@ -346,7 +345,7 @@ protected:
file(const file& a_from)
:ifile(a_from)
,m_out(a_from.m_out)
,m_root_directory(*this)
,m_root_directory(get_me())
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
@@ -542,7 +541,7 @@ protected:
}
bool write_streamer_infos() {
List<StreamerInfo> sinfos;
obj_list<StreamerInfo> sinfos;
fill_infos(sinfos,m_out);
if(sinfos.empty()) return false;
@@ -551,7 +550,7 @@ protected:
if(!sinfos.stream(bref)) {
m_out << "tools::wroot::file::write_streamer_infos :"
<< " cannot stream List<StreamerInfo>."
<< " cannot stream obj_list<StreamerInfo>."
<< std::endl;
return false;
}
@@ -693,7 +692,7 @@ protected:
}
static bool zip(std::ostream& a_out,
tools::compress_func a_func,
compress_func a_func,
int a_level,
uint32 a_srcsize,char* a_src,
uint32 a_tgtsize,char* a_tgt,
@@ -29,7 +29,7 @@ class icol {
virtual void set_def() = 0;
virtual const std::string& name() const = 0;
virtual void set_basket_size(uint32) = 0;
virtual branch* get_branch() const = 0;
virtual branch& get_branch() const = 0;
virtual base_leaf* get_leaf() const = 0;
};
@@ -0,0 +1,22 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_impi_ntuple
#define tools_wroot_impi_ntuple
#include "../impi"
namespace tools {
namespace wroot {
class impi_ntuple {
public:
virtual bool add_row(impi&,int,int) = 0;
virtual bool end_fill(impi&,int,int) = 0;
public:
virtual ~impi_ntuple() {}
};
}}
#endif
@@ -0,0 +1,25 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_imt_ntuple
#define tools_wroot_imt_ntuple
// mt = multi-threads.
#include "imutex"
#include "ifile"
namespace tools {
namespace wroot {
class imt_ntuple {
public:
virtual bool add_row(imutex&,ifile&) = 0;
virtual bool end_fill(imutex&,ifile&) = 0;
public:
virtual ~imt_ntuple() {}
};
}}
#endif
@@ -96,7 +96,7 @@ protected:
unsigned int fCheckSum; //checksum of original class
int fStreamedClassVersion; //Class version identifier
//int fNumber; //!Unique identifier
ObjArray<streamer_element> fElements; //Array of TStreamerElements
obj_array<streamer_element> fElements; //Array of TStreamerElements
};
}}
@@ -18,7 +18,7 @@ inline void acs(unsigned int& a_cs,int a_n,int* a_dims) {
for(int i=0;i<a_n;i++) a_cs = a_cs*3+(unsigned int)a_dims[i];
}
inline void fill_vec(List<StreamerInfo>& a_infos,const std::string& a_type,streamer_info::Type a_si_type) {
inline void fill_vec(obj_list<StreamerInfo>& a_infos,const std::string& a_type,streamer_info::Type a_si_type) {
unsigned int check = 196608;
StreamerInfo* info = new StreamerInfo(std::string("vector<")+a_type+">",4,check);
a_infos.push_back(info);
@@ -30,7 +30,7 @@ inline int size_VIRTUAL() {return 4;}
inline int size_TObject() {return 12;}
inline int size_TNamed() {return 28;}
inline void fill_infos_core(List<StreamerInfo>& a_infos,std::ostream& a_out) {
inline void fill_infos_core(obj_list<StreamerInfo>& a_infos,std::ostream& a_out) {
// sizeof(TString) = 8 (4 (virtual ~) + 1 + 3 (align))
// sizeof(TObject) = 12
@@ -358,7 +358,7 @@ inline void fill_infos_core(List<StreamerInfo>& a_infos,std::ostream& a_out) {
}
inline void fill_infos_cont(List<StreamerInfo>& a_infos,std::ostream&) {
inline void fill_infos_cont(obj_list<StreamerInfo>& a_infos,std::ostream&) {
// sizeof(TString) = 8 (4 (virtual ~) + 1 + 3 (align))
// sizeof(TObject) = 12
@@ -438,7 +438,7 @@ inline int size_TAttLine() {return 10;} //12?
inline int size_TAttFill() {return 8;}
inline int size_TAttMarker() {return 12;}
inline void fill_infos_graf(List<StreamerInfo>& a_infos,std::ostream& a_out) {
inline void fill_infos_graf(obj_list<StreamerInfo>& a_infos,std::ostream& a_out) {
//sizeof(Font_t) = 2
//sizeof(Style_t) = 2
@@ -536,7 +536,7 @@ inline int size_TBranch() {return 264;} //256?
inline int size_TLeaf() {return 60;} //52?
inline int size_TTree() {return 254;} //240?
inline void fill_infos_tree(List<StreamerInfo>& a_infos,std::ostream& a_out) {
inline void fill_infos_tree(obj_list<StreamerInfo>& a_infos,std::ostream& a_out) {
const int size_CHAR = 1;
const int size_INT = 4;
@@ -1061,7 +1061,7 @@ inline int size_TH1() {return 560;} //568?
inline int size_TH2() {return 592;} //600?
inline int size_TH2D() {return 604;} //612?
inline void fill_infos_histo(List<StreamerInfo>& a_infos,std::ostream& a_out) {
inline void fill_infos_histo(obj_list<StreamerInfo>& a_infos,std::ostream& a_out) {
typedef streamer_basic_type sbt;
@@ -1561,7 +1561,7 @@ inline void fill_infos_histo(List<StreamerInfo>& a_infos,std::ostream& a_out) {
}
inline void fill_infos(List<StreamerInfo>& a_infos,std::ostream& a_out) {
inline void fill_infos(obj_list<StreamerInfo>& a_infos,std::ostream& a_out) {
fill_infos_core(a_infos,a_out);
fill_infos_cont(a_infos,a_out);
@@ -59,10 +59,7 @@ public:
mem::increment(s_class().c_str());
#endif
if(m_version>big_file_version_tag()) {
} else {
if(a_seek_directory>START_BIG_FILE()) m_version += big_file_version_tag();
}
if(a_seek_directory>START_BIG_FILE()) m_version += big_file_version_tag();
m_key_length = record_size(m_version);
+206 -25
View File
@@ -7,6 +7,7 @@
#include "base_leaf"
#include "../cids"
#include "../vdata"
namespace tools {
namespace wroot {
@@ -39,16 +40,21 @@ inline const std::string& leaf_element_store_class() {
static const std::string s_v("TLeafElement");
return s_v;
}
inline const std::string& leaf_object_store_class() {
static const std::string s_v("TLeafObject");
return s_v;
}
template <class T>
class leaf : public base_leaf {
class leaf_ref : public base_leaf {
typedef base_leaf parent;
public:
static cid id_class() {return base_leaf_cid()+_cid(T());}
static cid id_class() {return base_leaf_cid()+_cid(T())+10000;} //10000 same as in ntuple::column_ref.
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<leaf>(this,a_class)) {return p;}
return base_leaf::cast(a_class);
if(void* p = cmp_cast<leaf_ref>(this,a_class)) {return p;}
return parent::cast(a_class);
}
virtual cid id_cls() const {return id_class();}
public: //ibo
virtual const std::string& store_cls() const {return leaf_store_class(T());}
virtual bool stream(buffer& a_buffer) const {
@@ -61,16 +67,55 @@ public: //ibo
return true;
}
public: //base_leaf
virtual bool fill_buffer(buffer& a_buffer) const {return a_buffer.write<T>(m_value);}
virtual bool fill_buffer(buffer& a_buffer) const {
if(m_is_range) {
if(m_ref>=m_max) {
leaf_ref& self = const_cast<leaf_ref&>(*this);
self.m_max = m_ref;
}
}
return a_buffer.write<T>(m_ref);
}
public:
leaf(std::ostream& a_out,const std::string& a_name,const std::string& a_title)
:parent(a_out,a_name,a_title)
leaf_ref(std::ostream& a_out,const std::string& a_name,const T& a_ref)
:parent(a_out,a_name,a_name)
,m_min(T()),m_max(T())
,m_value(T())
,m_ref(a_ref)
{
m_length = 1;
m_length_type = sizeof(T);
}
virtual ~leaf_ref(){}
protected:
leaf_ref(const leaf_ref& a_from):ibo(a_from),parent(a_from),m_ref(a_from.m_ref){}
leaf_ref& operator=(const leaf_ref&){return *this;}
public:
T get_max() const {return m_max;}
void set_max(const T& a_value) {m_max = a_value;}
public:
const T& variable() const {return m_ref;}
T& variable() {return const_cast<T&>(m_ref);}
protected:
T m_min; //Minimum value if leaf range is specified
T m_max; //Maximum value if leaf range is specified
const T& m_ref;
};
template <class T>
class leaf : public leaf_ref<T> {
typedef leaf_ref<T> parent;
public:
static cid id_class() {return base_leaf_cid()+_cid(T());}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<leaf>(this,a_class)) {return p;}
return parent::cast(a_class);
}
virtual cid id_cls() const {return id_class();}
public:
leaf(std::ostream& a_out,const std::string& a_name)
:parent(a_out,a_name,m_value)
,m_value(T())
{}
virtual ~leaf(){}
protected:
leaf(const leaf& a_from):ibo(a_from),parent(a_from){}
@@ -78,19 +123,18 @@ protected:
public:
void fill(const T& a_value) {m_value = a_value;}
protected:
T m_min; //Minimum value if leaf range is specified
T m_max; //Maximum value if leaf range is specified
T m_value;
};
class leaf_string : public base_leaf {
class leaf_string_ref : public base_leaf {
typedef base_leaf parent;
public:
static cid id_class() {return leaf_string_cid();}
static cid id_class() {return leaf_string_cid()+10000;}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<leaf_string>(this,a_class)) {return p;}
return base_leaf::cast(a_class);
if(void* p = cmp_cast<leaf_string_ref>(this,a_class)) {return p;}
return parent::cast(a_class);
}
virtual cid id_cls() const {return id_class();}
public: //ibo
virtual const std::string& store_cls() const {return leaf_string_store_class();}
virtual bool stream(buffer& a_buffer) const {
@@ -104,8 +148,8 @@ public: //ibo
}
public: //base_leaf
virtual bool fill_buffer(buffer& a_buffer) const {
size_t len = ::strlen(m_value.c_str());
leaf_string& self = const_cast<leaf_string&>(*this);
leaf_string_ref& self = const_cast<leaf_string_ref&>(*this);
size_t len = ::strlen(m_ref.c_str());
if(len >= (size_t)m_max) self.m_max = int(len)+1;
if(len >= m_length) self.m_length = uint32(len)+1;
if(len < 255) {
@@ -114,30 +158,111 @@ public: //base_leaf
if(!a_buffer.write<unsigned char>(255)) return false;
if(!a_buffer.write<uint32>(uint32(len))) return false;
}
if(len) if(!a_buffer.write_fast_array(m_value.c_str(),uint32(len))) return false;
if(len) if(!a_buffer.write_fast_array(m_ref.c_str(),uint32(len))) return false;
return true;
}
public:
leaf_string(std::ostream& a_out,const std::string& a_name,const std::string& a_title)
:parent(a_out,a_name,a_title)
leaf_string_ref(std::ostream& a_out,const std::string& a_name,const std::string& a_ref)
:parent(a_out,a_name,a_name)
,m_min(0),m_max(0)
,m_ref(a_ref)
{
m_length_type = 1;
}
virtual ~leaf_string_ref(){}
protected:
leaf_string_ref(const leaf_string_ref& a_from):ibo(a_from),parent(a_from),m_ref(a_from.m_ref){}
leaf_string_ref& operator=(const leaf_string_ref&){return *this;}
public:
int get_max() const {return m_max;}
void set_max(int a_value) {m_max = a_value;}
public:
const std::string& variable() const {return m_ref;}
std::string& variable() {return const_cast<std::string&>(m_ref);}
protected:
int m_min; //Minimum value if leaf range is specified
int m_max; //Maximum value if leaf range is specified
const std::string& m_ref;
};
class leaf_string : public leaf_string_ref {
typedef leaf_string_ref parent;
public:
static cid id_class() {return leaf_string_cid();}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<leaf_string>(this,a_class)) {return p;}
return parent::cast(a_class);
}
virtual cid id_cls() const {return id_class();}
public:
leaf_string(std::ostream& a_out,const std::string& a_name)
:parent(a_out,a_name,m_value)
{}
virtual ~leaf_string(){}
protected:
leaf_string(const leaf_string& a_from):ibo(a_from),parent(a_from){}
leaf_string& operator=(const leaf_string&){return *this;}
public:
void fill(const std::string& a_value) {m_value = a_value;}
int get_max() const {return m_max;}
void set_max(int a_value) {m_max = a_value;}
protected:
int m_min; //Minimum value if leaf range is specified
int m_max; //Maximum value if leaf range is specified
std::string m_value;
};
// to store vector columns of a row_wise ntuple :
template <class T>
class leaf_std_vector_ref : public base_leaf {
typedef base_leaf parent;
public:
static cid id_class() {return base_leaf_cid()+_cid(std::vector<T>())+10000;} //10000 same as in ntuple::column_ref.
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<leaf_std_vector_ref>(this,a_class)) {return p;}
return parent::cast(a_class);
}
virtual cid id_cls() const {return id_class();}
public: //ibo
virtual const std::string& store_cls() const {return leaf_store_class(T());}
virtual bool stream(buffer& a_buffer) const {
unsigned int c;
if(!a_buffer.write_version(1,c)) return false;
if(!parent::stream(a_buffer)) return false;
if(!a_buffer.write(m_min)) return false;
if(!a_buffer.write(m_max)) return false;
if(!a_buffer.set_byte_count(c)) return false;
return true;
}
public: //base_leaf
virtual bool fill_buffer(buffer& a_buffer) const {
if(!a_buffer.write_fast_array(vec_data(m_ref),uint32(m_ref.size()))) return false;
return true;
}
public:
leaf_std_vector_ref(std::ostream& a_out,const std::string& a_name,
base_leaf& a_leaf_count,const std::vector<T>& a_ref)
:parent(a_out,a_name,a_name)
,m_min(T()),m_max(T())
,m_ref(a_ref)
{
parent::m_leaf_count = &a_leaf_count;
a_leaf_count.set_is_range(true);
m_length = 1;
m_length_type = sizeof(T);
}
virtual ~leaf_std_vector_ref(){}
protected:
leaf_std_vector_ref(const leaf_std_vector_ref& a_from):ibo(a_from),parent(a_from),m_ref(a_from.m_ref){}
leaf_std_vector_ref& operator=(const leaf_std_vector_ref&){return *this;}
public:
T get_max() const {return m_max;}
void set_max(const T& a_value) {m_max = a_value;}
public:
const std::vector<T>& variable() const {return m_ref;}
std::vector<T>& variable() {return const_cast< std::vector<T>& >(m_ref);}
protected:
T m_min; //Minimum value if leaf range is specified
T m_max; //Maximum value if leaf range is specified
const std::vector<T>& m_ref;
};
class leaf_element : public base_leaf {
typedef base_leaf parent;
public:
@@ -146,6 +271,7 @@ public:
if(void* p = cmp_cast<leaf_element>(this,a_class)) {return p;}
return base_leaf::cast(a_class);
}
virtual cid id_cls() const {return id_class();}
public:
virtual const std::string& store_cls() const {return leaf_element_store_class();}
virtual bool stream(buffer& a_buffer) const {
@@ -165,8 +291,8 @@ public: //base_leaf
return false;
}
public:
leaf_element(std::ostream& a_out,const std::string& a_name,const std::string& a_title,int a_id,int a_type)
:parent(a_out,a_name,a_title)
leaf_element(std::ostream& a_out,const std::string& a_name,int a_id,int a_type)
:parent(a_out,a_name,a_name)
,fID(a_id)
,fType(a_type)
{}
@@ -184,4 +310,59 @@ protected:
}}
#include "iobject"
namespace tools {
namespace wroot {
class leaf_object : public base_leaf {
typedef base_leaf parent;
public:
static cid id_class() {return leaf_object_cid();}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<leaf_object>(this,a_class)) {return p;}
return base_leaf::cast(a_class);
}
virtual cid id_cls() const {return id_class();}
public:
virtual const std::string& store_cls() const {return leaf_object_store_class();}
virtual bool stream(buffer& a_buffer) const {
unsigned int c;
if(!a_buffer.write_version(4,c)) return false;
if(!parent::stream(a_buffer)) return false;
if(!a_buffer.write(fVirtual)) return false;
if(!a_buffer.set_byte_count(c)) return false;
return true;
}
public: //base_leaf
virtual bool fill_buffer(buffer& a_buffer) const {
if(fVirtual) {
const std::string& _class = m_obj.store_class_name();
if(_class.size()>255) return false;
unsigned char n = (unsigned char)_class.size();
if(!a_buffer.write(n)) return false;
if(!a_buffer.write_fast_array(_class.c_str(),n+1)) return false;
}
return m_obj.stream(a_buffer);
}
public:
leaf_object(std::ostream& a_out,const std::string& a_name,const iobject& a_obj)
:parent(a_out,a_name,a_obj.store_class_name()) //CERN-ROOT/TLeafObject::Streamer() wants store class name on m_title.
,m_obj(a_obj)
,fVirtual(true)
{}
virtual ~leaf_object(){}
protected:
leaf_object(const leaf_object& a_from):ibo(a_from),parent(a_from),m_obj(a_from.m_obj),fVirtual(true){}
leaf_object& operator=(const leaf_object& a_from){
parent::operator=(a_from);
return *this;
}
protected:
const iobject& m_obj;
bool fVirtual; // Support for Virtuality
};
}}
#endif
@@ -0,0 +1,76 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_mpi_basket_add
#define tools_wroot_mpi_basket_add
#include "branch"
#include "mpi_protocol"
#include "../impi"
namespace tools {
namespace wroot {
class mpi_basket_add : public virtual branch::iadd_basket {
typedef branch::iadd_basket parent;
public:
virtual bool add_basket(basket& a_basket) {
m_mpi.pack_reset();
if(!m_mpi.pack(mpi_protocol_basket())) return false;
if(!m_mpi.pack(m_id)) 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:
mpi_basket_add(impi& a_mpi,int a_dest,int a_tag,uint32 a_id,uint32 a_icol)
:m_mpi(a_mpi),m_dest(a_dest),m_tag(a_tag),m_id(a_id),m_icol(a_icol)
{}
protected:
mpi_basket_add(const mpi_basket_add& a_from):parent()
,m_mpi(a_from.m_mpi),m_dest(a_from.m_dest),m_tag(a_from.m_tag)
,m_id(a_from.m_id),m_icol(a_from.m_icol)
{}
mpi_basket_add& operator=(const mpi_basket_add& a_from){
m_dest = a_from.m_dest;
m_tag = a_from.m_tag;
m_id = a_from.m_id;
m_icol = a_from.m_icol;
return *this;
}
protected:
impi& m_mpi;
int m_dest;
int m_tag;
uint32 m_id;
uint32 m_icol;
};
}}
#endif
@@ -0,0 +1,63 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_mpi_create_basket
#define tools_wroot_mpi_create_basket
#include "basket"
#include "../impi"
namespace tools {
namespace wroot {
inline basket* mpi_create_basket(std::ostream& a_out,impi& a_mpi,bool a_byte_swap,seek a_seek_directory,uint32 a_basket_size) {
std::string oname;
if(!a_mpi.sunpack(oname)) return 0;
std::string otitle;
if(!a_mpi.sunpack(otitle)) return 0;
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) {
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) {
uint32 n;
if(!a_mpi.unpack(n,displacement)) return 0;
}}
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());
basket* _basket = new 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,96 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_mpi_ntuple_column_wise
#define tools_wroot_mpi_ntuple_column_wise
// MPI pntuple. It uses the inlib/impi interface.
#include "base_pntuple_column_wise"
#include "mpi_basket_add"
#include "impi_ntuple"
#include "../S_STRING"
#include "../forit"
namespace tools {
namespace wroot {
class mpi_ntuple_column_wise : public base_pntuple_column_wise, public virtual impi_ntuple {
typedef base_pntuple_column_wise parent;
public:
virtual bool add_row(impi& a_mpi,int a_dest,int a_tag) {
if(m_cols.empty()) return false;
tools_vforit(icol*,m_cols,it) (*it)->add();
uint32 _icol = 0;
tools_vforit(icol*,m_cols,it) {
mpi_basket_add _badd(a_mpi,a_dest,a_tag,m_id,_icol);_icol++;
if(!(*it)->get_branch().pfill(_badd)) return false;
}
tools_vforit(icol*,m_cols,it) (*it)->set_def();
return true;
}
virtual bool end_fill(impi& a_mpi,int a_dest,int a_tag) {
uint32 _icol = 0;
tools_vforit(icol*,m_cols,it) {
mpi_basket_add _badd(a_mpi,a_dest,a_tag,m_id,_icol);_icol++;
if(!(*it)->get_branch().end_pfill(_badd)) return false;
}
a_mpi.pack_reset();
if(!a_mpi.pack(mpi_protocol_end_fill())) return false;
if(!a_mpi.pack(m_id)) return false;
if(!end_leaves(a_mpi)) return false;
if(!a_mpi.send_buffer(a_dest,a_tag)) return false;
return true;
}
public:
mpi_ntuple_column_wise(uint32 a_id,std::ostream& a_out,
bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
const std::string& a_name,const std::string& a_title,
bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
,m_id(a_id)
{}
mpi_ntuple_column_wise(uint32 a_id,std::ostream& a_out,
bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
const std::vector<uint32>& a_basket_sizes,const 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)
,m_id(a_id)
{}
virtual ~mpi_ntuple_column_wise() {}
protected:
mpi_ntuple_column_wise(const mpi_ntuple_column_wise& a_from):impi_ntuple(a_from),parent(a_from){}
mpi_ntuple_column_wise& operator=(const mpi_ntuple_column_wise& a_from){parent::operator=(a_from);return *this;}
protected:
bool end_leaves(impi& a_mpi) const {
#include "MPI_SET_MAX.icc"
tools_vforcit(icol*,m_cols,pit) {
base_leaf* _pleaf = (*pit)->get_leaf();
bool set_done = false;
TOOLS_WROOT_MPI_NTUPLE_LEAF_STRING_SET_LENGTH_MAX
if(!set_done) {
if(!a_mpi.pack((uint32)0)) return false;
if(!a_mpi.pack((int)0)) return false;
}
}
#undef TOOLS_WROOT_MPI_NTUPLE_SET_MAX
#undef TOOLS_WROOT_MPI_NTUPLE_STRING_SET_MAX
return true;
}
protected:
uint32 m_id;
};
}}
#endif
@@ -0,0 +1,106 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_mpi_ntuple_row_wise
#define tools_wroot_mpi_ntuple_row_wise
// MPI pntuple. It uses the inlib/impi interface.
#include "base_pntuple_row_wise"
#include "mpi_basket_add"
#include "impi_ntuple"
#include "../S_STRING"
#include "../forit"
namespace tools {
namespace wroot {
class mpi_ntuple_row_wise : public base_pntuple_row_wise, public virtual impi_ntuple {
typedef base_pntuple_row_wise parent;
public:
virtual bool add_row(impi& a_mpi,int a_dest,int a_tag) {
if(m_cols.empty()) return false;
tools_vforit(icol*,m_cols,it) (*it)->add();
mpi_basket_add _badd(a_mpi,a_dest,a_tag,m_id,0);
if(!m_row_wise_branch.pfill(_badd)) return false;
tools_vforit(icol*,m_cols,it) (*it)->set_def();
return true;
}
virtual bool end_fill(impi& a_mpi,int a_dest,int a_tag) {
mpi_basket_add _badd(a_mpi,a_dest,a_tag,m_id,0);
if(!m_row_wise_branch.end_pfill(_badd)) return false;
a_mpi.pack_reset();
if(!a_mpi.pack(mpi_protocol_end_fill())) return false;
if(!a_mpi.pack(m_id)) return false;
if(!end_leaves(a_mpi)) return false;
if(!a_mpi.send_buffer(a_dest,a_tag)) return false;
return true;
}
public:
mpi_ntuple_row_wise(uint32 a_id,std::ostream& a_out,
bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
const std::string& a_name,const std::string& a_title,
uint32 a_basket_size,
bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_basket_size,a_verbose)
,m_id(a_id)
{}
mpi_ntuple_row_wise(uint32 a_id,std::ostream& a_out,
bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
uint32 a_basket_size,
const ntuple_booking& a_bkg,bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_basket_size,a_bkg,a_verbose)
,m_id(a_id)
{}
virtual ~mpi_ntuple_row_wise() {}
protected:
mpi_ntuple_row_wise(const mpi_ntuple_row_wise& a_from):impi_ntuple(a_from),parent(a_from){}
mpi_ntuple_row_wise& operator=(const mpi_ntuple_row_wise& a_from){parent::operator=(a_from);return *this;}
protected:
bool end_leaves(impi& a_mpi) const {
#include "MPI_SET_MAX.icc"
tools_vforcit(base_leaf*,m_row_wise_branch.leaves(),pit) {
base_leaf* _pleaf = *pit;
bool set_done = false;
TOOLS_WROOT_MPI_NTUPLE_LEAF_SET_LENGTH_MAX(char)
TOOLS_WROOT_MPI_NTUPLE_LEAF_SET_LENGTH_MAX(short)
TOOLS_WROOT_MPI_NTUPLE_LEAF_SET_LENGTH_MAX(int)
TOOLS_WROOT_MPI_NTUPLE_LEAF_SET_LENGTH_MAX(float)
TOOLS_WROOT_MPI_NTUPLE_LEAF_SET_LENGTH_MAX(double)
TOOLS_WROOT_MPI_NTUPLE_LEAF_STD_VECTOR_SET_LENGTH_MAX(char)
TOOLS_WROOT_MPI_NTUPLE_LEAF_STD_VECTOR_SET_LENGTH_MAX(short)
TOOLS_WROOT_MPI_NTUPLE_LEAF_STD_VECTOR_SET_LENGTH_MAX(int)
TOOLS_WROOT_MPI_NTUPLE_LEAF_STD_VECTOR_SET_LENGTH_MAX(float)
TOOLS_WROOT_MPI_NTUPLE_LEAF_STD_VECTOR_SET_LENGTH_MAX(double)
TOOLS_WROOT_MPI_NTUPLE_LEAF_STRING_SET_LENGTH_MAX
if(!set_done) {
m_out << "tools::wroot::mpi_ntuple_column_wise::end_leaves :"
<< " leaf " << _pleaf->name() << " with cid " << _pleaf->id_cls() << " not treated." << std::endl;
return false;
}
}
#undef TOOLS_WROOT_MPI_NTUPLE_SET_MAX
#undef TOOLS_WROOT_MPI_NTUPLE_STRING_SET_MAX
return true;
}
protected:
uint32 m_id;
};
}}
#endif
@@ -0,0 +1,17 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_mpi_protocol
#define tools_wroot_mpi_protocol
#include "../typedefs"
namespace tools {
namespace wroot {
inline uint32 mpi_protocol_basket() {return 1;}
inline uint32 mpi_protocol_end_fill() {return 2;}
}}
#endif
@@ -0,0 +1,110 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_mt_ntuple_column_wise
#define tools_wroot_mt_ntuple_column_wise
// mt = multi-threads.
#include "base_pntuple_column_wise"
#include "basket_add"
#include "imt_ntuple"
namespace tools {
namespace wroot {
class mt_ntuple_column_wise : public base_pntuple_column_wise, public virtual imt_ntuple {
typedef base_pntuple_column_wise parent;
public:
virtual bool add_row(imutex& a_mutex,ifile& a_main_file) {
if(m_cols.empty()) return false;
{tools_vforit(icol*,m_cols,it) (*it)->add();}
if(m_main_branches.size()!=m_cols.size()) {
m_file.out() << "tools::wroot::mt_ntuple_column_wise::add_row :"
<< " m_main_branches.size() (" << m_main_branches.size() << ") != "
<< "m_cols.size() (" << m_cols.size() << ")."
<< std::endl;
return false;
}
{basket_add _badd(a_mutex,a_main_file);
std::vector<branch*>::const_iterator itb = m_main_branches.begin();
tools_vforit(icol*,m_cols,it) {
branch* main_branch = (*itb);itb++;
_badd.set_main_branch(main_branch);
if(!(*it)->get_branch().pfill(_badd)) return false;
}}
{tools_vforit(icol*,m_cols,it) (*it)->set_def();}
return true;
}
virtual bool end_fill(imutex& a_mutex,ifile& a_main_file) {
if(m_main_branches.size()!=m_cols.size()) {
m_file.out() << "tools::wroot::mt_ntuple_column_wise::end_fill :"
<< " m_main_branches.size() (" << m_main_branches.size() << ") != "
<< "m_cols.size() (" << m_cols.size() << ")."
<< std::endl;
return false;
}
basket_add _badd(a_mutex,a_main_file);
std::vector<branch*>::const_iterator itb = m_main_branches.begin();
tools_vforit(icol*,m_cols,it) {
branch* main_branch = (*itb);itb++;
_badd.set_main_branch(main_branch);
if(!(*it)->get_branch().end_pfill(_badd)) return false;
}
return end_leaves(a_mutex);
}
public:
mt_ntuple_column_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
std::vector<branch*>& a_main_branches,
const std::string& a_name,const std::string& a_title,
bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
,m_main_branches(a_main_branches)
{}
mt_ntuple_column_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
std::vector<branch*>& a_main_branches,
const std::vector<uint32>& a_basket_sizes,
const 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)
,m_main_branches(a_main_branches)
{}
virtual ~mt_ntuple_column_wise() {}
protected:
mt_ntuple_column_wise(const mt_ntuple_column_wise& a_from)
:imt_ntuple(a_from)
,parent(a_from)
,m_main_branches(a_from.m_main_branches)
{}
mt_ntuple_column_wise& operator=(const mt_ntuple_column_wise& a_from){parent::operator=(a_from);return *this;}
protected:
bool end_leaves(imutex& a_mutex) const {
#include "MT_SET_MAX.icc"
std::vector<icol*>::const_iterator pit = m_cols.begin();
tools_vforcit(branch*,m_main_branches,mit) {
if((*mit)->leaves().empty()) {
m_file.out() << "tools::wroot::mt_ntuple_column_wise::end_leaves :"
<< " branch " << (*mit)->name() << " without leaf." << std::endl;
return false;
}
base_leaf* _mleaf = *((*mit)->leaves().begin());
base_leaf* _pleaf = (*pit)->get_leaf(); pit++; //WARNING.
TOOLS_WROOT_MT_NTUPLE_STRING_SET_MAX
}
#undef TOOLS_WROOT_MT_NTUPLE_STRING_SET_MAX
return true;
}
protected:
std::vector<branch*>& m_main_branches;
};
}}
#endif
@@ -0,0 +1,97 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_mt_ntuple_row_wise
#define tools_wroot_mt_ntuple_row_wise
// pntuple = for parallel ntupling.
#include "base_pntuple_row_wise"
#include "basket_add"
#include "imt_ntuple"
namespace tools {
namespace wroot {
class mt_ntuple_row_wise : public base_pntuple_row_wise, public virtual imt_ntuple {
typedef base_pntuple_row_wise parent;
public:
virtual bool add_row(imutex& a_mutex,ifile& a_main_file) {
if(m_cols.empty()) return false;
tools_vforit(icol*,m_cols,it) (*it)->add();
basket_add _badd(a_mutex,a_main_file);
_badd.set_main_branch(&m_main_branch);
if(!m_row_wise_branch.pfill(_badd)) return false;
tools_vforit(icol*,m_cols,it) (*it)->set_def();
return true;
}
virtual bool end_fill(imutex& a_mutex,ifile& a_main_file) {
basket_add _badd(a_mutex,a_main_file);
_badd.set_main_branch(&m_main_branch);
if(!m_row_wise_branch.end_pfill(_badd)) return false;
return end_leaves(a_mutex);
}
public:
mt_ntuple_row_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
branch& a_main_branch,
const std::string& a_name,const std::string& a_title,
uint32 a_basket_size,
bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_basket_size,a_verbose)
,m_main_branch(a_main_branch)
{}
mt_ntuple_row_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
branch& a_main_branch,
uint32 a_basket_size,
const ntuple_booking& a_bkg,bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_basket_size,a_bkg,a_verbose)
,m_main_branch(a_main_branch)
{}
virtual ~mt_ntuple_row_wise() {}
protected:
mt_ntuple_row_wise(const mt_ntuple_row_wise& a_from)
:imt_ntuple(a_from)
,parent(a_from)
,m_main_branch(a_from.m_main_branch)
{}
mt_ntuple_row_wise& operator=(const mt_ntuple_row_wise& a_from){parent::operator=(a_from);return *this;}
protected:
bool end_leaves(imutex& a_mutex) const {
if(m_main_branch.leaves().size()!=m_row_wise_branch.leaves().size()) {
m_out << "tools::wroot::mt_ntuple_row_wise::end_leaves :"
<< " m_main_branch.leaves().size() (" << m_main_branch.leaves().size() << ") != "
<< "m_row_wise_branch.leaves().size() (" << m_row_wise_branch.leaves().size() << ")."
<< std::endl;
return false;
}
#include "MT_SET_MAX.icc"
std::vector<base_leaf*>::iterator pit = const_cast< std::vector<base_leaf*>& >(m_row_wise_branch.leaves()).begin();
tools_vforcit(base_leaf*,m_main_branch.leaves(),mit) {
base_leaf* _mleaf = *mit;
base_leaf* _pleaf = *pit; pit++; //WARNING.
TOOLS_WROOT_MT_NTUPLE_SET_MAX(char)
TOOLS_WROOT_MT_NTUPLE_SET_MAX(short)
TOOLS_WROOT_MT_NTUPLE_SET_MAX(int)
TOOLS_WROOT_MT_NTUPLE_SET_MAX(float)
TOOLS_WROOT_MT_NTUPLE_SET_MAX(double)
TOOLS_WROOT_MT_NTUPLE_STRING_SET_MAX
}
#undef TOOLS_WROOT_MT_NTUPLE_SET_MAX
#undef TOOLS_WROOT_MT_NTUPLE_STRING_SET_MAX
return true;
}
protected:
branch& m_main_branch;
};
}}
#endif
@@ -31,7 +31,7 @@ inline bool Named_stream(buffer& a_buffer,const std::string& a_name,const std::s
}
template <class T>
class ObjArray : public virtual ibo, public std::vector<T*> {
class obj_array : public virtual ibo, public std::vector<T*> {
static unsigned int kNullTag() {return 0;}
public: //ibo
virtual const std::string& store_cls() const {
@@ -61,19 +61,19 @@ public: //ibo
return true;
}
public:
ObjArray(){}
virtual ~ObjArray(){tools::clear<T>(*this);}
obj_array(){}
virtual ~obj_array(){safe_clear<T>(*this);}
public:
ObjArray(const ObjArray& a_from): ibo(a_from),std::vector<T*>() {
obj_array(const obj_array& a_from): ibo(a_from),std::vector<T*>() {
typedef typename std::vector<T*>::const_iterator it_t;
it_t it;
for(it=a_from.begin();it!=a_from.end();++it) {
std::vector<T*>::push_back((*it)->copy());
}
}
ObjArray& operator=(const ObjArray& a_from){
obj_array& operator=(const obj_array& a_from){
if(&a_from==this) return *this;
tools::clear<T>(*this);
safe_clear<T>(*this);
typedef typename std::vector<T*>::const_iterator it_t;
it_t it;
@@ -82,10 +82,12 @@ public:
}
return *this;
}
public:
void clear_objs() {safe_clear<T>(*this);}
};
template <class T>
class List : public virtual ibo, public std::vector<T*> {
class obj_list : public virtual ibo, public std::vector<T*> {
public: //ibo
virtual const std::string& store_cls() const {
static const std::string s_v("TList");
@@ -112,11 +114,11 @@ public: //ibo
return true;
}
public:
List(){}
virtual ~List(){tools::clear<T>(*this);}
obj_list(){}
virtual ~obj_list(){safe_clear<T>(*this);}
protected:
List(const List& a_from):ibo(a_from),std::vector<T*>(){}
List& operator=(const List&){return *this;}
obj_list(const obj_list& a_from):ibo(a_from),std::vector<T*>(){}
obj_list& operator=(const obj_list&){return *this;}
};
inline bool AttLine_stream(buffer& a_buffer){
+395 -290
View File
@@ -18,6 +18,9 @@
#include "../scast"
#include "../forit"
// for mpi :
#include "mpi_create_basket"
#ifdef TOOLS_MEM
#include "../mem"
#endif
@@ -27,320 +30,174 @@ namespace wroot {
class ntuple : public tree {
public:
//typedef tools::wroot::icol icol; //for backward compatibility.
//typedef wroot::icol icol; //for backward compatibility.
public:
template <class T>
class column : public virtual icol {
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column<"+stype(T())+">");
return s_v;
}
#endif
public:
static cid id_class() {
static const T s_v = T(); //do that for T = std::string.
return _cid(s_v);
}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {m_leaf->fill(m_tmp);}
virtual void set_def() {m_tmp = m_def;}
virtual const std::string& name() const {return m_leaf->name();}
virtual void set_basket_size(uint32 a_size) {m_branch->set_basket_size(a_size);}
virtual branch* get_branch() const {return m_branch;}
virtual base_leaf* get_leaf() const {return m_leaf;}
public:
column(tree& a_tree,const std::string& a_name,const T& a_def)
:m_tree(a_tree),m_branch(0),m_leaf(0)
,m_def(a_def),m_tmp(a_def)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
m_branch = m_tree.create_branch(a_name);
m_leaf = m_branch->create_leaf<T>(a_name,a_name);
}
virtual ~column(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column(const column& a_from)
:icol(a_from)
,m_tree(a_from.m_tree)
,m_branch(0)
,m_leaf(0)
,m_def(a_from.m_def)
,m_tmp(a_from.m_tmp)
{}
column& operator=(const column& a_from){
if(&a_from==this) return *this;
m_branch = 0;
m_leaf = 0;
m_def = a_from.m_def;
m_tmp = a_from.m_tmp;
return *this;
}
public:
bool fill(const T& a_value) {m_tmp = a_value;return true;}
protected:
tree& m_tree;
branch* m_branch;
leaf<T>* m_leaf;
T m_def;
T m_tmp;
};
class column_string : public virtual icol {
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::column_string");
return s_v;
}
#endif
public:
static cid id_class() {
static const std::string s_v;
return _cid(s_v);
}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<column_string>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {m_leaf->fill(m_tmp);}
virtual void set_def() {m_tmp = m_def;}
virtual const std::string& name() const {return m_leaf->name();}
virtual void set_basket_size(uint32 a_size) {m_branch->set_basket_size(a_size);}
virtual branch* get_branch() const {return m_branch;}
virtual base_leaf* get_leaf() const {return m_leaf;}
public:
column_string(tree& a_tree,const std::string& a_name,const std::string& a_def)
:m_tree(a_tree),m_branch(0),m_leaf(0)
,m_def(a_def),m_tmp(a_def)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
m_branch = m_tree.create_branch(a_name);
m_leaf = m_branch->create_leaf_string(a_name,a_name);
}
virtual ~column_string(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
column_string(const column_string& a_from)
:icol(a_from)
,m_tree(a_from.m_tree)
,m_branch(0)
,m_leaf(0)
,m_def(a_from.m_def)
,m_tmp(a_from.m_tmp)
{}
column_string& operator=(const column_string& a_from){
if(&a_from==this) return *this;
m_branch = 0;
m_leaf = 0;
m_def = a_from.m_def;
m_tmp = a_from.m_tmp;
return *this;
}
public:
bool fill(const std::string& a_value) {m_tmp = a_value;return true;}
protected:
tree& m_tree;
branch* m_branch;
leaf_string* m_leaf;
std::string m_def;
std::string m_tmp;
};
template <class T>
class std_vector_column : public virtual icol {
#ifdef TOOLS_MEM
static const std::string& s_class() {
static const std::string s_v("tools::wroot::ntuple::std_vector_column<"+stype(T())+">");
return s_v;
}
#endif
public:
static cid id_class() {return _cid_std_vector<T>();}
virtual void* cast(cid a_class) const {
if(void* p = cmp_cast<std_vector_column>(this,a_class)) {return p;}
else return 0;
}
virtual cid id_cls() const {return id_class();}
public: //icol
virtual void add() {}
virtual void set_def() {}
virtual const std::string& name() const {return m_leaf->name();}
virtual void set_basket_size(uint32 a_size) {m_branch->set_basket_size(a_size);}
virtual branch* get_branch() const {return m_branch;}
virtual base_leaf* get_leaf() const {return m_leaf;}
public:
std_vector_column(tree& a_tree,const std::string& a_name,std::vector<T>& a_user_vec)
:m_tree(a_tree)
,m_user_vec(a_user_vec)
,m_branch(0)
,m_leaf(0)
{
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
std_vector_be<T>* br = m_tree.create_std_vector_be<T>(a_name,m_user_vec);
m_leaf = br->create_leaf_element(a_name,a_name);
m_branch = br;
}
virtual ~std_vector_column(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
protected:
std_vector_column(const std_vector_column& a_from)
:icol(a_from)
,m_tree(a_from.m_tree)
,m_user_vec(a_from.m_user_vec)
,m_branch(0)
,m_leaf(0)
{}
std_vector_column& operator=(const std_vector_column& a_from){
if(&a_from==this) return *this;
m_branch = 0;
m_leaf = 0;
return *this;
}
protected:
tree& m_tree;
std::vector<T>& m_user_vec;
branch* m_branch;
leaf_element* m_leaf;
};
#include "columns.icc"
public:
ntuple(idir& a_dir,const std::string& a_name,const std::string& a_title):tree(a_dir,a_name,a_title){}
ntuple(idir& a_dir,const std::string& a_name,const std::string& a_title,bool a_row_wise = false)
:tree(a_dir,a_name,a_title),m_row_wise(a_row_wise),m_row_wise_branch(0)
{
if(m_row_wise) m_row_wise_branch = create_branch("row_wise_branch");
}
ntuple(idir& a_dir,const ntuple_booking& a_bkg):tree(a_dir,a_bkg.name(),a_bkg.title()) {
ntuple(idir& a_dir,const ntuple_booking& a_bkg,bool a_row_wise = false)
:tree(a_dir,a_bkg.name(),a_bkg.title()),m_row_wise(a_row_wise),m_row_wise_branch(0)
{
if(m_row_wise) m_row_wise_branch = create_branch("row_wise_branch");
const std::vector<column_booking>& cols = a_bkg.columns();
tools_vforcit(column_booking,cols,it){
if((*it).cls_id()==_cid(char(0))) {
create_column<char>((*it).name());
} else if((*it).cls_id()==_cid(short(0))) {
create_column<short>((*it).name());
} else 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_string((*it).name());
#define TOOLS_WROOT_NTUPLE_CREATE_COL(a__type) \
if((*it).cls_id()==_cid(a__type())) {\
a__type* user = (a__type*)(*it).user_obj();\
if(user) {\
if(!create_column_ref<a__type>((*it).name(),*user)) {\
m_out << "tools::wroot::ntuple : create_column_ref(" << (*it).name() << ") failed." << std::endl;\
safe_clear<icol>(m_cols);\
safe_clear<branch>(m_branches);\
return;\
}\
} else {\
if(!create_column<a__type>((*it).name())) {\
m_out << "tools::wroot::ntuple : create_column(" << (*it).name() << ") failed." << std::endl;\
safe_clear<icol>(m_cols);\
safe_clear<branch>(m_branches);\
return;\
}\
}\
}
#define TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(a__type) \
if((*it).cls_id()==_cid_std_vector<a__type>()) {\
std::vector<a__type>* vec = (std::vector<a__type>*)(*it).user_obj();\
if(vec) {\
if(!create_column_vector_ref<a__type>((*it).name(),*vec)) {\
m_out << "tools::wroot::ntuple : create_column_vector_ref(" << (*it).name() << ") failed." << std::endl;\
safe_clear<icol>(m_cols);\
safe_clear<branch>(m_branches);\
return;\
}\
} else {\
if(!create_column_vector<a__type>((*it).name())) {\
m_out << "tools::wroot::ntuple : create_column_vector(" << (*it).name() << ") failed." << std::endl;\
safe_clear<icol>(m_cols);\
safe_clear<branch>(m_branches);\
return;\
}\
}\
}
//below types are in sync with rroot/ntuple.
TOOLS_WROOT_NTUPLE_CREATE_COL(char)
else TOOLS_WROOT_NTUPLE_CREATE_COL(short)
else TOOLS_WROOT_NTUPLE_CREATE_COL(int)
else TOOLS_WROOT_NTUPLE_CREATE_COL(float)
else TOOLS_WROOT_NTUPLE_CREATE_COL(double)
else if((*it).cls_id()==_cid(std::string())) {
std::string* user = (std::string*)(*it).user_obj();
if(user) {
if(!create_column_string_ref((*it).name(),*user)) {
m_out << "tools::wroot::ntuple : create_column_string_ref(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
} else {
if(!create_column_string((*it).name())) {
m_out << "tools::wroot::ntuple : create_column_string(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
}
}
else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(char)
else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(short)
else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(int)
else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(float)
else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(double)
} else if((*it).cls_id()==_cid_std_vector<char>()) {
std::vector<char>* vec = (std::vector<char>*)(*it).user_obj();
if(vec) {
create_column<char>((*it).name(),*vec);
else if((*it).cls_id()==_cid_std_vector<std::string>()) {\
std::vector<std::string>* user = (std::vector<std::string>*)(*it).user_obj();
char sep = '\n';
if(user) {
if(!create_column_vector_string_ref((*it).name(),*user,sep)) {
m_out << "tools::wroot::ntuple : create_column_vector_string_ref(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
} else {
m_out << "tools::wroot::ntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(m_cols);
tools::clear<branch>(m_branches);
return;
}
} else if((*it).cls_id()==_cid_std_vector<short>()) {
std::vector<short>* vec = (std::vector<short>*)(*it).user_obj();
if(vec) {
create_column<short>((*it).name(),*vec);
} else {
m_out << "tools::wroot::ntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(m_cols);
tools::clear<branch>(m_branches);
return;
}
} 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 {
m_out << "tools::wroot::ntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(m_cols);
tools::clear<branch>(m_branches);
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 {
m_out << "tools::wroot::ntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(m_cols);
tools::clear<branch>(m_branches);
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 {
m_out << "tools::wroot::ntuple :"
<< " for std::vector column " << sout((*it).name())
<< ", the user vector pointer is null."
<< std::endl;
tools::clear<icol>(m_cols);
tools::clear<branch>(m_branches);
return;
if(!create_column_vector_string((*it).name(),std::vector<std::string>(),sep)) {
m_out << "tools::wroot::ntuple : create_column_vector_string(" << (*it).name() << ") failed." << std::endl;
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
}
}
// no leaf_store_class() defined for the other types.
} else {
else {
m_out << "tools::wroot::ntuple :"
<< " for column " << sout((*it).name())
<< ", type with cid " << (*it).cls_id() << " not yet handled."
<< std::endl;
//throw
tools::clear<icol>(m_cols);
tools::clear<branch>(m_branches);
safe_clear<icol>(m_cols);
safe_clear<branch>(m_branches);
return;
}
}
#undef TOOLS_WROOT_NTUPLE_CREATE_VEC_COL
#undef TOOLS_WROOT_NTUPLE_CREATE_COL
}
virtual ~ntuple() {
tools::clear<icol>(m_cols);
safe_clear<icol>(m_cols);
}
protected:
ntuple(const ntuple& a_from):iobject(a_from),itree(a_from),tree(a_from){}
ntuple(const ntuple& a_from):iobject(a_from),itree(a_from),tree(a_from),m_row_wise(a_from.m_row_wise){}
ntuple& operator=(const ntuple&){return *this;}
public:
const std::vector<icol*>& columns() const {return m_cols;}
std::vector<icol*>& columns() {return m_cols;}
template <class T>
column_ref<T>* create_column_ref(const std::string& a_name,const T& a_ref) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
if(!_branch) return 0;
column_ref<T>* col = new column_ref<T>(*_branch,a_name,a_ref);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
template <class T>
column<T>* create_column(const std::string& a_name,const T& a_def = T()) {
if(find_named<icol>(m_cols,a_name)) return 0;
column<T>* col = new column<T>(*this,a_name,a_def);
branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
if(!_branch) return 0;
column<T>* col = new column<T>(*_branch,a_name,a_def);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
column_string_ref* create_column_string_ref(const std::string& a_name,const std::string& a_ref) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
if(!_branch) return 0;
column_string_ref* col = new column_string_ref(*_branch,a_name,a_ref);
if(!col) return 0;
m_cols.push_back(col);
return col;
@@ -348,28 +205,86 @@ public:
column_string* create_column_string(const std::string& a_name,const std::string& a_def = std::string()) {
if(find_named<icol>(m_cols,a_name)) return 0;
column_string* col = new column_string(*this,a_name,a_def);
branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
if(!_branch) return 0;
column_string* col = new column_string(*_branch,a_name,a_def);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
column_vector_string_ref* create_column_vector_string_ref(const std::string& a_name,
const std::vector<std::string>& a_ref,char a_sep) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
if(!_branch) return 0;
column_vector_string_ref* col = new column_vector_string_ref(*_branch,a_name,a_ref,a_sep);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
column_vector_string* create_column_vector_string(const std::string& a_name,
const std::vector<std::string>& a_def,char a_sep) {
if(find_named<icol>(m_cols,a_name)) return 0;
branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
if(!_branch) return 0;
column_vector_string* col = new column_vector_string(*_branch,a_name,a_def,a_sep);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
template <class T>
std_vector_column<T>* create_column(const std::string& a_name,std::vector<T>& a_user_vec) {
//NOTE : to optimize, we do not handle a default std::vector value logic.
std_vector_column_ref<T>* create_column_vector_ref(const std::string& a_name,const std::vector<T>& a_ref) {
if(find_named<icol>(m_cols,a_name)) return 0;
std_vector_column<T>* col = new std_vector_column<T>(*this,a_name,a_user_vec);
branch* _branch = m_row_wise?m_row_wise_branch:create_std_vector_be_ref<T>(a_name,a_ref);
if(!_branch) return 0;
std_vector_column_ref<T>* col = new std_vector_column_ref<T>(*_branch,a_name,a_ref);
if(!col) return 0;
m_cols.push_back(col);
return col;
}
template <class T>
std_vector_column<T>* create_column_vector(const std::string& a_name,const std::vector<T>& a_def = std::vector<T>()) {
if(find_named<icol>(m_cols,a_name)) return 0;
if(m_row_wise) {
branch* _branch = m_row_wise_branch;
std_vector_column<T>* col = new std_vector_column<T>(*_branch,a_name,a_def);
if(!col) return 0;
m_cols.push_back(col);
return col;
} else {
std_vector_be_pointer<T>* _branch = create_std_vector_be_pointer<T>(a_name,0);
if(!_branch) return 0;
std_vector_column<T>* col = new std_vector_column<T>(*_branch,a_name,a_def);
if(!col) return 0;
_branch->set_pointer(&(col->variable()));
m_cols.push_back(col);
return col;
}
}
template <class T>
column_ref<T>* find_column_ref(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, column_ref<T> >(*col);
}
template <class T>
column<T>* find_column(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, column<T> >(*col);
}
column_string_ref* find_column_string_ref(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, column_string_ref >(*col);
}
column_string* find_column_string(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
@@ -377,6 +292,39 @@ public:
return id_cast<icol, column_string >(*col);
}
template <class T>
std_vector_column_ref<T>* find_column_vector_ref(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, std_vector_column_ref<T> >(*col);
}
template <class T>
std_vector_column<T>* find_column_vector(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, std_vector_column<T> >(*col);
}
column_vector_string_ref* find_column_vector_string_ref(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, column_vector_string_ref >(*col);
}
column_vector_string* find_column_vector_string(const std::string& a_name) {
icol* col = find_named<icol>(m_cols,a_name);
if(!col) return 0;
return id_cast<icol, column_vector_string >(*col);
}
void print_columns(std::ostream& a_out) {
a_out << "for ntuple named " << sout(m_name) << ", number of columns " << m_cols.size() << " :" << std::endl;
tools_vforit(icol*,m_cols,it) {
a_out << " " << (*it)->name() << std::endl;
}
}
bool add_row() {
if(m_cols.empty()) return false;
tools_vforit(icol*,m_cols,it) (*it)->add();
@@ -386,14 +334,21 @@ public:
return status;
}
void set_basket_size(uint32 a_size) {tools_vforit(icol*,m_cols,it) (*it)->set_basket_size(a_size);}
void set_basket_size(uint32 a_size) {
if(m_row_wise) {
if(m_row_wise_branch) m_row_wise_branch->set_basket_size(a_size);
} else {
tools_vforit(icol*,m_cols,it) (*it)->set_basket_size(a_size);
}
}
///////////////////////////////////////////////////////////////////////////
/// for parallelization : /////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
branch* get_row_wise_branch() const {return m_row_wise_branch;}
void get_branches(std::vector<branch*>& a_vec) const {
a_vec.clear();
tools_vforcit(icol*,m_cols,it) a_vec.push_back((*it)->get_branch());
tools_vforcit(icol*,m_cols,it) a_vec.push_back(&((*it)->get_branch()));
}
bool merge_number_of_entries() {
@@ -403,20 +358,170 @@ public:
bool status = true;
tools_vforit(icol*,m_cols,it) {
if(it==m_cols.begin()) {
m_entries = (*it)->get_branch()->entries();
} else if(m_entries!=(*it)->get_branch()->entries()) {
m_entries = (*it)->get_branch().entries();
} else if(m_entries!=(*it)->get_branch().entries()) {
m_out << "tools::wroot::ntuple::merge_number_of_entries :"
<< " branches do not have same number of entries."
<< std::endl;
status = false;
}
m_tot_bytes += (*it)->get_branch()->tot_bytes();
m_zip_bytes += (*it)->get_branch()->zip_bytes();
m_tot_bytes += (*it)->get_branch().tot_bytes();
m_zip_bytes += (*it)->get_branch().zip_bytes();
}
return status;
}
bool mpi_add_basket(impi& a_impi) {
uint32 icol; //not used if row_wise.
if(!a_impi.unpack(icol)) {
m_out << "tools::wroot::ntuple::mpi_add_baset : unpack(icol) failed."<< std::endl;
return false;
}
if(m_row_wise) {
if(!m_row_wise_branch) return false;
basket* basket = mpi_create_basket(m_out,a_impi,
m_dir.file().byte_swap(),m_dir.seek_directory(),
m_row_wise_branch->basket_size());
if(!basket) {
m_out << "tools::wroot::ntuple::mpi_add_baset : mpi_create_basket() failed."<< std::endl;
return false;
}
uint32 add_bytes,nout;
if(!m_row_wise_branch->add_basket(m_dir.file(),*basket,add_bytes,nout)) {
m_out << "tools::wroot::ntuple::mpi_add_baset : row wise : branch.add_basket() failed."<< std::endl;
return false;
}
delete basket;
m_row_wise_branch->set_tot_bytes(m_row_wise_branch->tot_bytes()+add_bytes);
m_row_wise_branch->set_zip_bytes(m_row_wise_branch->zip_bytes()+nout);
} else {
if(icol>=m_cols.size()) {
m_out << "tools::wroot::ntuple::mpi_add_baset : column index " << icol << " >= " << m_cols.size() << std::endl;
return false;
}
branch& _branch = m_cols[icol]->get_branch();
basket* basket = mpi_create_basket(m_out,a_impi,
m_dir.file().byte_swap(),m_dir.seek_directory(),
_branch.basket_size());
if(!basket) {
m_out << "tools::wroot::ntuple::mpi_add_baset : mpi_create_basket() failed."<< std::endl;
return false;
}
uint32 add_bytes,nout;
if(!_branch.add_basket(m_dir.file(),*basket,add_bytes,nout)) {
m_out << "tools::wroot::ntuple::mpi_add_baset : column wise : branch.add_basket() failed."<< std::endl;
return false;
}
delete basket;
_branch.set_tot_bytes(_branch.tot_bytes()+add_bytes);
_branch.set_zip_bytes(_branch.zip_bytes()+nout);
}
return true;
}
bool mpi_end_fill(impi& a_impi) {
#define TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(a__type) \
{leaf_ref<a__type>* _mleaf_ = _mleaf?id_cast<base_leaf, leaf_ref<a__type> >(*_mleaf):0;\
if(_mleaf_) {\
uint32 _len;\
if(!a_impi.unpack(_len)) return false;\
a__type _mx;\
if(!a_impi.unpack(_mx)) return false;\
_mleaf_->set_length(mx(_len,_mleaf_->length()));\
_mleaf_->set_max(mx(_mx,_mleaf_->get_max()));\
set_done = true;\
}}
#define TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(a__type) \
{leaf_std_vector_ref<a__type>* _mleaf_ = _mleaf?id_cast<base_leaf, leaf_std_vector_ref<a__type> >(*_mleaf):0;\
if(_mleaf_) {\
uint32 _len;\
if(!a_impi.unpack(_len)) return false;\
a__type _mx;\
if(!a_impi.unpack(_mx)) return false;\
_mleaf_->set_length(mx(_len,_mleaf_->length()));\
_mleaf_->set_max(mx(_mx,_mleaf_->get_max()));\
set_done = true;\
}}
#define TOOLS_WROOT_NTUPLE_SET_LEAF_STRING_LENGTH_MAX \
{leaf_string_ref* _mleaf_ = _mleaf?id_cast<base_leaf,leaf_string_ref>(*_mleaf):0;\
if(_mleaf_) {\
uint32 _len;\
if(!a_impi.unpack(_len)) return false;\
int _mx;\
if(!a_impi.unpack(_mx)) return false;\
_mleaf_->set_length(mx(_len,_mleaf_->length()));\
_mleaf_->set_max(mx(_mx,_mleaf_->get_max()));\
set_done = true;\
}}
if(m_row_wise) {
if(!m_row_wise_branch) return false;
tools_vforcit(base_leaf*,m_row_wise_branch->leaves(),mit) {
base_leaf* _mleaf = *mit;
bool set_done = false;
TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(char)
TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(short)
TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(int)
TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(float)
TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(double)
TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(char)
TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(short)
TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(int)
TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(float)
TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(double)
TOOLS_WROOT_NTUPLE_SET_LEAF_STRING_LENGTH_MAX
if(!set_done) {
m_out << "tools::wroot::ntuple::mpi_end_fill :"
<< " leaf " << _mleaf->name() << " with cid " << _mleaf->id_cls() << " not treated." << std::endl;
return false;
}
}
} else { // column wise :
tools_vforcit(wroot::icol*,m_cols,it) {
base_leaf* _mleaf = (*it)->get_leaf();
bool set_done = false;
TOOLS_WROOT_NTUPLE_SET_LEAF_STRING_LENGTH_MAX
if(!set_done) {
uint32 _len;
if(!a_impi.unpack(_len)) return false;
int _mx;
if(!a_impi.unpack(_mx)) return false;
}
}
}
#undef TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX
#undef TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX
#undef TOOLS_WROOT_NTUPLE_SET_LEAF_STRING_LENGTH_MAX
return true;
}
protected:
std::vector<icol*> m_cols;
bool m_row_wise;
branch* m_row_wise_branch; //used if row_wise.
};
}}
@@ -1,129 +0,0 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_wroot_pntuple
#define tools_wroot_pntuple
// pntuple = for parallel ntupling.
#include "base_pntuple"
namespace tools {
namespace wroot {
class pntuple : public base_pntuple {
typedef base_pntuple parent;
public:
pntuple(std::ostream& a_out,
bool a_byte_swap,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,uint32 a_compression,seek a_seek_directory,
const std::vector<uint32>& a_basket_sizes,const 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 branch::iadd_basket {
typedef branch::iadd_basket parent;
public:
virtual bool add_basket(basket& a_basket) {
m_mutex.lock();
uint32 add_bytes,nout;
if(!m_main_branch->add_basket(m_main_file,a_basket,add_bytes,nout)) {
m_mutex.unlock();
return false;
}
m_main_branch->set_tot_bytes(m_main_branch->tot_bytes()+add_bytes);
m_main_branch->set_zip_bytes(m_main_branch->zip_bytes()+nout);
m_mutex.unlock();
return true;
}
public:
basket_add(imutex& a_mutex,ifile& a_main_file)
:m_mutex(a_mutex),m_main_file(a_main_file),m_main_branch(0)
{}
protected:
basket_add(const basket_add& a_from):parent()
,m_mutex(a_from.m_mutex),m_main_file(a_from.m_main_file),m_main_branch(0)
{}
basket_add& operator=(const basket_add&){return *this;}
public:
void set_main_branch(branch* a_main_branch) {m_main_branch = a_main_branch;}
protected:
imutex& m_mutex;
ifile& m_main_file;
branch* m_main_branch;
};
public:
bool add_row(imutex& a_mutex,ifile& a_main_file,const std::vector<branch*>& a_main_branches) {
if(m_cols.empty()) return false;
tools_vforit(icol*,m_cols,it) (*it)->add();
basket_add _badd(a_mutex,a_main_file);
std::vector<branch*>::const_iterator itb = a_main_branches.begin();
tools_vforit(icol*,m_cols,it) {
branch* main_branch = (*itb);itb++;
_badd.set_main_branch(main_branch);
if(!(*it)->get_branch()->pfill(_badd)) return false;
}
tools_vforit(icol*,m_cols,it) (*it)->set_def();
return true;
}
protected:
bool end_leaves(imutex& a_mutex,std::vector<branch*>& a_main_branches) const {
std::vector<icol*>::const_iterator pit = m_cols.begin();
tools_vforcit(branch*,a_main_branches,mit) {
base_leaf* _pleaf = (*pit)->get_leaf();
leaf_string* _pleafs = _pleaf?id_cast<base_leaf,leaf_string>(*_pleaf):0;
base_leaf* _mleaf = *((*mit)->leaves().begin());
leaf_string* _mleafs = _mleaf?tools::id_cast<base_leaf,leaf_string>(*_mleaf):0;
pit++; //WARNING.
if((_mleafs&&!_pleafs)||(!_mleafs&&_pleafs)) {
m_file.out() << "tools::wroot::pntuple::end_leaves : merge string leaves problem." << std::endl;
return false;
}
if(_mleafs && _pleafs) {
//m_file.out() << "tools::wroot::pntuple::end_leaves : merge string leaves ok." << std::endl;
tools::uint32 _length = _pleafs->length();
int _mx = _pleafs->get_max();
a_mutex.lock(); //do it here (and not outside loop) because of upper m_out.
_mleafs->set_length(tools::mx(_length,_mleafs->length()));
_mleafs->set_max(tools::mx(_mx,_mleafs->get_max()));
a_mutex.unlock();
}
}
return true;
}
public:
bool end_fill(imutex& a_mutex,ifile& a_main_file,std::vector<branch*>& a_main_branches) {
std::vector<branch*>::const_iterator itb = a_main_branches.begin();
basket_add _badd(a_mutex,a_main_file);
tools_vforit(icol*,m_cols,it) {
branch* main_branch = (*itb);itb++;
_badd.set_main_branch(main_branch);
if(!(*it)->get_branch()->end_pfill(_badd)) return false;
}
return end_leaves(a_mutex,a_main_branches);
}
};
}}
#endif
@@ -267,7 +267,9 @@ inline bool TH_write_3D(buffer& a_buffer,
inline bool TH1F_stream(buffer& a_buffer,const histo::h1df& a_h,const std::string& a_name) {
if(!a_buffer.write_version(1)) return false;
if(!TH_write_1D(a_buffer,a_h,a_name,convert<float,double>(a_h.bins_sum_w2()))) return false;
std::vector<double> bins_sum_w2d;
convert<float,double>(a_h.bins_sum_w2(),bins_sum_w2d);
if(!TH_write_1D(a_buffer,a_h,a_name,bins_sum_w2d)) return false;
if(!a_buffer.write_array(a_h.bins_sum_w())) return false;
return true;
}
@@ -275,7 +277,9 @@ inline bool TH1F_stream(buffer& a_buffer,const histo::h1df& a_h,const std::strin
inline bool TH1F_stream(buffer& a_buffer,const histo::h1d& a_h,const std::string& a_name) {
if(!a_buffer.write_version(1)) return false;
if(!TH_write_1D(a_buffer,a_h,a_name,a_h.bins_sum_w2())) return false;
if(!a_buffer.write_array(convert<double,float>(a_h.bins_sum_w()))) return false;
std::vector<float> bins_sum_wf;
convert<double,float>(a_h.bins_sum_w(),bins_sum_wf);
if(!a_buffer.write_array(bins_sum_wf)) return false;
return true;
}
@@ -289,13 +293,17 @@ inline bool TH1D_stream(buffer& a_buffer,const histo::h1d& a_h,const std::string
inline bool TH2F_stream(buffer& a_buffer,const histo::h2d& a_h,const std::string& a_name){
if(!a_buffer.write_version(3)) return false;
if(!TH_write_2D(a_buffer,a_h,a_name,a_h.bins_sum_w2())) return false;
if(!a_buffer.write_array(convert<double,float>(a_h.bins_sum_w()))) return false; //fArray TArrayF
std::vector<float> bins_sum_wf;
convert<double,float>(a_h.bins_sum_w(),bins_sum_wf);
if(!a_buffer.write_array(bins_sum_wf)) return false; //fArray TArrayF
return true;
}
inline bool TH2F_stream(buffer& a_buffer,const histo::h2df& a_h,const std::string& a_name){
if(!a_buffer.write_version(3)) return false;
if(!TH_write_2D(a_buffer,a_h,a_name,convert<float,double>(a_h.bins_sum_w2()))) return false;
std::vector<double> bins_sum_w2d;
convert<float,double>(a_h.bins_sum_w2(),bins_sum_w2d);
if(!TH_write_2D(a_buffer,a_h,a_name,bins_sum_w2d)) return false;
if(!a_buffer.write_array(a_h.bins_sum_w())) return false;
return true;
}
@@ -310,13 +318,17 @@ inline bool TH2D_stream(buffer& a_buffer,const histo::h2d& a_h,const std::string
inline bool TH3F_stream(buffer& a_buffer,const histo::h3d& a_h,const std::string& a_name){
if(!a_buffer.write_version(3)) return false;
if(!TH_write_3D(a_buffer,a_h,a_name,a_h.bins_sum_w2())) return false;
if(!a_buffer.write_array(convert<double,float>(a_h.bins_sum_w()))) return false; //fArray TArrayF
std::vector<float> bins_sum_wf;
convert<double,float>(a_h.bins_sum_w(),bins_sum_wf);
if(!a_buffer.write_array(bins_sum_wf)) return false; //fArray TArrayF
return true;
}
inline bool TH3F_stream(buffer& a_buffer,const histo::h3df& a_h,const std::string& a_name){
if(!a_buffer.write_version(3)) return false;
if(!TH_write_3D(a_buffer,a_h,a_name,convert<float,double>(a_h.bins_sum_w2()))) return false;
std::vector<double> bins_sum_w2d;
convert<float,double>(a_h.bins_sum_w2(),bins_sum_w2d);
if(!TH_write_3D(a_buffer,a_h,a_name,bins_sum_w2d)) return false;
if(!a_buffer.write_array(a_h.bins_sum_w())) return false; //fArray TArrayF
return true;
}
@@ -9,6 +9,7 @@
#include "idir"
#include "branch_element"
#include "branch_object"
namespace tools {
namespace wroot {
@@ -58,7 +59,7 @@ public: //iobject
if(!m_branches.stream(a_buffer)) return false;
{ObjArray<base_leaf> m_leaves;
{obj_array<base_leaf> m_leaves;
tools_vforcit(branch*,m_branches,itb) {
const std::vector<base_leaf*>& leaves = (*itb)->leaves();
tools_vforcit(base_leaf*,leaves,itl) {
@@ -82,7 +83,7 @@ public: //itree
virtual idir& dir() {return m_dir;}
virtual const idir& dir() const {return m_dir;}
public:
tree(idir& a_dir,const std::string& a_name,const std::string& a_title)
tree(idir& a_dir,const std::string& a_name,const std::string& a_title,bool a_managed = true)
:m_dir(a_dir)
,m_out(a_dir.file().out())
,m_name(a_name)
@@ -94,7 +95,7 @@ public:
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
a_dir.append_object(this); //a_dir takes ownership of tree.
if(a_managed) a_dir.append_object(this); //a_dir takes ownership of tree.
}
virtual ~tree(){
#ifdef TOOLS_MEM
@@ -109,6 +110,7 @@ protected:
{}
tree& operator=(const tree&){return *this;}
public:
std::ostream& out() const {return m_out;}
const std::vector<branch*>& branches() const {return m_branches;}
//uint64 tot_bytes() const {return m_tot_bytes;}
//uint64 zip_bytes() const {return m_zip_bytes;}
@@ -118,19 +120,81 @@ public:
const ifile& _file = m_dir.file();
branch* br = new branch(m_out,_file.byte_swap(),_file.compression(),
m_dir.seek_directory(),a_name,m_name,_file.verbose());
if(!br) return 0;
m_branches.push_back(br);
return br;
}
////////////////////////////////////////////////
/// ref : //////////////////////////////////////
////////////////////////////////////////////////
template <class TYPE>
leaf_ref<TYPE>* create_leaf_ref(const std::string& a_name,const TYPE& a_ref){
branch* br = create_branch(a_name);
if(!br) return 0;
return br->create_leaf_ref<TYPE>(a_name,a_ref);
}
leaf_string_ref* create_leaf_string_ref(const std::string& a_name,const std::string& a_ref){
branch* br = create_branch(a_name);
if(!br) return 0;
return br->create_leaf_string_ref(a_name,a_ref);
}
template <class T>
leaf_element* create_std_vector_leaf_ref(const std::string& a_name,const std::vector<T>& a_ref){
const ifile& _file = m_dir.file();
std_vector_be_ref<T>* br = new std_vector_be_ref<T>(m_out,_file.byte_swap(),_file.compression(),
m_dir.seek_directory(),a_name,m_name,a_ref,_file.verbose());
leaf_element* le = br->create_leaf_element(a_name);
m_branches.push_back(br);
return le;
}
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
template <class T>
std_vector_be_ref<T>* create_std_vector_be_ref(const std::string& a_name,const std::vector<T>& a_ref){
const ifile& _file = m_dir.file();
std_vector_be_ref<T>* br = new std_vector_be_ref<T>(m_out,_file.byte_swap(),_file.compression(),
m_dir.seek_directory(),a_name,m_name,a_ref,_file.verbose());
m_branches.push_back(br);
return br;
}
template <class T>
std_vector_be<T>* create_std_vector_be(const std::string& a_name,std::vector<T>& a_vec){
std_vector_be<T>* create_std_vector_be(const std::string& a_name,const std::vector<T>& a_def = std::vector<T>()){
const ifile& _file = m_dir.file();
std_vector_be<T>* br = new std_vector_be<T>(m_out,_file.byte_swap(),_file.compression(),
m_dir.seek_directory(),a_name,m_name,a_vec,_file.verbose());
m_dir.seek_directory(),a_name,m_name,a_def,_file.verbose());
m_branches.push_back(br);
return br;
}
template <class T>
std_vector_be_pointer<T>* create_std_vector_be_pointer(const std::string& a_name,std::vector<T>* a_pointer){
const ifile& _file = m_dir.file();
std_vector_be_pointer<T>* br = new std_vector_be_pointer<T>(m_out,_file.byte_swap(),_file.compression(),
m_dir.seek_directory(),a_name,m_name,a_pointer,_file.verbose());
m_branches.push_back(br);
return br;
}
template <class TYPE>
leaf<TYPE>* create_leaf(const std::string& a_name){
branch* br = create_branch(a_name);
if(!br) return 0;
return br->create_leaf<TYPE>(a_name);
}
leaf_object* create_leaf(const std::string& a_name,const iobject& a_obj){
const ifile& _file = m_dir.file();
branch_object* br = new branch_object(m_out,_file.byte_swap(),_file.compression(),
m_dir.seek_directory(),a_name,m_name,_file.verbose());
m_branches.push_back(br);
return br->create_leaf(a_name,a_obj);
}
bool fill(uint32& a_nbytes) {
// Fill all branches of a Tree :
// This function loops on all the branches of this tree.
@@ -157,6 +221,16 @@ public:
return true;
}
void reset() {
// Reset buffers and entries count in all branches/leaves
m_entries = 0;
m_tot_bytes = 0;
m_zip_bytes = 0;
//fSavedBytes = 0;
//fTotalBuffers = 0;
//fChainOffset = 0;
{tools_vforcit(branch*,m_branches,it) (*it)->reset();}
}
protected:
idir& m_dir;
std::ostream& m_out;
@@ -164,7 +238,7 @@ protected:
std::string m_name;
std::string m_title;
ObjArray<branch> m_branches;
obj_array<branch> m_branches;
uint64 m_entries; // Number of entries
uint64 m_tot_bytes; // Total number of bytes in branches before compression
uint64 m_zip_bytes; // Total number of bytes in branches after compression