ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CoraCoolObjectIter Class Reference

#include <CoraCoolObjectIter.h>

Collaboration diagram for CoraCoolObjectIter:

Classes

class  QueryBuilder
 

Public Member Functions

 CoraCoolObjectIter (CoraCoolFolder *coracoolfolder, cool::IObjectIteratorPtr coolptr)
 
 ~CoraCoolObjectIter ()
 
CoraCoolObjectPtr next ()
 
bool hasNext ()
 
bool goToNext ()
 
CoraCoolObjectcurrentRef ()
 
void close ()
 

Private Member Functions

 CoraCoolObjectIter ()
 
 CoraCoolObjectIter (const CoraCoolObjectIter &)
 
CoraCoolObjectIteroperator= (const CoraCoolObjectIter &)
 
void readDataToBuffer ()
 
bool iHasNext ()
 
bool equalAttr (const coral::Attribute &a1, const coral::Attribute &a2) const
 
bool isNumAttr (const std::string &spec) const
 
long long numAttr (const std::string &spec, const coral::Attribute &a) const
 

Private Attributes

unsigned int m_buflen
 
unsigned int m_inbuf
 
unsigned int m_nextobj
 
bool m_refValid
 
bool m_allDone
 
CoraCoolFolderm_folder
 
cool::IObjectIteratorPtr m_coolitr
 
coral::AttributeListSpecification * m_spec
 
std::vector< CoraCoolObjectPtrm_data
 

Detailed Description

Definition at line 37 of file CoraCoolObjectIter.h.

Constructor & Destructor Documentation

◆ CoraCoolObjectIter() [1/3]

CoraCoolObjectIter::CoraCoolObjectIter ( CoraCoolFolder coracoolfolder,
cool::IObjectIteratorPtr  coolptr 
)

Definition at line 32 of file CoraCoolObjectIter.cxx.

33  :
35  m_refValid(false),m_allDone(false),
36  m_folder(coracoolfolder),m_coolitr(coolitr) {
37  m_data.resize(m_buflen);
38  // assemble an AttributeListSpecification to share with the data objects
39  const cool::RecordSpecification recspec=m_folder->payloadSpecification();
40  const coral::AttributeList speclist = cool::Record(recspec).attributeList();
41  m_spec=new coral::AttributeListSpecification();
42  for (coral::AttributeList::const_iterator itr=speclist.begin();
43  itr!=speclist.end();++itr) {
44  const coral::AttributeSpecification& aspec=itr->specification();
45  m_spec->extend(aspec.name(),aspec.typeName());
46  }
47 }

◆ ~CoraCoolObjectIter()

CoraCoolObjectIter::~CoraCoolObjectIter ( )

Definition at line 49 of file CoraCoolObjectIter.cxx.

49  {
50  if (m_spec!=0) m_spec->release();
51 }

◆ CoraCoolObjectIter() [2/3]

CoraCoolObjectIter::CoraCoolObjectIter ( )
private

◆ CoraCoolObjectIter() [3/3]

CoraCoolObjectIter::CoraCoolObjectIter ( const CoraCoolObjectIter )
private

Member Function Documentation

◆ close()

void CoraCoolObjectIter::close ( )

Definition at line 182 of file CoraCoolObjectIter.cxx.

182  {
183  // release any resources associated with the query
184  // close underlying COOL query
185  m_coolitr->close();
186  // release ownership of any CoraCoolObjects we have
187  for (unsigned int i=0;i<m_buflen;++i) m_data[i].reset();
188 }

◆ currentRef()

CoraCoolObject & CoraCoolObjectIter::currentRef ( )

Definition at line 178 of file CoraCoolObjectIter.cxx.

178  {
179  return *(m_data.at(m_nextobj-1));
180 }

◆ equalAttr()

bool CoraCoolObjectIter::equalAttr ( const coral::Attribute &  a1,
const coral::Attribute &  a2 
) const
private

Definition at line 190 of file CoraCoolObjectIter.cxx.

