| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

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

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

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

Standard destructor.

Definition at line 139 of file PersSvc.cpp.

    00141 {
    00142   if ( m_hfile != 0 ) {
    00143     delete m_hfile;
    00144     m_hfile = 0;
    00145   }
    00146 }

## 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( msgSvc(), 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" << endmsg;
    00044     return StatusCode::FAILURE;
    00045   }
    00046   if (m_outputEnabled) {
    00047     // Initialize ROOT if output file name is defined
    00048     if( undefFileName != m_defFileName ) {
    00049       m_hfile = TFile::Open(m_defFileName.c_str(),"RECREATE","GAUDI Histograms");
    00050     } else {
    00051       m_hfile = 0;
    00052     }
    00053     log << MSG::INFO << "Writing ROOT histograms to: " << m_defFileName
    00054         << endmsg;
    00055   }
    00056   else {
    00057     log << MSG::INFO << "Writing ROOT histograms disabled." << endmsg;
    00058   }
    00059   return StatusCode(StatusCode::SUCCESS,true);
    00060 }

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

Finalise the service.

Reimplemented from ConversionSvc.

Definition at line 64 of file PersSvc.cpp.

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

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.

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

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

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

Flag to enable/disable the output to file.

Definition at line 46 of file PersSvc.h.

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

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