24 #include "GaudiKernel/IAddressCreator.h"
25 #include "GaudiKernel/IClassIDSvc.h"
26 #include "GaudiKernel/IConversionSvc.h"
27 #include "GaudiKernel/IOpaqueAddress.h"
28 #include "GaudiKernel/IConverter.h"
38 #include "CoolKernel/IDatabase.h"
39 #include "CoolKernel/IFolder.h"
40 #include "CoolKernel/RecordSpecification.h"
41 #include "CoolKernel/FolderSpecification.h"
42 #include "CoolKernel/Record.h"
51 m_iov_db (
"IOVDbSvc",
name ),
52 m_detStore(
"DetectorStore",
name ),
53 m_persSvc (
"EventPersistencySvc",
name ),
54 m_clidSvc (
"ClassIDSvc",
name )
66 return IIOVRegistrationSvc::interfaceID();
76 if (
sc.isFailure() ) {
78 return StatusCode::FAILURE;
85 return StatusCode::FAILURE;
90 if (
sc.isFailure() ) {
92 return StatusCode::FAILURE;
98 if (
sc != StatusCode::SUCCESS ) {
99 ATH_MSG_ERROR (
" Cannot get IAddressCreator interface of the EventPersistencySvc ");
107 if (
sc != StatusCode::SUCCESS ) {
108 ATH_MSG_ERROR (
" Cannot get IClassIDSvc interface of the CLIDSvc " );
132 ATH_MSG_FATAL (
"Inconsistent settings of OverrideNames and OverrideTypes parameters");
133 return StatusCode::FAILURE;
138 return StatusCode::SUCCESS;
146 return StatusCode::SUCCESS;
153 std::string
key =
"";
187 std::string
key =
"";
220 const std::string&
tag )
const
253 const std::string&
tag,
254 unsigned int beginRun,
256 unsigned int beginLB,
257 unsigned int endLB )
const
260 start.setRunEvent( (
unsigned long)beginRun, (
unsigned long)beginLB );
262 stop.setRunEvent ( (
unsigned long)endRun, (
unsigned long)endLB );
263 std::string
key =
"";
275 const std::string&
tag,
280 start.setTimestamp( beginTime );
284 std::string
key =
"";
296 const std::string&
key,
297 const std::string&
tag,
298 unsigned int beginRun,
300 unsigned int beginLB,
301 unsigned int endLB )
const
304 start.setRunEvent( (
unsigned long)beginRun, (
unsigned long)beginLB );
306 stop.setRunEvent ( (
unsigned long)endRun, (
unsigned long)endLB );
318 const std::string&
key,
319 const std::string&
tag,
324 start.setTimestamp( beginTime );
338 const std::string&
key,
339 const std::string&
folder,
340 const std::string&
tag,
341 unsigned int beginRun,
343 unsigned int beginLB,
344 unsigned int endLB )
const
347 start.setRunEvent( (
unsigned long)beginRun, (
unsigned long)beginLB );
349 stop.setRunEvent ( (
unsigned long)endRun, (
unsigned long)endLB );
362 const std::string&
key,
363 const std::string&
folder,
364 const std::string&
tag,
369 start.setTimestamp( beginTime );
388 const std::string& spec_key,
389 const std::string&
folder,
390 const std::string&
tag,
400 if (spec_key.empty())
406 msg() <<
" spec_key " << spec_key <<
endmsg;
409 <<
" - end time: " <<
stop
414 start.isTimestamp() !=
stop.isTimestamp() ||
415 start.isRunEvent() !=
stop.isRunEvent()) {
417 <<
" isBoth: " <<
start.isBoth() <<
":" <<
stop.isBoth()
418 <<
" isTimestamp: " <<
start.isTimestamp() <<
":" <<
stop.isTimestamp()
419 <<
" isRunEvent: " <<
start.isRunEvent() <<
":" <<
stop.isRunEvent());
420 return( StatusCode::FAILURE);
436 const std::string& spec_key,
438 const std::string&
tag,
452 if (
sc.isFailure()) {
454 return( StatusCode::FAILURE);
472 bool storeRef =
true;
473 bool storeAttrListColl =
false;
474 bool needSGaddr=
false;
475 if (
"AthenaAttributeList" ==
typeName) {
479 if (
"CondAttrListCollection" ==
typeName) {
481 storeAttrListColl =
true;
489 IOpaqueAddress* addr=0;
490 std::string
key = spec_key;
491 std::vector<CLID> symlinks;
499 return( StatusCode::FAILURE);
506 addr =
proxy->address();
511 ATH_MSG_ERROR (
"Could not get proxy for clid " << clid <<
" and key " <<
key);
512 return( StatusCode::FAILURE );
516 addr =
proxy->address();
521 symlinks =
proxy->transientID();
522 auto it =
std::find (symlinks.begin(), symlinks.end(), clid);
523 if (
it != symlinks.end()) {
532 storeAttrListColl =
true;
537 if (
sc.isFailure()) {
538 ATH_MSG_WARNING (
"Could not get string from IOpaqueAddress for clid " << clid
539 <<
" is BAD_STORAGE_TYPE: " << (
sc == IConversionSvc::Status::BAD_STORAGE_TYPE));
540 return( StatusCode::FAILURE);
549 return( StatusCode::FAILURE );
553 if (
"AthenaAttributeList" ==
typeName) {
554 saddr=
"<address_header service_type=\"256\" clid=\"40774348\" /> POOLContainer_AthenaAttributeList][CLID=x";
555 }
else if (
"CondAttrListCollection" ==
typeName) {
556 saddr=
"<address_header service_type=\"256\" clid=\"1238547719\" /> POOLContainer_CondAttrListCollection][CLID=x";
565 <<
" Storing AttrListCollection: " << storeAttrListColl);
570 std::string local_folder;
579 cool::IDatabasePtr
db =
m_iov_db->getDatabase(
false);
582 return(StatusCode::FAILURE);
585 const cool::DatabaseId& dbid=
db->databaseId();
587 bool dbidprod=(dbid.find(
"oracle")!=std::string::npos && (
588 dbid.find(
"ATLAS_COOLONL_")!=std::string::npos ||
589 dbid.find(
"ATLAS_COOLOFL_")!=std::string::npos ||
590 dbid.find(
"ATLAS_COOL_")!=std::string::npos));
592 bool dbidwriter=(dbid.find(
"oracle")!=std::string::npos &&
593 dbid.find(
"_W")!=std::string::npos);
594 ATH_MSG_DEBUG (
"Identified prod/writer " << dbidprod << dbidwriter);
597 ATH_MSG_FATAL (
"Direct update of production Oracle servers from Athena is FORBIDDEN");
598 ATH_MSG_FATAL (
"Please write to SQLite file and then merge with AtlCoolMerge.py");
599 return StatusCode::FAILURE;
607 if (
"CondAttrListCollection"==
typeName) {
612 return StatusCode::FAILURE;
614 }
else if (storeAttrListColl) {
623 << addr <<
" " << attrAddr <<
" " << attrListColl);
625 ATH_MSG_ERROR (
"Could not extract ptr for CondAttrListCollAddress ");
626 return StatusCode::FAILURE;
629 ATH_MSG_ERROR (
"Cannot write out collection of POOLref without streaming them first" );
630 return StatusCode::FAILURE;
634 if (StatusCode::SUCCESS!=
m_detStore->retrieve(attrList,
key)) {
637 return StatusCode::FAILURE;
652 bool createFolders =
false;
654 if(
db->existsFolder(local_folder)) {
658 if (dbidprod || dbidwriter) {
659 ATH_MSG_FATAL (
"Apparent attempt to delete folder on production COOL schema " << dbid);
660 return StatusCode::FAILURE;
663 ATH_MSG_DEBUG (
" Deleting existing COOL Folder " << local_folder);
664 db->dropNode( local_folder );
665 createFolders =
true;
670 folder =
db->getFolder(local_folder);
676 <<
" does not exist - must create it");
677 createFolders =
true;
681 std::string address_header;
682 std::string address_data;
685 if (
sc.isFailure()) {
687 <<
"addr: " << saddr <<
"\n"
688 <<
"hdr: " << address_header <<
"\n"
689 <<
"data " << address_data);
690 return( StatusCode::FAILURE);
693 <<
" hdr: " << address_header <<
endmsg
694 <<
" data: " << address_data <<
endmsg;
700 ATH_MSG_FATAL (
"Apparent attempt to create folder using writer account, dbID is: " << dbid);
701 return StatusCode::FAILURE;
720 std::string mergedNames;
724 if (
sc.isFailure()) {
725 ATH_MSG_ERROR (
"Could not merge towards merged description: "
727 return( StatusCode::FAILURE);
732 if (
sc.isFailure()) {
733 ATH_MSG_ERROR (
"Could not merge towards merged description: "
734 <<
"addrHeader: " << address_header);
735 return( StatusCode::FAILURE);
745 if (
sc.isFailure()) {
746 ATH_MSG_ERROR (
"Could not merge towards merged description: "
748 return( StatusCode::FAILURE);
753 if (!symlinks.empty()) {
754 std::string symlinkTypes;
755 for (
unsigned int i = 0;
i < symlinks.size(); ++
i) {
758 if (
sc.isFailure()) {
761 return( StatusCode::FAILURE);
765 << symlinks[
i] <<
" " <<
type);
767 if (symlinkTypes.size()) symlinkTypes +=
':';
768 symlinkTypes +=
type;
771 if (
sc.isFailure()) {
772 msg() << MSG::ERROR <<
"Could not merge symlinks to merged description: "
773 <<
"symlink types: ";
774 for (
unsigned int i = 0;
i < symlinkTypes.size(); ++
i) {
775 msg() << MSG::ERROR << symlinkTypes[
i] <<
" ";
778 return( StatusCode::FAILURE);
782 << symlinkTypes <<
" " << mergedNames);
789 if (!
start.isValid() ||
791 start.isTimestamp() !=
stop.isTimestamp() ||
792 start.isRunEvent() !=
stop.isRunEvent()) {
793 ATH_MSG_ERROR (
"Invalid times: start isValid/isTimeStamp/isRunEvent "
794 <<
"addrHeader: " << address_header
795 <<
start.isValid() <<
" " <<
start.isTimestamp() <<
" "
796 <<
start.isRunEvent());
797 ATH_MSG_ERROR (
"Invalid times: stop isValid/isTimeStamp/isRunEvent "
798 <<
"addrHeader: " << address_header
799 <<
stop.isValid() <<
" " <<
stop.isTimestamp() <<
" "
800 <<
stop.isRunEvent());
801 return( StatusCode::FAILURE);
803 bool isTimeStamp =
false;
804 if (
start.isTimestamp()) isTimeStamp =
true;
816 if (
sc.isFailure()) {
817 ATH_MSG_ERROR (
"Could not merge timeStamp flag towards merged description. ");
818 return( StatusCode::FAILURE);
821 if (storeAttrListColl && attrListColl!=0 &&
822 attrListColl->
name_size()>0) mergedNames+=
"<named/>";
825 <<
" with description " << mergedNames);
836 payloadSpec.extend(
"PoolRef",cool::StorageType::String4k);
841 if (storeAttrListColl) {
845 if (0 == attrListColl) {
847 return( StatusCode::FAILURE);
850 if (0 == attrListColl->
size()) {
852 return( StatusCode::FAILURE);
856 attrListColl->
size());
866 for (coral::AttributeList::const_iterator itr=
867 atr4spec->begin();itr!=atr4spec->end();++itr) {
872 itr->specification().typeName()));
877 cool::FolderVersioning::MULTI_VERSION;
879 version=cool::FolderVersioning::SINGLE_VERSION;
890 local_folder <<
" done");
893 if (storeAttrListColl && attrListColl!=0 &&
896 " channels in " << local_folder);
899 nitr!=attrListColl->
name_end();++nitr) {
900 folder->createChannel(nitr->first,nitr->second);
907 if (storeAttrListColl) {
909 <<
start <<
" " <<
stop <<
" Note: will be ignored for channels with differnt IOVs " );
916 cool::ValidityKey ivStart =
start.re_time();
917 cool::ValidityKey ivStop =
stop.re_time();
918 if(
start.isTimestamp()) {
919 ivStart =
start.timestamp();
920 ivStop =
stop.timestamp();
925 const cool::RecordSpecification& rspec=
folder->payloadSpecification();
927 if (storeAttrListColl) {
937 ATH_MSG_ERROR (
"Trying to store a ref for a CondAttrListCollection. ");
938 return( StatusCode::FAILURE);
942 <<
", " <<
tag <<
" )");
956 cool::ValidityKey ivStart1 = ivStart;
957 cool::ValidityKey ivStop1 = ivStop;
959 std::ostringstream attr;
960 payload.toOutputStream( attr );
964 if(
range.start().isTimestamp()) {
965 ivStart1 =
range.start().timestamp();
966 ivStop1 =
range.stop().timestamp();
969 ivStart1 =
range.start().re_time();
970 ivStop1 =
range.stop().re_time();
973 <<
range.start() <<
" " <<
range.stop() <<
" ");
981 cool::Record record(rspec,
payload);
984 folder->storeObject( ivStart1,
989 folder->storeObject( ivStart1,
998 cool::Record record(rspec);
1001 record[
"PoolRef"].setValue<std::string>(address_data);
1005 record=cool::Record(rspec,*attrList);
1011 folder->storeObject( ivStart,
1015 folder->storeObject( ivStart,
1021 <<
", " <<
tag <<
" )");
1030 ATH_MSG_DEBUG (
" tag is empty - folder is not being tagged ");
1033 ATH_MSG_INFO (
" Tagging HEAD of folder " << local_folder <<
1034 " with tag " <<
tag);
1038 catch ( cool::TagExists&
e) {
1040 " exists - attempt to delete tag and retag HEAD");
1045 ATH_MSG_ERROR (
"Tag is defined in another folder - tag names must be global");
1046 }
else if (
folder->existsUserTag(
tag)) {
1050 " is already USER tag - cannot mix tagging modes");
1057 catch ( cool::TagNotFound&
e) {
1064 return StatusCode::SUCCESS;
1071 return StatusCode::FAILURE;
1078 const std::string&
parname,
const std::string& coralName)
const {
1080 std::string coralType=coralName;
1085 ATH_MSG_INFO (
"Override default type for attribute " <<
1086 parname <<
" - use " << coralType);
1092 if (coralType==
"bool")
return cool::StorageType::Bool;
1093 if (coralType==
"UChar" || coralType==
"unsigned char")
return cool::StorageType::UChar;
1094 if (coralType==
"Int16")
return cool::StorageType::Int16;
1095 if (coralType==
"UInt16")
return cool::StorageType::UInt16;
1096 if (coralType==
"Int32" || coralType==
"int")
return cool::StorageType::Int32;
1097 if (coralType==
"UInt32" || coralType==
"unsigned int")
return cool::StorageType::UInt32;
1098 if (coralType==
"UInt63" || coralType==
"unsigned long long")
return cool::StorageType::UInt63;
1099 if (coralType==
"Int64" || coralType==
"long long")
return cool::StorageType::Int64;
1100 if (coralType==
"Float" || coralType==
"float")
return cool::StorageType::Float;
1101 if (coralType==
"Double" || coralType==
"double")
return cool::StorageType::Double;
1102 if (coralType==
"String255")
return cool::StorageType::String255;
1103 if (coralType==
"String4k" || coralType==
"string")
return cool::StorageType::String4k;
1104 if (coralType==
"String64k")
return cool::StorageType::String64k;
1105 if (coralType==
"String16M")
return cool::StorageType::String16M;
1106 if (coralType==
"blob" || coralType==
"Blob64k")
1107 return cool::StorageType::Blob64k;
1108 if (coralType==
"Blob16M")
return cool::StorageType::Blob16M;
1111 ATH_MSG_FATAL (
"No COOL mapping defined for CORAL type " << coralName);
1125 return static_cast<uint64_t>(timesec)*1000000000;
1130 const std::string&
value,
1136 return StatusCode::FAILURE;
1139 return StatusCode::SUCCESS;
1143 std::string& address_header,
1144 std::string& address_data )
const {
1150 std::string::size_type
p1=
address.find(
" />");
1151 if (
p1!=std::string::npos) {
1154 return StatusCode::SUCCESS;
1156 return StatusCode::FAILURE;