191 {
192  // compare two Attributes based on type and value
193  // deal with some special cases where the types are not the same
194  // the easy part - if types are same
195  std::string spec1=a1.specification().typeName();
196  std::string spec2=a2.specification().typeName();
197  if (spec1==spec2) {
198  return (a1==a2);
199  } else if (isNumAttr(spec1) && isNumAttr(spec2)) {
200  // convert to long long and compare
201  long long v1=numAttr(spec1,a1);
202  long long v2=numAttr(spec2,a2);
203  return (v1==v2);
204  } else {
205  // unhandled case
206  return false;
207  }
208 }

◆ goToNext()

bool CoraCoolObjectIter::goToNext ( )

Definition at line 166 of file CoraCoolObjectIter.cxx.

166  {
167  const bool nextExists=hasNext();
168  if (m_inbuf>m_nextobj){
169  ++m_nextobj;//just update the index
170  } else if (iHasNext()){
172  } else {
173  //throw CoraCoolException("No more data in CoraCoolObjectIter","CoraCoolObjectIter::goToNext");
174  }
175  return nextExists;
176 }

◆ hasNext()

bool CoraCoolObjectIter::hasNext ( )

Definition at line 162 of file CoraCoolObjectIter.cxx.

162  {
163  return (m_inbuf>m_nextobj || iHasNext());
164 }

◆ iHasNext()

bool CoraCoolObjectIter::iHasNext ( )
private

Definition at line 210 of file CoraCoolObjectIter.cxx.

210  {
211  // implement old-COOL-style iterator behaviour - return if next is valid
212  // can be called multiple times - after call currentRef will give data
213  if (m_refValid) return true;
214  if (m_allDone) return false;
215  if (m_coolitr->goToNext()) {
216  m_refValid=true;
217  return true;
218  } else {
219  m_refValid=false;
220  m_allDone=true;
221  return false;
222  }
223 }

◆ isNumAttr()

bool CoraCoolObjectIter::isNumAttr ( const std::string &  spec) const
private

Definition at line 225 of file CoraCoolObjectIter.cxx.

225  {
226  return (spec=="long long" || spec=="unsigned long long" ||
227  spec=="int" || spec=="unsigned int" ||
228  spec=="long" || spec=="unsigned long");
229 }

◆ next()

CoraCoolObjectPtr CoraCoolObjectIter::next ( )

Definition at line 53 of file CoraCoolObjectIter.cxx.

53  {
54  if (m_inbuf>m_nextobj) {
55  // return data directly from the buffer - just increment counter
56  ++m_nextobj;
57  } else if (iHasNext()) {
59  } else {
60  throw CoraCoolException("No more data in CoraCoolObjectIter",
61  "CoraCoolObjectIter::next");
62  }
63  return m_data.at(m_nextobj-1);
64 }

◆ numAttr()

long long CoraCoolObjectIter::numAttr ( const std::string &  spec,
const coral::Attribute &  a 
) const
private

Definition at line 231 of file CoraCoolObjectIter.cxx.

232  {
233  long long v=0;
234  if (spec=="long long") {
235  v=a.data<long long>();
236  } else if (spec=="unsigned long long") {
237  v=static_cast<long long>(a.data<unsigned long long>());
238  } else if (spec=="int") {
239  v=static_cast<long long>(a.data<int>());
240  } else if (spec=="unsigned int") {
241  v=static_cast<long long>(a.data<unsigned int>());
242  } else if (spec=="long") {
243  v=static_cast<long long>(a.data<long>());
244  } else if (spec=="unsigned long") {
245  v=static_cast<long long>(a.data<unsigned long>());
246  }
247  return v;
248 }

◆ operator=()

CoraCoolObjectIter& CoraCoolObjectIter::operator= ( const CoraCoolObjectIter )
private

◆ readDataToBuffer()

void CoraCoolObjectIter::readDataToBuffer ( )
private

Definition at line 66 of file CoraCoolObjectIter.cxx.

