g4tools  5.4.0
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tools::waxml::ntuple Class Reference

Classes

class  column
 
class  iobj
 
class  leaf
 
class  std_vector_column
 
class  sub_ntuple
 

Public Member Functions

 ntuple (std::ostream &a_writer, unsigned int a_spaces=0)
 
 ntuple (std::ostream &a_writer, std::ostream &a_out, const ntuple_booking &a_bkg, unsigned int a_spaces=0)
 
virtual ~ntuple ()
 
const std::vector< iobj * > & columns () const
 
template<class T >
column< T > * create_column (const std::string &a_name, const T &a_def=T())
 
template<class T >
std_vector_column< T > * create_column (const std::string &a_name, std::vector< T > &a_user_vec)
 
template<class T >
column< T > * find_column (const std::string &a_name)
 
sub_ntuplecreate_sub_ntuple (const std::string &a_name)
 
void write_header (const std::string &a_path, const std::string &a_name, const std::string &a_title)
 
bool add_row ()
 
void write_trailer ()
 
std::string booking (bool a_xml_esc) const
 

Static Public Member Functions

static leafis_std_vector_column (iobj &a_obj)
 

Protected Member Functions

 ntuple (const ntuple &a_from)
 
ntupleoperator= (const ntuple &a_from)
 

Static Protected Member Functions

static const std::string & s_aida_type (int)
 
static const std::string & s_aida_type (float)
 
static const std::string & s_aida_type (double)
 
static const std::string & s_aida_type (const std::string &)
 
static const std::string & s_aida_type_ituple ()
 
static void get_booking (const std::vector< iobj * > &a_cols, bool a_xml_esc, std::string &a_string)
 

Protected Attributes

std::ostream & m_writer
 
std::string m_spaces
 
std::vector< iobj * > m_cols
 

Detailed Description

Definition at line 28 of file ntuple.

Constructor & Destructor Documentation

◆ ntuple() [1/3]

tools::waxml::ntuple::ntuple ( std::ostream &  a_writer,
unsigned int  a_spaces = 0 
)
inline

Definition at line 268 of file ntuple.

269  :m_writer(a_writer){
270  for(unsigned int i=0;i<a_spaces;i++) m_spaces += " ";
271  }

◆ ntuple() [2/3]

tools::waxml::ntuple::ntuple ( std::ostream &  a_writer,
std::ostream &  a_out,
const ntuple_booking a_bkg,
unsigned int  a_spaces = 0 
)
inline

Definition at line 272 of file ntuple.

276  :m_writer(a_writer){
277  for(unsigned int i=0;i<a_spaces;i++) m_spaces += " ";
278 
279  const std::vector<column_booking>& cols = a_bkg.columns();
280  tools_vforcit(column_booking,cols,it){
281 
282  if((*it).cls_id()==_cid(int(0))) {
283  create_column<int>((*it).name());
284  } else if((*it).cls_id()==_cid(float(0))) {
285  create_column<float>((*it).name());
286  } else if((*it).cls_id()==_cid(double(0))) {
287  create_column<double>((*it).name());
288  } else if((*it).cls_id()==_cid(std::string())) {
289  create_column<std::string>((*it).name());
290 
291  } else if((*it).cls_id()==_cid_std_vector<int>()) {
292  std::vector<int>* vec = (std::vector<int>*)(*it).user_obj();
293  if(vec) {
294  create_column<int>((*it).name(),*vec);
295  } else {
296  a_out << "tools::waxml::ntuple :"
297  << " for std::vector column " << sout((*it).name())
298  << ", the user vector pointer is null."
299  << std::endl;
300  safe_clear<iobj>(m_cols);
301  return;
302  }
303  } else if((*it).cls_id()==_cid_std_vector<float>()) {
304  std::vector<float>* vec = (std::vector<float>*)(*it).user_obj();
305  if(vec) {
306  create_column<float>((*it).name(),*vec);
307  } else {
308  a_out << "tools::waxml::ntuple :"
309  << " for std::vector column " << sout((*it).name())
310  << ", the user vector pointer is null."
311  << std::endl;
312  safe_clear<iobj>(m_cols);
313  return;
314  }
315  } else if((*it).cls_id()==_cid_std_vector<double>()) {
316  std::vector<double>* vec = (std::vector<double>*)(*it).user_obj();
317  if(vec) {
318  create_column<double>((*it).name(),*vec);
319  } else {
320  a_out << "tools::waxml::ntuple :"
321  << " for std::vector column " << sout((*it).name())
322  << ", the user vector pointer is null."
323  << std::endl;
324  safe_clear<iobj>(m_cols);
325  return;
326  }
327 
328  } else {
329  a_out << "tools::waxml::ntuple :"
330  << " for column " << sout((*it).name())
331  << ", type with cid " << (*it).cls_id() << " not yet handled."
332  << std::endl;
333  //throw
334  safe_clear<iobj>(m_cols);
335  return;
336  }
337  }
338  }

◆ ~ntuple()

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

Definition at line 339 of file ntuple.

339  {
340  safe_clear<iobj>(m_cols);
341  }

