ATLAS Offline Software
Loading...
Searching...
No Matches
CoraCoolObjectIter::QueryBuilder Class Reference
Collaboration diagram for CoraCoolObjectIter::QueryBuilder:

Public Member Functions

 QueryBuilder (const unsigned int size)
 ~QueryBuilder ()
unsigned int size () const
unsigned int terms () const
unsigned int add (const long long value)
void getQuery (std::string &where, const std::string &coralkey, coral::AttributeList &fkeys, const coral::AttributeSpecification &spec)

Private Member Functions

 QueryBuilder ()
 QueryBuilder (const QueryBuilder &)
QueryBuilderoperator= (const QueryBuilder &)
std::string addKey (unsigned int &key, coral::AttributeList &fkeys, const coral::AttributeSpecification &spec, const long long value)

Private Attributes

unsigned int m_terms
unsigned int m_size
unsigned int m_maxsize
long long * m_lower
long long * m_upper

Detailed Description

Definition at line 68 of file CoraCoolObjectIter.h.

Constructor & Destructor Documentation

◆ QueryBuilder() [1/3]

CoraCoolObjectIter::QueryBuilder::QueryBuilder ( const unsigned int size)

◆ ~QueryBuilder()

CoraCoolObjectIter::QueryBuilder::~QueryBuilder ( )

Definition at line 256 of file CoraCoolObjectIter.cxx.

256 {
257 delete [] m_lower;
258 delete [] m_upper;
259}

◆ QueryBuilder() [2/3]

CoraCoolObjectIter::QueryBuilder::QueryBuilder ( )
private

◆ QueryBuilder() [3/3]

CoraCoolObjectIter::QueryBuilder::QueryBuilder ( const QueryBuilder & )
private

Member Function Documentation

◆ add()

unsigned int CoraCoolObjectIter::QueryBuilder::add ( const long long value)

Definition at line 261 of file CoraCoolObjectIter.cxx.

261 {
262 // add the given value to the query sequence
263 // find where it must be inserted
264 unsigned int i=0;
265 unsigned int j=0;
266 bool done=false;
267 for (unsigned int i=0;i<m_size;++i) {
268 if (m_lower[i]-value<2 && value-m_upper[i]<2) {
269 // current range contains object or can be extended by one to contain it
270 // value is in current range or extends it
271 if (m_lower[i]-value==1) --m_lower[i];
272 if (value-m_upper[i]==1) ++m_upper[i];
273 // if range is of size 1, just changed from one to two-term query
274 if (m_upper[i]-m_lower[i]==1) ++m_terms;
275 done=true;
276 break;
277 }
278 // check if value has to be inserted after this position, if not found
279 if (m_upper[i]<value) ++j;
280 }
281 if (not done) {
282 // did not add to an existing range - make a new one at j
283 // move existing values up
284 if (m_size<m_maxsize) {
285 for (i=m_size;i!=j;--i) {
286 m_lower[i]=m_lower[i-1];
287 m_upper[i]=m_upper[i-1];
288 }
289 ++m_size;
290 // add new range at j
291 m_lower[j]=value;
292 m_upper[j]=value;
293 ++m_terms;
294 } else {
295 // if not enough room, return zero to signal error
296 return 0;
297 }
298 }
299 return m_terms;
300}

◆ addKey()

std::string CoraCoolObjectIter::QueryBuilder::addKey ( unsigned int & key,
coral::AttributeList & fkeys,
const coral::AttributeSpecification & spec,
const long long value )
private

Definition at line 353 of file CoraCoolObjectIter.cxx.

