g4tools  5.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::hdf5::ntuple Class Reference
Inheritance diagram for tools::hdf5::ntuple:
Inheritance graph
[legend]
Collaboration diagram for tools::hdf5::ntuple:
Collaboration graph
[legend]

Classes

class  column
 
class  column_ref
 
class  column_string
 
class  column_string_ref
 
class  icol
 
class  std_vector_column
 
class  std_vector_column_ref
 

Public Member Functions

 ntuple (std::ostream &a_out, hid_t a_group, const std::string &a_name, unsigned int a_compress, size_t)
 
 ntuple (std::ostream &a_out, hid_t a_group, const std::string &a_name)
 
 ntuple (std::ostream &a_out, hid_t a_group, const std::string &a_name, const tools::ntuple_binding &a_bd)
 
 ntuple (std::ostream &a_out, hid_t a_group, const tools::ntuple_booking &a_bkg, unsigned int a_compress, size_t a_basket_size)
 
virtual ~ntuple ()
 
bool initialize (std::ostream &a_out, const tools::ntuple_binding &a_bd=tools::ntuple_binding())
 
const std::string & title () const
 
const std::vector< icol * > & columns () const
 
std::vector< icol * > & columns ()
 
template<class T >
column_ref< T > * create_column_ref (const std::string &a_name, size_t a_basket_size, T &a_ref)
 
template<class T >
column< T > * create_column (const std::string &a_name, size_t a_basket_size)
 
column_stringcreate_column_string (const std::string &a_name, size_t a_basket_size)
 
template<class T >
std_vector_column_ref< T > * create_std_column_ref (const std::string &a_name, size_t a_basket_size, std::vector< T > &a_ref)
 
template<class T >
column_ref< T > * find_column_ref (const std::string &a_name)
 
template<class T >
column< T > * find_column (const std::string &a_name)
 
template<class T >
std_vector_column_ref< T > * find_std_vector_column_ref (const std::string &a_name)
 
template<class T >
std_vector_column< T > * find_std_vector_column (const std::string &a_name)
 
column_stringfind_column_string (const std::string &a_name)
 
bool add_row ()
 
bool get_row ()
 
bool set_basket_size (size_t a_size)
 
void reset ()
 
- Public Member Functions inherited from tools::hdf5::store
 store (std::ostream &a_out, hid_t a_group, const std::string &a_name, bool a_write, unsigned int a_compress)
 
virtual ~store ()
 
std::ostream & out () const
 
bool entries (tools::uint64 &a_entries) const
 
pagescreate_pages (const std::string &a_name, const std::string &a_form)
 
hid_t group () const
 
unsigned int compress_level () const
 

Protected Member Functions

 ntuple (const ntuple &a_from)
 
ntupleoperator= (const ntuple &)
 
- Protected Member Functions inherited from tools::hdf5::store
 store (const store &a_from)
 
storeoperator= (const store &)
 

Protected Attributes

std::string m_title
 
std::vector< icol * > m_cols
 
- Protected Attributes inherited from tools::hdf5::store
std::ostream & m_out
 
std::string m_name
 
bool m_write
 
unsigned int m_compress
 
hid_t m_group
 
std::vector< pages * > m_pagess
 

Detailed Description

Definition at line 28 of file ntuple.

Constructor & Destructor Documentation

◆ ntuple() [1/5]

tools::hdf5::ntuple::ntuple ( std::ostream &  a_out,
hid_t  a_group,
const std::string &  a_name,
unsigned int  a_compress,
size_t   
)
inline

Definition at line 692 of file ntuple.

694  :store(a_out,a_group,a_name,true,a_compress) //true=write
695  {}

◆ ntuple() [2/5]

tools::hdf5::ntuple::ntuple ( std::ostream &  a_out,
hid_t  a_group,
const std::string &  a_name 
)
inline

Definition at line 697 of file ntuple.