66  {
67  // read some data from the database - initialise buffer to empty
68  m_inbuf=0;
69  // coloumn name of the FK in the CORAL table
70  const std::string& coralkey=m_folder->coralFKey();
71  // buffer to build the query
72  QueryBuilder qbuf(QB_SIZE);
73  coral::AttributeList fktype;
74  std::string fktypestr;
75  // keep map of FKvalue to list of associated COOL channels
76  typedef std::vector<unsigned int> KeyVec;
77  typedef std::unordered_map<long long,KeyVec > KeyMap;
78  KeyMap keymap;
79 
80  while (m_inbuf<m_buflen && iHasNext() &&
81  qbuf.size()<QB_SIZE && qbuf.terms()<QB_TERMS) {
82  // get the COOL object
83  const cool::IObject& coolobj=m_coolitr->currentRef();
84  // reset so that next call to iHasNext will read the next one
85  m_refValid=false;
86  // prepare CoraCoolObject to receive the payload data
87  CoraCoolObjectPtr data(new CoraCoolObject(coolobj.since(),
88  coolobj.until(),coolobj.channelId(),m_spec));
90  // setup the foreign key reference
91  const coral::AttributeList& payload=coolobj.payload().attributeList();
92  // remember the type of the FK
93  if (m_inbuf==0) {
94  fktypestr=payload[0].specification().typeName();
95  fktype=payload;
96  }
97  long long ikeyval=numAttr(fktypestr,payload[0]);
98  qbuf.add(ikeyval);
99  KeyMap::iterator kdata=keymap.find(ikeyval);
100  if (kdata==keymap.end()) {
101  // new FK value - create vector of buffer positions for this one
102  kdata=keymap.insert(kdata,
103  KeyMap::value_type(ikeyval,KeyVec(8)));
104  KeyVec& keyvec=kdata->second;
105  keyvec.resize(1);
106  keyvec[0]=m_inbuf;
107  } else {
108  // add to list of buffers using this key
109  KeyVec& keyvec=kdata->second;
110  keyvec.push_back(m_inbuf);
111  }
112  ++m_inbuf;
113  }
114  // setup the query
115  std::string bwhere;
116  coral::AttributeList bfkeys;
117  qbuf.getQuery(bwhere,coralkey,bfkeys,fktype[0].specification());
118  // execute the query
119  try {
120  m_folder->proxy()->transaction().start(true);
121  coral::IQuery* query=m_folder->table()->newQuery();
122  query->setCondition(bwhere,bfkeys);
123  query->setRowCacheSize(OI_ROWCACHE);
125  coral::ICursor& cursor=query->execute();
126  KeyMap::const_iterator kdata=keymap.end();
127  long long okeyval=0;
128  while (cursor.next()) {
129  const coral::AttributeList& res=cursor.currentRow();
130  // check which buffer(s) this data is associated with
131  // maybe associated with more than one if referenceObject has been used
132  // so have to check all - no optimisation possible
133  const long long keyval=numAttr(fktypestr,res[coralkey]);
134  if (keyval!=okeyval || kdata==keymap.end()) {
135  kdata=keymap.find(keyval);
136  okeyval=keyval;
137  }
138  if (kdata!=keymap.end()) {
139  KeyVec keyvec=kdata->second;
140  for (KeyVec::const_iterator kitr=keyvec.begin();
141  kitr!=keyvec.end();++kitr) {
142  m_data[*kitr]->add(res);
143  }
144  } else {
145  std::ostringstream skey;
146  skey << "CoraCool key remapping error for key " << keyval;
147  throw CoraCoolException(skey.str(),"CoraCoolObjectIter::next");
148  }
149  }
150  delete query;
151  m_folder->proxy()->transaction().commit();
152  }
153  catch (coral::Exception& e) {
154  throw CoraCoolException(e.what(),"CoraCoolObjectIter::next");
155  }
156  // next read will access next object from buffer (if existing)
157  // this invocation will return first object
158  m_nextobj=1;
159  return;
160 }

Member Data Documentation

◆ m_allDone

bool CoraCoolObjectIter::m_allDone
private

Definition at line 110 of file CoraCoolObjectIter.h.

◆ m_buflen

unsigned int CoraCoolObjectIter::m_buflen
private

Definition at line 106 of file CoraCoolObjectIter.h.

◆ m_coolitr

cool::IObjectIteratorPtr CoraCoolObjectIter::m_coolitr
private

Definition at line 112 of file CoraCoolObjectIter.h.

◆ m_data

std::vector<CoraCoolObjectPtr> CoraCoolObjectIter::m_data
private

Definition at line 114 of file CoraCoolObjectIter.h.

◆ m_folder

CoraCoolFolder* CoraCoolObjectIter::m_folder
private

