The Gaudi Framework  master (37c0b60a)
RootDatabaseCnv.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 //------------------------------------------------------------------------------
12 //
13 // Implementation of class : RootDatabaseCnv
14 //
15 // Author : Markus Frank
16 //
17 //------------------------------------------------------------------------------
18 // Framework include files
21 
23 #include <GaudiKernel/IRegistry.h>
24 #include <GaudiKernel/NTuple.h>
25 
26 #if 0
28  ConverterID(ROOT_StorageType,CLID_StatisticsFile) )
29 #endif
30 
31 using namespace Gaudi;
32 using namespace std;
33 
34 // Standard Constructor
35 RootDatabaseCnv::RootDatabaseCnv( long typ, const CLID& cl, ISvcLocator* svc, RootCnvSvc* mgr )
36  : RootDirectoryCnv( typ, cl, svc, mgr ) {}
37 
38 // Create database object
41  if ( pAddr ) {
42  RootDataConnection* con = nullptr;
43  IRegistry* pReg = pAddr->registry();
44  const unsigned long* ipars = pAddr->ipar();
45  const string* spars = pAddr->par();
46  char mode = char( ipars[1] );
47  string fname = spars[0];
48  auto oname = pReg->name();
49  bool recrea = mode == 'R';
50  bool create = mode == 'N';
51  bool update = mode == 'U';
52  bool read = mode == 'O';
53  const CLID& clid = objType();
54  status = StatusCode::SUCCESS;
55  string cntName = containerName( pReg );
56  if ( create ) {
58  status = saveDescription( fname, cntName, "File containing statistics results.", "", clid );
59  if ( status.isSuccess() ) {
60  log() << MSG::INFO << "Opened NEW Database file:" << fname << " as " << oname << endmsg;
61  }
62  } else if ( update ) {
64  status = saveDescription( fname, cntName, "File containing statistics results.", "", clid );
65  if ( status.isSuccess() ) {
66  log() << MSG::INFO << "Connect to existing Database file:" << fname << " as " << oname << " for UPDATE"
67  << endmsg;
68  }
69  } else if ( read ) {
70  status = m_dbMgr->connectDatabase( fname, IDataConnection::READ, &con );
71  if ( status.isSuccess() ) {
72  log() << MSG::INFO << "Connect to existing Database file:" << fname << " as " << oname << " for READ" << endmsg;
73  }
74  } else if ( recrea ) {
76  status = saveDescription( fname, cntName, "File containing statistics results.", "", clid );
77  if ( status.isSuccess() ) {
78  log() << MSG::INFO << "Recreate Database file:" << fname << " as " << oname << endmsg;
79  }
80  } else {
81  log() << MSG::ERROR << "Don't know what to do:" << fname << endmsg;
82  status = StatusCode::FAILURE;
83  }
84  // Now create object
85  if ( status.isSuccess() ) {
86  NTuple::File* pFile = new NTuple::File( objType(), fname, oname );
87  pFile->setOpen( false );
88  refpObj = pFile;
89  }
90  }
91  return status;
92 }
Gaudi::RootDatabaseCnv::createObj
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Converter overrides: Create transient object from persistent data.
Definition: RootDatabaseCnv.cpp:39
Gaudi::RootDatabaseCnv::RootDatabaseCnv
RootDatabaseCnv(long typ, const CLID &, ISvcLocator *svc, RootCnvSvc *mgr)
Initializing Constructor.
Definition: RootDatabaseCnv.cpp:35
NTuple::File
Small class representing an N tuple file in the transient store.
Definition: NTuple.h:923
IOpaqueAddress::par
virtual const std::string * par() const =0
Retrieve String parameters.
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
MSG::INFO
@ INFO
Definition: IMessageSvc.h:25
Gaudi::RootCnvSvc::connectDatabase
StatusCode connectDatabase(const std::string &dataset, int mode, RootDataConnection **con)
Connect the output file to the service with open mode.
Definition: RootCnvSvc.cpp:210
Gaudi::RootConverter::m_dbMgr
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:45
Gaudi::RootCnvSvc
Definition: RootCnvSvc.h:62
IOpaqueAddress
Definition: IOpaqueAddress.h:33
Gaudi::RootDatabaseCnv
Definition: RootDatabaseCnv.h:38
ISvcLocator
Definition: ISvcLocator.h:46
Gaudi::IDataConnection::RECREATE
@ RECREATE
Definition: IIODataManager.h:49
IRegistry
Definition: IRegistry.h:32
RootDataConnection.h
RootDatabaseCnv.h
Gaudi::RootDataConnection
Definition: RootDataConnection.h:112
DECLARE_COMPONENT_WITH_ID
#define DECLARE_COMPONENT_WITH_ID(type, id)
Definition: PluginServiceV1.h:47
Gaudi::RootDatabaseCnv::containerName
const std::string containerName(IRegistry *) const override
Retrieve the name of the container a given object is placed into.
Definition: RootDatabaseCnv.h:54
Gaudi::IDataConnection::CREATE
@ CREATE
Definition: IIODataManager.h:49
ConverterID
Definition: Converter.h:147
IRegistry::name
virtual const name_type & name() const =0
Name of the directory (or key)
StatusCode
Definition: StatusCode.h:65
Gaudi::RootStatCnv::saveDescription
StatusCode saveDescription(const std::string &path, const std::string &ident, const std::string &desc, const std::string &opt, const CLID &clid)
Save statistics object description.
Definition: RootStatCnv.cpp:109
IOpaqueAddress.h
Gaudi::IDataConnection::UPDATE
@ UPDATE
Definition: IIODataManager.h:49
Gaudi::IDataConnection::READ
@ READ
Definition: IIODataManager.h:49
NTuple.h
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
ROOT_StorageType
const long ROOT_StorageType
Definition: ClassID.h:62
Converter::objType
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition: Converter.cpp:23
Gaudi::RootDirectoryCnv
Definition: RootDirectoryCnv.h:40
IRegistry.h
IOpaqueAddress::registry
virtual IRegistry * registry() const =0
Update branch name.
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
Gaudi::RootStatCnv::log
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:48
hivetimeline.read
def read(f, regex=".*", skipevents=0)
Definition: hivetimeline.py:32
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
GaudiPython.Pythonizations.update
update
Definition: Pythonizations.py:145
std
STL namespace.
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
DataObject
Definition: DataObject.h:36
NTuple::File::setOpen
void setOpen(bool flag)
Set "open" flag.
Definition: NTuple.h:957
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
IOpaqueAddress::ipar
virtual const unsigned long * ipar() const =0
Access to generic link parameters.