![]() |
|
|
Generated: 24 Nov 2008 |
00001 // $Id: TupleObj.h,v 1.23 2008/10/27 19:22:20 marcocle Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: v11r2 $, 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 TupleObj 00181 { 00182 public: 00183 // ======================================================================== 00187 typedef NTuple::Item<int> Int ; 00188 // ======================================================================== 00192 typedef NTuple::Item<float> Float ; 00193 // ======================================================================== 00195 typedef NTuple::Item<IOpaqueAddress*> Address ; 00196 // ======================================================================== 00198 typedef NTuple::Array<float> FArray ; 00199 // ======================================================================== 00201 typedef NTuple::Matrix<float> FMatrix ; 00202 // ======================================================================== 00203 // the actual type for variable size matrix indices 00204 typedef unsigned short MIndex ; 00205 // ======================================================================== 00206 // the map of items 00207 typedef std::map<std::string,std::string> ItemMap ; 00208 // ======================================================================== 00209 protected: 00210 // ======================================================================== 00218 TupleObj 00219 ( const std::string& name , 00220 NTuple::Tuple* tuple , 00221 const CLID& clid = CLID_ColumnWiseTuple , 00222 const Tuples::Type type = Tuples::NTUPLE ) ; 00223 // ======================================================================== 00224 protected: 00225 // ======================================================================== 00227 virtual ~TupleObj(); 00228 // ======================================================================== 00229 public: 00230 // ======================================================================== 00246 StatusCode column ( const std::string& name , 00247 const int value ) 00248 { 00249 if ( invalid() ) { return InvalidTuple ; } 00250 Int* item = ints( name ) ; 00251 if ( 0 == item ) { return InvalidColumn ; } 00252 *item = value ; 00253 return StatusCode::SUCCESS ; 00254 } 00255 // ======================================================================== 00273 StatusCode column ( const std::string& name , 00274 const int value , 00275 const int minv , 00276 const int maxv ) 00277 { 00278 if ( invalid() ) { return InvalidTuple ; } 00279 Int* item = ints ( name , minv , maxv ) ; 00280 if ( 0 == item ) { return InvalidColumn ; } 00281 *item = value ; 00282 return StatusCode::SUCCESS ; 00283 } 00284 // ======================================================================== 00285 public: 00286 // ======================================================================== 00302 StatusCode column ( const std::string& name , 00303 const unsigned int value ) 00304 { 00305 StatusCode sc1 = StatusCode::SUCCESS ; 00306 static const unsigned int s_max = std::numeric_limits<int>::max() ; 00307 if ( s_max < value ) 00308 { sc1 = Warning 00309 (" column('" + name + "'): truncate unsigned int" , TruncateValue ) ; } 00310 const int val = (int) value ; 00311 StatusCode sc2 = column ( name , val ) ; 00312 return sc2.isFailure() ? sc2 : sc1 ; 00313 } 00314 // ======================================================================== 00331 StatusCode column ( const std::string& name , 00332 const long value ) 00333 { 00334 StatusCode sc1 = StatusCode::SUCCESS ; 00335 if ( sizeof(int) != sizeof(long) 00336 && ( std::numeric_limits<int>::max() < value || 00337 std::numeric_limits<int>::min() > value ) ) 00338 { sc1 = Warning (" column('" + name + "'): truncate long value" , 00339 TruncateValue ) ; } 00340 const int val = (int) value ; 00341 StatusCode sc2 = column ( name , val ) ; 00342 return sc2.isFailure() ? sc2 : sc1 ; 00343 } 00344 // ======================================================================== 00361 StatusCode column ( const std::string& name , 00362 const unsigned long value ) 00363 { 00364 StatusCode sc1 = StatusCode::SUCCESS ; 00365 static const unsigned long s_max = std::numeric_limits<int>::max() ; 00366 if ( sizeof (int) != sizeof (unsigned long) && s_max < value ) 00367 { sc1 = Warning (" column('" + name + "'): truncate unsigned long value" , 00368 TruncateValue ) ; } 00369 const int val = (int) value ; 00370 StatusCode sc2 = column ( name , val ) ; 00371 return sc2.isFailure() ? sc2 : sc1 ; 00372 } 00373 // ======================================================================== 00389 StatusCode column ( const std::string& name , 00390 const short value ) 00391 { 00392 return column 00393 ( name , 00394 value , 00395 std::numeric_limits<short>::min() , 00396 std::numeric_limits<short>::max() ) ; 00397 } 00398 // ======================================================================== 00414 StatusCode column ( const std::string& name , 00415 const unsigned short value ) 00416 { 00417 return column 00418 ( name , 00419 value , 00420 std::numeric_limits<unsigned short>::min() , 00421 std::numeric_limits<unsigned short>::max() ) ; 00422 } 00423 // ======================================================================== 00439 StatusCode column ( const std::string& name , 00440 const char value ) 00441 { 00442 return column 00443 ( name , 00444 value , 00445 std::numeric_limits<char>::min() , 00446 std::numeric_limits<char>::max() ) ; 00447 } 00448 // ======================================================================== 00464 StatusCode column ( const std::string& name , 00465 const unsigned char value ) 00466 { 00467 return column 00468 ( name , 00469 value , 00470 std::numeric_limits<unsigned char>::min() , 00471 std::numeric_limits<unsigned char>::max() ) ; 00472 } 00473 // ======================================================================== 00489 StatusCode column ( const std::string& name , 00490 const signed char value ) 00491 { 00492 return column 00493 ( name , 00494 value , 00495 std::numeric_limits<signed char>::min() , 00496 std::numeric_limits<signed char>::max() ) ; 00497 } 00498 // ======================================================================== 00499 public: 00500 // ======================================================================== 00516 StatusCode column ( const std::string& name , 00517 const float value ) 00518 { 00519 if ( invalid() ) { return InvalidTuple ; } 00520 Float* item = floats ( name ) ; 00521 if ( 0 == item ) { return InvalidColumn ; } 00522 *item = value ; 00523 return StatusCode::SUCCESS ; 00524 } 00525 // ======================================================================== 00542 StatusCode column ( const std::string& name , 00543 const double value ) 00544 { 00545 StatusCode sc1 = StatusCode::SUCCESS ; 00546 static const double s_max = std::numeric_limits<float>::max() ; 00547 static const double s_min = -1 * std::numeric_limits<float>::max() ; 00548 if ( s_max < value || s_min > value ) 00549 { sc1 = Warning (" column('" + name + "'): truncate double value " , 00550 TruncateValue ) ; } 00551 const float val = (float) value ; 00552 StatusCode sc2 = column ( name , val ) ; 00553 return sc2.isFailure() ? sc2 : sc1 ; 00554 } 00555 // ======================================================================== 00570 StatusCode column ( const std::string& name , 00571 const bool value ) 00572 { 00573 const int val = value ; 00574 return column ( name , val , 0 , 1 ) ; 00575 } 00576 // ======================================================================== 00577 public: 00578 // ======================================================================== 00597 StatusCode column ( const std::string& name , 00598 IOpaqueAddress* address ) ; 00599 // ======================================================================== 00616 StatusCode column ( IOpaqueAddress* address ) ; 00617 // ======================================================================== 00618 public: 00619 // ======================================================================== 00643 StatusCode fill( const char* format ... ) ; 00644 // ======================================================================= 00645 public: 00646 // ======================================================================= 00695 template <class DATA> 00696 StatusCode farray ( const std::string& name , 00697 DATA first , 00698 DATA last , 00699 const std::string& length , 00700 const size_t maxv ) 00701 { 00702 if ( invalid () ) { return InvalidTuple ; } 00703 if ( rowWise () ) { return InvalidOperation ; } 00704 00705 // adjust the length 00706 if( first + maxv < last ) 00707 { 00708 Warning(" farray('"+name+"'): array is overflow, skip extra items") ; 00709 last = first + maxv ; 00710 }; 00711 00712 // get the length item 00713 Int* len = ints( length , 0 , maxv ) ; 00714 if( 0 == len ) { return InvalidColumn; } 00715 00716 // adjust the length item 00717 *len = last - first ; 00718 00719 // get the array itself 00720 FArray* var = fArray ( name , len ) ; 00721 if( 0 == var ) { return InvalidColumn ; } 00722 00724 size_t index = 0 ; 00725 for( ; first != last ; ++first ) 00726 { (*var)[ index ] = (float)(*first) ; ++index ; } 00727 00728 return StatusCode::SUCCESS ; 00729 } 00730 // ======================================================================= 00773 template <class DATA> 00774 StatusCode farray ( const std::string& name , 00775 const DATA& data , 00776 const std::string& length , 00777 const size_t maxv ) 00778 { return farray ( name , data.begin() , data.end() , length , maxv ) ; } 00779 // ======================================================================= 00842 template <class FUNCTION, class DATA> 00843 StatusCode farray ( const std::string& name , 00844 const FUNCTION& function , 00845 DATA first , 00846 DATA last , 00847 const std::string& length , 00848 const size_t maxv ) 00849 { 00850 if ( invalid () ) { return InvalidTuple ; } 00851 if ( rowWise () ) { return InvalidOperation ; } 00852 00853 // adjust the length 00854 if( first + maxv < last ) 00855 { 00856 Warning(" farray('" 00857 + name + "'): array is overflow, skip extra entries") ; 00858 last = first + maxv ; 00859 }; 00860 00861 // get the length item 00862 Int* len = ints( length , 0 , maxv ) ; 00863 if( 0 == len ) { return InvalidColumn ; } 00864 00865 // adjust the length 00866 *len = last - first ; 00867 00868 // get the array itself 00869 FArray* var = fArray ( name , len ) ; 00870 if( 0 == var ) { return InvalidColumn ; } 00871 00872 // fill the array 00873 size_t index = 0 ; 00874 for( ; first != last ; ++first ) 00875 { (*var)[ index ] = function( *first ) ; ++index ; } 00876 00877 return StatusCode::SUCCESS ; 00878 } 00879 // ======================================================================= 00911 template <class FUNC1, class FUNC2, class DATA> 00912 StatusCode farray ( const std::string& name1 , 00913 const FUNC1& func1 , 00914 const std::string& name2 , 00915 const FUNC2& func2 , 00916 DATA first , 00917 DATA last , 00918 const std::string& length , 00919 const size_t maxv ) 00920 { 00921 if ( invalid () ) { return InvalidTuple ; } 00922 if ( rowWise () ) { return InvalidOperation ; } 00923 00924 // adjust the lenfth 00925 if( first + maxv < last ) 00926 { 00927 Warning(" farray('" 00928 + name1 + "," 00929 + name2 + "'): array is overflow, skip extra entries") ; 00930 Warning(" farray('"+name1+"'): array is overflow, skip extra items") ; 00931 last = first + maxv ; 00932 }; 00933 00934 // get the length item 00935 Int* len = ints ( length , 0 , maxv ) ; 00936 if ( 0 == len ) { return InvalidColumn ; } 00937 00938 // adjust the length 00939 *len = last - first ; 00940 00941 // get the array itself 00942 FArray* var1 = fArray ( name1 , len ) ; 00943 if ( 0 == var1 ) { return InvalidColumn ; } 00944 00945 // get the array itself 00946 FArray* var2 = fArray ( name2 , len ) ; 00947 if ( 0 == var2 ) { return InvalidColumn ; } 00948 00949 // fill the array 00950 size_t index = 0 ; 00951 for( ; first != last ; ++first ) 00952 { 00953 ( *var1 ) [ index ] = func1 ( *first ) ; 00954 ( *var2 ) [ index ] = func2 ( *first ) ; 00955 ++index ; 00956 } 00957 00958 return StatusCode::SUCCESS ; 00959 } 00960 // ======================================================================= 00997 template <class FUNC1, class FUNC2, class FUNC3, class DATA> 00998 StatusCode farray ( const std::string& name1 , 00999 const FUNC1& func1 , 01000 const std::string& name2 , 01001 const FUNC2& func2 , 01002 const std::string& name3 , 01003 const FUNC3& func3 , 01004 DATA first , 01005 DATA last , 01006 const std::string& length , 01007 const size_t maxv ) 01008 { 01009 if ( invalid () ) { return InvalidTuple ; } 01010 if ( rowWise () ) { return InvalidOperation ; } 01011 01012 // adjust the lenfth 01013 if( first + maxv < last ) 01014 { 01015 Warning(" farray('" 01016 + name1 + "," 01017 + name2 + "," 01018 + name3 + "'): array is overflow, skip extra entries") ; 01019 last = first + maxv ; 01020 }; 01021 01022 // get the length item 01023 Int* len = ints ( length , 0 , maxv ) ; 01024 if( 0 == len ) { return InvalidColumn ; } 01025 01026 // adjust the length 01027 *len = last - first ; 01028 01029 // get the array itself 01030 FArray* var1 = fArray ( name1 , len ) ; 01031 if( 0 == var1 ) { return InvalidColumn ; } 01032 01033 // get the array itself 01034 FArray* var2 = fArray ( name2 , len ) ; 01035 if( 0 == var2 ) { return InvalidColumn ; } 01036 01037 // get the array itself 01038 FArray* var3 = fArray ( name3 , len ) ; 01039 if( 0 == var3 ) { return InvalidColumn ; } 01040 01041 // fill the array 01042 size_t index = 0 ; 01043 for( ; first != last ; ++first ) 01044 { 01045 ( *var1 ) [ index ] = (float)func1 ( *first ) ; 01046 ( *var2 ) [ index ] = (float)func2 ( *first ) ; 01047 ( *var3 ) [ index ] = (float)func3 ( *first ) ; 01048 ++index ; 01049 } 01050 return StatusCode::SUCCESS ; 01051 } 01052 // ======================================================================= 01092 template <class FUNC1, class FUNC2, class FUNC3, class FUNC4, class DATA> 01093 StatusCode farray ( const std::string& name1 , 01094 const FUNC1& func1 , 01095 const std::string& name2 , 01096 const FUNC2& func2 , 01097 const std::string& name3 , 01098 const FUNC3& func3 , 01099 const std::string& name4 , 01100 const FUNC4& func4 , 01101 DATA first , 01102 DATA last , 01103 const std::string& length , 01104 const size_t maxv ) 01105 { 01106 if ( invalid () ) { return InvalidTuple ; } 01107 if ( rowWise () ) { return InvalidOperation ; } 01108 01109 // adjust the lenfth 01110 if( first + maxv < last ) 01111 { 01112 Warning(" farray('" 01113 + name1 + "," 01114 + name2 + "," 01115 + name3 + "," 01116 + name4 + "'): array is overflow, skip extra entries") ; 01117 last = first + maxv ; 01118 }; 01119 01120 // get the length item 01121 Int* len = ints ( length , 0 , maxv ) ; 01122 if( 0 == len ) { return InvalidColumn ; } 01123 01124 // adjust the length 01125 *len = last - first ; 01126 01127 // get the array itself 01128 FArray* var1 = fArray ( name1 , len ) ; 01129 if( 0 == var1 ) { return InvalidColumn ; } 01130 01131 // get the array itself 01132 FArray* var2 = fArray ( name2 , len ) ; 01133 if( 0 == var2 ) { return InvalidColumn ; } 01134 01135 // get the array itself 01136 FArray* var3 = fArray ( name3 , len ) ; 01137 if( 0 == var3 ) { return InvalidColumn ; } 01138 01139 // get the array itself 01140 FArray* var4 = fArray ( name4 , len ) ; 01141 if( 0 == var4 ) { return InvalidColumn ; } 01142 01143 // fill the array 01144 size_t index = 0 ; 01145 for( ; first != last ; ++first ) 01146 { 01147 ( *var1 ) [ index ] = static_cast<float> ( func1 ( *first ) ); 01148 ( *var2 ) [ index ] = static_cast<float> ( func2 ( *first ) ); 01149 ( *var3 ) [ index ] = static_cast<float> ( func3 ( *first ) ); 01150 ( *var4 ) [ index ] = static_cast<float> ( func4 ( *first ) ); 01151 ++index ; 01152 } 01153 01154 return StatusCode::SUCCESS ; 01155 } 01156 // ======================================================================= 01157 public: 01158 // ======================================================================= 01209 template <class MATRIX> 01210 StatusCode fmatrix ( const std::string& name , 01211 const MATRIX& data , 01212 size_t rows , 01213 const MIndex& cols , 01214 const std::string& length , 01215 const size_t maxv ) 01216 { 01217 if ( invalid () ) { return InvalidTuple ; } 01218 if ( rowWise () ) { return InvalidOperation ; } 01219 01220 // adjust the length 01221 if ( rows >= maxv ) 01222 { 01223 Warning ( " fmatrix('"+name+"'): matrix is overflow, skip extra items") ; 01224 rows = ( 0 < maxv ) ? ( maxv - 1 ) : 0 ; 01225 }; 01226 01227 // get the length item 01228 Int* len = ints( length , 0 , maxv ) ; 01229 if ( 0 == len ) { return InvalidColumn; } 01230 01231 // adjust the length item 01232 *len = rows ; 01233 01234 // get the array itself 01235 FMatrix* var = fMatrix ( name , len , cols ) ; 01236 if ( 0 == var ) { return InvalidColumn ; } 01237 01239 for ( size_t iCol = 0 ; iCol < cols ; ++iCol ) 01240 { 01241 for ( MIndex iRow = 0 ; iRow < rows ; ++iRow ) 01242 { (*var)[ iRow ] [ iCol ] = (float)(data[ iRow ][ iCol ]) ; } 01243 }; 01244 01245 return StatusCode::SUCCESS ; 01246 } 01247 // ======================================================================= 01284 template <class DATA> 01285 StatusCode fmatrix ( const std::string& name , 01286 DATA first , 01287 DATA last , 01288 const MIndex& cols , 01289 const std::string& length , 01290 const size_t maxv ) 01291 { 01292 if ( invalid () ) { return InvalidTuple ; } 01293 if ( rowWise () ) { return InvalidOperation ; } 01294 01295 // adjust the length 01296 if ( first + maxv < last ) 01297 { 01298 Warning(" fmatrix('"+name+"'): matrix is overflow, skip extra items") ; 01299 last = first + maxv ; 01300 }; 01301 01302 // get the length item 01303 Int* len = ints( length , 0 , maxv ) ; 01304 if ( 0 == len ) { return InvalidColumn; } 01305 01306 // adjust the length item 01307 *len = last - first ; 01308 01309 // get the array itself 01310 FMatrix* var = fMatrix ( name , len , cols ) ; 01311 if ( 0 == var ) { return InvalidColumn ; } 01312 01314 size_t iRow = 0 ; 01315 for ( ; first != last ; ++first ) 01316 { 01317 // 01318 for ( MIndex iCol = 0 ; iCol < cols ; ++iCol ) 01319 { (*var)[ iRow ] [ iCol ] = (float)((*first)[ iCol ]) ; } 01320 // 01321 ++iRow ; 01322 }; 01323 01324 return StatusCode::SUCCESS ; 01325 } 01326 // ======================================================================= 01405 template <class FUN,class DATA> 01406 StatusCode fmatrix ( const std::string& name , 01407 FUN funF , 01408 FUN funL , 01409 DATA first , 01410 DATA last , 01411 const std::string& length , 01412 const size_t maxv ) 01413 { 01414 if ( invalid () ) { return InvalidTuple ; } 01415 if ( rowWise () ) { return InvalidOperation ; } 01416 01417 // adjust the length 01418 if ( first + maxv < last ) 01419 { 01420 Warning(" fmatrix('"+name+"'): matrix is overflow, skip extra items") ; 01421 last = first + maxv ; 01422 }; 01423 01424 // get the length item 01425 Int* len = ints( length , 0 , maxv ) ; 01426 if ( 0 == len ) { return InvalidColumn; } 01427 01428 // adjust the length item 01429 *len = last - first ; 01430 01431 // get the array itself 01432 const size_t cols = funL - funF ; 01433 FMatrix* var = fMatrix ( name , len , cols ) ; 01434 if ( 0 == var ) { return InvalidColumn ; } 01435 01437 size_t iRow = 0 ; 01438 for ( ; first != last ; ++first ) 01439 { 01440 // 01441 for ( FUN fun = funF ; fun < funL ; ++fun ) 01442 { (*var)[ iRow ] [ fun - funF ] = (float)((*fun) ( *first )) ; } 01443 // 01444 ++iRow; 01445 }; 01446 01447 return StatusCode::SUCCESS ; 01448 } 01449 // ======================================================================= 01450 public: 01451 // ======================================================================= 01474 template <class DATA> 01475 StatusCode array ( const std::string& name , 01476 DATA first , 01477 DATA last ) 01478 01479 { 01480 if ( invalid () ) { return InvalidTuple ; } 01481 if ( rowWise () ) { return InvalidOperation ; } 01482 01483 // get the length (fixed!) 01484 const size_t length = last - first ; 01485 01486 // get the array itself 01487 FArray* var = fArray ( name , length ) ; 01488 if ( 0 == var ) { return InvalidColumn ; } 01489 01491 size_t iCol = 0 ; 01492 for ( ; first != last ; ++first ) 01493 { (*var)[ iCol ] = (float)(*first) ; ++iCol ; } 01494 01495 return StatusCode::SUCCESS ; 01496 } 01497 // ======================================================================= 01536 template <class ARRAY> 01537 StatusCode array ( const std::string& name , 01538 const ARRAY& data , 01539 const MIndex& length ) 01540 { 01541 if ( invalid () ) { return InvalidTuple ; } 01542 if ( rowWise () ) { return InvalidOperation ; } 01543 01544 // get the array itself 01545 FArray* var = fArray ( name , length ) ; 01546 if ( 0 == var ) { return InvalidColumn ; } 01547 01549 for ( size_t index = 0 ; index < length ; ++index ) 01550 { (*var)[ index ] = (float) data[index] ; } 01551 01552 return StatusCode::SUCCESS ; 01553 } 01554 // ======================================================================= 01584 template <class ARRAY> 01585 StatusCode array ( const std::string& name , 01586 const ARRAY& data ) 01587 { return array ( name , data.begin() , data.end() ) ; } 01588 // ======================================================================= 01589 public: 01590 // ======================================================================= 01639 template <class MATRIX> 01640 StatusCode matrix ( const std::string& name , 01641 const MATRIX& data , 01642 const MIndex& rows , 01643 const MIndex& cols ) 01644 { 01645 if ( invalid () ) { return InvalidTuple ; } 01646 if ( rowWise () ) { return InvalidOperation ; } 01647 01648 // get the matrix itself 01649 FMatrix* var = fMatrix ( name , rows , cols ) ; 01650 if ( 0 == var ) { return InvalidColumn ; } 01651 01653 for ( size_t iCol = 0 ; iCol < cols ; ++iCol ) 01654 { 01655 for ( size_t iRow = 0 ; iRow < rows ; ++iRow ) 01656 { (*var)[iRow][iCol] = (float)(data[iRow][iCol]) ; } 01657 }; 01658 return StatusCode::SUCCESS ; 01659 } 01660 // ======================================================================= 01661 public: 01662 // ======================================================================= 01679 template <class TYPE> 01680 StatusCode column 01681 ( const std::string& name , 01682 const ROOT::Math::LorentzVector<TYPE>& v ) 01683 { 01684 if ( invalid() ) { return InvalidTuple ; } 01685 // fill all separate columns: 01686 StatusCode sc1 = this -> column ( name + "E" , v.E () ) ; 01687 StatusCode sc2 = this -> column ( name + "X" , v.Px () ) ; 01688 StatusCode sc3 = this -> column ( name + "Y" , v.Py () ) ; 01689 StatusCode sc4 = this -> column ( name + "Z" , v.Pz () ) ; 01690 return 01691 sc1.isFailure () ? sc1 : 01692 sc2.isFailure () ? sc2 : 01693 sc3.isFailure () ? sc3 : 01694 sc4.isFailure () ? sc4 : StatusCode(StatusCode::SUCCESS) ; 01695 } 01696 // ======================================================================= 01713 template <class TYPE,class TAG> 01714 StatusCode column 01715 ( const std::string& name , 01716 const ROOT::Math::DisplacementVector3D<TYPE,TAG>& v ) 01717 { 01718 if ( invalid() ) { return InvalidTuple ; } 01720 StatusCode sc1 = this -> column ( name + "X" , v.X () ) ; 01721 StatusCode sc2 = this -> column ( name + "Y" , v.Y () ) ; 01722 StatusCode sc3 = this -> column ( name + "Z" , v.Z () ) ; 01723 return 01724 sc1.isFailure () ? sc1 : 01725 sc2.isFailure () ? sc2 : 01726 sc3.isFailure () ? sc3 : StatusCode(StatusCode::SUCCESS) ; 01727 } 01728 // ======================================================================= 01745 template <class TYPE,class TAG> 01746 StatusCode column 01747 ( const std::string& name , 01748 const ROOT::Math::PositionVector3D<TYPE,TAG>& v ) 01749 { 01750 if ( invalid() ) { return InvalidTuple ; } 01752 StatusCode sc1 = this -> column ( name + "X" , v.X () ) ; 01753 StatusCode sc2 = this -> column ( name + "Y" , v.Y () ) ; 01754 StatusCode sc3 = this -> column ( name + "Z" , v.Z () ) ; 01755 return 01756 sc1.isFailure () ? sc1 : 01757 sc2.isFailure () ? sc2 : 01758 sc3.isFailure () ? sc3 : StatusCode(StatusCode::SUCCESS) ; 01759 } 01760 // ======================================================================= 01777 template <class TYPE,unsigned int DIM> 01778 StatusCode array 01779 ( const std::string& name , 01780 const ROOT::Math::SVector<TYPE,DIM>& vect ) 01781 { 01782 return this->array( name , vect.begin() , vect.end() ) ; 01783 } 01784 // ======================================================================= 01793 template <class TYPE,unsigned int D1,unsigned int D2,class REP> 01794 StatusCode matrix 01795 ( const std::string& name , 01796 const ROOT::Math::SMatrix<TYPE,D1,D2,REP>& mtrx ) 01797 { 01798 if ( invalid () ) { return InvalidTuple ; } 01799 if ( rowWise () ) { return InvalidOperation ; } 01800 01801 // get the matrix itself 01802 FMatrix* var = fMatrix ( name , D1 , D2 ) ; 01803 if ( 0 == var ) { return InvalidColumn ; } 01804 01806 for ( size_t iCol = 0 ; iCol < D2 ; ++iCol ) 01807 { 01808 for ( size_t iRow = 0 ; iRow < D1 ; ++iRow ) 01809 { (*var)[iRow][iCol] = (float) mtrx(iRow,iCol) ; } 01810 }; 01811 01812 return StatusCode::SUCCESS ; 01813 } 01814 // ======================================================================= 01832 template <class KEY, class VALUE> 01833 StatusCode fmatrix 01834 ( const std::string& name , 01835 const GaudiUtils::VectorMap<KEY,VALUE>& info , 01836 const std::string& length , 01837 const size_t maxv = 100 ) 01838 { 01839 01840 if ( invalid () ) { return InvalidTuple ; } 01841 if ( rowWise () ) { return InvalidOperation ; } 01842 01843 typename GaudiUtils::VectorMap<KEY,VALUE>::const_iterator begin = info.begin () ; 01844 typename GaudiUtils::VectorMap<KEY,VALUE>::const_iterator end = info.end () ; 01845 01846 // adjust the length 01847 if ( maxv < info.size() ) 01848 { 01849 Warning(" fmatrix('"+name+"'): matrix is overflow, skip extra items") ; 01850 end = begin + maxv ; 01851 } ; 01852 01853 // get the length item 01854 Int* len = ints( length , 0 , maxv ) ; 01855 if ( 0 == len ) { return InvalidColumn; } 01856 01857 // adjust the length item 01858 *len = end - begin ; 01859 01860 // get the array itself 01861 FMatrix* var = fMatrix ( name , len , 2 ) ; 01862 if ( 0 == var ) { return InvalidColumn ; } 01863 01865 size_t iRow = 0 ; 01866 for ( ; begin != end ; ++begin) 01867 { 01868 // 01869 (*var)[iRow][0] = (float) begin->first ; 01870 (*var)[iRow][1] = (float) begin->second ; 01871 // 01872 ++iRow ; 01873 } ; 01874 01875 return StatusCode::SUCCESS ; 01876 } 01877 // ======================================================================= 01878 public: 01879 // ======================================================================= 01887 template <class TYPE> 01888 StatusCode put 01889 ( const std::string& name , const TYPE* obj ) ; 01890 // ======================================================================= 01891 public: 01892 // ======================================================================= 01896 StatusCode write () ; 01897 // ======================================================================= 01899 const std::string& name() const { return m_name ; } 01900 // ======================================================================= 01904 NTuple::Tuple* tuple() const { return m_tuple ; } 01905 // ======================================================================= 01909 unsigned long refCount() const { return m_refCount ; } 01910 // ======================================================================= 01914 unsigned long addRef () { return ++m_refCount ; } 01915 // ======================================================================= 01920 void release () ; 01921 // ======================================================================= 01923 const CLID& clid() const { return m_clid ; } 01924 // ======================================================================= 01926 Tuples::Type type() const { return m_type ; } 01927 // ======================================================================= 01929 bool columnWise() const { return CLID_ColumnWiseTuple == clid() ; } 01930 // ======================================================================= 01932 bool rowWise () const { return CLID_RowWiseTuple == clid() ; } 01933 // ======================================================================= 01935 bool evtColType() const { return Tuples::EVTCOL == type() ; } 01936 // ======================================================================= 01938 bool valid () const { return 0 != tuple() ; } 01939 // ======================================================================= 01941 bool invalid () const { return 0 == tuple() ; } 01942 // ======================================================================= 01943 public: 01944 // ======================================================================= 01950 bool addItem ( const std::string& name , 01951 const std::string& type ) 01952 { return m_items.insert ( std::make_pair ( name , type ) ).second ; } 01953 // ======================================================================= 01958 bool goodItem ( const std::string& name ) const 01959 { return m_items.end() == m_items.find ( name ) ; } 01960 // ======================================================================= 01962 const ItemMap& items() const { return m_items ; } 01963 // ======================================================================= 01964 public: 01965 // ======================================================================= 01966 virtual StatusCode Error 01967 ( const std::string& msg , 01968 const StatusCode sc = StatusCode::FAILURE ) const = 0 ; 01969 // ======================================================================= 01970 virtual StatusCode Warning 01971 ( const std::string& msg , 01972 const StatusCode sc = StatusCode::FAILURE ) const = 0 ; 01973 // ======================================================================= 01974 private: 01975 // ======================================================================= 01977 Float* floats ( const std::string& name ); 01978 // ======================================================================= 01980 Int* ints ( const std::string& name ); 01981 // ======================================================================= 01983 Int* ints ( const std::string& name , 01984 const int minv , 01985 const int maxv ) ; 01986 // ======================================================================= 01988 FArray* fArray ( const std::string& name , 01989 Int* item ) ; 01990 // ======================================================================= 01992 FArray* fArray ( const std::string& name , 01993 const MIndex& rows ) ; 01994 // ======================================================================= 01996 Address* addresses ( const std::string& name ) ; 01997 // ======================================================================= 01999 FMatrix* fMatrix ( const std::string& name , 02000 Int* item , 02001 const MIndex& cols ) ; 02002 // ======================================================================= 02004 FMatrix* fMatrix ( const std::string& name , 02005 const MIndex& rows , 02006 const MIndex& cols ) ; 02007 // ======================================================================= 02008 private: 02009 // ======================================================================= 02011 TupleObj () ; 02012 // ======================================================================= 02014 TupleObj ( const TupleObj& ) ; 02015 // ======================================================================= 02017 TupleObj& operator= ( const TupleObj& ) ; 02018 // ======================================================================= 02019 private: 02020 // ======================================================================= 02022 typedef GaudiUtils::HashMap<std::string,Int*> Ints; 02023 // ======================================================================= 02025 typedef GaudiUtils::HashMap<std::string,Float*> Floats; 02026 // ======================================================================= 02028 typedef GaudiUtils::HashMap<std::string,Address*> Addresses; 02029 // ======================================================================= 02031 typedef GaudiUtils::HashMap<std::string,FArray*> FArrays; 02032 // ======================================================================= 02034 typedef GaudiUtils::HashMap<std::string,FMatrix*> FMatrices; 02035 // ======================================================================= 02036 private: 02037 // ======================================================================= 02038 // name 02039 std::string m_name ; 02040 // ======================================================================= 02041 // tuple itself 02042 NTuple::Tuple* m_tuple ; 02043 // ======================================================================= 02044 // tuple CLID 02045 CLID m_clid ; 02046 // ======================================================================= 02047 // tuple 'type' 02048 Tuples::Type m_type ; 02049 // ======================================================================= 02050 // reference counter 02051 size_t m_refCount ; 02052 // ======================================================================= 02053 // the actual storage of all 'Int' columns 02054 mutable Ints m_ints ; 02055 // ======================================================================= 02056 // the actual storage of all 'Float' columns 02057 mutable Floats m_floats ; 02058 // ======================================================================= 02059 // the actual storage of all 'Address' columns 02060 mutable Addresses m_addresses ; 02061 // ======================================================================= 02062 // the actual storage of all 'FArray' columns 02063 mutable FArrays m_farrays ; 02064 // ======================================================================= 02065 // the actual storage of all 'FArray' columns (fixed) 02066 mutable FArrays m_arraysf ; 02067 // ======================================================================= 02068 // the actual storage of all 'FArray' columns 02069 mutable FMatrices m_fmatrices ; 02070 // ======================================================================= 02071 // the actual storage of all 'FMatrix' columns (fixed) 02072 mutable FMatrices m_matricesf ; 02073 // ======================================================================= 02074 // all booked types: 02075 ItemMap m_items ; 02076 // ======================================================================= 02077 } ; 02078 // ========================================================================== 02079 } // end of namespace Tuples 02080 // ============================================================================ 02081 // GaudiAlg 02082 // ============================================================================ 02083 #include "GaudiAlg/TuplePut.h" 02084 // ============================================================================ 02085 // The END 02086 // ============================================================================ 02087 #endif // GAUDIALG_TUPLEOBJ_H 02088 // ============================================================================