| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# RootHistCnv::PersSvc Class Reference

`#include <PersSvc.h>`

Inheritance diagram for RootHistCnv::PersSvc:

[legend]
Collaboration diagram for RootHistCnv::PersSvc:

[legend]

List of all members.

## Detailed Description

Persistency service - to store histograms in ROOT format.

Author:
  Charles Leggett

Definition at line 21 of file PersSvc.h.

## 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.
## Friends
class | SvcFactory< PersSvc >

## Constructor & Destructor Documentation

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

Standard constructor.

Definition at line 125 of file PersSvc.cpp.

    00127 : ConversionSvc(name, svc, ROOT_StorageType), m_prtWar(false) {
    00128   declareProperty("OutputFile", m_defFileName = undefFileName);
    00129   declareProperty("ForceAlphaIds", m_alphaIds = false);
    00130 }

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

Standard destructor.

Definition at line 133 of file PersSvc.cpp.

    00135 {
    00136   if ( m_hfile != 0 ) {
    00137     delete m_hfile;
    00138     m_hfile = 0;
    00139   }
    00140 }

## Member Function Documentation

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

Initialise the service.

Reimplemented from ConversionSvc.

Definition at line 33 of file PersSvc.cpp.

    00035 {
    00036   MsgStream log( messageService(), name() );
    00037
    00038   StatusCode status = ConversionSvc::initialize();
    00039   if( status.isFailure() ) return status;
    00040
    00041   // Get my properties from the JobOptionsSvc
    00042   if (setProperties().isFailure()) {
    00043     log << MSG::ERROR << "Could not set my properties" << endreq;
    00044     return StatusCode::FAILURE;
    00045   }
    00046   // Initialize ROOT if output file name is defined
    00047   if( undefFileName != m_defFileName ) {
    00048     m_hfile = TFile::Open(m_defFileName.c_str(),"RECREATE","GAUDI Histograms");
    00049   } else {
    00050     m_hfile = 0;
    00051   }
    00052   log << MSG::INFO << "Writing ROOT histograms to: " << m_defFileName
    00053       << endreq;
    00054
    00055   return StatusCode(StatusCode::SUCCESS,true);
    00056 }

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

Finalise the service.

Reimplemented from ConversionSvc.

Definition at line 60 of file PersSvc.cpp.

    00062 {
    00063   // Close ROOT only if the output file name is defined
    00064   MsgStream log( messageService(), name() );
    00065   log << MSG::DEBUG << "RootHistCnv::PersSvc::finalize()" << endreq;
    00066   if( undefFileName != m_defFileName ) {
    00067     m_hfile->Write("",TObject::kOverwrite);
    00068     m_hfile->Close();
    00069   }
    00070   return ConversionSvc::finalize();
    00071 }

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 74 of file PersSvc.cpp.

    00077 {
    00078   // There are objects in the HDS to be stored
    00079   if( undefFileName != m_defFileName )  {
    00080     SmartDataPtr<DataObject> top(dataProvider(), stat_dir);
    00081     if ( 0 != top )    {
    00082       IRegistry* pReg = top->registry();
    00083       if ( pReg )   {
    00084         if ( top.ptr() == pObject )   {
    00085           TDirectory* pDir = m_hfile;
    00086           refpAddress = new RootObjAddress( repSvcType(),
    00087                                             CLID_DataObject,
    00088                                             stat_dir,
    00089                                             m_defFileName,
    00090                                             long(pDir),
    00091                                             long(0));
    00092           return StatusCode::SUCCESS;
    00093         }
    00094         else    {
    00095           StatusCode sc = ConversionSvc::createRep(pObject, refpAddress);
    00096           if( sc.isFailure() )   {
    00097             MsgStream log( messageService(), name() );
    00098             log << MSG::ERROR
    00099                 << "Error while creating persistent Histogram:"
    00100                 << pReg->identifier()
    00101                 << endreq;
    00102           }
    00103           return sc;
    00104         }
    00105       }
    00106     }
    00107     MsgStream err( messageService(), name() );
    00108     err << MSG::ERROR
    00109         << "Internal error while creating Histogram persistent representations"
    00110         << endreq;
    00111     return StatusCode::FAILURE;
    00112   } else {
    00113     if (!m_prtWar) {
    00114       m_prtWar = true;
    00115       MsgStream log( messageService(), name() );
    00116       log << MSG::WARNING
    00117           << "no ROOT output file name, "
    00118           << "Histograms cannot be persistified" << endreq;
    00119     }
    00120   }
    00121   return StatusCode::SUCCESS;
    00122 }

## Friends And Related Function Documentation

friend class SvcFactory< PersSvc >`[friend]`

Definition at line 23 of file PersSvc.h.

## Member Data Documentation

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_prtWar`[private]`

Already printed a Warning.

Definition at line 44 of file PersSvc.h.

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

Force alphabetic histograms/ntuple IDs.

Definition at line 45 of file PersSvc.h.

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

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