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

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

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# RootHistCnv::RFileCnv Class Reference

`#include <RFileCnv.h>`

Inheritance diagram for RootHistCnv::RFileCnv:

[legend]
Collaboration diagram for RootHistCnv::RFileCnv:

[legend]
List of all members.

## Detailed Description

NTuple converter class definition.

- Major cleanup and debugging for Gaudi v9
- Removal of all static storage

Author:
  Charles Leggett

  Markus Frank

Definition at line 23 of file RFileCnv.h.

## Public Member Functions
virtual StatusCode | createObj (IOpaqueAddress *pAddress, DataObject *&refpObject)
| Create the transient representation of an object.
virtual StatusCode | createRep (DataObject *pObject, IOpaqueAddress *&refpAddress)
| Convert the transient object to the requested representation.
virtual StatusCode | updateRep (IOpaqueAddress *pAddress, DataObject *pObject)
| Convert the transient object to the requested representation.
| RFileCnv (ISvcLocator *svc)
| Standard constructor.
virtual | ~RFileCnv ()
| Standard destructor.
## Static Public Member Functions
static const CLID & | classID ()
| Inquire class type.
## Protected Attributes
TFile * | rfile

## Constructor & Destructor Documentation

RootHistCnv::RFileCnv::RFileCnv | ( | ISvcLocator * | svc | ) | `[inline]`

Standard constructor.

Definition at line 37 of file RFileCnv.h.

    00037                                  : RDirectoryCnv(svc, classID())    {
    00038     }

RootHistCnv::RFileCnv::~RFileCnv | ( |  | ) | `[virtual]`

Standard destructor.

Definition at line 176 of file RFileCnv.cpp.

    00178 {
    00179 }

## Member Function Documentation

StatusCode RootHistCnv::RFileCnv::createObj | ( | IOpaqueAddress * | pAddress,
|  | DataObject *& | refpObject |
| ) |  |  | `[virtual]`

Create the transient representation of an object.

Reimplemented from RootHistCnv::RDirectoryCnv.

Definition at line 19 of file RFileCnv.cpp.

References std::basic_string< _CharT, _Traits, _Alloc >::c_str(), MSG::DEBUG, endreq(), MSG::ERROR, StatusCode::FAILURE, find(), MSG::INFO, oname(), NTuple::File::setOpen(), std::basic_string< _CharT, _Traits, _Alloc >::substr(), StatusCode::SUCCESS, and MSG::VERBOSE.

    00022 {
    00023   MsgStream log(msgSvc(), "RFileCnv");
    00024   unsigned long*     ipar = (unsigned long*)pAddress->ipar();
    00025   char mode[2] = { char(ipar[1]), 0 };
    00026
    00027   std::string fname  = pAddress->par()[0]; // Container name
    00028   std::string ooname = pAddress->par()[1]; // Object name
    00029
    00030   const std::string* spar = pAddress->par();
    00031   // Strip of store name to get the top level RZ directory
    00032   std::string oname = spar[1].substr(spar[1].find("/",1)+1, spar[1].length());
    00033
    00034   // Protect against multiple instances of TROOT
    00035   if ( 0 == gROOT )   {
    00036     static TROOT root("root","ROOT I/O");
    00037     //    gDebug = 99;
    00038   } else {
    00039     log << MSG::VERBOSE << "ROOT already initialized, debug = "
    00040         << gDebug<< endreq;
    00041   }
    00042
    00043
    00044   // Determine access mode:
    00045
    00046   if ( mode[0] == 'O' ) {
    00047
    00048     if (findTFile(ooname,rfile).isFailure()) {
    00049
    00050       log << MSG::INFO << "opening Root file \"" << fname << "\" for reading"
    00051           << endreq;
    00052
    00053       rfile = TFile::Open(fname.c_str(),"READ");
    00054       if ( rfile != 0 && rfile->IsOpen() ) {
    00055         regTFile(ooname,rfile).ignore();
    00056
    00057         ipar[0] = (unsigned long)rfile;
    00058         NTuple::File* pFile = new NTuple::File(objType(), fname, oname);
    00059         pFile->setOpen(true);
    00060         refpObject = pFile;
    00061
    00062         return StatusCode::SUCCESS;
    00063
    00064       } else {
    00065         log << MSG::ERROR << "Couldn't open \"" << fname << "\" for reading"
    00066             << endreq;
    00067         return StatusCode::FAILURE;
    00068       }
    00069
    00070     } else {
    00071       log << MSG::DEBUG << "Root file \"" << fname << "\" already opened"
    00072           << endreq;
    00073       return StatusCode::SUCCESS;
    00074     }
    00075
    00076
    00077   } else if ( mode[0] == 'U' ) {
    00078     log << MSG::INFO << "opening Root file \"" << fname << "\" for updating"
    00079         << endreq;
    00080
    00081     log << MSG::ERROR << "don't know how to do this yet. Aborting." << endreq;
    00082     exit(1);
    00083
    00084
    00085   } else if ( mode[0] == 'N' ) {
    00086     log << MSG::INFO << "opening Root file \"" << fname << "\" for writing"
    00087         << endreq;
    00088
    00089
    00090     rfile = TFile::Open(fname.c_str(),"RECREATE","Gaudi Trees");
    00091     if (! rfile->IsOpen() ) {
    00092       log << MSG::ERROR << "Could not open file " << fname << " for writing"
    00093           << endreq;
    00094       return StatusCode::FAILURE;
    00095     }
    00096
    00097     regTFile(ooname,rfile).ignore();
    00098
    00099     log << MSG::DEBUG << "creating ROOT file " << fname << endreq;
    00100
    00101     ipar[0] = (unsigned long)rfile;
    00102     NTuple::File* pFile = new NTuple::File(objType(), fname, oname);
    00103     pFile->setOpen(true);
    00104     refpObject = pFile;
    00105     return StatusCode::SUCCESS;
    00106
    00107   } else {
    00108
    00109     log << MSG::ERROR << "Uknown mode to access ROOT file" << endreq;
    00110     return StatusCode::FAILURE;
    00111
    00112   }
    00113
    00114   return StatusCode::FAILURE;
    00115
    00116
    00117   //    TFile* rfile = TFile::Open(spar[0].c_str(),"RECREATE","Gaudi ROOT Ntuples");
    00118   //    if (! rfile->IsOpen() ) {
    00119   //      log << MSG::ERROR << "Could not open file " << spar[0] << " for writing" << endreq;
    00120   //      return StatusCode::FAILURE;
    00121   //    }
    00122   //    ipar[0] = (unsigned long)rfile;
    00123   //    NTuple::File* pFile = new NTuple::File(objType(), spar[0], oname);
    00124   //    pFile->setOpen(true);
    00125   //    refpObject = pFile;
    00126   //    return StatusCode::SUCCESS;
    00127
    00128 }

