Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/BdbEventStore/BdbAbsCollectionT.cc

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: BdbAbsCollectionT.cc,v 1.5 2002/06/18 05:34:52 becla Exp $
00004 //
00005 // Description:
00006 //      Class BdbAbsCollectionT interface (.cc) file. This file declares the 
00007 //      abstract templated collection class.
00008 //
00009 // Environment:
00010 //      Software developed for the BaBar Detector at the SLAC B-Factory
00011 //
00012 // Author List:
00013 //      David R. Quarrie        Original Author (source in BdbAbsCollection)
00014 //      Jacek Becla             Modified to break dependency between Event Store
00015 //                              and BdbEvent
00016 //
00017 // Copyright Information:
00018 //      Copyright (C) 2002      Stanford Linear Accelerator Center
00019 //
00020 //------------------------------------------------------------------------------
00021 
00022 extern "C" {
00023 #include <assert.h>
00024 }
00025 
00026 //-------------------------------
00027 // Collaborating Class Headers --
00028 //-------------------------------
00029 #include "BdbEventStore/BdbEventStoreErrors.hh"
00030 #include "BdbEventStore/BdbEventStore.hh"
00031 #include "BdbApplication/BdbDomain.hh"
00032 #include "BdbTrees/BdbGenericHdr.hh"
00033 #include "BdbTrees/BdbTreeNode.hh"
00034 #include "BdbTrees/BdbMetaData.hh"
00035 
00036 
00037 //              ----------------------------------------
00038 //              -- Public Function Member Definitions --
00039 //              ----------------------------------------
00040 
00041 //------------------
00042 // Constructor(s) --
00043 //------------------
00044 
00045 template < class T > 
00046 BdbAbsCollectionT<T>::BdbAbsCollectionT( )
00047 : BdbAbsWrapper ( ),
00048   _descrOverride( 0 )
00049 {
00050 }
00051 
00052 template < class T > 
00053 BdbAbsCollectionT<T>::BdbAbsCollectionT( const BdbAbsCollectionT<T>& theOther )
00054 : BdbAbsWrapper( ),
00055   _descrOverride( 0 )
00056 {
00057     BdbHandle(BdbCollectionP) self = theOther.persistent( );
00058     setPersistent   ( self );
00059     setDescrOverride( theOther.descrOverride( ) );
00060 }
00061 
00062 //--------------
00063 // Destructor --
00064 //--------------
00065 
00066 template < class T > 
00067 BdbAbsCollectionT<T>::~BdbAbsCollectionT( )
00068 {
00069    delete _descrOverride;
00070 }
00071 
00072 //-------------
00073 // Selectors --
00074 //-------------
00075     
00076 template < class T > 
00077 const char*
00078 BdbAbsCollectionT<T>::name( ) const
00079 {
00080     return persistent( )->name( );
00081 }
00082 
00083 template < class T > 
00084 const char*
00085 BdbAbsCollectionT<T>::pathName( ) const
00086 {
00087     return persistent( )->pathName( );
00088 }
00089 
00090 template < class T > 
00091 d_ULong
00092 BdbAbsCollectionT<T>::collections( ) const
00093 {
00094     return persistent( )->collections( );
00095 }
00096 
00097 template < class T >
00098 d_ULong
00099 BdbAbsCollectionT<T>::size( ) const
00100 {
00101     return persistent( )->size( );
00102 }
00103 
00104 template < class T >
00105 d_ULong
00106 BdbAbsCollectionT<T>::ownedSize( ) const
00107 {
00108     return persistent( )->ownedSize( );
00109 }
00110 
00111 //--------------
00112 // Operations --
00113 //--------------
00114     
00115 template < class T > 
00116 BdbStatus
00117 BdbAbsCollectionT<T>::upgradeName( )
00118 {
00119     return persistent( )->upgradeName( );
00120 }
00121 
00122 template < class T > 
00123 BdbStatus 
00124 BdbAbsCollectionT<T>::add( T& anItem ) 
00125 {
00126     BdbEventStore* theEvs = BdbEventStore::instance( );
00127     BdbHandle(BdbCollectionP) self = persistent( );
00128     BdbHandle(BdbCollectionP) comp = component( );
00129     BdbStatus result;
00130 
00131     // Lock the collection for sole access. Note that we 
00132     // need to lock a component collection rather than the
00133     // collection itself if the concrete representation is
00134     // as a TreeCollection. Hence the use of the component( )
00135     // rather than persistent( ).
00136     result = theEvs->updateAndWait( comp, 
00137         BdbDomain::DomainNames[BdbDomain::Events] );
00138     if ( BdbcSuccess == result ) {
00139         BdbRefAny aRef = anItem.getPersistent();
00140         BdbHandleAny aH = aRef;
00141         result = self->add( aH );
00142     } else {
00143         BdbSignal( BdbcUserError, BdbEventStoreErrUnableToUpdate, 0, 
00144                    "BdbAbsCollectionT<T>::add", name( ) ); 
00145     }
00146     if ( (anItem.getPersistent())->ooIsKindOf( ooTypeN( BdbGenericHdr ) ) ) {
00147         BdbRef(BdbGenericHdr) theHdrRef = (BdbRef(BdbGenericHdr)&) anItem.getPersistent();
00148         BdbHandle(BdbGenericHdr) theHdr = theHdrRef;
00149         BdbHandleAny oldOwner;
00150         result = theHdr->owner( oldOwner );
00151         if ( BdbIsNull( oldOwner ) ) {
00152             result = theEvs->updateAndWait( theHdr, 
00153                 BdbDomain::DomainNames[BdbDomain::Events] );
00154             if ( BdbcSuccess == result ) {
00155                 theHdr->setOwner( self );
00156             } else {
00157                 BdbSignal( BdbcUserError, BdbEventStoreErrUnableToUpdate, 0, 
00158                            "BdbAbsCollectionT<T>::add", name( ) ); 
00159             }
00160         }
00161     }
00162     return result;
00163 }
00164 
00165 template < class T > 
00166 BdbStatus 
00167 BdbAbsCollectionT<T>::clear( ) 
00168 {
00169     BdbEventStore* theEvs = BdbEventStore::instance( );
00170     BdbHandle(BdbCollectionP) self = persistent( );
00171     BdbStatus result;
00172 
00173     // Lock the collection for sole access. 
00174     result = theEvs->updateAndWait( self, 
00175         BdbDomain::DomainNames[BdbDomain::Events] );
00176     if ( BdbcSuccess == result ) {
00177         result = self->clear( );
00178     } else {
00179         BdbSignal( BdbcUserError, BdbEventStoreErrUnableToUpdate, 0, 
00180                    "BdbAbsCollectionT<T>::clear", name( ) ); 
00181     }
00182     return result;
00183 }
00184 
00185 template < class T > 
00186 d_Boolean 
00187 BdbAbsCollectionT<T>::contains( T& anItem ) const
00188 {
00189     BdbRefAny aRef = anItem.getPersistent();
00190     BdbHandleAny aH = aRef;
00191     return persistent( )->contains( aH );
00192 }
00193 
00194 template < class T > 
00195 d_Boolean 
00196 BdbAbsCollectionT<T>::containsCollection( BdbAbsCollectionT<T>& theOther,
00197                                          d_Boolean descend ) const
00198 {
00199     BdbHandle(BdbCollectionP) theObj = theOther.persistent( );
00200     return persistent( )->containsCollection( theObj, descend );
00201 }
00202 
00203 template < class T > 
00204 BdbStatus
00205 BdbAbsCollectionT<T>::item( T& anItem, d_ULong index ) const
00206 {
00207     BdbHandle(HepExplorableDescr) theDesc;
00208     BdbRefAny aRef = anItem.getPersistent();
00209     BdbHandleAny aH = aRef;
00210     BdbStatus result = persistent( )->item( aH , 
00211                                             theDesc, index );
00212     BdbAbsCollectionT<T>* self = (BdbAbsCollectionT<T>*) this;
00213     self->setDescrOverride( theDesc );
00214     return result;
00215 }
00216 
00217 template < class T > 
00218 BdbStatus 
00219 BdbAbsCollectionT<T>::remove( T& anItem ) 
00220 {
00221     BdbEventStore* theEvs = BdbEventStore::instance( );
00222     BdbHandle(BdbCollectionP) self = persistent( );
00223     BdbStatus result;
00224 
00225     // Lock the collection for sole access. 
00226     result = theEvs->updateAndWait( self, 
00227         BdbDomain::DomainNames[BdbDomain::Events] );
00228     if ( BdbcSuccess == result ) {
00229         BdbRefAny aRef = anItem.getPersistent();
00230         BdbHandleAny aH = aRef;
00231         result = self->remove( aH );
00232     } else {
00233         BdbSignal( BdbcUserError, BdbEventStoreErrUnableToUpdate, 0, 
00234                    "BdbAbsCollectionT<T>::remove", name( ) ); 
00235     }
00236     return result;
00237 }
00238 
00239 template < class T > 
00240 d_Boolean 
00241 BdbAbsCollectionT<T>::isCompatible( BdbAbsCollectionT<T>& theOther ) const
00242 {
00243     d_Boolean result = d_True;
00244     BdbHandle(BdbCollectionP) theOtherP = theOther.persistent( );
00245     if ( ! isNull( ) && ! theOther.isNull( ) ) {
00246         result = persistent( )->isCompatible( theOtherP );
00247     }
00248     return result;
00249 }
00250 
00251 template < class T > 
00252 BdbHandle(BdbCollectionP) 
00253 BdbAbsCollectionT<T>::persistent( ) const
00254 {
00255     assert( ! BdbIsNull( object( ) ) );
00256 
00257     // gg did this on 14/10/98 for HP/aCC.
00258     BdbHandleAny objectGG = object( );
00259     BdbHandle(BdbCollectionP) objectGH;
00260     objectGH = (BdbHandle(BdbCollectionP)&) objectGG;
00261     //    return (BdbHandle(BdbCollectionP)&) object( ) ;
00262     return objectGH;
00263 
00264 }
00265 
00266 template < class T >
00267 void
00268 BdbAbsCollectionT<T>::setPersistent( BdbHandle(BdbCollectionP)& aCollection )
00269 {
00270     setObject( aCollection );
00271 }
00272 
00273 template < class T >
00274 BdbStatus
00275 BdbAbsCollectionT<T>::createDescription( const char* const theName )
00276 {
00277     BdbHandle(HepExplorableDescr) nullDesc( 0 );
00278     BdbStatus result = persistent( )->createDescription( theName );
00279     setDescrOverride( nullDesc );
00280     return result;
00281 }
00282 
00283 template < class T >
00284 d_Boolean
00285 BdbAbsCollectionT<T>::hasDescription( ) const
00286 {
00287     return persistent( )->hasDescription( );
00288 }
00289 
00290 template < class T >
00291 BdbStatus
00292 BdbAbsCollectionT<T>::setDescription( BdbHandle(HepExplorableDescr)& theDesc )
00293 {
00294     BdbHandle(HepExplorableDescr) nullDesc( 0 );
00295     BdbStatus result = persistent( )->setDescription( theDesc );
00296     setDescrOverride( nullDesc );
00297     return result;
00298 }
00299 
00300 template < class T >
00301 BdbStatus
00302 BdbAbsCollectionT<T>::description( BdbHandle(HepExplorableDescr)& theDesc ) const
00303 {
00304     BdbStatus result = BdbcSuccess;
00305     BdbHandle(HepExplorableDescr) theUseDesc = descrOverride( );
00306     if ( BdbIsNull(theUseDesc) ) {
00307         result = persistent( )->description( theUseDesc );
00308     }
00309     theDesc = theUseDesc;
00310     return result;
00311 }
00312 
00313 template < class T > 
00314 BdbHandle(HepExplorableDescr)
00315 BdbAbsCollectionT<T>::descrOverride( ) const
00316 {
00317     if( 0 == _descrOverride ) {
00318         return 0 ;
00319     }
00320     return *_descrOverride;
00321 }
00322 
00323 template < class T > 
00324 void 
00325 BdbAbsCollectionT<T>::setDescrOverride( const BdbHandle(HepExplorableDescr)& theOverride )
00326 {
00327     delete _descrOverride ;
00328     _descrOverride = new BdbHandle(HepExplorableDescr)( theOverride ) ;
00329 }
00330 
00331 template < class T >
00332 void 
00333 BdbAbsCollectionT<T>::useTag( BdbHandle(BdbEventTag)& theTag )
00334 {
00335     persistent( )->useTag( theTag );
00336 }
00337 
00338 template < class T >
00339 void 
00340 BdbAbsCollectionT<T>::useAndResizeTag( BdbHandle(BdbEventTag)& theTag )
00341 {
00342     BdbHandle(BdbEventTag) theTagH = theTag;
00343     persistent( )->useAndResizeTag( theTagH );
00344 }
00345 
00346 template < class T >
00347 void 
00348 BdbAbsCollectionT<T>::fillTag( BdbHandle(BdbEventTag)& theTag, AbsEventTag* theTrans )
00349 {
00350     BdbAbsCollectionT<T>* override = descrOverride( );
00351     override->persistent( )->fillTag( theTag, theTrans );
00352 }
00353 
00354 template < class T >
00355 BdbStatus 
00356 BdbAbsCollectionT<T>::treeNode( BdbTreeNode& theNode ) const
00357 {
00358     BdbHandle(BdbTreeNodeP) theNodeP;
00359     BdbStatus result = persistent( )->treeNode( theNodeP );
00360     if ( BdbcSuccess == result ) {
00361         theNode.setPersistent( theNodeP );
00362     }
00363     return result;
00364 }
00365 
00366 template < class T >
00367 BdbStatus 
00368 BdbAbsCollectionT<T>::fetchMetaData( BdbMetaData& theData )
00369 {
00370     BdbHandle(BdbMetaDataP) theDataP;
00371     BdbEventStore* theEvs = BdbEventStore::instance( );
00372     BdbHandle(BdbCollectionP) self = persistent( );
00373     BdbStatus result;
00374 
00375     // Lock the collection for sole access. 
00376     result = theEvs->updateAndWait( self, 
00377         BdbDomain::DomainNames[BdbDomain::Events] );
00378     if ( BdbcSuccess == result ) {
00379         result = self->fetchMetaData( theDataP );
00380         theData.setPersistent( theDataP );
00381     } else {
00382         BdbSignal( BdbcUserError, BdbEventStoreErrUnableToUpdate, 0, 
00383                    "BdbAbsCollectionT<T>::fetchMetaData", name( ) ); 
00384     }
00385     return result;
00386 }
00387 
00388 template < class T >
00389 BdbStatus 
00390 BdbAbsCollectionT<T>::metaData( BdbMetaData& theData ) const
00391 {
00392     BdbHandle(BdbMetaDataP) theDataP;
00393     BdbStatus result = persistent( )->metaData( theDataP );
00394     theData.setPersistent( theDataP );
00395     return result;
00396 }
00397 
00398 template < class T >
00399 d_Boolean
00400 BdbAbsCollectionT<T>::isDeleted( ) const
00401 {
00402     d_Boolean result = persistent( )->isDeleted( );
00403     return result;
00404 }
00405 
00406 template < class T >
00407 void
00408 BdbAbsCollectionT<T>::setDeleted( )
00409 {
00410     persistent( )->setDeleted( );
00411 }
00412 
00413 template < class T >
00414 void
00415 BdbAbsCollectionT<T>::invalidateCachedHandle() const
00416 {
00417    BdbAbsWrapper::invalidateCachedHandle();
00418 }
00419 
00420 //              -------------------------------------------
00421 //              -- Protected Function Member Definitions --
00422 //              -------------------------------------------
00423 
00424 //----------------
00425 // Constructors --
00426 //----------------
00427 
00428 template < class T > 
00429 BdbAbsCollectionT<T>::BdbAbsCollectionT( BdbHandle(BdbCollectionP)& theColl )
00430    : BdbAbsWrapper( theColl ) ,
00431      _descrOverride(0)
00432 {
00433 }

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002