ATLAS Offline Software
Loading...
Searching...
No Matches
CoraCoolDatabase.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef CORACOOL_CORACOOLDATABASE_H
6#define CORACOOL_CORACOOLDATABASE_H
7// CoraCoolDatabase.h - interface to a CoraCool database instance
8// for managing referenced payload data associated to a COOL database instance
9// Richard Hawkings, started 10/06
10
11#include<string>
12#include "RelationalAccess/IConnectionService.h"
13#include "CoralBase/MessageStream.h"
14#include "CoolKernel/IDatabase.h"
15#include "CoolKernel/IRecordSpecification.h"
16#include "CoralBase/AttributeListSpecification.h"
18
19namespace coral {
20 class ISessionProxy;
21 class ITable;
22}
23
25 public:
26 // instantiate a new CoraCoolDatabase instance
27 // this should not normally be used - use openDatabase in CoraCoolDatabaseSvc
28 CoraCoolDatabase(const std::string& m_dbconn, cool::IDatabasePtr cooldb,
29 coral::IConnectionService& coralsvc, const bool readonly=false);
30
31 // connect to the underlying database, return true if connected
32 // users should not normally need to call this directly
33 bool connect();
34 // disconnect from the underlying database, returns false if disconnected
35 // users should not normally need to call this directly
36 bool disconnect();
37
38 // return the COOL database name associated with the folder
39 const std::string& dbname() const;
40
41 // return the COOL database connection associated with the folder
42 cool::IDatabasePtr coolDatabase() const;
43
44 // create a CoraCool folder by creating the corresponding COOL folder and
45 // the CoraCool table with the given name (with COOL dbinstance prepended)
46 // the CoraCool metadata is added to the given descrpition string
47 // throws CoraCool and Cool exceptions in case of problems
48 CoraCoolFolderPtr createFolder(const std::string& coolpath,
49 const std::string& coraltable,
50 const cool::IRecordSpecification& fkspec,
51 const cool::IRecordSpecification& payloadspec,
52 const std::string& coralfk,
53 const std::string& coralpk,
54 const std::string& description="",
55 const cool::FolderVersioning::Mode mode=cool::FolderVersioning::SINGLE_VERSION,
56 const bool createParents=false);
57
58 // get a pointer to the CoraCoolFolder object
59 // throws CoraCool or Cool exceptions if folder does not exist, problems
60 // with <coracool> metadata etc
61 CoraCoolFolderPtr getFolder(const std::string& coolfolder);
62
63 // check if the folder exists as a CoraCool folder
64 // true if the corresponding COOL folder exists and there is the
65 // <coracool> meta data in the COOL description string
66 bool existsFolder(const std::string& coolfolder);
67
68 // parse the COOL folder description to extract the CORAL table name,
69 // COOL and CORAL foreign and primary key names
70 // returns true if all information extracted, false if syntax problems
71 bool parseFolderDescription(const std::string& folderdesc,
72 std::string& tablename,
73 std::string& keycolcool,
74 std::string& fkeycolcoral,
75 std::string& pkeycolcoral);
76
77 // delete the COOL folder and any associated CORAL table
78 // returns true if folder successfully dropped
79 // throws Cool or CoraCool exceptions if problems
80 bool deleteFolder(const std::string& coolfolder);
81
82 private:
83 bool extractCoralConStr(std::string_view coolstr);
84 std::string encodeAttrSpec(const cool::IRecordSpecification& spec);
85 bool storeSpec(const std::string& tablename,const std::string& spec);
86
87 cool::IDatabasePtr m_cooldb; // pointer to COOL database instance
88 std::string m_dbconn; // CORAL database connection string
89 std::string m_dbname; // COOL database instance name
90 bool m_connected; // true when connection is active
91 bool m_readonly; // true for readonly instance (can share connection)
92 coral::IConnectionService& m_coralsvc; // CORAL connection service to use
93 coral::ISessionProxy* m_proxy;
94 coral::MessageStream m_log;
95};
96
97inline const std::string& CoraCoolDatabase::dbname() const { return m_dbname; }
98
99inline cool::IDatabasePtr CoraCoolDatabase::coolDatabase() const
100{return m_cooldb; }
101
102#endif // CORACOOL_CORACOOLDATABASE_H
boost::shared_ptr< CoraCoolFolder > CoraCoolFolderPtr
coral::IConnectionService & m_coralsvc
CoraCoolFolderPtr createFolder(const std::string &coolpath, const std::string &coraltable, const cool::IRecordSpecification &fkspec, const cool::IRecordSpecification &payloadspec, const std::string &coralfk, const std::string &coralpk, const std::string &description="", const cool::FolderVersioning::Mode mode=cool::FolderVersioning::SINGLE_VERSION, const bool createParents=false)
coral::ISessionProxy * m_proxy
coral::MessageStream m_log
bool extractCoralConStr(std::string_view coolstr)
CoraCoolDatabase(const std::string &m_dbconn, cool::IDatabasePtr cooldb, coral::IConnectionService &coralsvc, const bool readonly=false)
bool deleteFolder(const std::string &coolfolder)
CoraCoolFolderPtr getFolder(const std::string &coolfolder)
const std::string & dbname() const
bool existsFolder(const std::string &coolfolder)
cool::IDatabasePtr coolDatabase() const
cool::IDatabasePtr m_cooldb
bool parseFolderDescription(const std::string &folderdesc, std::string &tablename, std::string &keycolcool, std::string &fkeycolcoral, std::string &pkeycolcoral)
std::string encodeAttrSpec(const cool::IRecordSpecification &spec)
bool storeSpec(const std::string &tablename, const std::string &spec)
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91