| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

Public Member Functions | Static Public Member Functions | Protected Attributes

# RootHistCnv::RFileCnv Class Reference

NTuple converter class definition. More...

`#include <RFileCnv.h>`

Inheritance diagram for RootHistCnv::RFileCnv:
[legend]
Collaboration diagram for RootHistCnv::RFileCnv:
[legend]

List of all members.

## 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

## 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.

## Constructor & Destructor Documentation

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

Standard constructor.

Definition at line 37 of file RFileCnv.h.

                                     : RDirectoryCnv(svc, classID())    {
        }

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

Standard destructor.

Definition at line 176 of file RFileCnv.cpp.

    {
    }

## Member Function Documentation

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

Inquire class type.

Reimplemented from RootHistCnv::RDirectoryCnv.

Definition at line 32 of file RFileCnv.h.

                                        {
          return CLID_NTupleFile;
        }

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.

    {
      MsgStream log(msgSvc(), "RFileCnv");
      unsigned long*     ipar = (unsigned long*)pAddress->ipar();
      char mode[2] = { char(ipar[1]), 0 };

      std::string fname  = pAddress->par()[0]; // Container name
      std::string ooname = pAddress->par()[1]; // Object name

      const std::string* spar = pAddress->par();
      // Strip of store name to get the top level RZ directory
      std::string oname = spar[1].substr(spar[1].find("/",1)+1, spar[1].length());

      // Protect against multiple instances of TROOT
      if ( 0 == gROOT )   {
        static TROOT root("root","ROOT I/O");
        //    gDebug = 99;
      } else {
        log << MSG::VERBOSE << "ROOT already initialized, debug = "
            << gDebug<< endmsg;
      }

      // Determine access mode:

      if ( mode[0] == 'O' ) {

        if (findTFile(ooname,rfile).isFailure()) {

          log << MSG::INFO << "opening Root file \"" << fname << "\" for reading"
              << endmsg;

          rfile = TFile::Open(fname.c_str(),"READ");
          if ( rfile != 0 && rfile->IsOpen() ) {
            regTFile(ooname,rfile).ignore();

            ipar[0] = (unsigned long)rfile;
            NTuple::File* pFile = new NTuple::File(objType(), fname, oname);
            pFile->setOpen(true);
            refpObject = pFile;

            return StatusCode::SUCCESS;

          } else {
            log << MSG::ERROR << "Couldn't open \"" << fname << "\" for reading"
                << endmsg;
            return StatusCode::FAILURE;
          }

        } else {
          log << MSG::DEBUG << "Root file \"" << fname << "\" already opened"
              << endmsg;
          return StatusCode::SUCCESS;
        }

      } else if ( mode[0] == 'U' ) {
        log << MSG::INFO << "opening Root file \"" << fname << "\" for updating"
            << endmsg;

        log << MSG::ERROR << "don't know how to do this yet. Aborting." << endmsg;
        exit(1);

      } else if ( mode[0] == 'N' ) {
        log << MSG::INFO << "opening Root file \"" << fname << "\" for writing"
            << endmsg;

        rfile = TFile::Open(fname.c_str(),"RECREATE","Gaudi Trees");
        if ( ! ( rfile && rfile->IsOpen() ) ) {
          log << MSG::ERROR << "Could not open file " << fname << " for writing"
              << endmsg;
          return StatusCode::FAILURE;
        }

        regTFile(ooname,rfile).ignore();

        log << MSG::DEBUG << "creating ROOT file " << fname << endmsg;

        ipar[0] = (unsigned long)rfile;
        NTuple::File* pFile = new NTuple::File(objType(), fname, oname);
        pFile->setOpen(true);
        refpObject = pFile;
        return StatusCode::SUCCESS;

      } else {

        log << MSG::ERROR << "Uknown mode to access ROOT file" << endmsg;
        return StatusCode::FAILURE;

      }

      return StatusCode::FAILURE;

      //    TFile* rfile = TFile::Open(spar[0].c_str(),"RECREATE","Gaudi ROOT Ntuples");
      //    if (! rfile->IsOpen() ) {
      //      log << MSG::ERROR << "Could not open file " << spar[0] << " for writing" << endmsg;
      //      return StatusCode::FAILURE;
      //    }
      //    ipar[0] = (unsigned long)rfile;
      //    NTuple::File* pFile = new NTuple::File(objType(), spar[0], oname);
      //    pFile->setOpen(true);
      //    refpObject = pFile;
      //    return StatusCode::SUCCESS;

    }

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.

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

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.

    {
      MsgStream log(msgSvc(), "RFileCnv");
      std::string ooname = pAddress->par()[1];

      NTuple::File* pFile = dynamic_cast<NTuple::File*>(pObject);
      if ( pFile != 0 && pFile->isOpen() )    {

        unsigned long* ipar = (unsigned long*)pAddress->ipar();
        if (findTFile(ooname,rfile).isFailure()) {
          log << MSG::ERROR << "Problems closing TFile " << ooname << endmsg;
          return StatusCode::FAILURE;
        }

        rfile->Write(0,TObject::kOverwrite);
        if ( log.level() <= MSG::INFO ) {
          log << MSG::INFO << "dumping contents of " << ooname << endmsg;
          rfile->Print();
        }
        rfile->Close();
        delete rfile;

        ipar[0] = 0;
        pFile->setOpen(false);
        return StatusCode::SUCCESS;

      } else {
        log << MSG::ERROR << "TFile " << ooname << " is not open" << endmsg;
      }
      return StatusCode::FAILURE;
    }

## Member Data Documentation

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

Definition at line 43 of file RFileCnv.h.

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines