Gaudi Framework, version v23r0

Home   Generated: Mon Jan 30 2012
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:
Inheritance graph
[legend]
Collaboration diagram for RootHistCnv::PersSvc:
Collaboration graph
[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 (  ) [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 (  ) [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

Force alphabetic histograms/ntuple IDs.

Definition at line 45 of file PersSvc.h.

Default file name.

Definition at line 42 of file PersSvc.h.

Pointer to the ROOT file.

Definition at line 43 of file PersSvc.h.

Flag to enable/disable the output to file.

Definition at line 46 of file PersSvc.h.

Already printed a Warning.

Definition at line 44 of file PersSvc.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Jan 30 2012 13:53:36 for Gaudi Framework, version v23r0 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004