| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

Public Member Functions | Private Attributes | Friends

# RootHistCnv::PersSvc Class Reference

Persistency service - to store histograms in ROOT format. More...

`#include <PersSvc.h>`

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

List of all members.

## Public Member Functions
virtual StatusCode | initialize ()
| Initialise the service.
virtual StatusCode | finalize ()
| Finalise the service.
virtual StatusCode | createRep (DataObject *pObject, IOpaqueAddress *&refpAddress)
| Convert a collection of transient data objects into another representation.
| PersSvc (const std::string &name, ISvcLocator *svc)
| Standard constructor.
virtual | ~PersSvc ()
| Standard destructor.
## Private Attributes
std::string | m_defFileName
| Default file name.
TFile * | m_hfile
| Pointer to the ROOT file.
bool | m_prtWar
| Already printed a Warning.
bool | m_alphaIds
| Force alphabetic histograms/ntuple IDs.
bool | m_outputEnabled
| Flag to enable/disable the output to file.
## Friends
class | SvcFactory< PersSvc >

## Detailed Description

Persistency service - to store histograms in ROOT format.

Author:
  Charles Leggett

Definition at line 21 of file PersSvc.h.

## Constructor & Destructor Documentation

RootHistCnv::PersSvc::PersSvc | ( | const std::string & | name,
|  | ISvcLocator * | svc
| ) |  |

Standard constructor.

Definition at line 129 of file PersSvc.cpp.

    : ConversionSvc(name, svc, ROOT_StorageType), m_hfile(0), m_prtWar(false) {
      declareProperty("OutputFile", m_defFileName = undefFileName);
      declareProperty("ForceAlphaIds", m_alphaIds = false);
      declareProperty("OutputEnabled", m_outputEnabled = true,
                      "Flag to enable/disable the output to file.");
    }

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

Standard destructor.

Definition at line 139 of file PersSvc.cpp.

    {
      if ( m_hfile != 0 ) {
        delete m_hfile;
        m_hfile = 0;
      }
    }

## Member Function Documentation

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

Convert a collection of transient data objects into another representation.

Reimplemented from ConversionSvc.

Definition at line 78 of file PersSvc.cpp.

    {
      // There are objects in the HDS to be stored
      if( m_outputEnabled && undefFileName != m_defFileName )  {
        SmartDataPtr<DataObject> top(dataProvider(), stat_dir);
        if ( 0 != top )    {
          IRegistry* pReg = top->registry();
          if ( pReg )   {
            if ( top.ptr() == pObject )   {
              TDirectory* pDir = m_hfile;
              refpAddress = new RootObjAddress( repSvcType(),
                                                CLID_DataObject,
                                                stat_dir,
                                                m_defFileName,
                                                long(pDir),
                                                long(0));
              return StatusCode::SUCCESS;
            }
            else    {
              StatusCode sc = ConversionSvc::createRep(pObject, refpAddress);
              if( sc.isFailure() )   {
                MsgStream log( msgSvc(), name() );
                log << MSG::ERROR
                    << "Error while creating persistent Histogram:"
                    << pReg->identifier()
                    << endmsg;
              }
              return sc;
            }
          }
        }
        MsgStream err( msgSvc(), name() );
        err << MSG::ERROR
            << "Internal error while creating Histogram persistent representations"
            << endmsg;
        return StatusCode::FAILURE;
      } else {
        if (m_outputEnabled && !m_prtWar) {
          m_prtWar = true;
          MsgStream log( msgSvc(), name() );
          log << MSG::WARNING
              << "no ROOT output file name, "
              << "Histograms cannot be persistified" << endmsg;
        }
      }
      return StatusCode::SUCCESS;
    }

StatusCode RootHistCnv::PersSvc::finalize | ( | void | ) | `[virtual]`

Finalise the service.

Reimplemented from ConversionSvc.

Definition at line 64 of file PersSvc.cpp.

    {
      // Close ROOT only if the output file name is defined
      MsgStream log( msgSvc(), name() );
      log << MSG::DEBUG << "RootHistCnv::PersSvc::finalize()" << endmsg;
      if( undefFileName != m_defFileName ) {
        m_hfile->Write("",TObject::kOverwrite);
        m_hfile->Close();
      }
      return ConversionSvc::finalize();
    }

StatusCode RootHistCnv::PersSvc::initialize | ( | void | ) | `[virtual]`

Initialise the service.

Reimplemented from ConversionSvc.

Definition at line 33 of file PersSvc.cpp.

    {
      MsgStream log( msgSvc(), name() );

      StatusCode status = ConversionSvc::initialize();
      if( status.isFailure() ) return status;

      // Get my properties from the JobOptionsSvc
      if (setProperties().isFailure()) {
        log << MSG::ERROR << "Could not set my properties" << endmsg;
        return StatusCode::FAILURE;
      }
      if (m_outputEnabled) {
        // Initialize ROOT if output file name is defined
        if( undefFileName != m_defFileName ) {
          m_hfile = TFile::Open(m_defFileName.c_str(),"RECREATE","GAUDI Histograms");
        } else {
          m_hfile = 0;
        }
        log << MSG::INFO << "Writing ROOT histograms to: " << m_defFileName
            << endmsg;
      }
      else {
        log << MSG::INFO << "Writing ROOT histograms disabled." << endmsg;
      }
      return StatusCode(StatusCode::SUCCESS,true);
    }

## Friends And Related Function Documentation

friend class SvcFactory< PersSvc >`[friend]`

Definition at line 23 of file PersSvc.h.

## Member Data Documentation

bool RootHistCnv::PersSvc::m_alphaIds`[private]`

Force alphabetic histograms/ntuple IDs.

Definition at line 45 of file PersSvc.h.

std::string RootHistCnv::PersSvc::m_defFileName`[private]`

Default file name.

Definition at line 42 of file PersSvc.h.

TFile* RootHistCnv::PersSvc::m_hfile`[private]`

Pointer to the ROOT file.

Definition at line 43 of file PersSvc.h.

bool RootHistCnv::PersSvc::m_outputEnabled`[private]`

Flag to enable/disable the output to file.

Definition at line 46 of file PersSvc.h.

bool RootHistCnv::PersSvc::m_prtWar`[private]`

Already printed a Warning.

Definition at line 44 of file PersSvc.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/RootHistCnv/src/PersSvc.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/RootHistCnv/src/PersSvc.cpp

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