698  :store(a_out,a_group,a_name,false,0) //false=read
699  {
700  tools_vforcit(pages*,m_pagess,it){
701 
702 #define TOOLS_HDF5_NTUPLE_READ_CREATE_COL(a__type) \
703  if((*it)->form()==tools::stype(a__type())) {\
704  column<a__type>* col = new column<a__type>(*this,*(*it),false,(*it)->name(),0);\
705  if(!col) {tools::safe_clear<icol>(m_cols);return;}\
706  m_cols.push_back(col);\
707  }
708 
709 #define TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(a__vec_type,a__type) \
710  if((*it)->form()==s_vector_##a__vec_type()) {\
711  std_vector_column<a__type>* col = new std_vector_column<a__type>(*this,*(*it),false,(*it)->name(),0);\
712  if(!col) {tools::safe_clear<icol>(m_cols);return;}\
713  m_cols.push_back(col);\
714  }
715 
720 
723 
728 
729  //else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(bool) //use byte=uchar.
730 
731  else
732  if((*it)->form()==s_string()) {
733  column_string* col = new column_string(*this,*(*it),false,(*it)->name(),0);
734  if(!col) {tools::safe_clear<icol>(m_cols);return;}
735  m_cols.push_back(col);
736  }
737 
739  else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(short,short)
742 
743  else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(float,float)
744  else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(double,double)
745 
750 
751 // else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(std::string)
752 // else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(bool) //use byte=uchar.
753 
754  else {
755  m_out << "tools::hdf5::ntuple::ntuple(read) :"
756  << " for column " << tools::sout((*it)->name())
757  << ", type " << tools::sout((*it)->form()) << " not yet handled."
758  << std::endl;
759  //throw
760  tools::safe_clear<icol>(m_cols);
761  return;
762  }
763  }
764 #undef TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL
765 #undef TOOLS_HDF5_NTUPLE_READ_CREATE_COL
766  }

◆ ntuple() [3/5]

tools::hdf5::ntuple::ntuple ( std::ostream &  a_out,
hid_t  a_group,
const std::string &  a_name,
const tools::ntuple_binding a_bd 
)
inline

Definition at line 768 of file ntuple.

769  :store(a_out,a_group,a_name,false,0) //false=read
770  {
771  if(!initialize(a_out,a_bd)) {}
772  }

◆ ntuple() [4/5]

tools::hdf5::ntuple::ntuple ( std::ostream &  a_out,
hid_t  a_group,
const tools::ntuple_booking a_bkg,
unsigned int  a_compress,
size_t  a_basket_size 
)
inline

Definition at line 774 of file ntuple.

776  :store(a_out,a_group,a_bkg.name(),true,a_compress) //true=write
777  ,m_title(a_bkg.title())
778  {
779  const std::vector<tools::column_booking>& cols = a_bkg.columns();
781 
782 #define TOOLS_HDF5_NTUPLE_CREATE_COL(a__type) \
783  if((*it).cls_id()==tools::_cid(a__type())) {\
784  a__type* user = (a__type*)(*it).user_obj();\
785  if(user) {\
786  if(!create_column_ref<a__type>((*it).name(),a_basket_size,*user)) {\
787  m_out << "tools::hdf5::ntuple :"\
788  << " can't create column_ref " << tools::sout((*it).name()) << "."\
789  << std::endl;\
790  tools::safe_clear<icol>(m_cols);\
791  return;\
792  }\
793  } else {\
794  if(!create_column<a__type>((*it).name(),a_basket_size)) {\
795  m_out << "tools::hdf5::ntuple :"\
796  << " can't create column " << tools::sout((*it).name()) << "."\
797  << std::endl;\
798  tools::safe_clear<icol>(m_cols);\
799  return;\
800  }\
801  }\
802  }
803 
804 #define TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(a__type) \
805  if((*it).cls_id()==tools::_cid_std_vector<a__type>()) {\
806  std::vector<a__type>* vec = (std::vector<a__type>*)(*it).user_obj();\
807  if(!vec) {\
808  m_out << "tools::hdf5::ntuple :"\
809  << " for std::vector column " << tools::sout((*it).name())\
810  << ", the user vector pointer is null."\
811  << std::endl;\
812  tools::safe_clear<icol>(m_cols);\
813  return;\
814  }\
815  if(!create_std_column_ref<a__type>((*it).name(),a_basket_size,*vec)) {\
816  m_out << "tools::hdf5::ntuple :"\
817  << " can't create std::vector column " << tools::sout((*it).name()) << "."\
818  << std::endl;\
819  tools::safe_clear<icol>(m_cols);\
820  return;\
821  }\
822  }
823 
825  else TOOLS_HDF5_NTUPLE_CREATE_COL(short)
828 
829  else TOOLS_HDF5_NTUPLE_CREATE_COL(float)
830  else TOOLS_HDF5_NTUPLE_CREATE_COL(double)
831 
836 
837  //else TOOLS_HDF5_NTUPLE_CREATE_COL(bool) //use byte=uchar.
838 
839  else if((*it).cls_id()==tools::_cid(std::string())) {
840  if(!create_column_string((*it).name(),a_basket_size)) {
841  m_out << "tools::hdf5::ntuple :"
842  << " can't create string column " << tools::sout((*it).name()) << "."
843  << std::endl;
844  tools::safe_clear<icol>(m_cols);
845  return;
846  }
847 
852 
855 
860 
861 // else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(std::string)
862 // else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(bool) //use byte=uchar.
863 
864  else {
865  m_out << "tools::hdf5::ntuple :"
866  << " for column " << tools::sout((*it).name())
867  << ", type with cid " << (*it).cls_id() << " not yet handled."
868  << std::endl;
869  tools::safe_clear<icol>(m_cols);
870  return;
871  }
872  }
873 #undef TOOLS_HDF5_NTUPLE_CREATE_COL
874 #undef TOOLS_HDF5_NTUPLE_CREATE_VEC_COL
875 
876  }

