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

Classes

class  column
 
class  column_ref
 
class  icol
 
class  std_vector_column
 

Public Member Functions

 ntuple (std::ostream &a_writer, char a_sep=',', char a_vec_sep=';')
 
 ntuple (std::ostream &a_writer, std::ostream &a_out, const ntuple_booking &a_bkg, char a_sep=',', char a_vec_sep=';')
 
virtual ~ntuple ()
 
void write_hippo_header ()
 
bool write_commented_header (std::ostream &a_out)
 
template<class T >
column_ref< T > * create_column_ref (const std::string &a_name, const T &a_ref)
 
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, const 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)
 
bool add_row ()
 
const std::vector< icol * > & columns () const
 
void set_title (const std::string &a_value)
 
const std::string & title () const
 

Static Public Member Functions

static const std::string & s_class ()
 

Protected Member Functions

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

Protected Attributes

std::ostream & m_writer
 
char m_sep
 
char m_vec_sep
 
std::string m_title
 
std::vector< icol * > m_cols
 

Detailed Description

Definition at line 23 of file wcsv_ntuple.

Constructor & Destructor Documentation

◆ ntuple() [1/3]

tools::wcsv::ntuple::ntuple ( std::ostream &  a_writer,
char  a_sep = ',',
char  a_vec_sep = ';' 
)
inline

Definition at line 186 of file wcsv_ntuple.

187  :m_writer(a_writer)
188  ,m_sep(a_sep)
189  ,m_vec_sep(a_vec_sep)
190  {}

◆ ntuple() [2/3]

tools::wcsv::ntuple::ntuple ( std::ostream &  a_writer,
std::ostream &  a_out,
const ntuple_booking a_bkg,
char  a_sep = ',',
char  a_vec_sep = ';' 
)
inline

Definition at line 192 of file wcsv_ntuple.

196  :m_writer(a_writer)
197  ,m_sep(a_sep)
198  ,m_vec_sep(a_vec_sep)
199  ,m_title(a_bkg.title())
200  {
201  const std::vector<column_booking>& cols = a_bkg.columns();
202  std::vector<column_booking>::const_iterator it;
203  for(it=cols.begin();it!=cols.end();++it){
204 
205 #define TOOLS_WCSV_NTUPLE_CREATE_COL(a__type) \
206  if((*it).cls_id()==_cid(a__type())) {\
207  a__type* user = (a__type*)(*it).user_obj();\
208  if(user) {\
209  if(!create_column_ref<a__type>((*it).name(),*user)) {\
210  a_out << "tools::wcsv_ntuple::wcsv_ntuple : create_column_ref(" << (*it).name() << ") failed." << std::endl;\
211  safe_clear<icol>(m_cols);\
212  return;\
213  }\
214  } else {\
215  if(!create_column<a__type>((*it).name())) {\
216  a_out << "tools::wcsv_ntuple::wcsv_ntuple : create_column(" << (*it).name() << ") failed." << std::endl;\
217  safe_clear<icol>(m_cols);\
218  return;\
219  }\
220  }\
221  }
222 
223 #define TOOLS_WCSV_NTUPLE_CREATE_VEC_COL(a__type) \
224  if((*it).cls_id()==_cid_std_vector<a__type>()) {\
225  std::vector<a__type>* vec = (std::vector<a__type>*)(*it).user_obj();\
226  if(vec) {\
227  if(!create_column<a__type>((*it).name(),*vec)) {\
228  a_out << "tools::wcsv_ntuple::wcsv_ntuple : create_column(" << (*it).name() << ") failed." << std::endl;\
229  safe_clear<icol>(m_cols);\
230  return;\
231  }\
232  } else {\
233  a_out << "tools::wcsv_ntuple :"\
234  << " for std::vector column " << sout((*it).name())\
235  << ", the user vector pointer is null."\
236  << std::endl;\
237  safe_clear<icol>(m_cols);\
238  return;\
239  }\
240  }
241 
243  else TOOLS_WCSV_NTUPLE_CREATE_COL(short)
246 
247  else TOOLS_WCSV_NTUPLE_CREATE_COL(float)
248  else TOOLS_WCSV_NTUPLE_CREATE_COL(double)
249 
254 
256  else TOOLS_WCSV_NTUPLE_CREATE_COL(std::string)
257 
262 
265 
270 
271  else TOOLS_WCSV_NTUPLE_CREATE_VEC_COL(std::string)
273 
274 #undef TOOLS_WCSV_NTUPLE_CREATE_VEC_COL
275 #undef TOOLS_WCSV_NTUPLE_CREATE_COL
276 
277  else {
278  a_out << "tools::wcsv::ntuple :"
279  << " for column " << sout((*it).name())
280  << ", type with cid " << (*it).cls_id() << " not yet handled."
281  << std::endl;
282  //throw
283  safe_clear<icol>(m_cols);
284  return;
285  }
286  }
287  }

