ATLAS Offline Software
Loading...
Searching...
No Matches
CoraCoolFolder Class Reference

#include <CoraCoolFolder.h>

Collaboration diagram for CoraCoolFolder:

Public Types

typedef std::vector< coral::AttributeList >::const_iterator const_iterator

Public Member Functions

 CoraCoolFolder (const std::string &coolfolder, coral::ISessionProxy *proxy, cool::IDatabasePtr cooldb, CoraCoolDatabase *coradb, coral::MessageStream &log)
 ~CoraCoolFolder ()
 CoraCoolFolder (const CoraCoolFolder &)=delete
CoraCoolFolderoperator= (const CoraCoolFolder &)=delete
std::string coralTableName () const
const std::string & coralFKey () const
const std::string & coralPKey () const
const cool::IRecordSpecification & fkSpecification () const
const cool::RecordSpecification payloadSpecification () const
coral::AttributeList emptyAttrList () const
cool::IFolderPtr coolFolder ()
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=defaultTagName(), const bool userTagOnly=false)
bool setupStorageBuffer ()
void flushStorageBuffer ()
void referenceObject (const cool::ValidityKey &since, const cool::ValidityKey &until, const coral::Attribute &fkey, const cool::ChannelId &channelId=0, const std::string &tagName=defaultTagName(), const bool userTagOnly=false)
void referenceObject (const cool::ValidityKey &since, const cool::ValidityKey &until, const int ifkey, const cool::ChannelId &channelId=0, const std::string &tagName=defaultTagName(), const bool userTagOnly=false)
void addPayload (const_iterator begin, const_iterator end)
CoraCoolObjectPtr findObject (const cool::ValidityKey &pointInTime, const cool::ChannelId &channelId=0, const std::string &tagName=defaultTagName())
CoraCoolObjectIterPtr browseObjects (const cool::ValidityKey &pointInTime, const cool::ChannelSelection &channels, const std::string &tagName=defaultTagName())
CoraCoolObjectIterPtr browseObjects (const cool::ValidityKey &since=cool::ValidityKeyMin, const cool::ValidityKey &until=cool::ValidityKeyMax, const cool::ChannelSelection &channels=cool::ChannelSelection(0), const std::string &tagName=defaultTagName())
void setPrefetchAll (const bool prefetchAll)
bool setAttrKey (coral::Attribute &attr, const int keyval)
bool setFieldKey (cool::IField &attr, const int keyval)
bool setFieldAttr (cool::IField &attr, const coral::Attribute &keyval)
int getAttrKey (const coral::Attribute &attr)

Static Public Member Functions

static const std::string & defaultTagName ()

Private Types

typedef std::vector< std::pair< std::string, std::string > > AttrVec
typedef AttrVec::const_iterator AttrItr

Private Member Functions

coral::ISessionProxy * proxy ()
const coral::ISessionProxy * proxy () const
coral::ITable * table ()
void setOutputSpec (coral::IQuery *query)
bool decodeAttrSpec ()
cool::StorageType::TypeId nameToCoolType (const std::string &coolName) const
void bulkInsert (const_iterator begin, const_iterator end, const int fkey, bool updatefk)

Private Attributes

std::string m_foldername
std::string m_dbname
coral::ISessionProxy * m_proxy
cool::IDatabasePtr m_cooldb
CoraCoolDatabasem_coradb
coral::MessageStream & m_log
std::string m_tablename
std::string m_keycolcoral
std::string m_keycolcool
std::string m_pkeycolcoral
bool m_pkey
cool::IFolderPtr m_coolfolder
coral::ITable * m_table
const coral::ITableDescription * m_tabledesc
AttrVec m_attrvec
bool m_bulkactive
coral::AttributeList * m_payloadbuf
coral::IBulkOperation * m_bulki
CoraCoolSequencem_seqpk
CoraCoolSequencem_seqfk
int m_nextpk
int m_usedpk
int m_nextfk
int m_usedfk

Friends

class CoraCoolObjectIter

Detailed Description

Definition at line 37 of file CoraCoolFolder.h.

Member Typedef Documentation

◆ AttrItr

typedef AttrVec::const_iterator CoraCoolFolder::AttrItr
private

Definition at line 175 of file CoraCoolFolder.h.

◆ AttrVec

typedef std::vector<std::pair<std::string,std::string> > CoraCoolFolder::AttrVec
private

Definition at line 174 of file CoraCoolFolder.h.

◆ const_iterator

typedef std::vector<coral::AttributeList>::const_iterator CoraCoolFolder::const_iterator

Definition at line 43 of file CoraCoolFolder.h.

Constructor & Destructor Documentation

