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