ATLAS Offline Software
Loading...
Searching...
No Matches
CoraCoolFolder.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef CORACOOL_CORACOOLFOLDER_H
6#define CORACOOL_CORACOOLFOLDER_H
7// CoraCoolFolder.h - interface to a COOL folder with data stored in
8// a separate CORAL payload table
9// Richard Hawkings, started 10/2006
10
11#include <vector>
12#include <string>
13#include "CoralBase/MessageStream.h"
14#include "CoralBase/AttributeList.h"
15#include "CoralBase/Attribute.h"
16#include "CoolKernel/ValidityKey.h"
17#include "CoolKernel/ChannelSelection.h"
18#include "CoolKernel/RecordSpecification.h"
19#include "CoolKernel/IField.h"
20#include "CoolKernel/pointers.h"
22
24
25
27
28namespace coral {
29 class ISessionProxy;
30 class ITable;
31 class ITableDescription;
32 class IColumn;
33 class IQuery;
34 class IBulkOperation;
35}
36
38 // allow the object iterator to access internals
39 friend class CoraCoolObjectIter;
40 public:
41 static const std::string& defaultTagName();
42 // iterators for storing objects
43 typedef std::vector<coral::AttributeList>::const_iterator const_iterator;
44
45 // constructor - do not use this directly, use CoraCoolDatabase::getFolder
46 CoraCoolFolder(const std::string& coolfolder,
47 coral::ISessionProxy* proxy, cool::IDatabasePtr cooldb,
48 CoraCoolDatabase* coradb, coral::MessageStream& log);
49
50 // destructor
52
53 // Disallow, since we manage resources.
54 CoraCoolFolder (const CoraCoolFolder&) = delete;
56
57 // properties of the folder
58 std::string coralTableName() const;
59 const std::string& coralFKey() const;
60 const std::string& coralPKey() const;
61 const cool::IRecordSpecification& fkSpecification() const;
62 const cool::RecordSpecification payloadSpecification() const;
63 coral::AttributeList emptyAttrList() const;
64
65 // allow access to the underlying COOL folder
66 cool::IFolderPtr coolFolder();
67
68 // storing data - all these can throw CoraCool and Cool exceptions
69 // store a vector of coral::AtributeLists (identified by begin/end iterators)
70 // and store the reference in COOL, with IOV (since/until), channel and tag
71 // the primary and foreign key values of the AttributeLists will be ignored
72 // as the keys will be allocated internally by the API
73 // return the value of the FK in case it is required later
74 int storeObject (const cool::ValidityKey& since,
75 const cool::ValidityKey until,
76 const_iterator begin,
78 const cool::ChannelId& channelId=0,
79 const std::string& tagName=defaultTagName(),
80 const bool userTagOnly=false);
81
82 // setup storage buffer for bulk insertion via repeated storeObject calls
83 bool setupStorageBuffer();
84 // flush the storage buffer (execute bulk insertion of objects)
85 // unlike in COOL, flush deactivates the buffer - use setupStorageBuffer
86 // again after flush if you want to carry on
87 void flushStorageBuffer();
88
89 // add a reference in COOL to an existing stored payload object identified
90 // by its foreign key (as an Attribute - normally extracted from the
91 // AttributeList), specifying the COOL IOV, channel and tag
92 void referenceObject(const cool::ValidityKey& since,
93 const cool::ValidityKey& until,
94 const coral::Attribute& fkey,
95 const cool::ChannelId& channelId=0,
96 const std::string& tagName=defaultTagName(),
97 const bool userTagOnly=false);
98
99 // add a reference to COOL to an existing stored payload object
100 // same as above, but taking the FK as a plain int
101 void referenceObject(const cool::ValidityKey& since,
102 const cool::ValidityKey& until,
103 const int ifkey,
104 const cool::ChannelId& channelId=0,
105 const std::string& tagName=defaultTagName(),
106 const bool userTagOnly=false);
107
108 // add more payload AttributeLists to the CORAL payload table
109 // the foreign key column is used to determine which existing COOL entries
110 // will reference this data
111 // the primary key column will be ignored and values allocated by the API
113
114 // accessing data - all these can throw CoraCool and Cool exceptions
115 // find the one object valid at a given time/channel and tag
116 CoraCoolObjectPtr findObject(const cool::ValidityKey& pointInTime,
117 const cool::ChannelId& channelId=0,
118 const std::string& tagName=defaultTagName());
119
120 // return an iterator to a set of objects identified by a point in time
121 // and a channel specification (and optionally a tag)
123 const cool::ValidityKey& pointInTime,
124 const cool::ChannelSelection& channels,
125 const std::string& tagName=defaultTagName());
126
127 // return an interator to a set of objects identified by a range in
128 // time and a channel specification (and optionally a tag)
130 const cool::ValidityKey& since=cool::ValidityKeyMin,
131 const cool::ValidityKey& until=cool::ValidityKeyMax,
132 const cool::ChannelSelection& channels=cool::ChannelSelection(0),
133 const std::string& tagName=defaultTagName());
134
135 // setup folder preFetch status (passed on to COOL)
136 void setPrefetchAll(const bool prefetchAll);
137
138 // Helper functions to set and return a FK/PK Attribute as an int
139 // First oner eturns False if it fails
140 // keys can be int, unsigned int, long long / unsigned long long
141 bool setAttrKey(coral::Attribute& attr,const int keyval);
142 bool setFieldKey(cool::IField& attr,const int keyval);
143 bool setFieldAttr(cool::IField& attr,const coral::Attribute& keyval);
144 int getAttrKey(const coral::Attribute& attr);
145
146 private:
147 // accessors for friend class CoraCoolObjectIter
148 coral::ISessionProxy* proxy();
149 const coral::ISessionProxy* proxy() const;
150 coral::ITable* table();
151 void setOutputSpec(coral::IQuery* query);
152
153 bool decodeAttrSpec();
154 cool::StorageType::TypeId nameToCoolType(const std::string& coolName) const;
156 const int fkey,bool updatefk);
157
158 std::string m_foldername; // name of the COOL folder
159 std::string m_dbname; // name of the COOL database instance
160 coral::ISessionProxy* m_proxy; // database session proxy
161 cool::IDatabasePtr m_cooldb; // pointer to the COOL database
162 CoraCoolDatabase* m_coradb; // pointer to the parent CoraCool database
163 coral::MessageStream& m_log;
164
165 std::string m_tablename; // name of the CORAL table for the payload
166 std::string m_keycolcoral; // name of the foreign key in CORAL table
167 std::string m_keycolcool; // name of the foreign key in COOL table
168 std::string m_pkeycolcoral; // name of the primary key in CORAL table
169 bool m_pkey; // table has separate primary key (not reusing foreign key)
170 cool::IFolderPtr m_coolfolder; // pointer to the COOL folder
171 coral::ITable* m_table; // pointer to the payload table
172 const coral::ITableDescription* m_tabledesc; // and its description
173 // vector of pairs of column name/type
174 typedef std::vector<std::pair<std::string,std::string> > AttrVec;
175 typedef AttrVec::const_iterator AttrItr;
177 // variables for the bulk operations
179 coral::AttributeList* m_payloadbuf;
180 coral::IBulkOperation* m_bulki;
187};
188
189inline std::string CoraCoolFolder::coralTableName() const
190{ return m_tablename.substr(m_dbname.size()+1); }
191
192inline const std::string& CoraCoolFolder::coralFKey() const
193{ return m_keycolcoral; }
194
195inline const std::string& CoraCoolFolder::coralPKey() const
196{ return m_pkeycolcoral; }
197
198inline cool::IFolderPtr CoraCoolFolder::coolFolder()
199{ return m_coolfolder; }
200
201inline coral::ISessionProxy* CoraCoolFolder::proxy() {return m_proxy; }
202inline const coral::ISessionProxy* CoraCoolFolder::proxy() const {return m_proxy; }
203
204// inline coral::ITable* CoraCoolFolder::table() const { return m_table; }
205
206#endif // CORACOOL_CORACOOLFOLDER_H
boost::shared_ptr< CoraCoolObject > CoraCoolObjectPtr
boost::shared_ptr< CoraCoolObjectIter > CoraCoolObjectIterPtr
Define macros for attributes used to control the static checker.
std::string m_tablename
const cool::RecordSpecification payloadSpecification() const
coral::ITable * table()
cool::StorageType::TypeId nameToCoolType(const std::string &coolName) const
CoraCoolFolder(const std::string &coolfolder, coral::ISessionProxy *proxy, cool::IDatabasePtr cooldb, CoraCoolDatabase *coradb, coral::MessageStream &log)
cool::IFolderPtr m_coolfolder
std::string m_foldername
void addPayload(const_iterator begin, const_iterator end)
coral::IBulkOperation * m_bulki
void referenceObject(const cool::ValidityKey &since, const cool::ValidityKey &until, const coral::Attribute &fkey, const cool::ChannelId &channelId=0, const std::string &tagName=defaultTagName(), const bool userTagOnly=false)
std::string m_keycolcool
coral::ISessionProxy * proxy()
AttrVec::const_iterator AttrItr
std::string m_dbname
std::string m_keycolcoral
coral::ITable * m_table
std::vector< std::pair< std::string, std::string > > AttrVec
coral::MessageStream & m_log
CoraCoolSequence * m_seqfk
std::vector< coral::AttributeList >::const_iterator const_iterator
coral::AttributeList emptyAttrList() const
CoraCoolSequence * m_seqpk
coral::ISessionProxy * m_proxy
void setOutputSpec(coral::IQuery *query)
CoraCoolFolder & operator=(const CoraCoolFolder &)=delete
coral::AttributeList * m_payloadbuf
int storeObject(const cool::ValidityKey &since, const cool::ValidityKey until, const_iterator begin, const_iterator end, const cool::ChannelId &channelId=0, const std::string &tagName=defaultTagName(), const bool userTagOnly=false)
cool::IDatabasePtr m_cooldb
CoraCoolFolder(const CoraCoolFolder &)=delete
CoraCoolObjectIterPtr browseObjects(const cool::ValidityKey &pointInTime, const cool::ChannelSelection &channels, const std::string &tagName=defaultTagName())
CoraCoolObjectPtr findObject(const cool::ValidityKey &pointInTime, const cool::ChannelId &channelId=0, const std::string &tagName=defaultTagName())
friend class CoraCoolObjectIter
const std::string & coralPKey() const
bool setFieldKey(cool::IField &attr, const int keyval)
cool::IFolderPtr coolFolder()
int getAttrKey(const coral::Attribute &attr)
std::string coralTableName() const
const coral::ITableDescription * m_tabledesc
const cool::IRecordSpecification & fkSpecification() const
CoraCoolDatabase * m_coradb
bool setAttrKey(coral::Attribute &attr, const int keyval)
std::string m_pkeycolcoral
static const std::string & defaultTagName()
void setPrefetchAll(const bool prefetchAll)
bool setFieldAttr(cool::IField &attr, const coral::Attribute &keyval)
const std::string & coralFKey() const
void bulkInsert(const_iterator begin, const_iterator end, const int fkey, bool updatefk)
Definition query.py:1