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

CdbRooRoIdCollectionR.rdl

Go to the documentation of this file.
00001 #ifndef CDBROOREADONLY_ID_COLLECTION_R_RDL
00002 #define CDBROOREADONLY_ID_COLLECTION_R_RDL
00003 
00004 // File and Version Information:
00005 //      $Id: CdbRooRoIdCollectionR.rdl,v 1.5 2005/11/11 01:41:27 gapon Exp $
00006 
00007 #include "CdbBase/CdbCPtr.hh"
00008 #include "CdbBase/CdbItr.hh"
00009 
00010 #include "CdbRooReadonly/CdbRooRoPersistentCollectionR.hh"
00011 #include "CdbRooReadonly/CdbRooRoVectorCollectionR.hh"
00012 
00013 #include <iostream>
00014 #include <string>
00015 #include <vector>
00016 #include <map>
00017 
00018 /// A persistent collection of 'id'-ed objects
00019 /**
00020   * Classes eligible for this template must have the following minimal
00021   * interface:
00022   *
00023   *   class T {
00024   *   public:
00025   *     T();
00026   *     T( const T&);
00027   *     UShort_t id() const;
00028   *   };
00029   *
00030   * NOTE: The total number of elements stored in a collection of this type
00031   *       is limited by 64K. Therefore valid indexes of the elements lay in
00032   *       the following range: [0..0xFFFF], inclusive at both sides of the range.
00033   */
00034 template< class T >
00035 class CdbRooRoIdCollectionR : public CdbRooRoPersistentCollectionR {
00036 
00037 private:
00038 
00039   /// The assignment operator (NOT IMPLEMENTED)
00040 
00041     CdbRooRoIdCollectionR<T>& operator=( const CdbRooRoIdCollectionR<T>& theOther );
00042 
00043 public:
00044 
00045   /// The normal and the default constructor
00046   /**
00047     * It's also  needed for ROOT I/O.
00048     */
00049     CdbRooRoIdCollectionR( );
00050 
00051   /// The copy constructor
00052   /**
00053     * IMPORTANT NOTE:
00054     *
00055     *   Watch out for the implementation of this constructor because objects of
00056     *   the class can be in two states: "stored" and "transient". The same object
00057     *   can't be stored more than one time due to a unique naming scheme for
00058     *   persistent collections (and their sub-collections (and their elements)) in ROOT files.
00059     *   The same rule applies to copies of an object - after the master copy got stored
00060     *   then its copies can't be stored anymore.
00061     *
00062     *   The cache of objects gets always duplicated since it's using counted smart pointers.
00063     *
00064     *   And we don't care about supplementary transient context (other than the transient
00065     *   list of objects). That context is only used to populate the transient list
00066     *   from the persistent store. Copying this context accross objects can be
00067     *   dangerous too.
00068     */
00069     CdbRooRoIdCollectionR( const CdbRooRoIdCollectionR<T>& theOther );
00070 
00071   /// Destructor
00072 
00073     virtual ~CdbRooRoIdCollectionR( );
00074 
00075     UInt_t size( ) const { return _indexById.size( ); }
00076 
00077     virtual CdbStatus add( const T& theObject );
00078 
00079     virtual CdbStatus find( UShort_t theId,
00080                             T&       theObject ) const;
00081 
00082     virtual CdbStatus find( UShort_t      theId,
00083                             CdbCPtr< T >& theObjectPtr ) const;
00084 
00085   /// Return a sorted collection of identifiers
00086 
00087     void identifiers( std::vector<UShort_t>& theCollection ) const;
00088 
00089   /// Return an iterator producing a sorted sequence of identifiers
00090 
00091     CdbItr< UShort_t > iterator_identifiers( ) const;
00092 
00093     virtual void dump( std::ostream&      o,
00094                        const std::string& indent = "" ) const;
00095 
00096 protected:
00097 
00098   /// Store sub-collections
00099   /**
00100     * Implement the corresponding method defined in a base class.
00101     *
00102     * @see CdbRooRoPersistentCollectionR::storeSubCollectionsAt()
00103     */
00104     virtual CdbStatus storeSubCollectionsAt( const CdbRooRoCollectionAddressR& theCollectionAddress,
00105                                              const CdbCPtr<TFile>&             theFilePtr,
00106                                              Int_t&                            theNumBytesStored );
00107 private:
00108 
00109   // The vector collection of objects
00110 
00111     CdbRooRoVectorCollectionR<T> _objects;
00112 
00113   // This data structure maps identifiers of stored objects onto indexes of these objects
00114   // in the above defined vector collection.
00115 
00116     std::map<UShort_t,UInt_t> _indexById;
00117 
00118     ClassDefT(CdbRooRoIdCollectionR<T>,1);
00119 };
00120 
00121 // Implementation of the methods
00122 
00123 #ifndef __CINT__
00124 #include "CdbRooReadonly/CdbRooRoIdCollectionR.cc"
00125 #endif
00126 #endif /* CDBROOREADONLY_ID_COLLECTION_R_RDL */

Generated on Mon Dec 5 18:22:10 2005 for CDB by doxygen1.3-rc3