◆ ntuple() [3/3]

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

Definition at line 343 of file ntuple.

344  :m_writer(a_from.m_writer)
345  ,m_spaces(a_from.m_spaces)
346  {}

Member Function Documentation

◆ add_row()

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

Definition at line 432 of file ntuple.

432  {
433  if(m_cols.empty()) return false;
434  m_writer << m_spaces << " <row>" << std::endl;
435  tools_vforcit(iobj*,m_cols,it) {
436  if(leaf* vlf = is_std_vector_column(*(*it))) {
437  std::string _sv;
438  vlf->s_value(_sv);
439  m_writer << _sv;
440  } else if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
441  m_writer << m_spaces << " <entryITuple>" << std::endl;
442  m_writer << sub->value();
443  m_writer << m_spaces << " </entryITuple>" << std::endl;
444  sub->reset();
445  } else if(leaf* lf = id_cast<iobj,leaf>(*(*it))){
446  std::string _sv;
447  lf->s_value(_sv);
448  m_writer << m_spaces << " <entry"
449  << " value=" << sout(_sv)
450  << "/>" << std::endl;
451  }
452  }
453  m_writer << m_spaces << " </row>" << std::endl;
454  return true;
455  }

◆ booking()

std::string tools::waxml::ntuple::booking ( bool  a_xml_esc) const
inline

Definition at line 462 of file ntuple.

462  {
463  std::string s;
464  get_booking(m_cols,a_xml_esc,s);
465  return s;
466  }

◆ columns()

const std::vector<iobj*>& tools::waxml::ntuple::columns ( ) const
inline

Definition at line 352 of file ntuple.

352 {return m_cols;}

◆ create_column() [1/2]

template<class T >
column<T>* tools::waxml::ntuple::create_column ( const std::string &  a_name,
const T &  a_def = T() 
)
inline

Definition at line 355 of file ntuple.

355  {
356  if(find_named<iobj>(m_cols,a_name)) return 0;
357  column<T>* col = new column<T>(a_name,a_def);
358  if(!col) return 0;
359  m_cols.push_back(col);
360  return col;
361  }

◆ create_column() [2/2]

template<class T >
std_vector_column<T>* tools::waxml::ntuple::create_column ( const std::string &  a_name,
std::vector< T > &  a_user_vec 
)
inline

Definition at line 364 of file ntuple.

364  {
365  if(find_named<iobj>(m_cols,a_name)) return 0;
366  std::string spaces;
367  for(unsigned int i=0;i<8;i++) spaces += " ";
368  std_vector_column<T>* col = new std_vector_column<T>(a_name,a_user_vec,m_spaces+spaces);
369  if(!col) return 0;
370  m_cols.push_back(col);
371  return col;
372  }

◆ create_sub_ntuple()

sub_ntuple* tools::waxml::ntuple::create_sub_ntuple ( const std::string &  a_name)
inline

Definition at line 381 of file ntuple.

381  {
382  if(find_named<iobj>(m_cols,a_name)) return 0;
383  std::string spaces;
384  for(unsigned int i=0;i<10;i++) spaces += " ";
385  sub_ntuple* col = new sub_ntuple(a_name,m_spaces+spaces);
386  if(!col) return 0;
387  m_cols.push_back(col);
388  return col;
389  }

◆ find_column()

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

Definition at line 375 of file ntuple.

375  {
376  iobj* col = find_named<iobj>(m_cols,a_name);
377  if(!col) return 0;
378  return id_cast<iobj, column<T> >(*col);
379  }

◆ get_booking()

static void tools::waxml::ntuple::get_booking ( const std::vector< iobj * > &  a_cols,
bool  a_xml_esc,
std::string &  a_string 
)
inlinestaticprotected

Definition at line 469 of file ntuple.

470  {
471  a_string += "{"; //we need the + because of the tuple in tuple.
472 
473  tools_vforcit(iobj*,a_cols,it) {
474  if(it!=a_cols.begin()) a_string += ",";
475 
476  std::string sname = (*it)->name();
477  if(a_xml_esc) sname = to_xml(sname);
478 
479  if(leaf* vlf = is_std_vector_column(*(*it))) {
480  a_string += "ITuple " + (*it)->name() + " = {" + vlf->aida_type() + " " + sname + "}";
481 
482  } else if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
483  a_string += (*it)->aida_type() + " " + sname + " = ";
484 
485  get_booking(sub->columns(),a_xml_esc,a_string);
486  } else if(leaf* lf = id_cast<iobj,leaf>(*(*it))){
487  a_string += (*it)->aida_type() + " " + sname + " = " + lf->s_def();
488  }
489  }
490  a_string += "}";
491  }

◆ is_std_vector_column()

static leaf* tools::waxml::ntuple::is_std_vector_column ( iobj a_obj)
inlinestatic

Definition at line 260 of file ntuple.

260  {
261  //200+20+id(basic type) ?
262  int _id = (int)a_obj.id_cls()-220;
263  if((_id<=0)||(_id>=20)) return 0;
264  return id_cast<iobj,leaf>(a_obj);
265  }