◆ ~ntuple()

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

Definition at line 289 of file wcsv_ntuple.

289  {
290  safe_clear<icol>(m_cols);
291  }

◆ ntuple() [3/3]

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

Definition at line 293 of file wcsv_ntuple.

294  :m_writer(a_from.m_writer)
295  ,m_sep(a_from.m_sep)
296  ,m_vec_sep(a_from.m_vec_sep)
297  ,m_title(a_from.m_title)
298  {}

Member Function Documentation

◆ add_row()

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

Definition at line 379 of file wcsv_ntuple.

379  {
380  if(m_cols.empty()) return false;
381  std::vector<icol*>::iterator it;
382  it=m_cols.begin();
383  (*it)->add();
384  it++;
385  for(;it!=m_cols.end();++it) {
386  m_writer << m_sep;
387  (*it)->add();
388  }
389  m_writer << std::endl;
390  return true;
391  }

◆ columns()

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

Definition at line 393 of file wcsv_ntuple.

393 {return m_cols;}

◆ create_column() [1/2]

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

Definition at line 356 of file wcsv_ntuple.

356  {
357  //NOTE : to optimize, we do not handle a default std::vector value logic.
358  if(find_named<icol>(m_cols,a_name)) return 0;
359  std_vector_column<T>* col = new std_vector_column<T>(m_writer,a_name,a_ref,m_vec_sep);
360  if(!col) return 0;
361  m_cols.push_back(col);
362  return col;
363  }

◆ create_column() [2/2]

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

Definition at line 347 of file wcsv_ntuple.

347  {
348  if(find_named<icol>(m_cols,a_name)) return 0;
349  column<T>* col = new column<T>(m_writer,a_name,a_def);
350  if(!col) return 0;
351  m_cols.push_back(col);
352  return col;
353  }

◆ create_column_ref()

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

Definition at line 338 of file wcsv_ntuple.

338  {
339  if(find_named<icol>(m_cols,a_name)) return 0;
340  column_ref<T>* col = new column_ref<T>(m_writer,a_name,a_ref);
341  if(!col) return 0;
342  m_cols.push_back(col);
343  return col;
344  }

◆ find_column()

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

Definition at line 373 of file wcsv_ntuple.

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

◆ find_column_ref()

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

Definition at line 366 of file wcsv_ntuple.

366  {
367  icol* col = find_named<icol>(m_cols,a_name);
368  if(!col) return 0;
369  return id_cast<icol, column_ref<T> >(*col);
370  }

◆ operator=()

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

Definition at line 299 of file wcsv_ntuple.

299  {
300  m_sep = a_from.m_sep;
301  m_vec_sep = a_from.m_vec_sep;
302  m_title = a_from.m_title;
303  return *this;
304  }

◆ s_class()

static const std::string& tools::wcsv::ntuple::s_class ( )
inlinestatic

Definition at line 25 of file wcsv_ntuple.