◆ ~ntuple()

virtual tools::hdf5::ntuple::~ntuple ( )
inlinevirtual

Definition at line 878 of file ntuple.

878  {
879  tools::safe_clear<icol>(m_cols);
880  }

◆ ntuple() [5/5]

tools::hdf5::ntuple::ntuple ( const ntuple a_from)
inlineprotected

Definition at line 882 of file ntuple.

882 :store(a_from),m_title(a_from.m_title){}

Member Function Documentation

◆ add_row()

bool tools::hdf5::ntuple::add_row ( )
inline

Definition at line 1060 of file ntuple.

1060  { //write.
1061  if(m_cols.empty()) return false;
1062  bool status = true;
1063  tools_vforit(icol*,m_cols,it) {if(!(*it)->add()) status = false;}
1064  //tools::uint32 n;
1065  //bool status = store::fill(n);
1066  //tools_vforit(icol*,m_cols,it) (*it)->set_def();
1067  return status;
1068  }

◆ columns() [1/2]

std::vector<icol*>& tools::hdf5::ntuple::columns ( )
inline

Definition at line 982 of file ntuple.

982 {return m_cols;}

◆ columns() [2/2]

const std::vector<icol*>& tools::hdf5::ntuple::columns ( ) const
inline

Definition at line 981 of file ntuple.

981 {return m_cols;}

◆ create_column()

template<class T >
column<T>* tools::hdf5::ntuple::create_column ( const std::string &  a_name,
size_t  a_basket_size 
)
inline

Definition at line 996 of file ntuple.

996  {
997  if(tools::find_named<icol>(m_cols,a_name)) return 0;
998  pages* _pages = create_pages(a_name,tools::stype(T()));
999  if(!_pages) return 0;
1000  column<T>* col = new column<T>(*this,*_pages,true,a_name,a_basket_size);
1001  if(!col) return 0;
1002  m_cols.push_back(col);
1003  return col;
1004  }

◆ create_column_ref()

template<class T >
column_ref<T>* tools::hdf5::ntuple::create_column_ref ( const std::string &  a_name,
size_t  a_basket_size,
T &  a_ref 
)
inline

Definition at line 985 of file ntuple.

985  {
986  if(tools::find_named<icol>(m_cols,a_name)) return 0;
987  pages* _pages = create_pages(a_name,tools::stype(T()));
988  if(!_pages) return 0;
989  column_ref<T>* col = new column_ref<T>(*this,*_pages,true,a_name,a_basket_size,a_ref);
990  if(!col) return 0;
991  m_cols.push_back(col);
992  return col;
993  }

◆ create_column_string()

column_string* tools::hdf5::ntuple::create_column_string ( const std::string &  a_name,
size_t  a_basket_size 
)
inline

Definition at line 1006 of file ntuple.

1006  {
1007  if(tools::find_named<icol>(m_cols,a_name)) return 0;
1008  pages* _pages = create_pages(a_name,s_string());
1009  if(!_pages) return 0;
1010  column_string* col = new column_string(*this,*_pages,true,a_name,a_basket_size);
1011  if(!col) return 0;
1012  m_cols.push_back(col);
1013  return col;
1014  }

◆ create_std_column_ref()

template<class T >
std_vector_column_ref<T>* tools::hdf5::ntuple::create_std_column_ref ( const std::string &  a_name,
size_t  a_basket_size,
std::vector< T > &  a_ref 
)
inline

Definition at line 1017 of file ntuple.

1017  {
1018  //NOTE : to optimize, we do not handle a default std::vector value logic.
1019  if(tools::find_named<icol>(m_cols,a_name)) return 0;
1020  pages* _pages = create_pages(a_name,"vector<"+tools::stype(T())+">");
1021  if(!_pages) return 0;
1022  std_vector_column_ref<T>* col = new std_vector_column_ref<T>(*this,*_pages,true,a_name,a_basket_size,a_ref);
1023  if(!col) return 0;
1024  m_cols.push_back(col);
1025  return col;
1026  }

◆ find_column()