Definition at line 111 of file CoraCoolObjectIter.h.

◆ m_inbuf

unsigned int CoraCoolObjectIter::m_inbuf
private

Definition at line 107 of file CoraCoolObjectIter.h.

◆ m_nextobj

unsigned int CoraCoolObjectIter::m_nextobj
private

Definition at line 108 of file CoraCoolObjectIter.h.

◆ m_refValid

bool CoraCoolObjectIter::m_refValid
private

Definition at line 109 of file CoraCoolObjectIter.h.

◆ m_spec

coral::AttributeListSpecification* CoraCoolObjectIter::m_spec
private

Definition at line 113 of file CoraCoolObjectIter.h.


The documentation for this class was generated from the following files:
CoraCoolObjectIter::m_refValid
bool m_refValid
Definition: CoraCoolObjectIter.h:109
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
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
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CoraCoolObject
Definition: CoraCoolObject.h:20
CoraCoolObjectIter::isNumAttr
bool isNumAttr(const std::string &spec) const
Definition: CoraCoolObjectIter.cxx:225
CoraCoolObjectIter::m_spec
coral::AttributeListSpecification * m_spec
Definition: CoraCoolObjectIter.h:113
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
CoraCoolObjectIter::m_coolitr
cool::IObjectIteratorPtr m_coolitr
Definition: CoraCoolObjectIter.h:112
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
CoraCoolFolder::table
coral::ITable * table()
Definition: CoraCoolFolder.cxx:575
query
Definition: query.py:1
CoraCoolFolder::coralFKey
const std::string & coralFKey() const
Definition: CoraCoolFolder.h:191
CoraCoolObjectIter::m_folder
CoraCoolFolder * m_folder
Definition: CoraCoolObjectIter.h:111
lumiFormat.i
int i
Definition: lumiFormat.py:92
OI_BUFLEN
#define OI_BUFLEN
Definition: CoraCoolObjectIter.cxx:29
CoraCoolFolder::payloadSpecification
const cool::RecordSpecification payloadSpecification() const
Definition: CoraCoolFolder.cxx:107
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
query_example.query
query
Definition: query_example.py:15
CoraCoolFolder::proxy
coral::ISessionProxy * proxy()
Definition: CoraCoolFolder.h:200
CoraCoolObjectIter::m_data
std::vector< CoraCoolObjectPtr > m_data
Definition: CoraCoolObjectIter.h:114
QB_TERMS
#define QB_TERMS
Definition: CoraCoolObjectIter.cxx:26
CoraCoolFolder::setOutputSpec
void setOutputSpec(coral::IQuery *query)
Definition: CoraCoolFolder.cxx:489
QB_SIZE
#define QB_SIZE
Definition: CoraCoolObjectIter.cxx:25
CoraCoolObjectIter::m_allDone
bool m_allDone
Definition: CoraCoolObjectIter.h:110
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
CoraCoolObjectIter::iHasNext
bool iHasNext()
Definition: CoraCoolObjectIter.cxx:210
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
python.PyAthena.v
v
Definition: PyAthena.py:157
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
CoraCoolException
Definition: CoraCoolException.h:13
a
TList * a
Definition: liststreamerinfos.cxx:10
query_example.cursor
cursor
Definition: query_example.py:21
CoraCoolObjectIter::m_inbuf
unsigned int m_inbuf
Definition: CoraCoolObjectIter.h:107
CoraCoolObjectPtr
boost::shared_ptr< CoraCoolObject > CoraCoolObjectPtr
Definition: CoraCoolTypes.h:18
CxxUtils::reset
constexpr std::enable_if_t< is_bitmask_v< E >, E & > reset(E &lhs, E rhs)
Convenience function to clear bits in a class enum bitmask.
Definition: bitmask.h:243
CoraCoolObjectIter::readDataToBuffer
void readDataToBuffer()
Definition: CoraCoolObjectIter.cxx:66
OI_ROWCACHE
#define OI_ROWCACHE
Definition: CoraCoolObjectIter.cxx:30
CoraCoolObjectIter::hasNext
bool hasNext()
Definition: CoraCoolObjectIter.cxx:162
CoraCoolObjectIter::m_buflen
unsigned int m_buflen
Definition: CoraCoolObjectIter.h:106