◆ CoraCoolFolder() [1/2]

CoraCoolFolder::CoraCoolFolder ( const std::string & coolfolder,
coral::ISessionProxy * proxy,
cool::IDatabasePtr cooldb,
CoraCoolDatabase * coradb,
coral::MessageStream & log )

Definition at line 40 of file CoraCoolFolder.cxx.

43 :
44 m_foldername(coolfolder),
45 m_proxy(proxy),m_cooldb(std::move(cooldb)),m_coradb(coradb),
46 m_log(log),
49{
50 m_dbname=m_coradb->dbname();
51
52 // get information from COOL
53 m_log << coral::Debug << "Initialize CoraCoolFolder " << coolfolder <<
54 " in database instance " << m_dbname << coral::MessageStream::endmsg;
55
56 std::string folderdesc;
57 try {
59 folderdesc=m_coolfolder->description();
60 }
61 catch (cool::Exception& e) {
62 throw CoraCoolException(e.what(),"CoraCoolFolder::CoraCoolFolder");
63 }
64 m_log << coral::Debug << "COOL Folder description is: " << folderdesc
65 << coral::MessageStream::endmsg;
66
67 // set up linking information between COOL and CORAL folders
68 if (m_coradb->parseFolderDescription(folderdesc,m_tablename,m_keycolcool,
71 } else {
72 throw CoraCoolException("incorrect <coracool> description string ",
73 "CoraCoolFolder::CoraCoolFolder");
74 }
75
76 // obtain information about CORAL folder
77 try {
78 m_proxy->transaction().start(true);
79 coral::ISchema& schema=m_proxy->nominalSchema();
80 m_table=&schema.tableHandle(m_tablename);
81 m_tabledesc=&(m_table->description());
82 // find type of foreign key
83 // lookup attribute specification for query outputs
84 if (!decodeAttrSpec()) throw CoraCoolException(
85 "Problem extracting attribute specification",
86 "CoraCoolFolder::CoraCoolFolder");
87 m_proxy->transaction().commit();
88 }
89 catch (coral::SessionException& e) {
90 throw CoraCoolException("Problem accessing CORAL table "+m_tablename,
91 "CoraCoolFolder::CoraCoolFolder");
92 }
93}
std::string m_tablename
cool::IFolderPtr m_coolfolder
std::string m_foldername
coral::IBulkOperation * m_bulki
std::string m_keycolcool
coral::ISessionProxy * proxy()
std::string m_dbname
std::string m_keycolcoral
coral::ITable * m_table
coral::MessageStream & m_log
CoraCoolSequence * m_seqfk
CoraCoolSequence * m_seqpk
coral::ISessionProxy * m_proxy
coral::AttributeList * m_payloadbuf
cool::IDatabasePtr m_cooldb
const coral::ITableDescription * m_tabledesc
CoraCoolDatabase * m_coradb
std::string m_pkeycolcoral

◆ ~CoraCoolFolder()

CoraCoolFolder::~CoraCoolFolder ( )

Definition at line 95 of file CoraCoolFolder.cxx.

95 {
96 delete m_payloadbuf;
97
98 if (m_seqpk) delete m_seqpk;
99 if (m_seqfk) delete m_seqfk;
100}

◆ CoraCoolFolder() [2/2]

CoraCoolFolder::CoraCoolFolder ( const CoraCoolFolder & )
delete

Member Function Documentation

◆ addPayload()

void CoraCoolFolder::addPayload ( const_iterator begin,
const_iterator end )

Definition at line 300 of file CoraCoolFolder.cxx.

300 { // Copies AttributeList, giving shared specification.
301 // add payload to the CORAL table, using existing FKs in data
302 // but regenerating primary keys
303
304 // only makes sense to use this method for folders with separate pkeys
305 if (!m_pkey) throw CoraCoolException("Folder has no primary key",
306 "CoralCoolFolder::addPayload");
307 if (m_bulkactive) {
308 // via bulk operation buffer
309 bulkInsert(begin,end,0,false);
310 } else {
311 // first count number of CORAL rows to be inserted
312 unsigned int nrow=0;
313 for (const_iterator payitr=begin;payitr!=end;++payitr) ++nrow;
314 m_log << coral::Debug << "Adding " << nrow << " into CoraCool folder "
315 << m_foldername << coral::MessageStream::endmsg;
316 // generate keys - start transaction here
317 int pkey;
318 try {
319 m_proxy->transaction().start(false);
320 CoraCoolSequence seqfk(m_dbname,m_tablename+"_PK",m_proxy,false);
321 pkey=seqfk.fetch(nrow);
322 // commit key transaction, releasing lock on keytable
323 m_proxy->transaction().commit();
324 }
325 catch (coral::Exception& e) {
326 throw CoraCoolException(e.what(),"CoraCoolFolder::addPayload(key)");
327 }
328 // insert rows into CORAL
329 try {
330 m_proxy->transaction().start(false);
331 coral::ISchema& schema=m_proxy->nominalSchema();
332 m_table=&schema.tableHandle(m_tablename);
333 coral::ITableDataEditor& editor=m_table->dataEditor();
334
335 for (const_iterator payitr=begin;payitr!=end;++payitr) {
336 // store data, updating pkey
337 coral::AttributeList data=*payitr;
339 editor.insertRow(data);
340 }
341 m_proxy->transaction().commit();
342 }
343 catch (coral::Exception& e) {
344 throw CoraCoolException(e.what(),"CoraCoolFolder::addPayload(payload)");
345 }
346 }
347}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::vector< coral::AttributeList >::const_iterator const_iterator
bool setAttrKey(coral::Attribute &attr, const int keyval)
void bulkInsert(const_iterator begin, const_iterator end, const int fkey, bool updatefk)

◆ browseObjects() [1/2]

CoraCoolObjectIterPtr CoraCoolFolder::browseObjects ( const cool::ValidityKey & pointInTime,
const cool::ChannelSelection & channels,
const std::string & tagName = defaultTagName() )

Definition at line 557 of file CoraCoolFolder.cxx.

560 {
561 return browseObjects(pointInTime,pointInTime,channels,tagName);
562}
CoraCoolObjectIterPtr browseObjects(const cool::ValidityKey &pointInTime, const cool::ChannelSelection &channels, const std::string &tagName=defaultTagName())

◆ browseObjects() [2/2]

CoraCoolObjectIterPtr CoraCoolFolder::browseObjects ( const cool::ValidityKey & since = cool::ValidityKeyMin,
const cool::ValidityKey & until = cool::ValidityKeyMax,
const cool::ChannelSelection & channels = cool::ChannelSelection(0),
const std::string & tagName = defaultTagName() )

Definition at line 564 of file CoraCoolFolder.cxx.

569{
570 // first initialise COOL query
571 cool::IObjectIteratorPtr coolitr=m_coolfolder->browseObjects(since,until,
572 channels,tagName);
573 CoraCoolObjectIterPtr itr(new CoraCoolObjectIter(this,std::move(coolitr)));
574 return itr;
575}
boost::shared_ptr< CoraCoolObjectIter > CoraCoolObjectIterPtr
friend class CoraCoolObjectIter

◆ bulkInsert()

void CoraCoolFolder::bulkInsert ( const_iterator begin,
const_iterator end,
const int fkey,
bool updatefk )
private

Definition at line 503 of file CoraCoolFolder.cxx.

504 {
505 // do bulk insertion into CORAL table buffer
506 // if updateFK=true, update rows with given FK value
507 try {
508 for (const_iterator payitr=begin;payitr!=end;++payitr) {
509 // copy data into buffer bound to bulk insert
510 m_payloadbuf->fastCopyData(*payitr);
511 // update the keys
512 if (updatefk) setAttrKey((*m_payloadbuf)[m_keycolcoral],fkey);
513 if (m_pkey) {
515 ++m_usedpk;
516 }
517 // add to bulk operation
518 m_bulki->processNextIteration();
519 }
520 }
521 catch (coral::Exception& e) {
522 throw CoraCoolException(e.what(),"CoraCoolFolder::bulkInsert");
523 }
524}

◆ coolFolder()

cool::IFolderPtr CoraCoolFolder::coolFolder ( )
inline

Definition at line 198 of file CoraCoolFolder.h.

199{ return m_coolfolder; }

◆ coralFKey()

const std::string & CoraCoolFolder::coralFKey ( ) const
inline

Definition at line 192 of file CoraCoolFolder.h.

193{ return m_keycolcoral; }

◆ coralPKey()

const std::string & CoraCoolFolder::coralPKey ( ) const
inline

Definition at line 195 of file CoraCoolFolder.h.

196{ return m_pkeycolcoral; }

◆ coralTableName()

std::string CoraCoolFolder::coralTableName ( ) const
inline

Definition at line 189 of file CoraCoolFolder.h.

190{ return m_tablename.substr(m_dbname.size()+1); }

◆ decodeAttrSpec()

bool CoraCoolFolder::decodeAttrSpec ( )
private

Definition at line 430 of file CoraCoolFolder.cxx.

430 {
431 // read information from the CORACOOLATTR table
432 bool bres=false;
433 coral::IQuery* query=0;
434 try {
435 coral::ITable& table=m_proxy->nominalSchema().tableHandle(
436 m_dbname+"_CORACOOLATTR");
437 query=table.newQuery();
438 coral::AttributeList bindvar;
439 bindvar.extend<std::string>("SNAME");
440 bindvar[0].data<std::string>()=m_tablename;
441 query->setCondition("NAME=:SNAME",bindvar);
442 query->setRowCacheSize(1);
443 query->defineOutputType("NAME","string");
444 coral::ICursor& cursor=query->execute();
445 if (cursor.next()) {
446 const coral::AttributeList& res=cursor.currentRow();
447 std::string spec=res["ATTRSPEC"].data<std::string>();
448 // decode specification
449 std::string::size_type iofs1,iofs2,iofs3;
450 iofs1=0;
451 bool last=false;
452 while (!last) {
453 iofs2=spec.find(':',iofs1);
454 iofs3=spec.find(',',iofs2);
455 if (iofs3==std::string::npos) {
456 iofs3=spec.size();
457 last=true;
458 }
459 m_attrvec.emplace_back(spec.substr(iofs1,iofs2-iofs1),spec.substr(iofs2+1,iofs3-iofs2-1));
460 if (!last) iofs1=iofs3+1;
461 }
462 bres=true;
463 } else {
464 m_log << coral::Error << "No data obtained for CORACOOLATTR" <<
465 coral::MessageStream::endmsg;
466 }
467 }
468 catch (coral::Exception &e) {
469 m_log << coral::Error << "Exception reading CORACOOLATTR table: "
470 << e.what() << coral::MessageStream::endmsg;
471 }
472 delete query;
473 return bres;
474}
std::pair< std::vector< unsigned int >, bool > res
coral::ITable * table()
query
Definition index.py:72

◆ defaultTagName()

const std::string & CoraCoolFolder::defaultTagName ( )
static

Definition at line 104 of file CoraCoolFolder.cxx.

104 {
105 static const std::string empty;
106 return empty;
107}
static const Attributes_t empty

◆ emptyAttrList()

coral::AttributeList CoraCoolFolder::emptyAttrList ( ) const

Definition at line 123 of file CoraCoolFolder.cxx.

123 {
124 // assemble and return an attributelist for use in constructing payloads
125 coral::AttributeList atrlist;
126 for (AttrItr itr=m_attrvec.begin();itr!=m_attrvec.end();++itr)
127 atrlist.extend(itr->first,
128 cool::StorageType::storageType(nameToCoolType(itr->second)).cppType());
129 return atrlist;
130}
cool::StorageType::TypeId nameToCoolType(const std::string &coolName) const
AttrVec::const_iterator AttrItr

◆ findObject()

CoraCoolObjectPtr CoraCoolFolder::findObject ( const cool::ValidityKey & pointInTime,
const cool::ChannelId & channelId = 0,
const std::string & tagName = defaultTagName() )

Definition at line 526 of file CoraCoolFolder.cxx.

528 {
529 // first query cool to get foreign key
530 m_log << coral::Debug << "CoraCoolFolder query time " << pointInTime <<
531 " channel " << channelId << " tag " << tagName << coral::MessageStream::endmsg;
532 cool::IObjectPtr obj=m_coolfolder->findObject(pointInTime,channelId,tagName);
533 // create result object with IOV from COOL
534 CoraCoolObjectPtr result(new CoraCoolObject(obj->since(),obj->until(),
535 obj->channelId()));
536 // now query CORAL for payload
537 try {
538 m_proxy->transaction().start(true);
539 coral::IQuery* query=m_table->newQuery();
540 std::string where=m_keycolcoral+"=:"+m_keycolcool;
541 const coral::AttributeList& fkeybind=obj->payload().attributeList();
542 query->setCondition(where,fkeybind);
543 coral::ICursor& cursor=query->execute();
544 while (cursor.next()) {
545 const coral::AttributeList& res=cursor.currentRow();
546 result->add(res);
547 }
548 delete query;
549 m_proxy->transaction().commit();
550 }
551 catch (coral::Exception& e) {
552 throw CoraCoolException(e.what(),"CoraCoolFolder::findObject");
553 }
554 return result;
555}
boost::shared_ptr< CoraCoolObject > CoraCoolObjectPtr
where(filename, prepath=[])
"which" for python files -------------------------------------------------—
Definition unixtools.py:53

◆ fkSpecification()

const cool::IRecordSpecification & CoraCoolFolder::fkSpecification ( ) const

Definition at line 109 of file CoraCoolFolder.cxx.

111{ return m_coolfolder->payloadSpecification(); }

◆ flushStorageBuffer()

void CoraCoolFolder::flushStorageBuffer ( )

Definition at line 250 of file CoraCoolFolder.cxx.

250 {
251 if (!m_bulkactive) return;
252 // execute bulk store
253 try {
254 m_bulki->flush();
255 // update the keys
256 if (m_usedpk>0) m_seqpk->fetch(m_usedpk);
257 if (m_usedfk>0) m_seqfk->fetch(m_usedfk);
258 // commit transaction for payload table and keys
259 m_proxy->transaction().commit();
260 }
261 catch (coral::Exception& e) {
262 throw CoraCoolException(e.what(),"CoraCoolFolder::flushStorageBuffer");
263 }
264 m_coolfolder->flushStorageBuffer();
265 m_bulkactive=false;
266}

◆ getAttrKey()

int CoraCoolFolder::getAttrKey ( const coral::Attribute & attr)

Definition at line 413 of file CoraCoolFolder.cxx.

413 {
414 const std::string typen=attr.specification().typeName();
415 if (typen=="int") {
416 return attr.data<int>();
417 } else if (typen=="unsigned int") {
418 return static_cast<int>(attr.data<unsigned int>());
419 } else if (typen=="long long") {
420 return static_cast<int>(attr.data<long long>());
421 } else if (typen=="unsigned long long") {
422 return static_cast<int>(attr.data<unsigned long long>());
423 } else {
424 m_log << coral::Error << "Unrecognised key type " << typen <<
425 " in CoraCoolFolder::getAttrKey" << coral::MessageStream::endmsg;
426 return 0;
427 }
428}

◆ nameToCoolType()

cool::StorageType::TypeId CoraCoolFolder::nameToCoolType ( const std::string & coolName) const
private

Definition at line 476 of file CoraCoolFolder.cxx.

477 {
478 if (coolName=="Int16") return cool::StorageType::Int16;
479 if (coolName=="UInt16") return cool::StorageType::UInt16;
480 if (coolName=="Int32") return cool::StorageType::Int32;
481 if (coolName=="UInt32") return cool::StorageType::UInt32;
482 if (coolName=="UInt63") return cool::StorageType::UInt63;
483 if (coolName=="Int64") return cool::StorageType::Int64;
484 if (coolName=="Float") return cool::StorageType::Float;
485 if (coolName=="Double") return cool::StorageType::Double;
486 if (coolName=="String255") return cool::StorageType::String255;
487 if (coolName=="String4k") return cool::StorageType::String4k;
488 if (coolName=="String64k") return cool::StorageType::String64k;
489 if (coolName=="String16M") return cool::StorageType::String16M;
490 if (coolName=="Blob64k") return cool::StorageType::Blob64k;
491
492 throw CoraCoolException("Undefined type: "+coolName,
493 "CoraCoolFolder::nameToCoolType");
494}

◆ operator=()

CoraCoolFolder & CoraCoolFolder::operator= ( const CoraCoolFolder & )
delete

◆ payloadSpecification()

const cool::RecordSpecification CoraCoolFolder::payloadSpecification ( ) const

Definition at line 114 of file CoraCoolFolder.cxx.

114 {
115 // have to assemble a RecordSpecification and return the specification
116 // as ITableDescription does not allow to get this directly
117 cool::RecordSpecification atrspec;
118 for (AttrItr itr=m_attrvec.begin();itr!=m_attrvec.end();++itr)
119 atrspec.extend(itr->first,nameToCoolType(itr->second));
120 return atrspec;
121}

◆ proxy() [1/2]

coral::ISessionProxy * CoraCoolFolder::proxy ( )
inlineprivate

Definition at line 201 of file CoraCoolFolder.h.

201{return m_proxy; }

◆ proxy() [2/2]

const coral::ISessionProxy * CoraCoolFolder::proxy ( ) const
inlineprivate

Definition at line 202 of file CoraCoolFolder.h.

202{return m_proxy; }

◆ referenceObject() [1/2]

void CoraCoolFolder::referenceObject ( const cool::ValidityKey & since,
const cool::ValidityKey & until,
const coral::Attribute & fkey,
const cool::ChannelId & channelId = 0,
const std::string & tagName = defaultTagName(),
const bool userTagOnly = false )

Definition at line 268 of file CoraCoolFolder.cxx.

273 {
274 // add reference to existing payload object
275 // call COOL API, just checking fkey has correct name
276 if (fkey.specification().name()==m_keycolcool) {
277 cool::Record fkeylist(m_coolfolder->payloadSpecification());
278 setFieldAttr(fkeylist[m_keycolcool],fkey);
279 m_coolfolder->storeObject(since,until,fkeylist,channelId,tagName,
280 userTagOnly);
281 } else {
282 throw CoraCoolException("Foreign key name should be "+m_keycolcool,
283 "CoraCool::Folder::referenceObject");
284 }
285}
bool setFieldAttr(cool::IField &attr, const coral::Attribute &keyval)

◆ referenceObject() [2/2]

void CoraCoolFolder::referenceObject ( const cool::ValidityKey & since,
const cool::ValidityKey & until,
const int ifkey,
const cool::ChannelId & channelId = 0,
const std::string & tagName = defaultTagName(),
const bool userTagOnly = false )

Definition at line 287 of file CoraCoolFolder.cxx.

292 {
293 // add reference to existing payload object, supplying key as int
294 cool::Record fkeylist(m_coolfolder->payloadSpecification());
295 setFieldKey(fkeylist[m_keycolcool],ifkey);
296 m_coolfolder->storeObject(since,until,fkeylist,channelId,tagName,
297 userTagOnly);
298}
bool setFieldKey(cool::IField &attr, const int keyval)

◆ setAttrKey()

bool CoraCoolFolder::setAttrKey ( coral::Attribute & attr,
const int keyval )

Definition at line 349 of file CoraCoolFolder.cxx.

350 {
351 // set the value of the key in the attribute, regardless of type
352 const std::string typen=attr.specification().typeName();
353 if (typen=="int") {
354 attr.data<int>()=keyval;
355 } else if (typen=="unsigned int") {
356 attr.data<unsigned int>()=keyval;
357 } else if (typen=="long long") {
358 attr.data<long long>()=keyval;
359 } else if (typen=="unsigned long long") {
360 attr.data<unsigned long long>()=keyval;
361 } else {
362 // throw exception here?
363 m_log << coral::Error << "Unrecognised key type " << typen <<
364 " in CoraCoolFolder::setAttrKey" << coral::MessageStream::endmsg;
365 return false;
366 }
367 return true;
368}

◆ setFieldAttr()

bool CoraCoolFolder::setFieldAttr ( cool::IField & attr,
const coral::Attribute & keyval )

Definition at line 391 of file CoraCoolFolder.cxx.

392 {
393 // set the value of the key in the Record, from input Attribute
394 const cool::StorageType& typen=attr.specification().storageType();
395 if (typen==cool::StorageType::Int32) {
396 attr.setValue<int>(keyval.data<int>());
397 } else if (typen==cool::StorageType::UInt32) {
398 attr.setValue<unsigned int>(keyval.data<unsigned int>());
399 } else if (typen==cool::StorageType::Int64) {
400 attr.setValue<long long>(keyval.data<long long>());
401 } else if (typen==cool::StorageType::UInt63) {
402 attr.setValue<unsigned long long>(keyval.data<unsigned long long>());
403 } else {
404 // throw exception here?
405 m_log << coral::Error << "Unrecognised key type " << typen.name() <<
406 " in CoraCoolFolder::setFieldAttr" << coral::MessageStream::endmsg;
407 return false;
408 }
409 return true;
410}

◆ setFieldKey()

bool CoraCoolFolder::setFieldKey ( cool::IField & attr,
const int keyval )

Definition at line 370 of file CoraCoolFolder.cxx.

371 {
372 // set the value of the key in the Record, regardless of type
373 const cool::StorageType& typen=attr.specification().storageType();
374 if (typen==cool::StorageType::Int32) {
375 attr.setValue<int>(keyval);
376 } else if (typen==cool::StorageType::UInt32) {
377 attr.setValue<unsigned int>(keyval);
378 } else if (typen==cool::StorageType::Int64) {
379 attr.setValue<long long>(keyval);
380 } else if (typen==cool::StorageType::UInt63) {
381 attr.setValue<unsigned long long>(keyval);
382 } else {
383 // throw exception here?
384 m_log << coral::Error << "Unrecognised key type " << typen.name() <<
385 " in CoraCoolFolder::setFieldKey" << coral::MessageStream::endmsg;
386 return false;
387 }
388 return true;
389}

◆ setOutputSpec()

void CoraCoolFolder::setOutputSpec ( coral::IQuery * query)
private

Definition at line 496 of file CoraCoolFolder.cxx.

496 {
497 for (AttrItr itr=m_attrvec.begin();itr!=m_attrvec.end();++itr)
498 query->defineOutputType(itr->first,
499 coral::AttributeSpecification::typeNameForId(
500 cool::StorageType::storageType(nameToCoolType(itr->second)).cppType()));
501}

◆ setPrefetchAll()

void CoraCoolFolder::setPrefetchAll ( const bool prefetchAll)

Definition at line 577 of file CoraCoolFolder.cxx.

577 {
578 // pass setting onto COOL - no special actions for CoraCool yet
579 m_coolfolder->setPrefetchAll(prefetchAll);
580}

◆ setupStorageBuffer()

bool CoraCoolFolder::setupStorageBuffer ( )

Definition at line 218 of file CoraCoolFolder.cxx.

218 {
219 // flush any existing data first to get clean state
221 if (m_payloadbuf==0) {
222 // actions done if this is the first time setupStorageBuffer done for
223 // this folder
224 // create AttributeList as bulk buffer
225 m_payloadbuf=new coral::AttributeList(emptyAttrList());
226 // setup bulk storage for the COOL folder
227 m_coolfolder->setupStorageBuffer();
228 }
229 // setup bulk operation buffer - transaction begins here
230 m_proxy->transaction().start(false);
231 coral::ISchema& schema=m_proxy->nominalSchema();
232 m_table=&schema.tableHandle(m_tablename);
233 coral::ITableDataEditor& editor=m_table->dataEditor();
234 m_bulki=editor.bulkInsert(*m_payloadbuf,WB_SIZE);
235 // prepare the key sequences
236 if (m_pkey) {
237 if (m_seqpk==0)
238 m_seqpk=new CoraCoolSequence(m_dbname,m_tablename+"_PK",m_proxy,false);
239 m_seqpk->querySeq(m_nextpk,true,true);
240 m_usedpk=0;
241 }
242 if (m_seqfk==0)
243 m_seqfk=new CoraCoolSequence(m_dbname,m_tablename+"_FK",m_proxy,false);
244 m_seqfk->querySeq(m_nextfk,true,true);
245 m_usedfk=0;
246 m_bulkactive=true;
247 return true;
248}
#define WB_SIZE
coral::AttributeList emptyAttrList() const

◆ storeObject()

int CoraCoolFolder::storeObject ( const cool::ValidityKey & since,
const cool::ValidityKey until,
const_iterator begin,
const_iterator end,
const cool::ChannelId & channelId = 0,
const std::string & tagName = defaultTagName(),
const bool userTagOnly = false )

Definition at line 132 of file CoraCoolFolder.cxx.

138 {
139 // store objects into CORAL table, and reference in COOL table
140 // generate new FK and PK for CORAL data as needed
141
142 int fkey=0;
143 if (m_bulkactive) {
144 fkey=m_nextfk++;
145 ++m_usedfk;
146 bulkInsert(begin,end,fkey,true);
147 } else {
148 // non-bulk insert
149 // first count number of CORAL rows to be inserted
150 unsigned int nrow=0;
151 for (const_iterator payitr=begin;payitr!=end;++payitr) ++nrow;
152 m_log << coral::Debug << "Storing " << nrow << " rows in CoraCool folder "
153 << m_foldername << " channel " << channelId <<
154 coral::MessageStream::endmsg;
155
156 // generate keys - start transaction here
157 int pkey;
158 try {
159 m_proxy->transaction().start(false);
160 CoraCoolSequence seqfk(m_dbname,m_tablename+"_FK",m_proxy,false);
161 fkey=seqfk.fetch();
162 if (m_pkey) {
163 CoraCoolSequence seqfk(m_dbname,m_tablename+"_PK",m_proxy,false);
164 pkey=seqfk.fetch(nrow);
165 } else {
166 pkey=0; // set to 0 to satisfy compiler
167 }
168 // commit key transaction, releasing lock on keytable
169 m_proxy->transaction().commit();
170 }
171 catch (coral::Exception& e) {
172 throw CoraCoolException(e.what(),"CoraCoolFolder::storeObject(key)");
173 }
174
175 // insert rows into CORAL, using bulk operation
176 try {
177 m_proxy->transaction().start(false);
178 coral::ISchema& schema=m_proxy->nominalSchema();
179 m_table=&schema.tableHandle(m_tablename);
180 coral::ITableDataEditor& editor=m_table->dataEditor();
181 coral::AttributeList data=*begin;
182 coral::IBulkOperation* bulki=editor.bulkInsert(data,WB_SIZE);
183
184 for (const_iterator payitr=begin;payitr!=end;++payitr) {
185 // copy data from iterator
186 data.fastCopyData(*payitr);
187 // update the keys
189 if (m_pkey) setAttrKey(data[m_pkeycolcoral],pkey++);
190 // store data into CORAL table
191 bulki->processNextIteration();
192 }
193 bulki->flush();
194 m_proxy->transaction().commit();
195 }
196 catch (coral::Exception& e) {
197 throw CoraCoolException(e.what(),"CoraCoolFolder::storeObject(payload)");
198 }
199
200 // now store data in COOL, with correct foreign key (bulk/non bulk)
201 // in bulk case, the COOL operation is already going via storage buffer
202 }
203 cool::Record coolfk(m_coolfolder->payloadSpecification());
204 setFieldKey(coolfk[m_keycolcool],fkey);
205 try {
206 m_coolfolder->storeObject(since,until,coolfk,channelId,tagName,
207 userTagOnly);
208 }
209 catch (cool::Exception &e) {
210 throw CoraCoolException(e.what(),"CoraCoolFolder::storeObject");
211 }
212 // return FK value, in case user wants to use it in a reference object call
213 return fkey;
214}

◆ table()

coral::ITable * CoraCoolFolder::table ( )
private

Definition at line 582 of file CoraCoolFolder.cxx.

582 {
583 return &(m_proxy->nominalSchema().tableHandle(m_tablename));
584}

◆ CoraCoolObjectIter

friend class CoraCoolObjectIter
friend

Definition at line 39 of file CoraCoolFolder.h.

Member Data Documentation

◆ m_attrvec

AttrVec CoraCoolFolder::m_attrvec
private

Definition at line 176 of file CoraCoolFolder.h.

◆ m_bulkactive

bool CoraCoolFolder::m_bulkactive
private

Definition at line 178 of file CoraCoolFolder.h.

◆ m_bulki

coral::IBulkOperation* CoraCoolFolder::m_bulki
private

Definition at line 180 of file CoraCoolFolder.h.

◆ m_cooldb

cool::IDatabasePtr CoraCoolFolder::m_cooldb
private

Definition at line 161 of file CoraCoolFolder.h.

◆ m_coolfolder

cool::IFolderPtr CoraCoolFolder::m_coolfolder
private

Definition at line 170 of file CoraCoolFolder.h.

◆ m_coradb

CoraCoolDatabase* CoraCoolFolder::m_coradb
private

Definition at line 162 of file CoraCoolFolder.h.

◆ m_dbname

std::string CoraCoolFolder::m_dbname
private

Definition at line 159 of file CoraCoolFolder.h.

◆ m_foldername

std::string CoraCoolFolder::m_foldername
private

Definition at line 158 of file CoraCoolFolder.h.

◆ m_keycolcool

std::string CoraCoolFolder::m_keycolcool
private

Definition at line 167 of file CoraCoolFolder.h.

◆ m_keycolcoral

std::string CoraCoolFolder::m_keycolcoral
private

Definition at line 166 of file CoraCoolFolder.h.

◆ m_log

coral::MessageStream& CoraCoolFolder::m_log
private

Definition at line 163 of file CoraCoolFolder.h.

◆ m_nextfk

int CoraCoolFolder::m_nextfk
private

Definition at line 185 of file CoraCoolFolder.h.

◆ m_nextpk

int CoraCoolFolder::m_nextpk
private

Definition at line 183 of file CoraCoolFolder.h.

◆ m_payloadbuf

coral::AttributeList* CoraCoolFolder::m_payloadbuf
private

Definition at line 179 of file CoraCoolFolder.h.

◆ m_pkey

bool CoraCoolFolder::m_pkey
private

Definition at line 169 of file CoraCoolFolder.h.

◆ m_pkeycolcoral

std::string CoraCoolFolder::m_pkeycolcoral
private

Definition at line 168 of file CoraCoolFolder.h.

◆ m_proxy

coral::ISessionProxy* CoraCoolFolder::m_proxy
private

Definition at line 160 of file CoraCoolFolder.h.

◆ m_seqfk

CoraCoolSequence* CoraCoolFolder::m_seqfk
private

Definition at line 182 of file CoraCoolFolder.h.

◆ m_seqpk

CoraCoolSequence* CoraCoolFolder::m_seqpk
private

Definition at line 181 of file CoraCoolFolder.h.

◆ m_table

coral::ITable* CoraCoolFolder::m_table
private

Definition at line 171 of file CoraCoolFolder.h.

◆ m_tabledesc

const coral::ITableDescription* CoraCoolFolder::m_tabledesc
private

Definition at line 172 of file CoraCoolFolder.h.

◆ m_tablename

std::string CoraCoolFolder::m_tablename
private

Definition at line 165 of file CoraCoolFolder.h.

◆ m_usedfk

int CoraCoolFolder::m_usedfk
private

Definition at line 186 of file CoraCoolFolder.h.

◆ m_usedpk

int CoraCoolFolder::m_usedpk
private

Definition at line 184 of file CoraCoolFolder.h.


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