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="", 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="", 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="", 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="")
CoraCoolObjectIterPtr browseObjects (const cool::ValidityKey &pointInTime, const cool::ChannelSelection &channels, const std::string &tagName="")
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="")
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)

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 174 of file CoraCoolFolder.h.

◆ AttrVec

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

Definition at line 173 of file CoraCoolFolder.h.

◆ const_iterator

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

Definition at line 42 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 293 of file CoraCoolFolder.cxx.

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

Definition at line 550 of file CoraCoolFolder.cxx.

553 {
554 return browseObjects(pointInTime,pointInTime,channels,tagName);
555}
CoraCoolObjectIterPtr browseObjects(const cool::ValidityKey &pointInTime, const cool::ChannelSelection &channels, const std::string &tagName="")

◆ 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 = "" )

Definition at line 557 of file CoraCoolFolder.cxx.

562{
563 // first initialise COOL query
564 cool::IObjectIteratorPtr coolitr=m_coolfolder->browseObjects(since,until,
565 channels,tagName);
566 CoraCoolObjectIterPtr itr(new CoraCoolObjectIter(this,std::move(coolitr)));
567 return itr;
568}
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 496 of file CoraCoolFolder.cxx.

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

◆ coolFolder()

cool::IFolderPtr CoraCoolFolder::coolFolder ( )
inline

Definition at line 197 of file CoraCoolFolder.h.

198{ return m_coolfolder; }

◆ coralFKey()

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

Definition at line 191 of file CoraCoolFolder.h.

192{ return m_keycolcoral; }

◆ coralPKey()

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

Definition at line 194 of file CoraCoolFolder.h.

195{ return m_pkeycolcoral; }

◆ coralTableName()

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

Definition at line 188 of file CoraCoolFolder.h.

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

◆ decodeAttrSpec()

bool CoraCoolFolder::decodeAttrSpec ( )
private

Definition at line 423 of file CoraCoolFolder.cxx.

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

◆ emptyAttrList()

coral::AttributeList CoraCoolFolder::emptyAttrList ( ) const

Definition at line 116 of file CoraCoolFolder.cxx.

116 {
117 // assemble and return an attributelist for use in constructing payloads
118 coral::AttributeList atrlist;
119 for (AttrItr itr=m_attrvec.begin();itr!=m_attrvec.end();++itr)
120 atrlist.extend(itr->first,
121 cool::StorageType::storageType(nameToCoolType(itr->second)).cppType());
122 return atrlist;
123}
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 = "" )

Definition at line 519 of file CoraCoolFolder.cxx.

521 {
522 // first query cool to get foreign key
523 m_log << coral::Debug << "CoraCoolFolder query time " << pointInTime <<
524 " channel " << channelId << " tag " << tagName << coral::MessageStream::endmsg;
525 cool::IObjectPtr obj=m_coolfolder->findObject(pointInTime,channelId,tagName);
526 // create result object with IOV from COOL
527 CoraCoolObjectPtr result(new CoraCoolObject(obj->since(),obj->until(),
528 obj->channelId()));
529 // now query CORAL for payload
530 try {
531 m_proxy->transaction().start(true);
532 coral::IQuery* query=m_table->newQuery();
533 std::string where=m_keycolcoral+"=:"+m_keycolcool;
534 const coral::AttributeList& fkeybind=obj->payload().attributeList();
535 query->setCondition(where,fkeybind);
536 coral::ICursor& cursor=query->execute();
537 while (cursor.next()) {
538 const coral::AttributeList& res=cursor.currentRow();
539 result->add(res);
540 }
541 delete query;
542 m_proxy->transaction().commit();
543 }
544 catch (coral::Exception& e) {
545 throw CoraCoolException(e.what(),"CoraCoolFolder::findObject");
546 }
547 return result;
548}
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 102 of file CoraCoolFolder.cxx.

104{ return m_coolfolder->payloadSpecification(); }

◆ flushStorageBuffer()

void CoraCoolFolder::flushStorageBuffer ( )

Definition at line 243 of file CoraCoolFolder.cxx.

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

◆ getAttrKey()

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

Definition at line 406 of file CoraCoolFolder.cxx.

