00001 #ifndef CDBROOCONVERSIONFWK_BDB_2_ROO_PAYLOAD_CONVERTER_HH 00002 #define CDBROOCONVERSIONFWK_BDB_2_ROO_PAYLOAD_CONVERTER_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbBdb2RooPayloadConverter.hh,v 1.2 2005/07/14 16:11:04 jtinslay Exp $ 00006 00007 #include "CdbRooConversionFwk/CdbRooConverterBase.hh" 00008 00009 #include <string> 00010 00011 /// The generic "P-R" abstract base class for user defined converters 00012 /** 00013 * The only role of this interface is to obtain names of persistent types 00014 * to be converted. This is the class to be normally used by users as a base 00015 * one when making type-specific converters. 00016 * 00017 * IMPLEMENTATION NOTES: 00018 * 00019 * 1. The converter will derive the type names of the specified persistent classes 00020 * using the current Objectivity/DB (for 'P') schema and ROOT/CINT dictionary (for 'R'). 00021 * 00022 * 2. The virtual tables for Objectovity/DB classes must be loaded to prevent 00023 * crashes in case if the "T* P::transient() const" is defined as the virtual one. 00024 * 00025 * 3. The dictionary for the 'R' class must also be available. 00026 */ 00027 template < class P, 00028 class R > 00029 class CdbBdb2RooPayloadConverter : public CdbRooConverterBase { 00030 00031 private: 00032 00033 /// Translate the current 'P' type into its name 00034 /** 00035 * This is a utility method used by the current class's constructor. The method 00036 * will cause a run-time abort of the application in case if the desired name 00037 * can't be obtained. 00038 * 00039 * The method will also ensure that the type is a (direct or indirect) subclass of 00040 * the BdbObject class, which is a very base class of all _primary_ persistent 00041 * objects stored in Objectivity/DB based CDB implementations. 00042 * 00043 * TRANSACTION NOTE: 00044 * 00045 * The method will start (if none exists) a "read-only" mode transaction in 00046 * order to obtain the type information for an Objectivity/DB schema. 00047 * 00048 * @see BdbObject 00049 * @see CdbTransaction 00050 */ 00051 static std::string pTypeName( ); 00052 00053 /// Translate the current 'R' type into its name 00054 /** 00055 * This is a utility method used by the current class's constructor. The method 00056 * will cause a run-time abort of the application in case if the desired name 00057 * can't be obtained. 00058 * 00059 * The type information will be obtained from the ROOT/CINT dictionary which needs 00060 * to be loaded for the 'R' type. The method will also check if the specified type 00061 * is a (direct or indirect) subclass of the CdbRooObjectR class, which is a very 00062 * base class of all _primary_ persistent objects stored in ROOT I/O based CDB 00063 * implementations. 00064 * 00065 * @see CdbRooObjectR 00066 */ 00067 static std::string rTypeName( ); 00068 00069 protected: 00070 00071 /// The default constructor 00072 /** 00073 * Any type incompatibility will cause either compilation errors or run time 00074 * crash in the constructor. 00075 * 00076 * @see CdbBdb2RooPayloadConverter::pTypeName() 00077 * @see CdbBdb2RooPayloadConverter::rTypeName() 00078 */ 00079 CdbBdb2RooPayloadConverter( ); 00080 00081 /// The copy constructor 00082 00083 CdbBdb2RooPayloadConverter( const CdbBdb2RooPayloadConverter<P,R>& theOther ); 00084 00085 /// The assignment operator 00086 00087 CdbBdb2RooPayloadConverter<P,R>& operator=( const CdbBdb2RooPayloadConverter<P,R>& theOther ); 00088 00089 /// Implement a user-defined conversion 00090 /** 00091 * This pure virtual method is supposed to be implemented by subclasses for 00092 * the specified (in the constructor) pair of classes. 00093 * 00094 * The method will be invoked by the below defined "::conversion()" method. 00095 * 00096 * The method is supposed to return CdbStatus::Success in case of its successfull 00097 * completion, or any other value otherwise, which will be treated as a failure. 00098 * Also when a call is successfull then the ouput object pointer must be filled with 00099 * a valid pointer onto a nely created object. 00100 * 00101 * NOTE: The output object's ownership is also expected to be returned 00102 * with the object. 00103 * 00104 * @see CdbBdb2RooPayloadConverter::CdbBdb2RooPayloadConverter() 00105 * @see CdbBdb2RooPayloadConverter::conversion() 00106 */ 00107 virtual CdbStatus userDefinedConversion( const BdbRef(BdbObject)& theInputObjectRef, 00108 R*& theOutputObjectPtr 00109 ) const = 0; 00110 00111 /// Get a list of extra objects. 00112 /** 00113 * This list is meant to be used by the above defined user defined conversion algorithm 00114 * when merging multiple input objects into an output one. The list contains "extra" 00115 * objects in addition to the main input object. The order of objects in the list 00116 * is defined during the planing phase of the payload conversion. The objects passed 00117 * in the list ara guaranteed to be valid. 00118 * 00119 * The list returned by the method will contain no elements for regular (non-merging) 00120 * converters. 00121 * 00122 * @see CdbRooConverterBase::mergingConverter() 00123 */ 00124 const std::vector< BdbRef(BdbObject) >& extraObjects( ) const { return _extraObjects; } 00125 00126 public: 00127 00128 /// The destructor. 00129 00130 virtual ~CdbBdb2RooPayloadConverter( ); 00131 00132 /// A wrapper method for the conversion operation 00133 /** 00134 * Imnplement the corresponding method defined in the base class. 00135 * 00136 * @see CdbRooConverterBase::conversion() 00137 */ 00138 virtual CdbStatus conversion( const BdbRef(BdbObject)& theInputObjectRef, 00139 const std::vector< BdbRef(BdbObject) >& theExtraObjectsList 00140 ); 00141 00142 /// Create a new branch with specified parameters 00143 /** 00144 * Imnplement the corresponding method defined in the base class. 00145 * 00146 * @see CdbRooConverterBase::branchConstructor() 00147 */ 00148 virtual TBranch* branchConstructor( TTree& theTree, 00149 const char* theBranchName ); 00150 00151 private: 00152 00153 /// An optional list of extra objects to be used in the conversion process. 00154 /** 00155 * The list will be non-empty if an actual implementation of the converter 00156 * does allow merging input objects. 00157 * 00158 * @see CdbRooConverterBase::mergingConverter() 00159 */ 00160 std::vector< BdbRef(BdbObject) > _extraObjects; 00161 00162 /// The object pointer for the resuilting product of the conversion 00163 /** 00164 * This pointer is used to create a TBranch object. Then the pointer is filled 00165 * with converted objects each time the CdbRooConverterBase::conversion() 00166 * method gets called. It's up to the user of the current class to save result into 00167 * the corresponding TTree (the one used to create the TBranch object). 00168 */ 00169 R* _tObjectPtr; 00170 }; 00171 00172 #ifdef BABAR_COMP_INST 00173 #include "CdbRooConversionFwk/CdbBdb2RooPayloadConverter.cc" 00174 #endif // BABAR_COMP_INST 00175 00176 #endif // CDBROOCONVERSIONFWK_BDB_2_ROO_PAYLOAD_CONVERTER_HH
1.3-rc3