StatusCode RootHistCnv::RFileCnv::createRep | ( | DataObject * | pObject,
|  | IOpaqueAddress *& | refpAddress |
| ) |  |  | `[virtual]`

Convert the transient object to the requested representation.

Reimplemented from RootHistCnv::RDirectoryCnv.

Definition at line 132 of file RFileCnv.cpp.

References IRegistry::address(), DataObject::registry(), and updateRep().

    00135 {
    00136   refpAddress = pObject->registry()->address();
    00137   return RFileCnv::updateRep( refpAddress, pObject );
    00138 }

StatusCode RootHistCnv::RFileCnv::updateRep | ( | IOpaqueAddress * | pAddress,
|  | DataObject * | pObject |
| ) |  |  | `[virtual]`

Convert the transient object to the requested representation.

Reimplemented from RootHistCnv::RDirectoryCnv.

Definition at line 141 of file RFileCnv.cpp.

References endreq(), MSG::ERROR, StatusCode::FAILURE, RootHistCnv::RConverter::findTFile(), MSG::INFO, IOpaqueAddress::ipar(), NTuple::File::isOpen(), MsgStream::level(), Converter::msgSvc(), IOpaqueAddress::par(), rfile, NTuple::File::setOpen(), and StatusCode::SUCCESS.

Referenced by createRep().

    00144 {
    00145   MsgStream log(msgSvc(), "RFileCnv");
    00146   std::string ooname = pAddress->par()[1];
    00147
    00148   NTuple::File* pFile = dynamic_cast<NTuple::File*>(pObject);
    00149   if ( pFile != 0 && pFile->isOpen() )    {
    00150
    00151     unsigned long* ipar = (unsigned long*)pAddress->ipar();
    00152     if (findTFile(ooname,rfile).isFailure()) {
    00153       log << MSG::ERROR << "Problems closing TFile " << ooname << endreq;
    00154       return StatusCode::FAILURE;
    00155     }
    00156
    00157     rfile->Write(0,TObject::kOverwrite);
    00158     if ( log.level() <= MSG::INFO ) {
    00159       log << MSG::INFO << "dumping contents of " << ooname << endreq;
    00160       rfile->Print();
    00161     }
    00162     rfile->Close();
    00163     delete rfile;
    00164
    00165     ipar[0] = 0;
    00166     pFile->setOpen(false);
    00167     return StatusCode::SUCCESS;
    00168
    00169   } else {
    00170     log << MSG::ERROR << "TFile " << ooname << " is not open" << endreq;
    00171   }
    00172   return StatusCode::FAILURE;
    00173 }

static const CLID& RootHistCnv::RFileCnv::classID | ( |  | ) | `[inline, static]`

Inquire class type.

Reimplemented from RootHistCnv::RDirectoryCnv.

Definition at line 32 of file RFileCnv.h.

References CLID_NTupleFile.

    00032                                     {
    00033       return CLID_NTupleFile;
    00034     }

## Member Data Documentation

TFile* RootHistCnv::RFileCnv::rfile`[protected]`

Definition at line 43 of file RFileCnv.h.

Referenced by updateRep().

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/RootHistCnv/v9r16/src/RFileCnv.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/RootHistCnv/v9r16/src/RFileCnv.cpp