| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- File List
- File Members

# RDirectoryCnv.cpp

Go to the documentation of this file.

    00001 // Id: $
    00002 #define ROOTHISTCNV_RDIRECTORYCNV_CPP
    00003
    00004 // Include files
    00005 #include "GaudiKernel/CnvFactory.h"
    00006 #include "GaudiKernel/xtoa.h"
    00007 #include "GaudiKernel/IDataProviderSvc.h"
    00008 #include "GaudiKernel/IDataManagerSvc.h"
    00009 #include "GaudiKernel/IOpaqueAddress.h"
    00010 #include "GaudiKernel/IRegistry.h"
    00011 #include "GaudiKernel/MsgStream.h"
    00012 #include "GaudiKernel/NTuple.h"
    00013
    00014 #include "RDirectoryCnv.h"
    00015
    00016 // Root files
    00017 #include "TObject.h"
    00018 #include "TDirectory.h"
    00019 #include "TFile.h"
    00020 #include "TKey.h"
    00021 #include "TTree.h"
    00022 #include "TProfile.h"
    00023 #include "TProfile2D.h"
    00024 #include "TH1.h"
    00025 #include "TH2.h"
    00026 #include "TH3.h"
    00027
    00028 DECLARE_NAMESPACE_CONVERTER_FACTORY(RootHistCnv,RDirectoryCnv)
    00029
    00030
    00031 //-----------------------------------------------------------------------------
    00032 StatusCode RootHistCnv::RDirectoryCnv::createObj(IOpaqueAddress* /* pAddress */,
    00033                                                  DataObject*& refpObject)
    00034 //-----------------------------------------------------------------------------
    00035 {
    00036   refpObject = new NTuple::Directory();
    00037   return StatusCode::SUCCESS;
    00038 }
    00039
    00040
    00041 //-----------------------------------------------------------------------------
    00042 StatusCode RootHistCnv::RDirectoryCnv::createRep(DataObject* pObject,
    00043                                                  IOpaqueAddress*& refpAddress)
    00044 //-----------------------------------------------------------------------------
    00045 {
    00046   const std::string& loc = pObject->registry()->identifier();
    00047   if ( createDirectory(loc).isSuccess() )   {
    00048     setDirectory(loc);
    00049     setDiskDirectory(loc);
    00050 //  return createAddress(pObject, pObject->registry()->name(), refpAddress);
    00051     return createAddress(pObject, gDirectory, 0, refpAddress);
    00052   }
    00053   refpAddress = 0;
    00054   return StatusCode::FAILURE;
    00055 }
    00056
    00057
    00058 //-----------------------------------------------------------------------------
    00059 StatusCode RootHistCnv::RDirectoryCnv::updateRep(IOpaqueAddress* /* pAddress */,
    00060                                                  DataObject* pObject)
    00061 //-----------------------------------------------------------------------------
    00062 {
    00063   const std::string& loc = pObject->registry()->identifier();
    00064   if ( createDirectory(loc).isSuccess() )   {
    00065     setDirectory(loc);
    00066     return StatusCode::SUCCESS;
    00067   }
    00068   return StatusCode::FAILURE;
    00069 }
    00070
    00071
    00072 //-----------------------------------------------------------------------------
    00073 StatusCode
    00074 RootHistCnv::RDirectoryCnv::fillObjRefs(IOpaqueAddress* pAddr,DataObject* pObj)  {
    00075   MsgStream log(msgSvc(), "RDirectoryCnv");
    00076   IRegistry* pReg = pObj->registry();
    00077   std::string full  = pReg->identifier();
    00078   const std::string& fname = pAddr->par()[0];
    00079
    00080   TFile *tf;
    00081   findTFile(full,tf).ignore();
    00082
    00083   // cd to TFile:
    00084   setDirectory(full);
    00085   TIter nextkey(gDirectory->GetListOfKeys());
    00086   while (TKey *key = (TKey*)nextkey()) {
    00087     IOpaqueAddress* pA = 0;
    00088     TObject *obj = key->ReadObj();
    00089     std::string title = obj->GetTitle();
    00090     std::string sid = obj->GetName();
    00091     std::string f2 = full + "/" + sid;
    00092     int idh = ::strtol(sid.c_str(),NULL,10);
    00093     // introduced by Grigori Rybkine
    00094     std::string clname = key->GetClassName();
    00095     std::string clnm = clname.substr(0,3);
    00096     TClass* isa = obj->IsA();
    00097     if (isa->InheritsFrom("TTree")) {
    00098       createAddress(full, CLID_ColumnWiseTuple, idh, obj, pA).ignore();
    00099       TTree* tree = (TTree*) obj;
    00100       tree->Print();
    00101       log << MSG::DEBUG << "Reg CWNT \"" << obj->GetTitle()
    00102           << "\" as " << f2 << endreq;
    00103       title = "/" + sid;
    00104     } else if (isa->InheritsFrom("TDirectory")) {
    00105       createAddress(full,CLID_NTupleDirectory, title, obj, pA).ignore();
    00106     } else if ( isa == TProfile::Class() ) {
    00107       createAddress(full,CLID_ProfileH,idh,obj,pA).ignore();
    00108       title = sid;
    00109     } else if ( isa == TProfile2D::Class() ) {
    00110       createAddress(full,CLID_ProfileH2,idh,obj,pA).ignore();
    00111       title = sid;
    00112     } else if ( isa == TH1C::Class() ) {
    00113       createAddress(full,CLID_H1D,idh,obj,pA).ignore();
    00114       title = sid;
    00115     } else if ( isa == TH1S::Class() ) {
    00116       createAddress(full,CLID_H1D,idh,obj,pA).ignore();
    00117       title = sid;
    00118     } else if ( isa == TH1I::Class() ) {
    00119       createAddress(full,CLID_H1D,idh,obj,pA).ignore();
    00120       title = sid;
    00121     } else if ( isa == TH1F::Class() ) {
    00122       createAddress(full,CLID_H1D,idh,obj,pA).ignore();
    00123       title = sid;
    00124     } else if ( isa == TH1D::Class() ) {
    00125       createAddress(full,CLID_H1D,idh,obj,pA).ignore();
    00126       title = sid;
    00127     } else if ( isa == TH2C::Class() ) {
    00128       createAddress(full,CLID_H2D,idh,obj,pA).ignore();
    00129       title = sid;
    00130     } else if ( isa == TH2S::Class() ) {
    00131       createAddress(full,CLID_H2D,idh,obj,pA).ignore();
    00132       title = sid;
    00133     } else if ( isa == TH2I::Class() ) {
    00134       createAddress(full,CLID_H2D,idh,obj,pA).ignore();
    00135       title = sid;
    00136     } else if ( isa == TH2F::Class() ) {
    00137       createAddress(full,CLID_H2D,idh,obj,pA).ignore();
    00138       title = sid;
    00139     } else if ( isa == TH2D::Class() ) {
    00140       createAddress(full,CLID_H2D,idh,obj,pA).ignore();
    00141       title = sid;
    00142     } else if ( isa == TH3C::Class() ) {
    00143       createAddress(full,CLID_H3D,idh,obj,pA).ignore();
    00144       title = sid;
    00145     } else if ( isa == TH3S::Class() ) {
    00146       createAddress(full,CLID_H3D,idh,obj,pA).ignore();
    00147       title = sid;
    00148     } else if ( isa == TH3I::Class() ) {
    00149       createAddress(full,CLID_H3D,idh,obj,pA).ignore();
    00150       title = sid;
    00151     } else if ( isa == TH3F::Class() ) {
    00152       createAddress(full,CLID_H3D,idh,obj,pA).ignore();
    00153       title = sid;
    00154     } else if ( isa == TH3D::Class() ) {
    00155       createAddress(full,CLID_H3D,idh,obj,pA).ignore();
    00156       title = sid;
    00157     } else {
    00158       log << MSG::ERROR << "Encountered an unknown object with key: "
    00159           << obj->GetName() << " in ROOT file " << fname << endreq;
    00160       return StatusCode::FAILURE;
    00161     }
    00162     if ( 0 != pA )    {
    00163       StatusCode sc = dataManager()->registerAddress(pReg, title, pA);
    00164       if ( !sc.isSuccess() )  {
    00165         log << MSG::ERROR << "Failed to register address for " << full  << endmsg;
    00166         return sc;
    00167       }
    00168       log << MSG::VERBOSE << "Created address for " << clnm
    00169           << "'" << title << "' in " << full << endreq;
    00170     }
    00171   }
    00172   return StatusCode::SUCCESS;
    00173 }