355 {
356 // return the name of the FK and add it to the list of FK bind variables
357 std::ostringstream skey;
358 skey << "B" << ikey;
359 std::string keyname=skey.str();
360 fkeys.extend(keyname,spec.type());
361 std::string typeName=spec.typeName();
362 if (typeName=="long long") {
363 fkeys[keyname].data<long long>()=value;
364 } else if (typeName=="unsigned long long") {
365 fkeys[keyname].data<unsigned long long>()=value;
366 } else if (typeName=="int") {
367 fkeys[keyname].data<int>()=value;
368 } else if (typeName=="unsigned int") {
369 fkeys[keyname].data<unsigned int>()=value;
370 } else if (typeName=="long") {
371 fkeys[keyname].data<long>()=value;
372 } else if (typeName=="unsigned long") {
373 fkeys[keyname].data<unsigned long>()=value;
374 } else {
375 throw CoraCoolException("Unregognised type "+typeName,
376 "CoraCoolObjectIter::QueryBuilder::addKey");
377 }
378 ++ikey;
379 return keyname;
380}

◆ getQuery()

void CoraCoolObjectIter::QueryBuilder::getQuery ( std::string & where,
const std::string & coralkey,
coral::AttributeList & fkeys,
const coral::AttributeSpecification & spec )

Definition at line 302 of file CoraCoolObjectIter.cxx.

304 {
305 // try to compress the query by joining existing ranges if possible
306 unsigned int j=0;
307 for (unsigned int i=0;i<m_size;++i) {
308 long long lower=m_lower[i];
309 long long upper=m_upper[i];
310 // check if this range can be absorbed into previous one
311 if (i>0) {
312 if (m_lower[i]-m_upper[j]<2) {
313 // if so, adjust upper limit of previous range to encompass this one
314 // and do not copy current range
315 m_upper[j]=m_upper[i];
316 } else {
317 // note this never gets executed on first iteration - j lags 1 behind i
318 ++j;
319 m_lower[j]=lower;
320 m_upper[j]=upper;
321 }
322 }
323 }
324 m_size=j+1;
325 // build the query string and list of FK values to be used
326 unsigned int ikey=0;
327 for (unsigned int i=0;i<m_size;++i) {
328 if (where.size()>0) where+=" OR ";
329 if (m_lower[i]==m_upper[i]) {
330 // bounds are equal - simple equivalence term
331 std::string keyname=addKey(ikey,fkeys,spec,m_lower[i]);
332 where+=coralkey;
333 where+="=:";
334 where+=keyname;
335 } else {
336 // bounds are not equal - need A>=B and A<=C
337 std::string keyname=addKey(ikey,fkeys,spec,m_lower[i]);
338 where+='(';
339 where+=coralkey;
340 where+=">=:";
341 where+=keyname;
342 where+=" AND ";
343 where+=coralkey;
344 where+="<=:";
345
346 keyname=addKey(ikey,fkeys,spec,m_upper[i]);
347 where+=keyname;
348 where+=')';
349 }
350 }
351}
int upper(int c)
std::string addKey(unsigned int &key, coral::AttributeList &fkeys, const coral::AttributeSpecification &spec, const long long value)
where(filename, prepath=[])
"which" for python files -------------------------------------------------—
Definition unixtools.py:53

◆ operator=()

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

◆ size()

unsigned int CoraCoolObjectIter::QueryBuilder::size ( ) const
inline

Definition at line 117 of file CoraCoolObjectIter.h.

118{ return m_size; }

◆ terms()

unsigned int CoraCoolObjectIter::QueryBuilder::terms ( ) const
inline

Definition at line 119 of file CoraCoolObjectIter.h.

120{ return m_terms; }

Member Data Documentation

◆ m_lower

long long* CoraCoolObjectIter::QueryBuilder::m_lower
private

Definition at line 97 of file CoraCoolObjectIter.h.

◆ m_maxsize

unsigned int CoraCoolObjectIter::QueryBuilder::m_maxsize
private

Definition at line 96 of file CoraCoolObjectIter.h.

◆ m_size

unsigned int CoraCoolObjectIter::QueryBuilder::m_size
private

Definition at line 95 of file CoraCoolObjectIter.h.

◆ m_terms

unsigned int CoraCoolObjectIter::QueryBuilder::m_terms
private

Definition at line 94 of file CoraCoolObjectIter.h.

◆ m_upper

long long* CoraCoolObjectIter::QueryBuilder::m_upper
private

Definition at line 98 of file CoraCoolObjectIter.h.


The documentation for this class was generated from the following files: