Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012

TupleObj.h

Go to the documentation of this file.
00001 // $Id: TupleObj.h,v 1.23 2008/10/27 19:22:20 marcocle Exp $
00002 // ============================================================================
00003 // CVS tag $Name:  $, version $Revision: 1.23 $
00004 // ============================================================================
00005 #ifndef GAUDIALG_TUPLEOBJ_H
00006 #define GAUDIALG_TUPLEOBJ_H 1
00007 // ============================================================================
00008 // Include files
00009 // ============================================================================
00010 // STD&STL
00011 // ============================================================================
00012 #include <set>
00013 #include <string>
00014 #include <limits>
00015 // ============================================================================
00016 // GaudiKernel
00017 // ============================================================================
00018 #include "GaudiKernel/NTuple.h"
00019 #include "GaudiKernel/VectorMap.h"
00020 // ============================================================================
00021 // GaudiAlg
00022 // ============================================================================
00023 #include "GaudiAlg/Tuples.h"
00024 #include "GaudiAlg/Maps.h"
00025 // ============================================================================
00026 // ROOT
00027 // ============================================================================
00028 #include "Math/Point3D.h"
00029 #include "Math/Vector3D.h"
00030 #include "Math/Vector4D.h"
00031 #include "Math/SVector.h"
00032 #include "Math/SMatrix.h"
00033 // ============================================================================
00034 // forward declaration
00035 // ============================================================================
00036 // GaudiKernel
00037 // ============================================================================
00038 class IOpaqueAddress   ;
00039 // ============================================================================
00047 // ============================================================================
00055 namespace Tuples
00056 {
00057   // ==========================================================================
00063   enum Type
00064     {
00065       NTUPLE  , // Analysis nTuple
00066       EVTCOL    // Event Collection
00067     };
00068   // ==========================================================================
00076   enum ErrorCodes
00077     {
00078       InvalidTuple      = 100 ,
00079       InvalidColumn           ,
00080       InvalidOperation        ,
00081       InvalidObject           ,
00082       InvalidItem             ,
00083       TruncateValue     = 200
00084     };
00085   // ==========================================================================
00180   class GAUDI_API TupleObj
00181   {
00182   public:
00183     // ========================================================================
00185     typedef NTuple::Item<bool>                  Bool      ;
00186     // ========================================================================
00188     typedef NTuple::Item<char>                  Char      ;
00189     // ========================================================================
00191     typedef NTuple::Item<unsigned char>         UChar     ;
00192     // ========================================================================
00194     typedef NTuple::Item<short>                 Short     ;
00195     // ========================================================================
00197     typedef NTuple::Item<unsigned short>        UShort    ;
00198     // ========================================================================
00200     typedef NTuple::Item<int>                   Int       ;
00201     // ========================================================================
00203     typedef NTuple::Item<unsigned int>          UInt      ;
00204     // ========================================================================
00206     typedef NTuple::Item<long long>             LongLong  ;
00207     // ========================================================================
00209     typedef NTuple::Item<unsigned long long>    ULongLong ;
00210     // ========================================================================
00212     typedef NTuple::Item<float>                 Float     ;
00213     // ========================================================================
00215     typedef NTuple::Item<double>                Double    ;
00216     // ========================================================================
00218     typedef NTuple::Item<IOpaqueAddress*>       Address   ;
00219     // ========================================================================
00221     typedef NTuple::Array<float>                FArray    ;
00222     // ========================================================================
00224     typedef NTuple::Matrix<float>               FMatrix   ;
00225     // ========================================================================
00226     // the actual type for variable size matrix indices
00227     typedef unsigned short                      MIndex    ;
00228     // ========================================================================
00229     // the map of all items
00230     typedef std::map<std::string,std::string>   ItemMap   ;
00231     // ========================================================================
00232   protected:
00233     // ========================================================================
00241     TupleObj
00242     ( const std::string&    name                          ,
00243       NTuple::Tuple*        tuple                         ,
00244       const CLID&           clid = CLID_ColumnWiseTuple   ,
00245       const Tuples::Type    type = Tuples::NTUPLE         ) ;
00246     // ========================================================================
00247   protected:
00248     // ========================================================================
00250     virtual ~TupleObj();
00251     // ========================================================================
00252   public:
00253     // ========================================================================
00269     StatusCode column ( const std::string& name   ,
00270                         const float        value  );
00271     // ========================================================================
00272   public:
00273     // ========================================================================
00290     StatusCode column ( const std::string& name   ,
00291                         const double       value  );
00292     // ========================================================================
00293   public:
00294     // ========================================================================
00310     StatusCode column ( const std::string&   name  ,
00311                         const short          value );
00312     // ========================================================================
00330     StatusCode column ( const std::string&  name  ,
00331                         const short         value ,
00332                         const short         minv  ,
00333                         const short         maxv  );
00334     // ========================================================================
00335   public:
00336     // ========================================================================
00352     StatusCode column ( const std::string&   name  ,
00353                         const unsigned short value );
00354     // ========================================================================
00372     StatusCode column ( const std::string&   name  ,
00373                         const unsigned short value ,
00374                         const unsigned short minv  ,
00375                         const unsigned short maxv  );
00376     // ========================================================================
00377   public:
00378     // ========================================================================
00394     StatusCode column ( const std::string&   name  ,
00395                         const char           value );
00396     // ========================================================================
00414     StatusCode column ( const std::string&  name  ,
00415                         const char          value ,
00416                         const char          minv  ,
00417                         const char          maxv  );
00418     // ========================================================================
00419   public:
00420     // ========================================================================
00436     StatusCode column ( const std::string&   name  ,
00437                         const unsigned char  value );
00438     // ========================================================================
00456     StatusCode column ( const std::string&  name  ,
00457                         const unsigned char value ,
00458                         const unsigned char minv  ,
00459                         const unsigned char maxv  );
00460     // ========================================================================
00461   public:
00462     // ========================================================================
00478     StatusCode column ( const std::string&   name  ,
00479                         const int            value );
00480     // ========================================================================
00498     StatusCode column ( const std::string&   name  ,
00499                         const int            value ,
00500                         const int            minv  ,
00501                         const int            maxv  );
00502     // ========================================================================
00503   public:
00504     // ========================================================================
00520     StatusCode column ( const std::string&   name  ,
00521                         const unsigned int   value );
00522     // ========================================================================
00540     StatusCode column ( const std::string&   name  ,
00541                         const unsigned int   value ,
00542                         const unsigned int   minv  ,
00543                         const unsigned int   maxv  );
00544     // ========================================================================
00545   public:
00546     // ========================================================================
00563     StatusCode column ( const std::string&   name  ,
00564                         const long           value );
00565     // ========================================================================
00583     StatusCode column ( const std::string&   name  ,
00584                         const long           value ,
00585                         const long           minv  ,
00586                         const long           maxv  );
00587     // ========================================================================
00588   public:
00589     // ========================================================================
00606     StatusCode column ( const std::string&   name  ,
00607                         const unsigned long  value );
00608     // ========================================================================
00626     StatusCode column ( const std::string&   name  ,
00627                         const unsigned long  value ,
00628                         const unsigned long  minv  ,
00629                         const unsigned long  maxv  );
00630     // ========================================================================
00631   public:
00632     // ========================================================================
00648     StatusCode column ( const std::string&   name  ,
00649                         const long long      value );
00650     // ========================================================================
00668     StatusCode column ( const std::string&   name  ,
00669                         const long long      value ,
00670                         const long long      minv  ,
00671                         const long long      maxv  );
00672     // ========================================================================
00673   public:
00674     // ========================================================================
00690     StatusCode column ( const std::string&       name  ,
00691                         const unsigned long long value );
00692     // ========================================================================
00710     StatusCode column ( const std::string&       name  ,
00711                         const unsigned long long value ,
00712                         const unsigned long long minv  ,
00713                         const unsigned long long maxv  );
00714     // ========================================================================
00715   public:
00716     // ========================================================================
00732     StatusCode column ( const std::string& name  ,
00733                         const signed char  value )
00734     {
00735       return column
00736         ( name  ,
00737           value ,
00738           std::numeric_limits<signed char>::min() ,
00739           std::numeric_limits<signed char>::max() ) ;
00740     }
00741     // ========================================================================
00742   public:
00743     // ========================================================================
00758     StatusCode column ( const std::string& name  ,
00759                         const bool         value );
00760     // ========================================================================
00761   public:
00762     // ========================================================================
00781     StatusCode column ( const std::string&    name    ,
00782                         IOpaqueAddress*       address ) ;
00783     // ========================================================================
00800     StatusCode column ( IOpaqueAddress*       address ) ;
00801     // ========================================================================
00802   public:
00803     // ========================================================================
00827     StatusCode fill( const char* format ... ) ;
00828     // =======================================================================
00829   public:
00830     // =======================================================================
00879     template <class DATA>
00880     StatusCode farray ( const std::string& name          ,
00881                         DATA               first         ,
00882                         DATA               last          ,
00883                         const std::string& length        ,
00884                         const size_t       maxv          )
00885     {
00886       if ( invalid () ) { return InvalidTuple     ; }
00887       if ( rowWise () ) { return InvalidOperation ; }
00888 
00889       // adjust the length
00890       if( first + maxv < last )
00891       {
00892         Warning( "farray('"+name+"'): array is overflow, skip extra items") ;
00893         last = first + maxv ;
00894       }
00895 
00896       // get the length item
00897       Int* len  = ints( length , 0 , maxv ) ;
00898       if( 0 == len  ) { return InvalidColumn; }
00899 
00900       // adjust the length item
00901       *len = last - first ;
00902 
00903       // get the array itself
00904       FArray* var  = fArray ( name , len ) ;
00905       if( 0 == var ) { return InvalidColumn ; }
00906 
00908       size_t index = 0 ;
00909       for( ; first != last ; ++first )
00910       { (*var)[ index ] = (float)(*first) ; ++index ; }
00911 
00912       return StatusCode::SUCCESS ;
00913     }
00914     // =======================================================================
00957     template <class DATA>
00958     StatusCode farray ( const std::string& name          ,
00959                         const DATA&        data          ,
00960                         const std::string& length        ,
00961                         const size_t       maxv          )
00962     { return farray ( name , data.begin() , data.end() , length , maxv  ) ; }
00963     // =======================================================================
01026     template <class FUNCTION, class DATA>
01027     StatusCode farray ( const std::string& name          ,
01028                         const FUNCTION&    function      ,
01029                         DATA               first         ,
01030                         DATA               last          ,
01031                         const std::string& length        ,
01032                         const size_t       maxv          )
01033     {
01034       if ( invalid () ) { return InvalidTuple     ; }
01035       if ( rowWise () ) { return InvalidOperation ; }
01036 
01037       // adjust the length
01038       if( first + maxv < last )
01039       {
01040         Warning("farray('"
01041                 + name  + "'): array is overflow, skip extra entries") ;
01042         last = first + maxv ;
01043       }
01044 
01045       // get the length item
01046       Int* len  = ints( length , 0 , maxv ) ;
01047       if( 0 == len  ) { return InvalidColumn ; }
01048 
01049       // adjust the length
01050       *len = last - first ;
01051 
01052       // get the array itself
01053       FArray*  var  = fArray ( name , len ) ;
01054       if( 0 == var ) { return InvalidColumn ; }
01055 
01056       // fill the array
01057       size_t index = 0 ;
01058       for( ; first != last ; ++first )
01059       { (*var)[ index ] = function( *first )  ; ++index ; }
01060 
01061       return StatusCode::SUCCESS ;
01062     }
01063     // =======================================================================
01095     template <class FUNC1, class FUNC2, class DATA>
01096     StatusCode farray ( const std::string& name1         ,
01097                         const FUNC1&       func1         ,
01098                         const std::string& name2         ,
01099                         const FUNC2&       func2         ,
01100                         DATA               first         ,
01101                         DATA               last          ,
01102                         const std::string& length        ,
01103                         const size_t       maxv          )
01104     {
01105       if ( invalid () ) { return InvalidTuple     ; }
01106       if ( rowWise () ) { return InvalidOperation ; }
01107 
01108       // adjust the lenfth
01109       if( first + maxv < last )
01110       {
01111         Warning("farray('"
01112                 + name1 + ","
01113                 + name2 + "'): array is overflow, skip extra entries").ignore() ;
01114         Warning("farray('"+name1+"'): array is overflow, skip extra items").ignore() ;
01115         last = first + maxv ;
01116       }
01117 
01118       // get the length item
01119       Int* len  = ints ( length , 0 , maxv ) ;
01120       if ( 0 == len  ) { return InvalidColumn ; }
01121 
01122       // adjust the length
01123       *len = last - first ;
01124 
01125       // get the array itself
01126       FArray*  var1  = fArray ( name1 , len ) ;
01127       if ( 0 == var1 ) { return InvalidColumn ; }
01128 
01129       // get the array itself
01130       FArray*  var2 = fArray ( name2 , len ) ;
01131       if ( 0 == var2 ) { return InvalidColumn ; }
01132 
01133       // fill the array
01134       size_t index = 0 ;
01135       for( ; first != last ; ++first )
01136       {
01137         ( *var1 ) [ index ] = func1 ( *first )  ;
01138         ( *var2 ) [ index ] = func2 ( *first )  ;
01139         ++index ;
01140       }
01141 
01142       return StatusCode::SUCCESS ;
01143     }
01144     // =======================================================================
01181     template <class FUNC1, class FUNC2, class FUNC3, class DATA>
01182     StatusCode farray ( const std::string& name1         ,
01183                         const FUNC1&       func1         ,
01184                         const std::string& name2         ,
01185                         const FUNC2&       func2         ,
01186                         const std::string& name3         ,
01187                         const FUNC3&       func3         ,
01188                         DATA               first         ,
01189                         DATA               last          ,
01190                         const std::string& length        ,
01191                         const size_t       maxv          )
01192     {
01193       if ( invalid () ) { return InvalidTuple     ; }
01194       if ( rowWise () ) { return InvalidOperation ; }
01195 
01196       // adjust the length
01197       if( first + maxv < last )
01198       {
01199         Warning("farray('"
01200                 + name1 + ","
01201                 + name2 + ","
01202                 + name3 + "'): array is overflow, skip extra entries").ignore() ;
01203         last = first + maxv ;
01204       }
01205 
01206       // get the length item
01207       Int* len  = ints ( length , 0 , maxv ) ;
01208       if( 0 == len   ) { return InvalidColumn ; }
01209 
01210       // adjust the length
01211       *len = last - first ;
01212 
01213       // get the array itself
01214       FArray*  var1  = fArray ( name1 , len ) ;
01215       if( 0 == var1 ) { return InvalidColumn  ; }
01216 
01217       // get the array itself
01218       FArray*  var2 = fArray ( name2 , len ) ;
01219       if( 0 == var2 ) { return InvalidColumn ; }
01220 
01221       // get the array itself
01222       FArray*  var3 = fArray ( name3 , len ) ;
01223       if( 0 == var3 ) { return InvalidColumn ; }
01224 
01225       // fill the array
01226       size_t index = 0 ;
01227       for( ; first != last ; ++first )
01228       {
01229         ( *var1 ) [ index ] = (float)func1 ( *first )  ;
01230         ( *var2 ) [ index ] = (float)func2 ( *first )  ;
01231         ( *var3 ) [ index ] = (float)func3 ( *first )  ;
01232         ++index ;
01233       }
01234       return StatusCode::SUCCESS ;
01235     }
01236     // =======================================================================
01276     template <class FUNC1, class FUNC2, class FUNC3, class FUNC4, class DATA>
01277     StatusCode farray ( const std::string& name1         ,
01278                         const FUNC1&       func1         ,
01279                         const std::string& name2         ,
01280                         const FUNC2&       func2         ,
01281                         const std::string& name3         ,
01282                         const FUNC3&       func3         ,
01283                         const std::string& name4         ,
01284                         const FUNC4&       func4         ,
01285                         DATA               first         ,
01286                         DATA               last          ,
01287                         const std::string& length        ,
01288                         const size_t       maxv          )
01289     {
01290       if ( invalid () ) { return InvalidTuple     ; }
01291       if ( rowWise () ) { return InvalidOperation ; }
01292 
01293       // adjust the length
01294       if( first + maxv < last )
01295       {
01296         Warning("farray('"
01297                 + name1 + ","
01298                 + name2 + ","
01299                 + name3 + ","
01300                 + name4 + "'): array is overflow, skip extra entries").ignore() ;
01301         last = first + maxv ;
01302       }
01303 
01304       // get the length item
01305       Int* len  = ints ( length , 0 , maxv ) ;
01306       if( 0 == len  ) { return InvalidColumn ; }
01307 
01308       // adjust the length
01309       *len = last - first ;
01310 
01311       // get the array itself
01312       FArray*  var1  = fArray ( name1 , len ) ;
01313       if( 0 == var1 ) { return InvalidColumn ; }
01314 
01315       // get the array itself
01316       FArray*  var2 = fArray ( name2 , len ) ;
01317       if( 0 == var2 ) { return InvalidColumn ; }
01318 
01319       // get the array itself
01320       FArray*  var3 = fArray ( name3 , len ) ;
01321       if( 0 == var3 ) { return InvalidColumn ; }
01322 
01323       // get the array itself
01324       FArray*  var4 = fArray ( name4 , len ) ;
01325       if( 0 == var4 ) { return InvalidColumn ; }
01326 
01327       // fill the array
01328       size_t index = 0 ;
01329       for( ; first != last ; ++first )
01330       {
01331         ( *var1 ) [ index ] = static_cast<float> ( func1 ( *first ) );
01332         ( *var2 ) [ index ] = static_cast<float> ( func2 ( *first ) );
01333         ( *var3 ) [ index ] = static_cast<float> ( func3 ( *first ) );
01334         ( *var4 ) [ index ] = static_cast<float> ( func4 ( *first ) );
01335         ++index ;
01336       }
01337 
01338       return StatusCode::SUCCESS ;
01339     }
01340     // =======================================================================
01341   public:
01342     // =======================================================================
01393     template <class MATRIX>
01394     StatusCode fmatrix ( const std::string& name    ,
01395                          const MATRIX&      data    ,
01396                          size_t             rows    ,
01397                          const MIndex&      cols    ,
01398                          const std::string& length  ,
01399                          const size_t       maxv    )
01400     {
01401       if ( invalid () ) { return InvalidTuple     ; }
01402       if ( rowWise () ) { return InvalidOperation ; }
01403 
01404       // adjust the length
01405       if ( rows >= maxv )
01406       {
01407         Warning ( "fmatrix('"+name+"'): matrix is overflow, skip extra items").ignore() ;
01408         rows = ( 0 < maxv ) ? ( maxv - 1 ) : 0 ;
01409       }
01410 
01411       // get the length item
01412       Int* len  = ints( length , 0 , maxv ) ;
01413       if ( 0 == len  ) { return InvalidColumn; }
01414 
01415       // adjust the length item
01416       *len = rows ;
01417 
01418       // get the array itself
01419       FMatrix* var  = fMatrix ( name , len  , cols ) ;
01420       if ( 0 == var ) { return InvalidColumn ; }
01421 
01423       for ( size_t iCol = 0 ; iCol < cols ; ++iCol )
01424       {
01425         for ( MIndex iRow = 0 ; iRow < rows ; ++iRow )
01426         { (*var)[ iRow ] [ iCol ] = (float)(data[ iRow ][ iCol ]) ; }
01427       }
01428 
01429       return StatusCode::SUCCESS ;
01430     }
01431     // =======================================================================
01468     template <class DATA>
01469     StatusCode fmatrix ( const std::string& name   ,
01470                          DATA               first  ,
01471                          DATA               last   ,
01472                          const MIndex&      cols   ,
01473                          const std::string& length ,
01474                          const size_t       maxv   )
01475     {
01476       if ( invalid () ) { return InvalidTuple     ; }
01477       if ( rowWise () ) { return InvalidOperation ; }
01478 
01479       // adjust the length
01480       if ( first + maxv < last )
01481       {
01482         Warning("fmatrix('"+name+"'): matrix is overflow, skip extra items").ignore() ;
01483         last = first + maxv ;
01484       }
01485 
01486       // get the length item
01487       Int* len  = ints( length , 0 , maxv ) ;
01488       if ( 0 == len  ) { return InvalidColumn; }
01489 
01490       // adjust the length item
01491       *len = last - first ;
01492 
01493       // get the array itself
01494       FMatrix* var  = fMatrix ( name , len , cols ) ;
01495       if ( 0 == var ) { return InvalidColumn ; }
01496 
01498       size_t iRow = 0 ;
01499       for ( ; first != last ; ++first )
01500       {
01501         //
01502         for ( MIndex iCol = 0 ; iCol < cols ; ++iCol )
01503         { (*var)[ iRow ] [ iCol ] = (float)((*first)[ iCol ]) ; }
01504         //
01505         ++iRow ;
01506       }
01507 
01508       return StatusCode::SUCCESS ;
01509     }
01510     // =======================================================================
01589     template <class FUN,class DATA>
01590     StatusCode fmatrix ( const std::string& name   ,
01591                          FUN                funF   ,
01592                          FUN                funL   ,
01593                          DATA               first  ,
01594                          DATA               last   ,
01595                          const std::string& length ,
01596                          const size_t       maxv   )
01597     {
01598       if ( invalid () ) { return InvalidTuple     ; }
01599       if ( rowWise () ) { return InvalidOperation ; }
01600 
01601       // adjust the length
01602       if ( first + maxv < last )
01603       {
01604         Warning("fmatrix('"+name+"'): matrix is overflow, skip extra items").ignore() ;
01605         last = first + maxv ;
01606       }
01607 
01608       // get the length item
01609       Int* len  = ints( length , 0 , maxv ) ;
01610       if ( 0 == len  ) { return InvalidColumn; }
01611 
01612       // adjust the length item
01613       *len = last - first ;
01614 
01615       // get the array itself
01616       const size_t cols = funL - funF ;
01617       FMatrix* var  = fMatrix ( name , len , cols ) ;
01618       if ( 0 == var ) { return InvalidColumn ; }
01619 
01621       size_t iRow = 0 ;
01622       for ( ; first != last ; ++first )
01623       {
01624         //
01625         for ( FUN fun = funF ; fun < funL ; ++fun )
01626         { (*var)[ iRow ] [ fun - funF ] = (float)((*fun) ( *first )) ; }
01627         //
01628         ++iRow;
01629       }
01630 
01631       return StatusCode::SUCCESS ;
01632     }
01633     // =======================================================================
01634   public:
01635     // =======================================================================
01658     template <class DATA>
01659     StatusCode array ( const std::string& name          ,
01660                        DATA               first         ,
01661                        DATA               last          )
01662 
01663     {
01664       if ( invalid () ) { return InvalidTuple     ; }
01665       if ( rowWise () ) { return InvalidOperation ; }
01666 
01667       // get the length (fixed!)
01668       const size_t length = last - first ;
01669 
01670       // get the array itself
01671       FArray* var  = fArray ( name , length ) ;
01672       if ( 0 == var ) { return InvalidColumn ; }
01673 
01675       size_t iCol = 0 ;
01676       for ( ; first != last ; ++first )
01677       { (*var)[ iCol ] = (float)(*first) ; ++iCol ; }
01678 
01679       return StatusCode::SUCCESS ;
01680     }
01681     // =======================================================================
01720     template <class ARRAY>
01721     StatusCode array ( const std::string& name   ,
01722                        const ARRAY&       data   ,
01723                        const MIndex&      length )
01724     {
01725       if ( invalid () ) { return InvalidTuple     ; }
01726       if ( rowWise () ) { return InvalidOperation ; }
01727 
01728       // get the array itself
01729       FArray* var  = fArray ( name , length ) ;
01730       if ( 0 == var ) { return InvalidColumn ; }
01731 
01733       for ( size_t index = 0 ; index < length ; ++index )
01734       { (*var)[ index ] = (float) data[index] ; }
01735 
01736       return StatusCode::SUCCESS ;
01737     }
01738     // =======================================================================
01768     template <class ARRAY>
01769     StatusCode array ( const std::string& name  ,
01770                        const ARRAY&       data  )
01771     { return array ( name , data.begin() , data.end() ) ; }
01772     // =======================================================================
01773   public:
01774     // =======================================================================
01823     template <class MATRIX>
01824     StatusCode matrix ( const std::string& name  ,
01825                         const MATRIX&      data  ,
01826                         const MIndex&      rows  ,
01827                         const MIndex&      cols  )
01828     {
01829       if ( invalid () ) { return InvalidTuple     ; }
01830       if ( rowWise () ) { return InvalidOperation ; }
01831 
01832       // get the matrix itself
01833       FMatrix* var  = fMatrix ( name , rows , cols ) ;
01834       if ( 0 == var ) { return InvalidColumn ; }
01835 
01837       for ( size_t iCol = 0 ; iCol < cols ; ++iCol )
01838       {
01839         for ( size_t iRow = 0 ; iRow < rows ; ++iRow )
01840         { (*var)[iRow][iCol] = (float)(data[iRow][iCol]) ; }
01841       };
01842       return StatusCode::SUCCESS ;
01843     }
01844     // =======================================================================
01845   public:
01846     // =======================================================================
01863     template <class TYPE>
01864     StatusCode column
01865     ( const std::string& name ,
01866       const ROOT::Math::LorentzVector<TYPE>& v )
01867     {
01868       if ( invalid() ) { return InvalidTuple ; }
01869       // fill all separate columns:
01870       StatusCode sc1 = this -> column ( name + "E" , v.E  () ) ;
01871       StatusCode sc2 = this -> column ( name + "X" , v.Px () ) ;
01872       StatusCode sc3 = this -> column ( name + "Y" , v.Py () ) ;
01873       StatusCode sc4 = this -> column ( name + "Z" , v.Pz () ) ;
01874       return
01875         sc1.isFailure () ? sc1 :
01876         sc2.isFailure () ? sc2 :
01877         sc3.isFailure () ? sc3 :
01878         sc4.isFailure () ? sc4 : StatusCode(StatusCode::SUCCESS) ;
01879     }
01880     // =======================================================================
01897     template <class TYPE,class TAG>
01898     StatusCode column
01899     ( const std::string& name ,
01900       const ROOT::Math::DisplacementVector3D<TYPE,TAG>& v )
01901     {
01902       if ( invalid() ) { return InvalidTuple ; }
01904       StatusCode sc1 = this -> column ( name + "X" , v.X () ) ;
01905       StatusCode sc2 = this -> column ( name + "Y" , v.Y () ) ;
01906       StatusCode sc3 = this -> column ( name + "Z" , v.Z () ) ;
01907       return
01908         sc1.isFailure () ? sc1 :
01909         sc2.isFailure () ? sc2 :
01910         sc3.isFailure () ? sc3 : StatusCode(StatusCode::SUCCESS) ;
01911     }
01912     // =======================================================================
01929     template <class TYPE,class TAG>
01930     StatusCode column
01931     ( const std::string& name ,
01932       const ROOT::Math::PositionVector3D<TYPE,TAG>& v )
01933     {
01934       if ( invalid() ) { return InvalidTuple ; }
01936       StatusCode sc1 = this -> column ( name + "X" , v.X () ) ;
01937       StatusCode sc2 = this -> column ( name + "Y" , v.Y () ) ;
01938       StatusCode sc3 = this -> column ( name + "Z" , v.Z () ) ;
01939       return
01940         sc1.isFailure () ? sc1 :
01941         sc2.isFailure () ? sc2 :
01942         sc3.isFailure () ? sc3 : StatusCode(StatusCode::SUCCESS) ;
01943     }
01944     // =======================================================================
01961     template <class TYPE,unsigned int DIM>
01962     StatusCode array
01963     ( const std::string&                   name ,
01964       const ROOT::Math::SVector<TYPE,DIM>& vect )
01965     {
01966       return this->array( name , vect.begin() , vect.end() ) ;
01967     }
01968     // =======================================================================
01977     template <class TYPE,unsigned int D1,unsigned int D2,class REP>
01978     StatusCode matrix
01979     ( const std::string&                         name ,
01980       const ROOT::Math::SMatrix<TYPE,D1,D2,REP>& mtrx )
01981     {
01982       if ( invalid () ) { return InvalidTuple     ; }
01983       if ( rowWise () ) { return InvalidOperation ; }
01984 
01985       // get the matrix itself
01986       FMatrix* var  = fMatrix ( name , (MIndex)D1 , (MIndex)D2 ) ;
01987       if ( 0 == var   ) { return InvalidColumn ; }
01988 
01990       for ( size_t iCol = 0 ; iCol < D2 ; ++iCol )
01991       {
01992         for ( size_t iRow = 0 ; iRow < D1 ; ++iRow )
01993         { (*var)[iRow][iCol] = (float) mtrx(iRow,iCol) ; }
01994       };
01995 
01996       return StatusCode::SUCCESS ;
01997     }
01998     // =======================================================================
02016     template <class KEY, class VALUE>
02017     StatusCode fmatrix
02018     ( const std::string&                      name       ,
02019       const GaudiUtils::VectorMap<KEY,VALUE>& info       ,
02020       const std::string&                      length     ,
02021       const size_t                            maxv = 100 )
02022     {
02023 
02024       if ( invalid () ) { return InvalidTuple     ; }
02025       if ( rowWise () ) { return InvalidOperation ; }
02026 
02027       typename GaudiUtils::VectorMap<KEY,VALUE>::const_iterator begin = info.begin () ;
02028       typename GaudiUtils::VectorMap<KEY,VALUE>::const_iterator end   = info.end   () ;
02029 
02030       // adjust the length
02031       if ( maxv < info.size() )
02032       {
02033         Warning("fmatrix('"+name+"'): matrix is overflow, skip extra items") ;
02034         end = begin + maxv ;
02035       } ;
02036 
02037       // get the length item
02038       Int* len  = ints( length , 0 , maxv ) ;
02039       if ( 0 == len  ) { return InvalidColumn; }
02040 
02041       // adjust the length item
02042       *len = end - begin ;
02043 
02044       // get the array itself
02045       FMatrix* var  = fMatrix ( name , len , 2 ) ;
02046       if ( 0 == var ) { return InvalidColumn ; }
02047 
02049       size_t iRow = 0 ;
02050       for ( ; begin != end ; ++begin)
02051       {
02052         //
02053         (*var)[iRow][0] = (float) begin->first   ;
02054         (*var)[iRow][1] = (float) begin->second  ;
02055         //
02056         ++iRow ;
02057       } ;
02058 
02059       return StatusCode::SUCCESS ;
02060     }
02061     // =======================================================================
02062   public:
02063     // =======================================================================
02071     template <class TYPE>
02072     StatusCode put
02073     ( const std::string& name , const TYPE*  obj ) ;
02074     // =======================================================================
02075   public:
02076     // =======================================================================
02080     StatusCode write () ;
02081     // =======================================================================
02083     const std::string&  name() const { return m_name ; }
02084     // =======================================================================
02088     NTuple::Tuple* tuple() const  { return m_tuple ; }
02089     // =======================================================================
02093     unsigned long refCount() const { return   m_refCount ; }
02094     // =======================================================================
02098     unsigned long addRef  ()       { return ++m_refCount ; }
02099     // =======================================================================
02104     void          release () ;
02105     // =======================================================================
02107     const CLID&        clid() const { return m_clid ; }
02108     // =======================================================================
02110     Tuples::Type       type() const { return m_type ; }
02111     // =======================================================================
02113     bool columnWise() const { return CLID_ColumnWiseTuple == clid() ; }
02114     // =======================================================================
02116     bool rowWise   () const { return CLID_RowWiseTuple    == clid() ; }
02117     // =======================================================================
02119     bool evtColType() const { return Tuples::EVTCOL       == type()  ; }
02120     // =======================================================================
02122     bool valid     () const { return 0 != tuple() ; }
02123     // =======================================================================
02125     bool invalid   () const { return ! valid()    ; }
02126     // =======================================================================
02127   public:
02128     // =======================================================================
02134     bool addItem ( const std::string& name ,
02135                    const std::string& type )
02136     { return m_items.insert ( std::make_pair ( name , type ) ).second ; }
02137     // =======================================================================
02142     bool goodItem  ( const std::string& name ) const
02143     { return m_items.end() == m_items.find ( name ) ; }
02144     // =======================================================================
02146     const ItemMap& items() const { return m_items ; }
02147     // =======================================================================
02148   public:
02149     // =======================================================================
02150     virtual StatusCode Error
02151     ( const std::string& msg ,
02152       const StatusCode   sc  = StatusCode::FAILURE ) const = 0 ;
02153     // =======================================================================
02154     virtual StatusCode Warning
02155     ( const std::string& msg ,
02156       const StatusCode   sc  = StatusCode::FAILURE ) const = 0 ;
02157     // =======================================================================
02158   private:
02159     // =======================================================================
02161     Bool*    bools      ( const std::string& name ) ;
02162     // =======================================================================
02164     Float*   floats     ( const std::string& name ) ;
02165     // =======================================================================
02167     Double*  doubles    ( const std::string& name ) ;
02168     // =======================================================================
02170     Char*   chars     ( const std::string& name ) ;
02171     // =======================================================================
02173     Char*   chars     ( const std::string& name ,
02174                         const char         minv ,
02175                         const char         maxv ) ;
02176     // =======================================================================
02178     UChar*  uchars    ( const std::string& name ) ;
02179     // =======================================================================
02181     UChar*  uchars    ( const std::string&  name ,
02182                         const unsigned char minv ,
02183                         const unsigned char maxv ) ;
02184     // =======================================================================
02186     Short*   shorts     ( const std::string& name ) ;
02187     // =======================================================================
02189     Short*   shorts     ( const std::string& name ,
02190                           const short        minv ,
02191                           const short        maxv ) ;
02192     // =======================================================================
02194     UShort*   ushorts   ( const std::string& name ) ;
02195     // =======================================================================
02197     UShort*   ushorts   ( const std::string& name ,
02198                           const unsigned short minv ,
02199                           const unsigned short maxv ) ;
02200     // =======================================================================
02202     Int*     ints       ( const std::string& name ) ;
02203     // =======================================================================
02205     Int*     ints       ( const std::string& name ,
02206                           const int          minv ,
02207                           const int          maxv ) ;
02208     // =======================================================================
02210     UInt*     uints     ( const std::string& name ) ;
02211     // =======================================================================
02213     UInt*     uints     ( const std::string& name ,
02214                           const unsigned int minv ,
02215                           const unsigned int maxv ) ;
02216     // =======================================================================
02218     LongLong* longlongs ( const std::string& name );
02219     // =======================================================================
02221     LongLong* longlongs ( const std::string& name ,
02222                           const long long    minv ,
02223                           const long long    maxv ) ;
02224     // =======================================================================
02226     ULongLong* ulonglongs ( const std::string& name ) ;
02227     // =======================================================================
02229     ULongLong* ulonglongs ( const std::string&       name ,
02230                             const unsigned long long minv ,
02231                             const unsigned long long maxv ) ;
02232     // =======================================================================
02234     FArray*  fArray     ( const std::string& name ,
02235                           Int*               item ) ;
02236     // =======================================================================
02238     FArray*  fArray     ( const std::string& name ,
02239                           const MIndex&      rows ) ;
02240     // =======================================================================
02242     Address* addresses  ( const std::string& name ) ;
02243     // =======================================================================
02245     FMatrix* fMatrix    ( const std::string& name ,
02246                           Int*               item ,
02247                           const MIndex&      cols ) ;
02248     // =======================================================================
02250     FMatrix* fMatrix    ( const std::string& name ,
02251                           const MIndex&      rows ,
02252                           const MIndex&      cols ) ;
02253     // =======================================================================
02254   private:
02255     // =======================================================================
02257     TupleObj () ;
02258     // =======================================================================
02260     TupleObj            ( const TupleObj& ) ;
02261     // =======================================================================
02263     TupleObj& operator= ( const TupleObj& ) ;
02264     // =======================================================================
02265   private:
02266     // =======================================================================
02268     typedef GaudiUtils::HashMap<std::string,Bool*>   Bools;
02269     // =======================================================================
02271     typedef GaudiUtils::HashMap<std::string,Char*>   Chars;
02272     // =======================================================================
02274     typedef GaudiUtils::HashMap<std::string,UChar*>  UChars;
02275     // =======================================================================
02277     typedef GaudiUtils::HashMap<std::string,Short*>  Shorts;
02278     // =======================================================================
02280     typedef GaudiUtils::HashMap<std::string,UShort*> UShorts;
02281     // =======================================================================
02283     typedef GaudiUtils::HashMap<std::string,Int*>    Ints;
02284     // =======================================================================
02286     typedef GaudiUtils::HashMap<std::string,UInt*>   UInts;
02287     // =======================================================================
02289     typedef GaudiUtils::HashMap<std::string,LongLong*> LongLongs;
02290     // =======================================================================
02292     typedef GaudiUtils::HashMap<std::string,ULongLong*> ULongLongs;
02293     // =======================================================================
02295     typedef GaudiUtils::HashMap<std::string,Float*>   Floats;
02296     // =======================================================================
02298     typedef GaudiUtils::HashMap<std::string,Double*>  Doubles;
02299     // =======================================================================
02301     typedef GaudiUtils::HashMap<std::string,Address*> Addresses;
02302     // =======================================================================
02304     typedef GaudiUtils::HashMap<std::string,FArray*>  FArrays;
02305     // =======================================================================
02307     typedef GaudiUtils::HashMap<std::string,FMatrix*> FMatrices;
02308     // =======================================================================
02309   private:
02310     // =======================================================================
02312     std::string            m_name       ;
02313     // =======================================================================
02315     NTuple::Tuple*         m_tuple      ;
02316     // =======================================================================
02318     CLID                   m_clid       ;
02319     // =======================================================================
02321     Tuples::Type           m_type       ;
02322     // =======================================================================
02324     size_t                 m_refCount   ;
02325     // =======================================================================
02327     mutable Bools          m_bools      ;
02328     // =======================================================================
02330     mutable Chars          m_chars      ;
02331     // =======================================================================
02333     mutable UChars         m_uchars     ;
02334     // =======================================================================
02336     mutable Shorts         m_shorts     ;
02337     // =======================================================================
02339     mutable UShorts        m_ushorts    ;
02340     // =======================================================================
02342     mutable Ints           m_ints       ;
02343     // =======================================================================
02345     mutable UInts          m_uints      ;
02346     // =======================================================================
02348     mutable LongLongs      m_longlongs  ;
02349     // =======================================================================
02351     mutable ULongLongs     m_ulonglongs ;
02352     // =======================================================================
02354     mutable Floats         m_floats     ;
02355     // =======================================================================
02357     mutable Doubles        m_doubles    ;
02358     // =======================================================================
02360     mutable Addresses      m_addresses  ;
02361     // =======================================================================
02363     mutable FArrays        m_farrays    ;
02364     // =======================================================================
02366     mutable FArrays        m_arraysf    ;
02367     // =======================================================================
02369     mutable FMatrices      m_fmatrices  ;
02370     // =======================================================================
02372     mutable FMatrices      m_matricesf  ;
02373     // =======================================================================
02375     ItemMap                m_items      ;
02376     // =======================================================================
02377   } ;
02378   // ==========================================================================
02379 } // end of namespace Tuples
02380 // ============================================================================
02381 // GaudiAlg
02382 // ============================================================================
02383 #include "GaudiAlg/TuplePut.h"
02384 // ============================================================================
02385 // The END
02386 // ============================================================================
02387 #endif // GAUDIALG_TUPLEOBJ_H
02388 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:15 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004