00001 #ifndef CDBROOREADONLY_PERSISTENT_COLLECTION_R_RDL 00002 #define CDBROOREADONLY_PERSISTENT_COLLECTION_R_RDL 00003 00004 // File and Version Information: 00005 // $Id: CdbRooRoPersistentCollectionR.rdl,v 1.4 2005/11/11 01:41:28 gapon Exp $ 00006 00007 #include "CdbBase/CdbCPtr.hh" 00008 00009 #include "CdbRooReadonly/CdbRooRoCollectionAddressR.hh" 00010 00011 #include <TFile.h> 00012 00013 /// A base class for persistent collections of objects 00014 /** 00015 * This class enforces (and implements) an explicit storage interface for derived 00016 * persistent collections. 00017 * 00018 * The collection can be stored either on its own or as an "embedded" one being 00019 * a data member of another persistent class. Two storage methods are provided: 00020 * 00021 * @see CdbRooRoPersistentCollectionR::storeAt() 00022 * @see CdbRooRoPersistentCollectionR::storeAsEmbeddedAt() 00023 * 00024 * Sub-collections (if any) of derived classes can be stored by reimplementing 00025 * the below defined "storeSubCollectionsAt()" method: 00026 * 00027 * @see CdbRooRoPersistentCollectionR::storeSubCollectionsAt() 00028 */ 00029 class CdbRooRoPersistentCollectionR { 00030 00031 public: 00032 00033 /// Constructor 00034 00035 CdbRooRoPersistentCollectionR( ); 00036 00037 /// Copy constructor 00038 00039 CdbRooRoPersistentCollectionR( const CdbRooRoPersistentCollectionR& theOther ); 00040 00041 /// Assignment operator 00042 00043 CdbRooRoPersistentCollectionR& operator=( const CdbRooRoPersistentCollectionR& theOther ); 00044 00045 /// Destructor 00046 00047 virtual ~CdbRooRoPersistentCollectionR( ); 00048 00049 /// Store a collection (if not embedded) and its elements at the specified location 00050 /** 00051 * The collection itself will be stored at the specified file where 00052 * the collection name will be used as a key in the TDirectory/TFile. 00053 * 00054 * [ If the "isEmbedded" parameter is set to true then the colllection itself 00055 * won't be stored. Only its element will be. This level of control is meant 00056 * to be used for cases when the collection object is embedded as a data member 00057 * into other persistent objects. To help with this the helper storeAsEmbeddedAt 00058 * method is present in the class's interface. ] 00059 * 00060 * 00061 * NOTES: 00062 * 00063 * - The collection can be stored just once. If a subsequent attempt to store 00064 * it will be made then a error status will be returned by the current 00065 * procedure. The transient cache will be used as a source of the stored elements. 00066 * 00067 * - The method won't check a consistency between a name of the passed file 00068 * and a collection address. It's up to the method's caller to ensure this. 00069 * 00070 * Upon its successfull completion, the method will return a usual CdbStatus::Success 00071 * and a total number of bytes stored. This number will count both the collection object 00072 * itself and all sub-collections (if any). The number will be positive in that case. 00073 */ 00074 CdbStatus storeAt( const CdbRooRoCollectionAddressR& theCollectionAddress, 00075 const CdbCPtr<TFile>& theFilePtr, 00076 Int_t& theNumBytesStored, 00077 bool isEmbedded = false ); 00078 00079 CdbStatus storeAsEmbeddedAt( const CdbRooRoCollectionAddressR& theCollectionAddress, 00080 const CdbCPtr<TFile>& theFilePtr, 00081 Int_t& theNumBytesStored ) 00082 { 00083 return storeAt( theCollectionAddress, 00084 theFilePtr, 00085 theNumBytesStored, 00086 true ); 00087 } 00088 00089 protected: 00090 00091 /// Store user defined sub-collections 00092 /** 00093 * This method is meant to be implemented in a context of a derived collection 00094 * to store subcollections of that collection. The default implementation of the method 00095 * won't do anything, just return a successfull status. 00096 * 00097 * If the method returns a nono-successfull status then the overall storing sequence 00098 * will get aborted. 00099 * 00100 * NOTE: This method gets called before the current collection gets stored. 00101 */ 00102 virtual CdbStatus storeSubCollectionsAt( const CdbRooRoCollectionAddressR& theCollectionAddress, 00103 const CdbCPtr<TFile>& theFilePtr, 00104 Int_t& theNumBytesStored ); 00105 // Accessors 00106 00107 bool isStored( ) const { return _stored; } 00108 00109 const CdbRooRoCollectionAddressR& storedCollectionAddress( ) const { return _collectionAddress; } 00110 00111 private: 00112 00113 // Persistent context 00114 // 00115 // NOTES: 00116 // 00117 // 1. The collection address gets filled when the collection is being 00118 // stored in the corresponding 'host' file. 00119 // 00120 // 2. The collection address is also used to locate the location of 00121 // a TTree/TBranch with elements of the collection. 00122 00123 Bool_t _stored; 00124 00125 CdbRooRoCollectionAddressR _collectionAddress; 00126 00127 ClassDef(CdbRooRoPersistentCollectionR,1); 00128 }; 00129 00130 #endif /* CDBROOREADONLY_PERSISTENT_COLLECTION_R_RDL */
1.3-rc3