406 {
407 const std::string typen=attr.specification().typeName();
408 if (typen=="int") {
409 return attr.data<int>();
410 } else if (typen=="unsigned int") {
411 return static_cast<int>(attr.data<unsigned int>());
412 } else if (typen=="long long") {
413 return static_cast<int>(attr.data<long long>());
414 } else if (typen=="unsigned long long") {
415 return static_cast<int>(attr.data<unsigned long long>());
416 } else {
417 m_log << coral::Error << "Unrecognised key type " << typen <<
418 " in CoraCoolFolder::getAttrKey" << coral::MessageStream::endmsg;
419 return 0;
420 }
421}

◆ nameToCoolType()

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

Definition at line 469 of file CoraCoolFolder.cxx.

470 {
471 if (coolName=="Int16") return cool::StorageType::Int16;
472 if (coolName=="UInt16") return cool::StorageType::UInt16;
473 if (coolName=="Int32") return cool::StorageType::Int32;
474 if (coolName=="UInt32") return cool::StorageType::UInt32;
475 if (coolName=="UInt63") return cool::StorageType::UInt63;
476 if (coolName=="Int64") return cool::StorageType::Int64;
477 if (coolName=="Float") return cool::StorageType::Float;
478 if (coolName=="Double") return cool::StorageType::Double;
479 if (coolName=="String255") return cool::StorageType::String255;
480 if (coolName=="String4k") return cool::StorageType::String4k;
481 if (coolName=="String64k") return cool::StorageType::String64k;
482 if (coolName=="String16M") return cool::StorageType::String16M;
483 if (coolName=="Blob64k") return cool::StorageType::Blob64k;
484
485 throw CoraCoolException("Undefined type: "+coolName,
486 "CoraCoolFolder::nameToCoolType");
487}

◆ operator=()

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

◆ payloadSpecification()

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

Definition at line 107 of file CoraCoolFolder.cxx.

107 {
108 // have to assemble a RecordSpecification and return the specification
109 // as ITableDescription does not allow to get this directly
110 cool::RecordSpecification atrspec;
111 for (AttrItr itr=m_attrvec.begin();itr!=m_attrvec.end();++itr)
112 atrspec.extend(itr->first,nameToCoolType(itr->second));
113 return atrspec;
114}

◆ proxy() [1/2]

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

Definition at line 200 of file CoraCoolFolder.h.

200{return m_proxy; }

◆ proxy() [2/2]

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

Definition at line 201 of file CoraCoolFolder.h.

201{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 = "",
const bool userTagOnly = false )

Definition at line 261 of file CoraCoolFolder.cxx.

266 {
267 // add reference to existing payload object
268 // call COOL API, just checking fkey has correct name
269 if (fkey.specification().name()==m_keycolcool) {
270 cool::Record fkeylist(m_coolfolder->payloadSpecification());
271 setFieldAttr(fkeylist[m_keycolcool],fkey);
272 m_coolfolder->storeObject(since,until,fkeylist,channelId,tagName,
273 userTagOnly);
274 } else {
275 throw CoraCoolException("Foreign key name should be "+m_keycolcool,
276 "CoraCool::Folder::referenceObject");
277 }
278}
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 = "",
const bool userTagOnly = false )

Definition at line 280 of file CoraCoolFolder.cxx.

285 {
286 // add reference to existing payload object, supplying key as int
287 cool::Record fkeylist(m_coolfolder->payloadSpecification());
288 setFieldKey(fkeylist[m_keycolcool],ifkey);
289 m_coolfolder->storeObject(since,until,fkeylist,channelId,tagName,
290 userTagOnly);
291}
bool setFieldKey(cool::IField &attr, const int keyval)

◆ setAttrKey()

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

Definition at line 342 of file CoraCoolFolder.cxx.

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

◆ setFieldAttr()

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

Definition at line 384 of file CoraCoolFolder.cxx.

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

◆ setFieldKey()

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

Definition at line 363 of file CoraCoolFolder.cxx.

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

◆ setOutputSpec()

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

Definition at line 489 of file CoraCoolFolder.cxx.

489 {
490 for (AttrItr itr=m_attrvec.begin();itr!=m_attrvec.end();++itr)
491 query->defineOutputType(itr->first,
492 coral::AttributeSpecification::typeNameForId(
493 cool::StorageType::storageType(nameToCoolType(itr->second)).cppType()));
494}