template<class T >
column<T>* tools::hdf5::ntuple::find_column ( const std::string &  a_name)
inline

Definition at line 1035 of file ntuple.

1035  {
1036  icol* col = tools::find_named<icol>(m_cols,a_name);
1037  if(!col) return 0;
1038  return tools::id_cast<icol, column<T> >(*col);
1039  }

◆ find_column_ref()

template<class T >
column_ref<T>* tools::hdf5::ntuple::find_column_ref ( const std::string &  a_name)
inline

Definition at line 1029 of file ntuple.

1029  {
1030  icol* col = tools::find_named<icol>(m_cols,a_name);
1031  if(!col) return 0;
1032  return tools::id_cast<icol, column_ref<T> >(*col);
1033  }

◆ find_column_string()

column_string* tools::hdf5::ntuple::find_column_string ( const std::string &  a_name)
inline

Definition at line 1054 of file ntuple.

1054  {
1055  icol* col = tools::find_named<icol>(m_cols,a_name);
1056  if(!col) return 0;
1057  return tools::id_cast<icol, column_string >(*col);
1058  }

◆ find_std_vector_column()

template<class T >
std_vector_column<T>* tools::hdf5::ntuple::find_std_vector_column ( const std::string &  a_name)
inline

Definition at line 1048 of file ntuple.

1048  {
1049  icol* col = tools::find_named<icol>(m_cols,a_name);
1050  if(!col) return 0;
1051  return tools::id_cast<icol, std_vector_column<T> >(*col);
1052  }

◆ find_std_vector_column_ref()

template<class T >
std_vector_column_ref<T>* tools::hdf5::ntuple::find_std_vector_column_ref ( const std::string &  a_name)
inline

Definition at line 1042 of file ntuple.

1042  {
1043  icol* col = tools::find_named<icol>(m_cols,a_name);
1044  if(!col) return 0;
1045  return tools::id_cast<icol, std_vector_column_ref<T> >(*col);
1046  }

◆ get_row()

bool tools::hdf5::ntuple::get_row ( )
inline

Definition at line 1070 of file ntuple.

1070  { //read.
1071  bool status = true;
1072  tools_vforcit(icol*,m_cols,it) {
1073  if(!(*it)->fetch_entry()) status = false;
1074  }
1075  return status;
1076  }

◆ initialize()

bool tools::hdf5::ntuple::initialize ( std::ostream &  a_out,
const tools::ntuple_binding a_bd = tools::ntuple_binding() 
)
inline

Definition at line 885 of file ntuple.

885  {
886  tools::safe_clear<icol>(m_cols);
887  {tools_vforcit(pages*,m_pagess,it) (*it)->reset_pos();}
888 
889  tools_vforcit(pages*,m_pagess,it) {
890 
891 #define TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(a__type) \
892  if((*it)->form()==tools::stype(a__type())) {\
893  a__type* user_var = a_bd.find_variable<a__type>((*it)->name());\
894  if(user_var) {\
895  column_ref<a__type>* col = new column_ref<a__type>(*this,*(*it),false,(*it)->name(),0,*user_var);\
896  if(!col) {tools::safe_clear<icol>(m_cols);return false;}\
897  m_cols.push_back(col);\
898  } else {\
899  column<a__type>* col = new column<a__type>(*this,*(*it),false,(*it)->name(),0);\
900  if(!col) {tools::safe_clear<icol>(m_cols);return false;}\
901  m_cols.push_back(col);\
902  }\
903  }
904 
905 #define TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(a__vec_type,a__type) \
906  if((*it)->form()==s_vector_##a__vec_type()) {\
907  std::vector<a__type>* user_var = a_bd.find_variable< std::vector<a__type> >((*it)->name());\
908  if(user_var) {\
909  std_vector_column_ref<a__type>* col = \
910  new std_vector_column_ref<a__type>(*this,*(*it),false,(*it)->name(),0,*user_var);\
911  if(!col) {tools::safe_clear<icol>(m_cols);return false;}\
912  m_cols.push_back(col);\
913  } else {\
914  std_vector_column<a__type>* col = new std_vector_column<a__type>(*this,*(*it),false,(*it)->name(),0);\
915  if(!col) {tools::safe_clear<icol>(m_cols);return false;}\
916  m_cols.push_back(col);\
917  }\
918  }
919 
924 
927 
932 
933  //else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(bool) //use byte=uchar.
934 
935  else
936  if((*it)->form()==s_string()) {
937  std::string* user_var = a_bd.find_variable<std::string>((*it)->name());
938  if(user_var) {
939  column_string_ref* col = new column_string_ref(*this,*(*it),false,(*it)->name(),0,*user_var);
940  if(!col) {tools::safe_clear<icol>(m_cols);return false;}
941  m_cols.push_back(col);
942  } else {
943  column_string* col = new column_string(*this,*(*it),false,(*it)->name(),0);
944  if(!col) {tools::safe_clear<icol>(m_cols);return false;}
945  m_cols.push_back(col);
946  }
947  }
948 
953 
956 
961 
962 // else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(std::string)
963 // else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(bool) //use byte=uchar.
964 
965  else {
966  a_out << "tools::hdf5::ntuple::ntuple(read with binding) :"
967  << " for column " << tools::sout((*it)->name())
968  << ", type " << tools::sout((*it)->form()) << " not yet handled."
969  << std::endl;
970  tools::safe_clear<icol>(m_cols);
971  return false;
972  }
973  }
974 #undef TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL
975 #undef TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL
976  return true;
977  }

