/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 00019 #ifndef ROOTIOTYPEDCNV_H 00020 #define ROOTIOTYPEDCNV_H 00021 00022 #include "RootIOSvc/RootIOBaseCnv.h" 00023 #include "RootIOSvc/RootIOAddress.h" 00024 #include "RootIOSvc/RootOutputStream.h" 00025 #include "RootIOSvc/RootInputStream.h" 00026 00027 #include "GaudiKernel/MsgStream.h" 00028 #include "GaudiKernel/DataObject.h" 00029 #include "GaudiKernel/IRegistry.h" 00030 00031 #include "TClass.h" // debug 00032 00033 #include <string> 00034 00035 template<class PerType, class TranType> 00036 class RootIOTypedCnv : public RootIOBaseCnv 00037 { 00038 protected: 00039 std::string m_perclassName; 00040 PerType *m_perInObj, *m_perOutObj; 00041 00042 public: 00045 RootIOTypedCnv(std::string class_name, const CLID& clid, ISvcLocator* svc) 00046 : RootIOBaseCnv(clid,svc) 00047 , m_perclassName(class_name) 00048 , m_perInObj(new PerType) 00049 , m_perOutObj(new PerType) 00050 { 00051 m_perOutObj->clID = m_perInObj->clID = TranType::classID(); 00052 } 00053 00054 virtual ~RootIOTypedCnv() { 00055 MsgStream log(msgSvc(), m_perclassName + "Cnv"); 00056 log << MSG::DEBUG << "converter for " 00057 << m_perclassName << " destructing" << endreq; 00058 } 00059 00061 PerType& getPerInputObject() { return *m_perInObj; } 00062 PerType& getPerOutputObject() { return *m_perOutObj; } 00063 00065 const RootIOBaseObject* getBaseInputObject() { return m_perInObj; } 00066 const RootIOBaseObject* getBaseOutputObject() { return m_perOutObj; } 00067 00070 virtual StatusCode PerToTran(const PerType& pobj, TranType& tobj) = 0; 00071 00074 virtual StatusCode TranToPer(const TranType& tobj, PerType& pobj) = 0; 00075 00076 00078 00080 virtual StatusCode TranObjectToPerObject(DataObject& dat, 00081 const RootOutputAddress& /*roa*/) 00082 { 00083 MsgStream log(msgSvc(), m_perclassName + "Cnv"); 00084 TranType* tranobj = dynamic_cast<TranType*>(&dat); 00085 if (!tranobj) { 00086 log << MSG::ERROR 00087 << "Given a DataObject which does not corespond to " 00088 << m_perclassName << " at location " 00089 << dat.registry()->identifier() 00090 << endreq; 00091 return StatusCode::FAILURE; 00092 } 00093 00094 // Delegate actual copying to subclass. 00095 return this->TranToPer(*tranobj,*m_perOutObj); 00096 } 00097 00099 virtual StatusCode PerObjectToTranObject(DataObject*& dat) { 00100 MsgStream log(msgSvc(), m_perclassName + "Cnv"); 00101 TranType* tranobj = new TranType; 00102 StatusCode sc = this->PerToTran(*m_perInObj,*tranobj); 00103 if (sc.isFailure()) { 00104 delete tranobj; 00105 dat = 0; 00106 return sc; 00107 } 00108 dat = tranobj; 00109 00110 log << MSG::DEBUG << "Converted " << m_perclassName << endreq; 00111 00112 return sc; 00113 } 00114 00116 virtual RootInputStream* makeInputStream(const RootInputAddress& ria) { 00117 RootInputStream* ris = 00118 new RootInputStream(&m_perInObj, ria.tespath(), ria.branchname()); 00119 00120 MsgStream log(msgSvc(), m_perclassName + "Cnv"); 00121 log << MSG::DEBUG 00122 << "Made input stream for " << ria.tespath() 00123 << endreq; 00124 return ris; 00125 } 00126 00128 virtual RootOutputStream* makeOutputStream(const RootOutputAddress& ria) { 00129 MsgStream log(msgSvc(), m_perclassName + "Cnv"); 00130 log << MSG::DEBUG 00131 << "Making output stream with class " << m_perclassName 00132 << " and tespath " << ria.tespath() 00133 << " and branchname " << ria.branchname() 00134 << endreq; 00135 00136 return new RootOutputStream((void*)&m_perOutObj,m_perclassName.c_str(), 00137 ria.tespath(),ria.branchname()); 00138 } 00139 }; 00140 00141 #endif // ROOTIOTYPEDCNV_H