◆ setPrefetchAll()

void CoraCoolFolder::setPrefetchAll ( const bool prefetchAll)

Definition at line 570 of file CoraCoolFolder.cxx.

570 {
571 // pass setting onto COOL - no special actions for CoraCool yet
572 m_coolfolder->setPrefetchAll(prefetchAll);
573}

◆ setupStorageBuffer()

bool CoraCoolFolder::setupStorageBuffer ( )

Definition at line 211 of file CoraCoolFolder.cxx.

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

Definition at line 125 of file CoraCoolFolder.cxx.

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

◆ table()

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

Definition at line 575 of file CoraCoolFolder.cxx.

575 {
576 return &(m_proxy->nominalSchema().tableHandle(m_tablename));
577}

◆ 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 175 of file CoraCoolFolder.h.

◆ m_bulkactive

bool CoraCoolFolder::m_bulkactive
private

Definition at line 177 of file CoraCoolFolder.h.

◆ m_bulki

coral::IBulkOperation* CoraCoolFolder::m_bulki
private

Definition at line 179 of file CoraCoolFolder.h.

◆ m_cooldb

cool::IDatabasePtr CoraCoolFolder::m_cooldb
private

Definition at line 160 of file CoraCoolFolder.h.

◆ m_coolfolder

cool::IFolderPtr CoraCoolFolder::m_coolfolder
private

Definition at line 169 of file CoraCoolFolder.h.

◆ m_coradb

CoraCoolDatabase* CoraCoolFolder::m_coradb
private

Definition at line 161 of file CoraCoolFolder.h.

◆ m_dbname

std::string CoraCoolFolder::m_dbname
private

Definition at line 158 of file CoraCoolFolder.h.

◆ m_foldername

std::string CoraCoolFolder::m_foldername
private

Definition at line 157 of file CoraCoolFolder.h.

◆ m_keycolcool

std::string CoraCoolFolder::m_keycolcool
private

Definition at line 166 of file CoraCoolFolder.h.

◆ m_keycolcoral

std::string CoraCoolFolder::m_keycolcoral
private

Definition at line 165 of file CoraCoolFolder.h.

◆ m_log

coral::MessageStream& CoraCoolFolder::m_log
private

Definition at line 162 of file CoraCoolFolder.h.

◆ m_nextfk

int CoraCoolFolder::m_nextfk
private

Definition at line 184 of file CoraCoolFolder.h.

◆ m_nextpk

int CoraCoolFolder::m_nextpk
private

Definition at line 182 of file CoraCoolFolder.h.

◆ m_payloadbuf

coral::AttributeList* CoraCoolFolder::m_payloadbuf
private

Definition at line 178 of file CoraCoolFolder.h.

◆ m_pkey

bool CoraCoolFolder::m_pkey
private

Definition at line 168 of file CoraCoolFolder.h.

◆ m_pkeycolcoral

std::string CoraCoolFolder::m_pkeycolcoral
private

Definition at line 167 of file CoraCoolFolder.h.

◆ m_proxy

coral::ISessionProxy* CoraCoolFolder::m_proxy
private

Definition at line 159 of file CoraCoolFolder.h.

◆ m_seqfk

CoraCoolSequence* CoraCoolFolder::m_seqfk
private

Definition at line 181 of file CoraCoolFolder.h.

◆ m_seqpk

CoraCoolSequence* CoraCoolFolder::m_seqpk
private

Definition at line 180 of file CoraCoolFolder.h.

◆ m_table

coral::ITable* CoraCoolFolder::m_table
private

Definition at line 170 of file CoraCoolFolder.h.

◆ m_tabledesc

const coral::ITableDescription* CoraCoolFolder::m_tabledesc
private

Definition at line 171 of file CoraCoolFolder.h.

◆ m_tablename

std::string CoraCoolFolder::m_tablename
private

Definition at line 164 of file CoraCoolFolder.h.

◆ m_usedfk

int CoraCoolFolder::m_usedfk
private

Definition at line 185 of file CoraCoolFolder.h.

◆ m_usedpk

int CoraCoolFolder::m_usedpk
private

Definition at line 183 of file CoraCoolFolder.h.


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