The Gaudi Framework  v33r1 (b1225454)
RootDatabaseCnv.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 }
virtual const std::string * par() const =0
Retrieve String parameters.
void setOpen(bool flag)
Set "open" flag.
Definition: NTuple.h:954
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
const std::string containerName(IRegistry *) const override
Retrieve the name of the container a given object is placed into.
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:45
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Description:
Definition: RootCnvSvc.h:62
STL namespace.
def read(f, regex='.*', skipevents=0)
Definition: hivetimeline.py:33
virtual const name_type & name() const =0
Name of the directory (or key)
StatusCode connectDatabase(const std::string &dataset, int mode, RootDataConnection **con)
Connect the output file to the service with open mode.
Definition: RootCnvSvc.cpp:204
virtual IRegistry * registry() const =0
Update branch name.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:48
Statistics file converter class definition.
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.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:32
const long ROOT_StorageType
Definition: ClassID.h:62
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
bool isSuccess() const
Definition: StatusCode.h:365
Description: NTuple directory converter class definition Definition of the converter to manage the di...
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:168
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Converter overrides: Create transient object from persistent data.
constexpr static const auto FAILURE
Definition: StatusCode.h:101
RootDatabaseCnv(long typ, const CLID &, ISvcLocator *svc, RootCnvSvc *mgr)
Initializing Constructor.
#define DECLARE_COMPONENT_WITH_ID(type, id)
Opaque address interface definition.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:40
Concrete implementation of the IDataConnection interface to access ROOT files.
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition: Converter.cpp:23
Small class representing an N tuple file in the transient store.
Definition: NTuple.h:920