13 #include "CoolKernel/IDatabaseSvc.h"
14 #include "CoolKernel/ChannelSelection.h"
19 #include "CoralBase/Blob.h"
27 const std::string&
folder,
const int nfolder,
28 const int nobj,
const int nchan,
const int niov,
69 const int nobj,
const int nchan,
71 const int iov1,
const int iovinc) :
73 m_nobj(nobj), m_nchan(
nchan), m_niov(niov),m_iov1(
iov1),m_iovinc(iovinc) {
75 std::cout <<
"Option string: " <<
options << std::endl;
76 std::cout <<
"Objects per channel=" <<
m_nobj <<
" Channels=" <<
m_nchan
77 <<
" IOVs=" <<
m_niov << std::endl;
78 std::cout <<
"IOVstart=" <<
m_iov1 <<
" inc " <<
m_iovinc << std::endl;
84 }
else if (nfolder<1000) {
85 std::cout <<
"Defining multiple folders" << std::endl;
86 for (
int i=1;
i<=nfolder;++
i) {
89 std::cout <<
"Foldername " << o.str() << std::endl;
93 std::cout <<
"Attempt to define too many folders " << std::endl;
107 "Second reference will be included for each object" << std::endl;
109 "Additional rows will be added for each object" << std::endl;
110 if (
m_bulk) std::cout <<
"Writing will use bulk updates" << std::endl;
114 std::cout <<
"Initialise database for " <<
m_dbstring.substr(0,
idx) <<
124 std::cout <<
"Done the CoraCool initialisation" << std::endl;
129 std::cout <<
"Opening CORAL database" << std::endl;
132 std::cout <<
"Database connections open OK" << std::endl;
135 std::cout <<
"Problem opening CORAL database: " <<
e.what() << std::endl;
137 std::cout <<
"Done the database opening" << std::endl;
140 cool::IDatabasePtr cooldb=
m_coradb->coolDatabase();
141 const std::vector<std::string>&
folders=cooldb->listAllNodes();
142 std::cout <<
"COOL database has " <<
folders.size() <<
" folders defined"
144 for (std::vector<std::string>::const_iterator itr=
folders.begin();
145 itr!=
folders.end();++itr) std::cout << *itr << std::endl;
161 m_payloadspec.extend(
"ULongLong1",cool::StorageType::UInt63);
168 std::cout <<
"Including blob of size " <<
m_blobsize <<
" in data " <<
172 m_fkspec.extend(
"CoolKey",cool::StorageType::Int32);
176 for (std::vector<std::string>::const_iterator itr=
m_foldername.begin();
178 std::string::size_type iofs=itr->rfind(
"/");
179 if (iofs!=std::string::npos) {
189 const int chan,
const int iov) {
197 data[
"PrimKey"].data<
int>()=0;
198 data[
"ForeignKey"].data<
int>()=0;
200 data[
"IntObj"].data<
int>()=
obj;
211 data[
"String1"].data<std::string>()=
"A test string of data";
216 unsigned char*
p=
static_cast<unsigned char*
>(
blob.startingAddress());
225 if (
write()==
false) {
226 std::cout <<
"CoraCoolExample FAILURE from write" << std::endl;
232 std::cout <<
"CoraCoolExample FAILURE from read" << std::endl;
245 std::vector<std::string>::const_iterator ctitr=
m_coraltable.begin();
246 for (std::vector<std::string>::const_iterator fitr=
m_foldername.begin();
252 std::cout <<
"Deleting existing folder " << *fitr << std::endl;
254 std::cout <<
"Folder deleted" << std::endl;
256 catch (cool::Exception&
e) {
257 std::cout <<
"Problem deleting folder: " <<
e.what() << std::endl;
261 if (!
m_coradb->existsFolder(*fitr)) {
263 std::cout <<
"Creating folder with name " << *fitr << std::endl;
265 std::string
desc=
"<timeStamp>run-event</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"55403898\" /></addrHeader><typeName>CondAttrListVec</typeName>";
269 "ForeignKey",
"PrimKey",
desc,
270 cool::FolderVersioning::SINGLE_VERSION,
true);
271 std::cout <<
"Folder " << *fitr <<
" created" << std::endl;
273 catch (cool::Exception&
e) {
274 std::cout <<
"Problem creating folder: " <<
e.what() << std::endl;
283 for (
int iiov=0;iiov<
m_niov;++iiov) {
290 std::vector<coral::AttributeList> datavec;
291 for (
int iobj=0;iobj<
m_nobj;++iobj) {
293 datavec.push_back(adata);
297 datavec.end(),
ichan);
301 std::vector<coral::AttributeList> datavec2;
302 for (
int iobj=0;iobj<
m_nobj;++iobj) {
305 adata[
"ForeignKey"].data<
int>()=fkey;
306 datavec2.push_back(adata);
308 folder->addPayload(datavec2.begin(),datavec2.end());
316 catch (cool::Exception&
e) {
317 std::cout <<
"Problem writing data: " <<
e.what() << std::endl;
323 std::cout <<
"Written " << nobj <<
" objects to folder " << *fitr <<
332 for (std::vector<std::string>::const_iterator fitr=
m_foldername.begin();
334 std::cout <<
"Read back data from folder " << *fitr << std::endl;
339 catch (cool::Exception&
e) {
340 std::cout <<
"Exception during getFolder: " <<
e.what() << std::endl;
345 const cool::IRecordSpecification&
spec=
346 folder->payloadSpecification();
347 for (
unsigned int i=0;
i<
spec.size();++
i) {
348 std::cout <<
"Payload column: " <<
spec[
i].name() <<
" type: " <<
349 spec[
i].storageType().name() << std::endl;
353 for (
int iiov=0;iiov<
m_niov*nrep;++iiov) {
357 while (itr->hasNext()) {
362 payitr!=
obj->end();++payitr,++iobj) {
364 int iobj2=(*payitr)[
"IntObj"].data<
int>();
366 obj->channelId(),iovx);
369 bool match=(expect.size()==payitr->size() && expect.size()>2);
371 for (
unsigned int i=2;
i<expect.size();++
i) {
372 std::string
dtype=expect[
i].specification().typeName();
373 bool failmatch=
false;
375 dtype==
"std::string") {
376 failmatch=(expect[
i]!=(*payitr)[
i]);
377 }
else if (
dtype==
"float") {
378 failmatch=(fabsf(expect[
i].data<float>()-
379 (*payitr)[
i].data<float>())>1.E-3);
380 }
else if (
dtype==
"double") {
381 failmatch=(fabs(expect[
i].data<double>()-
382 (*payitr)[
i].data<double>())>1.E-3);
383 }
else if (
dtype==
"blob") {
385 failmatch=(expect[
i]!=(*payitr)[
i]);
389 std::cout << expect[
i].specification().name() <<
" does not match" << std::endl;
394 std::cout <<
"Objects do not match for object/channel/iov "
395 << iobj <<
"/" <<
obj->channelId() <<
"/" << iiov <<
397 std::cout <<
"Read from DB: ";
398 (*payitr).toOutputStream(std::cout);
399 std::cout << std::endl <<
"Expected object: ";
400 expect.toOutputStream(std::cout);
401 std::cout << std::endl;
408 std::cout <<
"Read a total of " << nobj <<
" objects from CoraCool folder "
409 << *fitr <<
" with " << nerr <<
" errors" << std::endl;
416 std::cout <<
"Check API not implemented yet" << std::endl;
422 std::cout <<
"Syntax: CoraCoolExample.exe <dbConnection> { <options> ...}"
424 std::cout <<
"See package mainpage.h for more information" << std::endl;
429 std::string
folder=
"/CoraCool/Test1";
450 std::cout <<
"Exception thrown from CoraCoolExample: " <<
e.what()
455 std::cout <<
"CoraCoolExample SUCCESS" << std::endl;
457 std::cout <<
"CoraCoolExample FAILURE with return code " <<
458 retcode << std::endl;