All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TupleObj.cpp
Go to the documentation of this file.
1 // $Id: TupleObj.cpp,v 1.8 2007/09/28 11:47:29 marcocle Exp $
2 // ============================================================================
3 // Include files
4 // ============================================================================
5 // STD & STL
6 // ============================================================================
7 #include <cstdarg>
8 #include <algorithm>
9 #include <map>
10 // ============================================================================
11 // GaudiKernel
12 // ============================================================================
14 // ============================================================================
15 // GaudiAlg
16 // ============================================================================
17 #include "GaudiAlg/Tuples.h"
18 #include "GaudiAlg/TupleObj.h"
19 // ============================================================================
20 // Boost
21 // ============================================================================
22 #include "boost/integer_traits.hpp"
23 #include "boost/static_assert.hpp"
24 // ============================================================================
32 // ============================================================================
33 namespace Tuples
34 {
35  namespace Local
36  {
37  class Counter
38  {
39  public:
40  // constructor
41  Counter ( const std::string& msg = " Misbalance ")
42  : m_map ()
43  , m_message ( msg )
44  {}
45  // destructor
46  ~Counter() { report() ; m_map.clear() ;}
47  // make the increment
48  long increment ( const std::string& object ) { return ++m_map[object] ; }
49  // make the decrement
50  long decrement ( const std::string& object ) { return --m_map[object] ; }
51  // current count
52  long counts ( const std::string& object ) { return m_map[object] ; }
53  // make a report
54  void report() const
55  {
56  for ( Map::const_iterator entry = m_map.begin() ;
57  m_map.end() != entry ; ++entry )
58  {
59  if( 0 == entry->second ) { continue ; }
60  std::cout << "Tuples::TupleObj WARNING " << m_message
61  << "'" << entry->first << "' Counts = " << entry->second
62  << std::endl ;
63  }
64  };
65 
66  private:
67  typedef std::map<std::string,long> Map;
69  std::string m_message ;
70  };
71 
77  static Counter s_InstanceCounter ( " Create/Destroy (mis)balance " ) ;
78  }
79 }
80 // ============================================================================
81 // Standard constructor
82 // ============================================================================
84 ( const std::string& name ,
85  NTuple::Tuple* tuple ,
86  const CLID& clid ,
87  const Tuples::Type type )
88 //
89  : m_name ( name )
90  , m_tuple ( tuple )
91  , m_clid ( clid )
92  , m_type ( type )
93 // for error handling
94  , m_refCount ( 0 )
95 // columns
96  , m_bools ()
97  , m_chars ()
98  , m_uchars ()
99  , m_shorts ()
100  , m_ushorts ()
101  , m_ints ()
102  , m_uints ()
103  , m_longlongs ()
104  , m_ulonglongs()
105  , m_floats ()
106  , m_doubles ()
107  , m_addresses ()
108  , m_farrays ()
109  , m_arraysf ()
110  , m_fmatrices ()
111  , m_matricesf ()
112 //
113  , m_items ()
114 {
115  // make counts
116  Tuples::Local::s_InstanceCounter.increment ( m_name ) ;
117 }
118 // ============================================================================
119 // destructor
120 // ============================================================================
122 {
123  {// delete 'bool' columns
124  for( Bools::iterator it = m_bools.begin() ;
125  m_bools.end() != it ; ++it )
126  { if( 0 != it->second ) { delete it->second ; } }
127  m_bools.clear() ;
128  }
129  {// delete 'char' columns
130  for( Chars::iterator it = m_chars.begin() ;
131  m_chars.end() != it ; ++it )
132  { if( 0 != it->second ) { delete it->second ; } }
133  m_chars.clear() ;
134  }
135  {// delete 'unsigned char' columns
136  for( UChars::iterator it = m_uchars.begin() ;
137  m_uchars.end() != it ; ++it )
138  { if( 0 != it->second ) { delete it->second ; } }
139  m_uchars.clear() ;
140  }
141  {// delete 'short' columns
142  for( Shorts::iterator it = m_shorts.begin() ;
143  m_shorts.end() != it ; ++it )
144  { if( 0 != it->second ) { delete it->second ; } }
145  m_shorts.clear() ;
146  }
147  {// delete 'unsigned short' columns
148  for( UShorts::iterator it = m_ushorts.begin() ;
149  m_ushorts.end() != it ; ++it )
150  { if( 0 != it->second ) { delete it->second ; } }
151  m_ushorts.clear() ;
152  }
153  {// delete 'int' columns
154  for( Ints::iterator it = m_ints.begin() ;
155  m_ints.end() != it ; ++it )
156  { if( 0 != it->second ) { delete it->second ; } }
157  m_ints.clear() ;
158  }
159  {// delete 'unsigned int' columns
160  for( UInts::iterator it = m_uints.begin() ;
161  m_uints.end() != it ; ++it )
162  { if( 0 != it->second ) { delete it->second ; } }
163  m_uints.clear() ;
164  }
165  {// delete 'longlong' columns
167  m_longlongs.end() != it ; ++it )
168  { if( 0 != it->second ) { delete it->second ; } }
169  m_longlongs.clear() ;
170  }
171  {// delete 'ulonglong' columns
173  m_ulonglongs.end() != it ; ++it )
174  { if( 0 != it->second ) { delete it->second ; } }
175  m_ulonglongs.clear() ;
176  }
177  {// delete 'float' columns
178  for( Floats::iterator it = m_floats.begin() ;
179  m_floats.end() != it ; ++it )
180  { if( 0 != it->second ) { delete it->second ; } }
181  m_floats.clear() ;
182  }
183  {// delete 'double' columns
184  for( Doubles::iterator it = m_doubles.begin() ;
185  m_doubles.end() != it ; ++it )
186  { if( 0 != it->second ) { delete it->second ; } }
187  m_doubles.clear() ;
188  }
189  {// delete 'fArray' columns
190  for( FArrays::iterator it = m_farrays.begin() ;
191  m_farrays.end() != it ; ++it )
192  { if( 0 != it->second ) { delete it->second ; } }
193  m_farrays.clear() ;
194  }
195  {// delete 'fArray' columns
196  for( FArrays::iterator it = m_arraysf.begin() ;
197  m_arraysf.end() != it ; ++it )
198  { if( 0 != it->second ) { delete it->second ; } }
199  m_arraysf.clear() ;
200  }
201  { // destroy and clean all "addresses"
203  m_addresses.end() != it ; ++it )
204  { if( 0 != it->second ) { delete it->second ; } }
205  m_addresses.clear();
206  }
207  { // destroy and clean all "matrices"
209  m_fmatrices.end() != it ; ++it )
210  { if( 0 != it->second ) { delete it->second ; } }
211  m_fmatrices.clear();
212  }
213  { // destroy and clean all "matrices" (fixed)
215  m_matricesf.end() != it ; ++it )
216  { if( 0 != it->second ) { delete it->second ; } }
217  m_matricesf.clear();
218  }
219 
220  // make counts
221  Tuples::Local::s_InstanceCounter.decrement ( m_name ) ;
222 }
223 // ============================================================================
224 // release the reference to TupleObj
225 // if reference counter becomes zero,
226 // object will be automatically deleted
227 // ============================================================================
229 {
230  // decrease the reference counter
231  if( 0 < refCount() ) { --m_refCount; }
232  // check references
233  if( 0 != refCount() ) { return; }
234  // delete the object
235  delete this ;
236 }
237 // ============================================================================
238 // write a record to NTuple
239 // ============================================================================
241 {
242  if ( invalid() ) { return InvalidTuple ; }
243  return tuple()->write() ;
244 }
245 // ============================================================================
246 namespace
247 {
249  typedef std::vector<std::string> Tokens;
254  size_t tokenize( const std::string& value ,
255  Tokens& tokens ,
256  const std::string& separators = " " )
257  {
258  // reset the existing tokens
259  tokens.clear();
260  if( value .empty () ) { return tokens.size () ; }
261  std::string::const_iterator it1 = value.begin() ;
262  std::string::const_iterator it2 = value.begin() ;
263  while( value.end() != it1 && value.end() != it2 )
264  {
265  it2 = std::find_first_of( it1 ,
266  value.end () ,
267  separators.begin () ,
268  separators.end () ) ;
269  if( it2 != it1 )
270  {
271  std::string aux( value , it1 - value.begin() , it2 - it1 ) ;
272  tokens.push_back( aux ) ;
273  it1 = it2 ;
274  }
275  else { ++it1 ; }
276 
277  }
278  return tokens.size();
279  }
280 }
281 // ============================================================================
283 {
284  // check the underlying tuple
285  if ( invalid() ) { return InvalidTuple ; }
286  // decode format string into tokens
287  Tokens tokens ;
288  tokenize( format , tokens , " ,;" );
289  if ( tokens.empty() ) { return StatusCode::SUCCESS ; }
291  va_list valist ;
292  va_start( valist , format ) ;
293  // loop over all tokens
295  for( Tokens::const_iterator token = tokens.begin() ;
296  tokens.end() != token && status.isSuccess() ; ++token )
297  {
298  const double val = va_arg( valist , double );
299  status = column( *token , val );
300  if( status.isFailure() )
301  { Error ( "fill(): Can not add column '" + *token + "' " ) ; }
302  }
303  // mandatory !!!
304  va_end( valist );
305  //
306  return status ;
307 }
308 
309 // ============================================================================
310 // put IOpaqueAddress in NTuple (has sense only for Event tag collection Ntuples)
311 // ============================================================================
313 ( const std::string& name ,
314  IOpaqueAddress* address )
315 {
316  if ( invalid () ) { return InvalidTuple ; }
317  if ( !evtColType () ) { return InvalidOperation ; }
318  if ( 0 == address )
319  { return Error ( "column('" + name +
320  "') IOpaqueAddress* is NULL!" , InvalidObject ) ; }
321  Address* item = addresses( name );
322  if ( 0 == item ) { return InvalidItem ; }
323  *item = address ;
324  return StatusCode::SUCCESS ;
325 }
326 
327 // ============================================================================
328 // put IOpaqueAddress in NTuple (has sense only for Event tag collection Ntuples)
329 // ============================================================================
331 ( IOpaqueAddress* address )
332 {
333  return column ( "Address" , address ) ;
334 }
335 
336 // ============================================================================
337 StatusCode Tuples::TupleObj::column ( const std::string& name ,
338  const float value )
339 {
340  if ( invalid() ) { return InvalidTuple ; }
341  Float* item = floats ( name ) ;
342  if ( !item ) { return InvalidColumn ; }
343  *item = value ;
344  return StatusCode::SUCCESS ;
345 }
346 // ============================================================================
347 StatusCode Tuples::TupleObj::column ( const std::string& name ,
348  const double value )
349 {
350  if ( invalid() ) { return InvalidTuple ; }
351  Double * item = doubles ( name ) ;
352  if ( !item ) { return InvalidColumn ; }
353  *item = value ;
354  return StatusCode::SUCCESS ;
355 }
356 // ============================================================================
357 StatusCode Tuples::TupleObj::column ( const std::string& name ,
358  const char value )
359 {
360  if ( invalid() ) { return InvalidTuple ; }
361  Char* item = chars( name ) ;
362  if ( !item ) { return InvalidColumn ; }
363  *item = value ;
364  return StatusCode::SUCCESS ;
365 }
366 // ============================================================================
367 StatusCode Tuples::TupleObj::column ( const std::string& name ,
368  const char value ,
369  const char minv ,
370  const char maxv )
371 {
372  if ( invalid() ) { return InvalidTuple ; }
373  Char* item = chars ( name , minv , maxv ) ;
374  if ( !item ) { return InvalidColumn ; }
375  *item = value ;
376  return StatusCode::SUCCESS ;
377 }
378 // ============================================================================
379 StatusCode Tuples::TupleObj::column ( const std::string& name ,
380  const unsigned char value )
381 {
382  if ( invalid() ) { return InvalidTuple ; }
383  UChar* item = uchars( name ) ;
384  if ( !item ) { return InvalidColumn ; }
385  *item = value ;
386  return StatusCode::SUCCESS ;
387 }
388 // ============================================================================
389 StatusCode Tuples::TupleObj::column ( const std::string& name ,
390  const unsigned char value ,
391  const unsigned char minv ,
392  const unsigned char maxv )
393 {
394  if ( invalid() ) { return InvalidTuple ; }
395  UChar* item = uchars ( name , minv , maxv ) ;
396  if ( !item ) { return InvalidColumn ; }
397  *item = value ;
398  return StatusCode::SUCCESS ;
399 }
400 // ============================================================================
401 StatusCode Tuples::TupleObj::column ( const std::string& name ,
402  const short value )
403 {
404  if ( invalid() ) { return InvalidTuple ; }
405  Short* item = shorts( name ) ;
406  if ( !item ) { return InvalidColumn ; }
407  *item = value ;
408  return StatusCode::SUCCESS ;
409 }
410 // ============================================================================
411 StatusCode Tuples::TupleObj::column ( const std::string& name ,
412  const short value ,
413  const short minv ,
414  const short maxv )
415 {
416  if ( invalid() ) { return InvalidTuple ; }
417  Short* item = shorts ( name , minv , maxv ) ;
418  if ( !item ) { return InvalidColumn ; }
419  *item = value ;
420  return StatusCode::SUCCESS ;
421 }
422 // ============================================================================
423 StatusCode Tuples::TupleObj::column ( const std::string& name ,
424  const unsigned short value )
425 {
426  if ( invalid() ) { return InvalidTuple ; }
427  UShort* item = ushorts( name ) ;
428  if ( !item ) { return InvalidColumn ; }
429  *item = value ;
430  return StatusCode::SUCCESS ;
431 }
432 // ============================================================================
433 StatusCode Tuples::TupleObj::column ( const std::string& name ,
434  const unsigned short value ,
435  const unsigned short minv ,
436  const unsigned short maxv )
437 {
438  if ( invalid() ) { return InvalidTuple ; }
439  UShort* item = ushorts ( name , minv , maxv ) ;
440  if ( !item ) { return InvalidColumn ; }
441  *item = value ;
442  return StatusCode::SUCCESS ;
443 }
444 // ============================================================================
445 StatusCode Tuples::TupleObj::column ( const std::string& name ,
446  const int value )
447 {
448  if ( invalid() ) { return InvalidTuple ; }
449  Int* item = ints( name ) ;
450  if ( !item ) { return InvalidColumn ; }
451  *item = value ;
452  return StatusCode::SUCCESS ;
453 }
454 // ============================================================================
455 StatusCode Tuples::TupleObj::column ( const std::string& name ,
456  const int value ,
457  const int minv ,
458  const int maxv )
459 {
460  if ( invalid() ) { return InvalidTuple ; }
461  Int* item = ints ( name , minv , maxv ) ;
462  if ( !item ) { return InvalidColumn ; }
463  *item = value ;
464  return StatusCode::SUCCESS ;
465 }
466 // ============================================================================
467 StatusCode Tuples::TupleObj::column ( const std::string& name ,
468  const unsigned int value )
469 {
470  if ( invalid() ) { return InvalidTuple ; }
471  UInt* item = uints( name ) ;
472  if ( !item ) { return InvalidColumn ; }
473  *item = value ;
474  return StatusCode::SUCCESS ;
475 }
476 // ============================================================================
477 StatusCode Tuples::TupleObj::column ( const std::string& name ,
478  const unsigned int value ,
479  const unsigned int minv ,
480  const unsigned int maxv )
481 {
482  if ( invalid() ) { return InvalidTuple ; }
483  UInt* item = uints ( name , minv , maxv ) ;
484  if ( !item ) { return InvalidColumn ; }
485  *item = value ;
486  return StatusCode::SUCCESS ;
487 }
488 // ============================================================================
489 StatusCode Tuples::TupleObj::column ( const std::string& name ,
490  const long value )
491 {
492  Warning( "'long' has different sizes on 32/64 bit systems. Casting '" +
493  name + "' to 'long long'", StatusCode::SUCCESS ).ignore();
494  return column( name, (long long)value );
495 }
496 // ============================================================================
497 StatusCode Tuples::TupleObj::column ( const std::string& name ,
498  const long value ,
499  const long minv ,
500  const long maxv )
501 {
502  Warning( "'long' has different sizes on 32/64 bit systems. Casting '" +
503  name + "' to 'long long'", StatusCode::SUCCESS ).ignore();
504  return column( name,
505  (long long)value,
506  (long long)minv,
507  (long long)maxv );
508 }
509 // ============================================================================
510 StatusCode Tuples::TupleObj::column ( const std::string& name ,
511  const unsigned long value )
512 {
513  Warning( "'unsigned long' has different sizes on 32/64 bit systems. Casting '" +
514  name + "' to 'unsigned long long'", StatusCode::SUCCESS ).ignore();
515  return column( name, (unsigned long long)value );
516 }
517 // ============================================================================
518 StatusCode Tuples::TupleObj::column ( const std::string& name ,
519  const unsigned long value ,
520  const unsigned long minv ,
521  const unsigned long maxv )
522 {
523  Warning( "'unsigned long' has different sizes on 32/64 bit systems. Casting '" +
524  name + "' to 'unsigned long long'", StatusCode::SUCCESS ).ignore();
525  return column( name,
526  (unsigned long long)value,
527  (unsigned long long)minv,
528  (unsigned long long)maxv );
529 }
530 // ============================================================================
531 StatusCode Tuples::TupleObj::column ( const std::string& name ,
532  const long long value )
533 {
534  if ( invalid() ) { return InvalidTuple ; }
535  LongLong* item = longlongs( name ) ;
536  if ( !item ) { return InvalidColumn ; }
537  *item = value ;
538  return StatusCode::SUCCESS ;
539 }
540 // ============================================================================
541 StatusCode Tuples::TupleObj::column ( const std::string& name ,
542  const long long value ,
543  const long long minv ,
544  const long long maxv )
545 {
546  if ( invalid() ) { return InvalidTuple ; }
547  LongLong* item = longlongs ( name , minv , maxv ) ;
548  if ( !item ) { return InvalidColumn ; }
549  *item = value ;
550  return StatusCode::SUCCESS ;
551 }
552 // ============================================================================
553 StatusCode Tuples::TupleObj::column ( const std::string& name ,
554  const unsigned long long value )
555 {
556  if ( invalid() ) { return InvalidTuple ; }
557  ULongLong* item = ulonglongs( name ) ;
558  if ( !item ) { return InvalidColumn ; }
559  *item = value ;
560  return StatusCode::SUCCESS ;
561 }
562 // ============================================================================
563 StatusCode Tuples::TupleObj::column ( const std::string& name ,
564  const unsigned long long value ,
565  const unsigned long long minv ,
566  const unsigned long long maxv )
567 {
568  if ( invalid() ) { return InvalidTuple ; }
569  ULongLong* item = ulonglongs ( name , minv , maxv ) ;
570  if ( !item ) { return InvalidColumn ; }
571  *item = value ;
572  return StatusCode::SUCCESS ;
573 }
574 // ============================================================================
575 StatusCode Tuples::TupleObj::column ( const std::string& name ,
576  const bool value )
577 {
578  if ( invalid() ) { return InvalidTuple ; }
579  Bool* item = bools( name ) ;
580  if ( !item ) { return InvalidColumn ; }
581  *item = value ;
582  return StatusCode::SUCCESS ;
583 }
584 // ============================================================================
586 ( const std::string& name )
587 {
588  Floats::iterator found = m_floats.find( name ) ;
589  if ( m_floats.end() != found ) { return found->second ; }
590  Float* item = new Float() ;
591  m_floats[ name ] = item ;
592  const StatusCode sc = tuple()->addItem( name , *item );
593  if ( sc.isFailure() )
594  { Error ( "floats ('" + name + "'): item is not added", sc ) ; }
595  if ( !addItem ( name , "F" ) )
596  { Error ( "floats ('" + name + "'): item is not unique" ) ; }
597  return item ;
598 }
599 // ============================================================================
601 ( const std::string& name )
602 {
603  Doubles::iterator found = m_doubles.find( name ) ;
604  if ( m_doubles.end() != found ) { return found->second ; }
605  Double* item = new Double() ;
606  m_doubles[ name ] = item ;
607  const StatusCode sc = tuple()->addItem( name , *item );
608  if ( sc.isFailure() )
609  { Error ( "doubles ('" + name + "'): item is not added", sc ) ; }
610  if ( !addItem ( name , "D" ) )
611  { Error ( "doubles ('" + name + "'): item is not unique" ) ; }
612  return item ;
613 }
614 // ============================================================================
616 ( const std::string& name )
617 {
618  Bools::iterator found = m_bools.find( name ) ;
619  if( m_bools.end() != found ) { return found->second ; }
620  Bool* item = new Bool() ;
621  m_bools[ name ] = item ;
622  StatusCode sc = tuple()->addItem( name , *item );
623  if( sc.isFailure() )
624  { Error ( "bools ('" + name + "'): item is not added", sc ) ; }
625  if ( !addItem ( name , "I" ) )
626  { Error ( "bools ('" + name + "'): item is not unique" ) ; }
627  return item ;
628 }
629 // ============================================================================
631 ( const std::string& name )
632 {
633  Chars::iterator found = m_chars.find( name ) ;
634  if( m_chars.end() != found ) { return found->second ; }
635  Char* item = new Char() ;
636  m_chars[ name ] = item ;
637  StatusCode sc = tuple()->addItem( name , *item );
638  if( sc.isFailure() )
639  { Error ( "chars ('" + name + "'): item is not added", sc ) ; }
640  if ( !addItem ( name , "I" ) )
641  { Error ( "chars ('" + name + "'): item is not unique" ) ; }
642  return item ;
643 }
644 // ============================================================================
646 ( const std::string& name ,
647  const char minv ,
648  const char maxv )
649 {
650  Chars::iterator found = m_chars.find( name ) ;
651  if( m_chars.end() != found ) { return found->second ; }
652  Char* item = new Char() ;
653  m_chars[ name ] = item ;
654  const StatusCode sc = tuple()->addItem( name , *item , minv , maxv );
655  if( sc.isFailure() )
656  { Error ( "chars ('" + name + "'): item is not added", sc ) ; }
657  if ( !addItem ( name , "I" ) )
658  { Error ( "chars ('" + name + "'): item is not unique" ) ; }
659  return item ;
660 }
661 // ============================================================================
663 ( const std::string& name )
664 {
665  UChars::iterator found = m_uchars.find( name ) ;
666  if( m_uchars.end() != found ) { return found->second ; }
667  UChar* item = new UChar() ;
668  m_uchars[ name ] = item ;
669  StatusCode sc = tuple()->addItem( name , *item );
670  if( sc.isFailure() )
671  { Error ( "uchars ('" + name + "'): item is not added", sc ) ; }
672  if ( !addItem ( name , "I" ) )
673  { Error ( "uchars ('" + name + "'): item is not unique" ) ; }
674  return item ;
675 }
676 // ============================================================================
678 ( const std::string& name ,
679  const unsigned char minv ,
680  const unsigned char maxv )
681 {
682  UChars::iterator found = m_uchars.find( name ) ;
683  if( m_uchars.end() != found ) { return found->second ; }
684  UChar* item = new UChar() ;
685  m_uchars[ name ] = item ;
686  const StatusCode sc = tuple()->addItem( name , *item , minv , maxv );
687  if( sc.isFailure() )
688  { Error ( "uchars ('" + name + "'): item is not added", sc ) ; }
689  if ( !addItem ( name , "I" ) )
690  { Error ( "uchars ('" + name + "'): item is not unique" ) ; }
691  return item ;
692 }
693 // ============================================================================
695 ( const std::string& name )
696 {
697  Shorts::iterator found = m_shorts.find( name ) ;
698  if( m_shorts.end() != found ) { return found->second ; }
699  Short* item = new Short() ;
700  m_shorts[ name ] = item ;
701  StatusCode sc = tuple()->addItem( name , *item );
702  if( sc.isFailure() )
703  { Error ( "shorts ('" + name + "'): item is not added", sc ) ; }
704  if ( !addItem ( name , "I" ) )
705  { Error ( "shorts ('" + name + "'): item is not unique" ) ; }
706  return item ;
707 }
708 // ============================================================================
710 ( const std::string& name ,
711  const short minv ,
712  const short maxv )
713 {
714  Shorts::iterator found = m_shorts.find( name ) ;
715  if( m_shorts.end() != found ) { return found->second ; }
716  Short* item = new Short() ;
717  m_shorts[ name ] = item ;
718  const StatusCode sc = tuple()->addItem( name , *item , minv , maxv );
719  if( sc.isFailure() )
720  { Error ( "shorts ('" + name + "'): item is not added", sc ) ; }
721  if ( !addItem ( name , "I" ) )
722  { Error ( "shorts ('" + name + "'): item is not unique" ) ; }
723  return item ;
724 }
725 // ============================================================================
727 ( const std::string& name )
728 {
729  UShorts::iterator found = m_ushorts.find( name ) ;
730  if( m_ushorts.end() != found ) { return found->second ; }
731  UShort* item = new UShort() ;
732  m_ushorts[ name ] = item ;
733  StatusCode sc = tuple()->addItem( name , *item );
734  if( sc.isFailure() )
735  { Error ( "ushorts ('" + name + "'): item is not added", sc ) ; }
736  if ( !addItem ( name , "I" ) )
737  { Error ( "ushorts ('" + name + "'): item is not unique" ) ; }
738  return item ;
739 }
740 // ============================================================================
742 ( const std::string& name ,
743  const unsigned short minv ,
744  const unsigned short maxv )
745 {
746  UShorts::iterator found = m_ushorts.find( name ) ;
747  if( m_ushorts.end() != found ) { return found->second ; }
748  UShort* item = new UShort() ;
749  m_ushorts[ name ] = item ;
750  const StatusCode sc = tuple()->addItem( name , *item , minv , maxv );
751  if( sc.isFailure() )
752  { Error ( "ushorts ('" + name + "'): item is not added", sc ) ; }
753  if ( !addItem ( name , "I" ) )
754  { Error ( "ushorts ('" + name + "'): item is not unique" ) ; }
755  return item ;
756 }
757 // ============================================================================
759 ( const std::string& name )
760 {
761  Ints::iterator found = m_ints.find( name ) ;
762  if( m_ints.end() != found ) { return found->second ; }
763  Int* item = new Int() ;
764  m_ints[ name ] = item ;
765  StatusCode sc = tuple()->addItem( name , *item );
766  if( sc.isFailure() )
767  { Error ( "ints ('" + name + "'): item is not added", sc ) ; }
768  if ( !addItem ( name , "I" ) )
769  { Error ( "ints ('" + name + "'): item is not unique" ) ; }
770  return item ;
771 }
772 // ============================================================================
774 ( const std::string& name ,
775  const int minv ,
776  const int maxv )
777 {
778  Ints::iterator found = m_ints.find( name ) ;
779  if( m_ints.end() != found ) { return found->second ; }
780  Int* item = new Int() ;
781  m_ints[ name ] = item ;
782  const StatusCode sc = tuple()->addItem( name , *item , minv , maxv );
783  if( sc.isFailure() )
784  { Error ( "ints ('" + name + "'): item is not added", sc ) ; }
785  if ( !addItem ( name , "I" ) )
786  { Error ( "ints ('" + name + "'): item is not unique" ) ; }
787  return item ;
788 }
789 // ============================================================================
791 ( const std::string& name )
792 {
793  UInts::iterator found = m_uints.find( name ) ;
794  if( m_uints.end() != found ) { return found->second ; }
795  UInt* item = new UInt() ;
796  m_uints[ name ] = item ;
797  StatusCode sc = tuple()->addItem( name , *item );
798  if( sc.isFailure() )
799  { Error ( "uints ('" + name + "'): item is not added", sc ) ; }
800  if ( !addItem ( name , "I" ) )
801  { Error ( "uints ('" + name + "'): item is not unique" ) ; }
802  return item ;
803 }
804 // ============================================================================
806 ( const std::string& name ,
807  const unsigned int minv ,
808  const unsigned int maxv )
809 {
810  UInts::iterator found = m_uints.find( name ) ;
811  if( m_uints.end() != found ) { return found->second ; }
812  UInt* item = new UInt() ;
813  m_uints[ name ] = item ;
814  const StatusCode sc = tuple()->addItem( name , *item , minv , maxv );
815  if( sc.isFailure() )
816  { Error ( "uints ('" + name + "'): item is not added", sc ) ; }
817  if ( !addItem ( name , "I" ) )
818  { Error ( "uints ('" + name + "'): item is not unique" ) ; }
819  return item ;
820 }
821 // ============================================================================
823 ( const std::string& name )
824 {
825  LongLongs::iterator found = m_longlongs.find( name ) ;
826  if( m_longlongs.end() != found ) { return found->second ; }
827  LongLong* item = new LongLong() ;
828  m_longlongs[ name ] = item ;
829  StatusCode sc = tuple()->addItem( name , *item );
830  if( sc.isFailure() )
831  { Error ( "ints ('" + name + "'): item is not added", sc ) ; }
832  if ( !addItem ( name , "ULL" ) )
833  { Error ( "ints ('" + name + "'): item is not unique" ) ; }
834  return item ;
835 }
836 // ============================================================================
838 ( const std::string& name ,
839  const long long minv ,
840  const long long maxv )
841 {
842  LongLongs::iterator found = m_longlongs.find( name ) ;
843  if( m_longlongs.end() != found ) { return found->second ; }
844  LongLong* item = new LongLong() ;
845  m_longlongs[ name ] = item ;
846  const StatusCode sc = tuple()->addItem( name , *item , minv , maxv );
847  if( sc.isFailure() )
848  { Error ( "longlongs ('" + name + "'): item is not added", sc ) ; }
849  if ( !addItem ( name , "ULL" ) )
850  { Error ( "longlongs ('" + name + "'): item is not unique" ) ; }
851  return item ;
852 }
853 // ============================================================================
855 ( const std::string& name )
856 {
857  ULongLongs::iterator found = m_ulonglongs.find( name ) ;
858  if( m_ulonglongs.end() != found ) { return found->second ; }
859  ULongLong* item = new ULongLong() ;
860  m_ulonglongs[ name ] = item ;
861  StatusCode sc = tuple()->addItem( name , *item );
862  if( sc.isFailure() )
863  { Error ( "ulonglongs ('" + name + "'): item is not added", sc ) ; }
864  if ( !addItem ( name , "ULL" ) )
865  { Error ( "ulonglongs ('" + name + "'): item is not unique" ) ; }
866  return item ;
867 }
868 // ============================================================================
870 ( const std::string& name ,
871  const unsigned long long minv ,
872  const unsigned long long maxv )
873 {
874  ULongLongs::iterator found = m_ulonglongs.find( name ) ;
875  if( m_ulonglongs.end() != found ) { return found->second ; }
876  ULongLong* item = new ULongLong() ;
877  m_ulonglongs[ name ] = item ;
878  const StatusCode sc = tuple()->addItem( name , *item , minv , maxv );
879  if( sc.isFailure() )
880  { Error ( "ulonglongs ('" + name + "'): item is not added", sc ) ; }
881  if ( !addItem ( name , "ULL" ) )
882  { Error ( "ulonglongs ('" + name + "'): item is not unique" ) ; }
883  return item ;
884 }
885 // ============================================================================
887 ( const std::string& name )
888 {
889  Addresses::iterator found = m_addresses.find( name ) ;
890  if( m_addresses.end() != found ) { return found->second ; }
891  Address* item = new Address() ;
892  m_addresses[ name ] = item ;
893  const StatusCode sc = tuple()->addItem( name , *item );
894  if( sc.isFailure() )
895  { Error ( "addresses ('" + name + "'): item is not added", sc ) ; }
896  if ( !addItem ( name , "IOpaqueAddress*" ) )
897  { Error ( "addresses ('" + name + "'): item is not unique" ) ; }
898  return item ;
899 }
900 // ============================================================================
901 // retrieve (book on demand) array-items for ntuple
902 // ============================================================================
904 ( const std::string& name ,
905  Tuples::TupleObj::Int* length )
906 {
907  // existing array ?
908  FArrays::iterator found = m_farrays.find( name ) ;
909  if( m_farrays.end() != found ) { return found->second ; }
910  // create new array
911  FArray* array = new FArray () ;
912  m_farrays[ name] = array ;
913  const StatusCode sc = tuple() -> addIndexedItem( name , *length , *array) ;
914  if( sc.isFailure() )
915  { Error ( "farray ('" + name + "'): item is not added", sc ) ; }
916  if ( !addItem ( name , "FArray" ) )
917  { Error ( "farray ('" + name + "'): item is not unique" ) ; }
918  return array ;
919 }
920 // ============================================================================
921 // retrieve (book on demand) array-items for ntuple (fixed)
922 // ============================================================================
924 ( const std::string& name ,
925  const Tuples::TupleObj::MIndex& rows )
926 {
927  // existing array ?
928  FArrays::iterator found = m_arraysf.find( name ) ;
929  if( m_arraysf.end() != found ) { return found->second ; }
930  // create new array
931  FArray* array = new FArray () ;
932  m_arraysf[ name] = array ;
933  const StatusCode sc = tuple() -> addItem ( name , rows , *array) ;
934  if( sc.isFailure() )
935  { Error ( "array ('" + name + "'): item is not added", sc ) ; }
936  if ( !addItem ( name , "FArray" ) )
937  { Error ( "array ('" + name + "'): item is not unique" ) ; }
938  return array ;
939 }
940 // ============================================================================
941 // retrieve (book on demand) matrix-items for ntuple
942 // ============================================================================
945 ( const std::string& name ,
946  Tuples::TupleObj::Int* length ,
947  const Tuples::TupleObj::MIndex& cols )
948 {
949  // existing array ?
950  FMatrices::iterator found = m_fmatrices.find( name ) ;
951  if( m_fmatrices.end() != found ) { return found->second ; }
952  // create new array
953  FMatrix* matrix = new FMatrix () ;
954  m_fmatrices[ name] = matrix ;
955  const StatusCode sc =
956  tuple() -> addIndexedItem( name , *length , cols , *matrix ) ;
957  if( sc.isFailure() )
958  { Error ( "fmatrix ('" + name + "'): item is not added", sc ) ; }
959  if ( !addItem ( name , "FMatrix" ) )
960  { Error ( "fmatrix ('" + name + "'): item is not unique" ) ; }
961  return matrix ;
962 }
963 // ============================================================================
964 // retrieve (book on demand) matrix-items for ntuple (fixed)
965 // ============================================================================
968 ( const std::string& name ,
969  const Tuples::TupleObj::MIndex& rows ,
970  const Tuples::TupleObj::MIndex& cols )
971 {
972  // existing array ?
973  FMatrices::iterator found = m_matricesf.find( name ) ;
974  if( m_matricesf.end() != found ) { return found->second ; }
975  // create new array
976  FMatrix* matrix = new FMatrix () ;
977  m_matricesf[ name] = matrix ;
978  const StatusCode sc =
979  tuple() -> addItem( name , rows , cols , *matrix ) ;
980  if( sc.isFailure() )
981  { Error ( "matrix ('" + name + "'): item is not added", sc ) ; }
982  if ( !addItem ( name , "FMatrix" ) )
983  { Error ( "matrix ('" + name + "'): item is not unique" ) ; }
984  return matrix ;
985 }
986 // ============================================================================
987 // The END
988 // ============================================================================
virtual StatusCode write()=0
Write record of the NTuple (Shortcut of writeRecord)
Address * addresses(const std::string &name)
get the column
Definition: TupleObj.cpp:887
UShorts m_ushorts
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:2339
FMatrices m_fmatrices
the actual storage of all 'FArray' columns
Definition: TupleObj.h:2369
void release()
release the reference to TupleObj if reference counter becomes zero, object will be automatically del...
Definition: TupleObj.cpp:228
long decrement(const std::string &object)
Definition: TupleObj.cpp:50
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:133
Float * floats(const std::string &name)
get the column
Definition: TupleObj.cpp:586
Header file for class TupleObj.
Doubles m_doubles
the actual storage of all 'Double' columns
Definition: TupleObj.h:2357
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:45
StatusCode fill(const char *format...)
Set the values for several columns simultaneously.
Definition: TupleObj.cpp:282
void report() const
Definition: TupleObj.cpp:54
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
Bool * bools(const std::string &name)
get the column
Definition: TupleObj.cpp:616
FMatrices m_matricesf
the actual storage of all 'FMatrix' columns (fixed)
Definition: TupleObj.h:2372
Floats m_floats
the actual storage of all 'Float' columns
Definition: TupleObj.h:2354
UShort * ushorts(const std::string &name)
get the column
Definition: TupleObj.cpp:727
FArrays m_farrays
the actual storage of all 'FArray' columns
Definition: TupleObj.h:2363
long counts(const std::string &object)
Definition: TupleObj.cpp:52
unsigned short MIndex
Definition: TupleObj.h:227
UChar * uchars(const std::string &name)
get the column
Definition: TupleObj.cpp:663
std::string m_name
name
Definition: TupleObj.h:2312
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
UInt * uints(const std::string &name)
get the column
Definition: TupleObj.cpp:791
FArrays m_arraysf
the actual storage of all 'FArray' columns (fixed)
Definition: TupleObj.h:2366
Bools m_bools
the actual storage of all 'bool' columns
Definition: TupleObj.h:2327
Counter(const std::string &msg=" Misbalance ")
Definition: TupleObj.cpp:41
ULongLong * ulonglongs(const std::string &name)
get the column
Definition: TupleObj.cpp:855
Chars m_chars
the actual storage of all 'Int' columns
Definition: TupleObj.h:2330
ULongLongs m_ulonglongs
the actual storage of all 'ulonglong' columns
Definition: TupleObj.h:2351
iterator end()
Definition: Map.h:131
string type
Definition: gaudirun.py:126
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
StatusCode column(const std::string &name, const float value)
Set the value for selected tuple column.
Definition: TupleObj.cpp:337
UInts m_uints
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:2345
StatusCode write()
write a record to NTuple
Definition: TupleObj.cpp:240
Specialization acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:299
Ints m_ints
the actual storage of all 'Int' columns
Definition: TupleObj.h:2342
unsigned int CLID
Class ID definition.
Definition: ClassID.h:9
LongLongs m_longlongs
the actual storage of all 'longlong' columns
Definition: TupleObj.h:2348
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:367
iterator begin()
Definition: Map.h:130
virtual ~TupleObj()
destructor is protected
Definition: TupleObj.cpp:121
Addresses m_addresses
the actual storage of all 'Address' columns
Definition: TupleObj.h:2360
FArray * fArray(const std::string &name, Int *item)
get the column
Definition: TupleObj.cpp:904
Short * shorts(const std::string &name)
get the column
Definition: TupleObj.cpp:695
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
TupleObj()
the default constructor is disabled
Char * chars(const std::string &name)
get the column
Definition: TupleObj.cpp:631
tuple item
print s1,s2
Definition: ana.py:146
StatusCode addItem(const std::string &name, Item< TYPE > &itm)
Add a scalar data item a N tuple.
Definition: NTuple.h:551
FMatrix * fMatrix(const std::string &name, Int *item, const MIndex &cols)
get the column
Definition: TupleObj.cpp:945
void clear()
Definition: Map.h:176
Shorts m_shorts
the actual storage of all 'Int' columns
Definition: TupleObj.h:2336
Double * doubles(const std::string &name)
get the column
Definition: TupleObj.cpp:601
Int * ints(const std::string &name)
get the column
Definition: TupleObj.cpp:759
Opaque address interface definition.
void ignore() const
Definition: StatusCode.h:107
std::string m_message
Definition: TupleObj.cpp:69
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:44
Type
the list of available types for ntuples
Definition: TupleObj.h:63
long increment(const std::string &object)
Definition: TupleObj.cpp:48
UChars m_uchars
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:2333
std::map< std::string, long > Map
Definition: TupleObj.cpp:64
LongLong * longlongs(const std::string &name)
get the column
Definition: TupleObj.cpp:823