◆ operator=()

ntuple& tools::hdf5::ntuple::operator= ( const ntuple )
inlineprotected

Definition at line 883 of file ntuple.

883 {return *this;}

◆ reset()

void tools::hdf5::ntuple::reset ( )
inline

Definition at line 1083 of file ntuple.

1083  { //read.
1084  tools_vforit(icol*,m_cols,it) (*it)->reset();
1085  }

◆ set_basket_size()

bool tools::hdf5::ntuple::set_basket_size ( size_t  a_size)
inline

Definition at line 1078 of file ntuple.

1078  {
1079  tools_vforit(icol*,m_cols,it) {if(!(*it)->set_basket_size(a_size)) return false;}
1080  return true;
1081  }

◆ title()

const std::string& tools::hdf5::ntuple::title ( ) const
inline

Definition at line 979 of file ntuple.

979 {return m_title;}

Member Data Documentation

◆ m_cols

std::vector<icol*> tools::hdf5::ntuple::m_cols
protected

Definition at line 1089 of file ntuple.

◆ m_title

std::string tools::hdf5::ntuple::m_title
protected

Definition at line 1088 of file ntuple.


The documentation for this class was generated from the following file:
tools::uint64
unsigned long long uint64
Definition: typedefs:72
tools::byte
unsigned char byte
Definition: typedefs:96
tools::int64
long long int64
Definition: typedefs:67
TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL
#define TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(a__vec_type, a__type)
tools::_cid
cid _cid(byte)
Definition: cids:14
tools::column_booking
Definition: ntuple_booking:17
tools::hdf5::ntuple::m_title
std::string m_title
Definition: ntuple:1088
tools::hdf5::ntuple::initialize
bool initialize(std::ostream &a_out, const tools::ntuple_binding &a_bd=tools::ntuple_binding())
Definition: ntuple:885
tools::hdf5::store::m_out
std::ostream & m_out
Definition: store:195
tools::hdf5::store::m_pagess
std::vector< pages * > m_pagess
Definition: store:200
tools::uchar
unsigned char uchar
Definition: typedefs:99
tools::sout
Definition: sout:17
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
TOOLS_HDF5_NTUPLE_READ_CREATE_COL
#define TOOLS_HDF5_NTUPLE_READ_CREATE_COL(a__type)
tools::hdf5::ntuple::m_cols
std::vector< icol * > m_cols
Definition: ntuple:1089
tools::ntuple_booking::columns
const std::vector< column_booking > & columns() const
Definition: ntuple_booking:93
tools::hdf5::store::store
store(std::ostream &a_out, hid_t a_group, const std::string &a_name, bool a_write, unsigned int a_compress)
Definition: store:19
tools::ntuple_booking::title
const std::string & title() const
Definition: ntuple_booking:92
TOOLS_HDF5_NTUPLE_CREATE_VEC_COL
#define TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(a__type)
TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL
#define TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(a__vec_type, a__type)
tools::hdf5::store::create_pages
pages * create_pages(const std::string &a_name, const std::string &a_form)
Definition: store:171
TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL
#define TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(a__type)
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::stype
const std::string & stype(const mat4f &)
Definition: mat4f:73
tools::ushort
unsigned short ushort
Definition: typedefs:101
tools::ntuple_booking::name
const std::string & name() const
Definition: ntuple_booking:91
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::hdf5::ntuple::create_column_string
column_string * create_column_string(const std::string &a_name, size_t a_basket_size)
Definition: ntuple:1006
TOOLS_HDF5_NTUPLE_CREATE_COL
#define TOOLS_HDF5_NTUPLE_CREATE_COL(a__type)
tools::ntuple_binding::find_variable
T * find_variable(const std::string &a_name) const
Definition: ntuple_binding:107