ATLAS Offline Software
CoraCoolObjectIter.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef CORACOOL_CORACOOLOBJECTITER_H
6 #define CORACOOL_CORACOOLOBJECTITER_H
7 // CoraCoolObjectIter.h - allows to iterate over the result of a CoraCool
8 // bulk query from the CoraCoolFolder browseObject method
9 //
10 // usage pattern is the same as for the COOL IObjectIterator, i.e.
11 // CoraCoolObjectIterPtr itr=CoraCoolFolderPtr->browseObjects(..)
12 // while (itr->hasNext()) {
13 // CoraCoolObjectPtr obj=itr->next()
14 // // do something with the object
15 // }
16 // itr->close()
17 //
18 // Richard Hawkings, started 10/2006
19 
32 #include "CoolKernel/IObjectIterator.h"
33 #include "CoraCool/CoraCoolTypes.h"
34 
35 class CoraCoolFolder;
36 
38  public:
39  // constructor - do not use this directly but create iterators using
40  // CoraCoolFolder::browseObject(..)
41  CoraCoolObjectIter(CoraCoolFolder* coracoolfolder, cool::IObjectIteratorPtr coolptr);
43 
44  // get the next object - call hasNext() first to check there is one
45  // throws CoraCoolException if there is none
47 
48  // does the iterator have a next object
49  bool hasNext();
50 
51  // go to next, if the folder has
52  bool goToNext();
53 
54  // return a reference to the current object
56 
57  // close the iterator, releasing resources
58  void close();
59 
60  private:
61  // hide default and copy constructors, and assignment operator
62  // declared but not implemented
66 
67  // implementation class to build queries
68  class QueryBuilder {
69  public:
70  // setup query builder with specified number size of range pairs
71  QueryBuilder(const unsigned int size);
72  ~QueryBuilder();
73 
74  // return current size (num of range pairs) and number of terms in query
75  unsigned int size() const;
76  unsigned int terms() const;
77  // add a FK value to the query list
78  unsigned int add(const long long value);
79  // prepare the DB query - return the where clause and the list of foreign
80  // key bind variables, given the coralkey name and FK attribute spec
81  void getQuery(std::string& where,const std::string& coralkey,
82  coral::AttributeList& fkeys, const coral::AttributeSpecification& spec);
83 
84  private:
85  // hide default and copy constructors, and assignment operator
89 
90  std::string addKey(unsigned int& key,
91  coral::AttributeList& fkeys,
92  const coral::AttributeSpecification& spec,
93  const long long value);
94  unsigned int m_terms;
95  unsigned int m_size; // number of ranges stored
96  unsigned int m_maxsize; // max size of the array
97  long long* m_lower; // array of lower and upper bounds for ranges
98  long long* m_upper;// assumed to be store in ascending numerical order
99  };
100  void readDataToBuffer();
101  bool iHasNext();
102  bool equalAttr(const coral::Attribute& a1, const coral::Attribute& a2) const;
103  bool isNumAttr(const std::string& spec) const;
104  long long numAttr(const std::string& spec, const coral::Attribute& a) const;
105 
106  unsigned int m_buflen; // size of the buffer for payload data
107  unsigned int m_inbuf; // number of objects in the buffer
108  unsigned int m_nextobj; // pointer to next object
109  bool m_refValid; // COOL iterator contains valid reference
110  bool m_allDone; // COOL iterator is exhausted
112  cool::IObjectIteratorPtr m_coolitr;
113  coral::AttributeListSpecification* m_spec;
114  std::vector<CoraCoolObjectPtr> m_data;
115 };
116 
117 inline unsigned int CoraCoolObjectIter::QueryBuilder::size() const
118 { return m_size; }
119 inline unsigned int CoraCoolObjectIter::QueryBuilder::terms() const
120 { return m_terms; }
121 
122 #endif // CORACOOL_CORACOOLOBJECTITER_H
123 
CoraCoolObjectIter::m_refValid
bool m_refValid
Definition: CoraCoolObjectIter.h:109
CoraCoolObjectIter::numAttr
long long numAttr(const std::string &spec, const coral::Attribute &a) const
Definition: CoraCoolObjectIter.cxx:231
CoraCoolObjectIter::m_nextobj
unsigned int m_nextobj
Definition: CoraCoolObjectIter.h:108
CoraCoolObject
Definition: CoraCoolObject.h:20
CoraCoolTypes.h
CoraCoolObjectIter::isNumAttr
bool isNumAttr(const std::string &spec) const
Definition: CoraCoolObjectIter.cxx:225
CoraCoolObjectIter::m_spec
coral::AttributeListSpecification * m_spec
Definition: CoraCoolObjectIter.h:113
CoraCoolObjectIter::QueryBuilder::QueryBuilder
QueryBuilder()
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
CoraCoolObjectIter::QueryBuilder::getQuery
void getQuery(std::string &where, const std::string &coralkey, coral::AttributeList &fkeys, const coral::AttributeSpecification &spec)
Definition: CoraCoolObjectIter.cxx:302
CoraCoolFolder
Definition: CoraCoolFolder.h:37
CoraCoolObjectIter::QueryBuilder::size
unsigned int size() const
Definition: CoraCoolObjectIter.h:117
CoraCoolObjectIter::operator=
CoraCoolObjectIter & operator=(const CoraCoolObjectIter &)
CoraCoolObjectIter::QueryBuilder::terms
unsigned int terms() const
Definition: CoraCoolObjectIter.h:119
CoraCoolObjectIter::CoraCoolObjectIter
CoraCoolObjectIter()
CoraCoolObjectIter::m_coolitr
cool::IObjectIteratorPtr m_coolitr
Definition: CoraCoolObjectIter.h:112
athena.value
value
Definition: athena.py:122
CoraCoolObjectIter::CoraCoolObjectIter
CoraCoolObjectIter(const CoraCoolObjectIter &)
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
CoraCoolObjectIter
Definition: CoraCoolObjectIter.h:37
CoraCoolObjectIter::QueryBuilder::QueryBuilder
QueryBuilder(const QueryBuilder &)
CoraCoolObjectIter::equalAttr
bool equalAttr(const coral::Attribute &a1, const coral::Attribute &a2) const
Definition: CoraCoolObjectIter.cxx:190
CoraCoolObjectIter::QueryBuilder
Definition: CoraCoolObjectIter.h:68
CoraCoolObjectIter::m_folder
CoraCoolFolder * m_folder
Definition: CoraCoolObjectIter.h:111
CoraCoolObjectIter::goToNext
bool goToNext()
Definition: CoraCoolObjectIter.cxx:166
CoraCoolObjectIter::QueryBuilder::m_upper
long long * m_upper
Definition: CoraCoolObjectIter.h:98
CoraCoolObjectIter::QueryBuilder::operator=
QueryBuilder & operator=(const QueryBuilder &)
python.Utils.unixtools.where
def where(filename, prepath=[])
"which" for python files -------------------------------------------------—
Definition: unixtools.py:53
CoraCoolObjectIter::next
CoraCoolObjectPtr next()
Definition: CoraCoolObjectIter.cxx:53
CoraCoolObjectIter::QueryBuilder::m_terms
unsigned int m_terms
Definition: CoraCoolObjectIter.h:94
CoraCoolObjectIter::m_data
std::vector< CoraCoolObjectPtr > m_data
Definition: CoraCoolObjectIter.h:114
CoraCoolObjectIter::QueryBuilder::m_maxsize
unsigned int m_maxsize
Definition: CoraCoolObjectIter.h:96
CoraCoolObjectIter::m_allDone
bool m_allDone
Definition: CoraCoolObjectIter.h:110
CoraCoolObjectIter::QueryBuilder::m_size
unsigned int m_size
Definition: CoraCoolObjectIter.h:95
CoraCoolObjectIter::~CoraCoolObjectIter
~CoraCoolObjectIter()
Definition: CoraCoolObjectIter.cxx:49
CoraCoolObjectIter::iHasNext
bool iHasNext()
Definition: CoraCoolObjectIter.cxx:210
a
TList * a
Definition: liststreamerinfos.cxx:10
CoraCoolObjectIter::m_inbuf
unsigned int m_inbuf
Definition: CoraCoolObjectIter.h:107
CoraCoolObjectIter::currentRef
CoraCoolObject & currentRef()
Definition: CoraCoolObjectIter.cxx:178
CoraCoolObjectPtr
boost::shared_ptr< CoraCoolObject > CoraCoolObjectPtr
Definition: CoraCoolTypes.h:18
CoraCoolObjectIter::QueryBuilder::~QueryBuilder
~QueryBuilder()
Definition: CoraCoolObjectIter.cxx:256
CoraCoolObjectIter::readDataToBuffer
void readDataToBuffer()
Definition: CoraCoolObjectIter.cxx:66
CoraCoolObjectIter::hasNext
bool hasNext()
Definition: CoraCoolObjectIter.cxx:162
CoraCoolObjectIter::QueryBuilder::m_lower
long long * m_lower
Definition: CoraCoolObjectIter.h:97
CoraCoolObjectIter::m_buflen
unsigned int m_buflen
Definition: CoraCoolObjectIter.h:106
CoraCoolObjectIter::QueryBuilder::addKey
std::string addKey(unsigned int &key, coral::AttributeList &fkeys, const coral::AttributeSpecification &spec, const long long value)
Definition: CoraCoolObjectIter.cxx:353
CoraCoolObjectIter::close
void close()
Definition: CoraCoolObjectIter.cxx:182
CoraCoolObjectIter::QueryBuilder::add
unsigned int add(const long long value)
Definition: CoraCoolObjectIter.cxx:261
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37