ATLAS Offline Software
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"
21 #include "CoraCool/CoraCoolTypes.h"
22 
24 
25 
26 class CoraCoolSequence;
27 
28 namespace 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;
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,
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
179  coral::IBulkOperation* m_bulki;
182  int m_nextpk;
183  int m_usedpk;
184  int m_nextfk;
185  int m_usedfk;
186 };
187 
188 inline std::string CoraCoolFolder::coralTableName() const
189 { return m_tablename.substr(m_dbname.size()+1); }
190 
191 inline const std::string& CoraCoolFolder::coralFKey() const
192 { return m_keycolcoral; }
193 
194 inline const std::string& CoraCoolFolder::coralPKey() const
195 { return m_pkeycolcoral; }
196 
197 inline cool::IFolderPtr CoraCoolFolder::coolFolder()
198 { return m_coolfolder; }
199 
200 inline coral::ISessionProxy* CoraCoolFolder::proxy() {return m_proxy; }
201 inline 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
CoraCoolFolder::nameToCoolType
cool::StorageType::TypeId nameToCoolType(const std::string &coolName) const
Definition: CoraCoolFolder.cxx:469
CoraCoolFolder::m_attrvec
AttrVec m_attrvec
Definition: CoraCoolFolder.h:175
CoraCoolFolder::setupStorageBuffer
bool setupStorageBuffer()
Definition: CoraCoolFolder.cxx:211
CoraCoolTypes.h
CoraCoolFolder::decodeAttrSpec
bool decodeAttrSpec()
Definition: CoraCoolFolder.cxx:423
CoraCoolFolder::setFieldKey
bool setFieldKey(cool::IField &attr, const int keyval)
Definition: CoraCoolFolder.cxx:363
CoraCoolDatabase
Definition: CoraCoolDatabase.h:24
CoraCoolFolder::AttrVec
std::vector< std::pair< std::string, std::string > > AttrVec
Definition: CoraCoolFolder.h:173
CoraCoolFolder::coolFolder
cool::IFolderPtr coolFolder()
Definition: CoraCoolFolder.h:197
CoraCoolFolder::m_pkeycolcoral
std::string m_pkeycolcoral
Definition: CoraCoolFolder.h:167
CoraCoolFolder
Definition: CoraCoolFolder.h:37
CoraCoolFolder::m_pkey
bool m_pkey
Definition: CoraCoolFolder.h:168
CoraCoolFolder::setPrefetchAll
void setPrefetchAll(const bool prefetchAll)
Definition: CoraCoolFolder.cxx:570
CoraCoolFolder::m_nextfk
int m_nextfk
Definition: CoraCoolFolder.h:184
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
CoraCoolFolder::m_seqfk
CoraCoolSequence * m_seqfk
Definition: CoraCoolFolder.h:181
CoraCoolFolder::m_nextpk
int m_nextpk
Definition: CoraCoolFolder.h:182
CoraCoolFolder::browseObjects
CoraCoolObjectIterPtr browseObjects(const cool::ValidityKey &pointInTime, const cool::ChannelSelection &channels, const std::string &tagName="")
Definition: CoraCoolFolder.cxx:550
CoraCoolFolder::bulkInsert
void bulkInsert(const_iterator begin, const_iterator end, const int fkey, bool updatefk)
Definition: CoraCoolFolder.cxx:496
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
CoraCoolFolder::emptyAttrList
coral::AttributeList emptyAttrList() const
Definition: CoraCoolFolder.cxx:116
CoraCoolObjectIter
Definition: CoraCoolObjectIter.h:37
CoraCoolFolder::table
coral::ITable * table()
Definition: CoraCoolFolder.cxx:575
CoraCoolFolder::coralPKey
const std::string & coralPKey() const
Definition: CoraCoolFolder.h:194
CoraCoolFolder::~CoraCoolFolder
~CoraCoolFolder()
Definition: CoraCoolFolder.cxx:95
CoraCoolFolder::m_table
coral::ITable * m_table
Definition: CoraCoolFolder.h:170
CoraCoolFolder::operator=
CoraCoolFolder & operator=(const CoraCoolFolder &)=delete
CoraCoolFolder::m_payloadbuf
coral::AttributeList * m_payloadbuf
Definition: CoraCoolFolder.h:178
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
CoraCoolFolder::m_bulki
coral::IBulkOperation * m_bulki
Definition: CoraCoolFolder.h:179
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
dq_defect_copy_defect_database.until
def until
Definition: dq_defect_copy_defect_database.py:55
coral
Definition: ISecondaryEventSelector.h:19
query
Definition: query.py:1
CoraCoolFolder::coralFKey
const std::string & coralFKey() const
Definition: CoraCoolFolder.h:191
CoraCoolFolder::setAttrKey
bool setAttrKey(coral::Attribute &attr, const int keyval)
Definition: CoraCoolFolder.cxx:342
CoraCoolFolder::m_keycolcoral
std::string m_keycolcoral
Definition: CoraCoolFolder.h:165
CoraCoolFolder::const_iterator
std::vector< coral::AttributeList >::const_iterator const_iterator
Definition: CoraCoolFolder.h:42
CoraCoolFolder::getAttrKey
int getAttrKey(const coral::Attribute &attr)
Definition: CoraCoolFolder.cxx:406
CoraCoolFolder::m_bulkactive
bool m_bulkactive
Definition: CoraCoolFolder.h:177
CoraCoolFolder::m_tablename
std::string m_tablename
Definition: CoraCoolFolder.h:164
CoraCoolFolder::payloadSpecification
const cool::RecordSpecification payloadSpecification() const
Definition: CoraCoolFolder.cxx:107
CoraCoolFolder::referenceObject
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)
Definition: CoraCoolFolder.cxx:261
CoraCoolSequence
Definition: CoraCoolSequence.h:15
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
CoraCoolFolder::coralTableName
std::string coralTableName() const
Definition: CoraCoolFolder.h:188
CoraCoolFolder::findObject
CoraCoolObjectPtr findObject(const cool::ValidityKey &pointInTime, const cool::ChannelId &channelId=0, const std::string &tagName="")
Definition: CoraCoolFolder.cxx:519
CoraCoolFolder::m_cooldb
cool::IDatabasePtr m_cooldb
Definition: CoraCoolFolder.h:160
CoraCoolFolder::proxy
coral::ISessionProxy * proxy()
Definition: CoraCoolFolder.h:200
CoraCoolFolder::CoraCoolFolder
CoraCoolFolder(const std::string &coolfolder, coral::ISessionProxy *proxy, cool::IDatabasePtr cooldb, CoraCoolDatabase *coradb, coral::MessageStream &log)
Definition: CoraCoolFolder.cxx:40
CoraCoolFolder::CoraCoolFolder
CoraCoolFolder(const CoraCoolFolder &)=delete
CoraCoolFolder::setOutputSpec
void setOutputSpec(coral::IQuery *query)
Definition: CoraCoolFolder.cxx:489
CoraCoolFolder::fkSpecification
const cool::IRecordSpecification & fkSpecification() const
Definition: CoraCoolFolder.cxx:102
CoraCoolFolder::m_coolfolder
cool::IFolderPtr m_coolfolder
Definition: CoraCoolFolder.h:169
CoraCoolFolder::m_dbname
std::string m_dbname
Definition: CoraCoolFolder.h:158
CoraCoolFolder::setFieldAttr
bool setFieldAttr(cool::IField &attr, const coral::Attribute &keyval)
Definition: CoraCoolFolder.cxx:384
CoraCoolFolder::AttrItr
AttrVec::const_iterator AttrItr
Definition: CoraCoolFolder.h:174
CoraCoolFolder::m_usedpk
int m_usedpk
Definition: CoraCoolFolder.h:183
CoraCoolObjectIterPtr
boost::shared_ptr< CoraCoolObjectIter > CoraCoolObjectIterPtr
Definition: CoraCoolTypes.h:21
CoraCoolFolder::m_seqpk
CoraCoolSequence * m_seqpk
Definition: CoraCoolFolder.h:180
CoraCoolObjectPtr
boost::shared_ptr< CoraCoolObject > CoraCoolObjectPtr
Definition: CoraCoolTypes.h:18
CoraCoolFolder::flushStorageBuffer
void flushStorageBuffer()
Definition: CoraCoolFolder.cxx:243
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
CoraCoolFolder::storeObject
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)
Definition: CoraCoolFolder.cxx:125
CoraCoolFolder::m_log
coral::MessageStream & m_log
Definition: CoraCoolFolder.h:162
CoraCoolFolder::m_foldername
std::string m_foldername
Definition: CoraCoolFolder.h:157
checker_macros.h
Define macros for attributes used to control the static checker.
Crest::TypeId
TypeId
Definition: CrestContainer.h:24
CoraCoolFolder::m_proxy
coral::ISessionProxy * m_proxy
Definition: CoraCoolFolder.h:159
CoraCoolFolder::m_tabledesc
const coral::ITableDescription * m_tabledesc
Definition: CoraCoolFolder.h:171
CoraCoolFolder::addPayload
void addPayload(const_iterator begin, const_iterator end)
Definition: CoraCoolFolder.cxx:293
Example_ReadSampleNoise.pointInTime
pointInTime
Definition: Example_ReadSampleNoise.py:14
CoraCoolFolder::m_coradb
CoraCoolDatabase * m_coradb
Definition: CoraCoolFolder.h:161
CoraCoolFolder::m_keycolcool
std::string m_keycolcool
Definition: CoraCoolFolder.h:166
CoraCoolFolder::m_usedfk
int m_usedfk
Definition: CoraCoolFolder.h:185