◆ operator=()

ntuple& tools::waxml::ntuple::operator= ( const ntuple a_from)
inlineprotected

Definition at line 347 of file ntuple.

347  {
348  m_spaces = a_from.m_spaces;
349  return *this;
350  }

◆ s_aida_type() [1/4]

static const std::string& tools::waxml::ntuple::s_aida_type ( const std::string &  )
inlinestaticprotected

Definition at line 73 of file ntuple.

73  {
74  static const std::string s_v("string");
75  return s_v;
76  }

◆ s_aida_type() [2/4]

static const std::string& tools::waxml::ntuple::s_aida_type ( double  )
inlinestaticprotected

Definition at line 69 of file ntuple.

69  {
70  static const std::string s_v("double");
71  return s_v;
72  }

◆ s_aida_type() [3/4]

static const std::string& tools::waxml::ntuple::s_aida_type ( float  )
inlinestaticprotected

Definition at line 65 of file ntuple.

65  {
66  static const std::string s_v("float");
67  return s_v;
68  }

◆ s_aida_type() [4/4]

static const std::string& tools::waxml::ntuple::s_aida_type ( int  )
inlinestaticprotected

Definition at line 61 of file ntuple.

61  {
62  static const std::string s_v("int");
63  return s_v;
64  }

◆ s_aida_type_ituple()

static const std::string& tools::waxml::ntuple::s_aida_type_ituple ( )
inlinestaticprotected

Definition at line 78 of file ntuple.

78  {
79  static const std::string s_v("ITuple");
80  return s_v;
81  }

◆ write_header()

void tools::waxml::ntuple::write_header ( const std::string &  a_path,
const std::string &  a_name,
const std::string &  a_title 
)
inline

Definition at line 391 of file ntuple.

391  {
392 
393  // <tuple> :
394  m_writer << m_spaces << " <tuple"
395  << " path=" << sout(to_xml(a_path))
396  << " name=" << sout(to_xml(a_name))
397  << " title=" << sout(to_xml(a_title))
398  << ">" << std::endl;
399 
400  // <columns> :
401  m_writer << m_spaces << " <columns>" << std::endl;
402 
403  tools_vforcit(iobj*,m_cols,it) {
404  if(leaf* vlf = is_std_vector_column(*(*it))) {
405  m_writer << m_spaces << " <column"
406  << " name=" << sout(to_xml((*it)->name()))
407  << " type=" << sout("ITuple")
408  << " booking=\"{" << vlf->aida_type() << " " << to_xml((*it)->name())
409  << "}\""
410  << "/>" << std::endl;
411  } else if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
412  m_writer << m_spaces << " <column"
413  << " name=" << sout(to_xml((*it)->name()))
414  << " type=" << sout("ITuple")
415  << " booking=" << sout(sub->booking(true))
416  << "/>" << std::endl;
417  } else if(/*leaf* lf =*/ id_cast<iobj,leaf>(*(*it))){
418  m_writer << m_spaces << " <column"
419  << " name=" << sout(to_xml((*it)->name()))
420  << " type=" << sout((*it)->aida_type())
421  //<< " default=" << sout(lf->s_def()) //not understood by jas3
422  << "/>" << std::endl;
423  }
424  }
425 
426  m_writer << m_spaces << " </columns>" << std::endl;
427 
428  // rows :
429  m_writer << m_spaces << " <rows>" << std::endl;
430  }

◆ write_trailer()

void tools::waxml::ntuple::write_trailer ( )
inline

Definition at line 457 of file ntuple.

457  {
458  m_writer << m_spaces << " </rows>" << std::endl;
459  m_writer << m_spaces << " </tuple>" << std::endl;
460  }

Member Data Documentation

◆ m_cols

std::vector<iobj*> tools::waxml::ntuple::m_cols
protected

Definition at line 499 of file ntuple.

◆ m_spaces

std::string tools::waxml::ntuple::m_spaces
protected

Definition at line 498 of file ntuple.

◆ m_writer

std::ostream& tools::waxml::ntuple::m_writer
protected

Definition at line 494 of file ntuple.


The documentation for this class was generated from the following file:
tools::sub
bool sub(std::vector< T > &a_vec, const std::vector< T > &a_v)
Definition: vmanip:283
tools::_cid
cid _cid(byte)
Definition: cids:14
tools::waxml::ntuple::m_spaces
std::string m_spaces
Definition: ntuple:498
tools::waxml::ntuple::get_booking
static void get_booking(const std::vector< iobj * > &a_cols, bool a_xml_esc, std::string &a_string)
Definition: ntuple:469
tools::to_xml
std::string to_xml(const std::string &a_string)
Definition: srep:68
tools::waxml::ntuple::m_writer
std::ostream & m_writer
Definition: ntuple:494
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::waxml::ntuple::m_cols
std::vector< iobj * > m_cols
Definition: ntuple:499
tools::waxml::ntuple::is_std_vector_column
static leaf * is_std_vector_column(iobj &a_obj)
Definition: ntuple:260