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

CdbRooRoNameIdCollectionR.rdl

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

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