25  {
26  static const std::string s_v("tools::wcsv::ntuple");
27  return s_v;
28  }

◆ set_title()

void tools::wcsv::ntuple::set_title ( const std::string &  a_value)
inline

Definition at line 395 of file wcsv_ntuple.

395 {m_title = a_value;}

◆ title()

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

Definition at line 396 of file wcsv_ntuple.

396 {return m_title;}

◆ write_commented_header()

bool tools::wcsv::ntuple::write_commented_header ( std::ostream &  a_out)
inline

Definition at line 316 of file wcsv_ntuple.

316  {
317  // commented header similar to the histo case.
318  m_writer << "#class " << s_class() << std::endl;
319  m_writer << "#title " << m_title << std::endl;
320  m_writer << "#separator " << (unsigned int)m_sep << std::endl;
321  m_writer << "#vector_separator " << (unsigned int)m_vec_sep << std::endl;
322  bool status = true;
323  {for(unsigned int count=0;count<m_cols.size();count++) {
324  icol* _col = m_cols[count];
325  std::string sid;
326  if(!cid2s(_col->id_cls(),sid)) {
327  a_out << "tools::wcsv::ntuple::write_commented_header :"
328  << " unknown column type id " << _col->id_cls() << std::endl;
329  status = false; //but we continue.
330  } else {
331  m_writer << "#column " << sid << " " << _col->name() << std::endl;
332  }
333  }}
334  return status;
335  }

◆ write_hippo_header()

void tools::wcsv::ntuple::write_hippo_header ( )
inline

Definition at line 306 of file wcsv_ntuple.

306  {
307  m_writer << m_title << std::endl;
308  std::vector<icol*>::const_iterator it;
309  for(it=m_cols.begin();it!=m_cols.end();++it){
310  if(it!=m_cols.begin()) m_writer << '\t';
311  m_writer << (*it)->name();
312  }
313  m_writer << std::endl;
314  }

Member Data Documentation

◆ m_cols

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

Definition at line 402 of file wcsv_ntuple.

◆ m_sep

char tools::wcsv::ntuple::m_sep
protected

Definition at line 399 of file wcsv_ntuple.

◆ m_title

std::string tools::wcsv::ntuple::m_title
protected

Definition at line 401 of file wcsv_ntuple.

◆ m_vec_sep

char tools::wcsv::ntuple::m_vec_sep
protected

Definition at line 400 of file wcsv_ntuple.

◆ m_writer

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

Definition at line 398 of file wcsv_ntuple.


The documentation for this class was generated from the following file:
tools::wcsv::ntuple::m_cols
std::vector< icol * > m_cols
Definition: wcsv_ntuple:402
tools::uint64
unsigned long long uint64
Definition: typedefs:72
tools::int64
long long int64
Definition: typedefs:67
TOOLS_WCSV_NTUPLE_CREATE_COL
#define TOOLS_WCSV_NTUPLE_CREATE_COL(a__type)
TOOLS_WCSV_NTUPLE_CREATE_VEC_COL
#define TOOLS_WCSV_NTUPLE_CREATE_VEC_COL(a__type)
tools::wcsv::ntuple::m_writer
std::ostream & m_writer
Definition: wcsv_ntuple:398
tools::cid2s
bool cid2s(cid a_id, std::string &a_s)
Definition: cids:66
tools::wcsv::ntuple::m_title
std::string m_title
Definition: wcsv_ntuple:401
tools::uchar
unsigned char uchar
Definition: typedefs:99
tools::wcsv::ntuple::m_vec_sep
char m_vec_sep
Definition: wcsv_ntuple:400
tools::wcsv::ntuple::s_class
static const std::string & s_class()
Definition: wcsv_ntuple:25
tools::wcsv::ntuple::m_sep
char m_sep
Definition: wcsv_ntuple:399
tools::ushort
unsigned short ushort
Definition: typedefs:101
tools::uint32
unsigned int uint32
Definition: typedefs:71