28 #include "GaudiKernel/IAddressCreator.h"
29 #include "GaudiKernel/IClassIDSvc.h"
30 #include "GaudiKernel/IConversionSvc.h"
31 #include "GaudiKernel/IOpaqueAddress.h"
32 #include "GaudiKernel/IConverter.h"
42 #include "CoolKernel/IDatabase.h"
43 #include "CoolKernel/IFolder.h"
44 #include "CoolKernel/RecordSpecification.h"
45 #include "CoolKernel/FolderSpecification.h"
46 #include "CoolKernel/Record.h"
55 m_recreateFolders(false),
60 m_beginTime(
IOVTime::MINTIMESTAMP),
64 m_tagDescription(
"Athena IOVRegistrationSvc"),
69 m_payloadTable(false),
70 m_forceGlobalIOV(false),
71 m_iov_db (
"IOVDbSvc",
name ),
72 m_detStore(
"DetectorStore",
name ),
73 m_persSvc (
"EventPersistencySvc",
name ),
74 m_clidSvc (
"ClassIDSvc",
name )
122 return AthService::queryInterface(riid, ppvInterface);
125 return StatusCode::SUCCESS;
136 if (
sc.isFailure() ) {
138 return StatusCode::FAILURE;
145 return StatusCode::FAILURE;
150 if (
sc.isFailure() ) {
152 return StatusCode::FAILURE;
158 if (
sc != StatusCode::SUCCESS ) {
159 ATH_MSG_ERROR (
" Cannot get IAddressCreator interface of the EventPersistencySvc ");
167 if (
sc != StatusCode::SUCCESS ) {
168 ATH_MSG_ERROR (
" Cannot get IClassIDSvc interface of the CLIDSvc " );
192 ATH_MSG_FATAL (
"Inconsistent settings of OverrideNames and OverrideTypes parameters");
193 return StatusCode::FAILURE;
198 return StatusCode::SUCCESS;
206 return StatusCode::SUCCESS;
213 std::string
key =
"";
247 std::string
key =
"";
280 const std::string&
tag )
const
313 const std::string&
tag,
314 unsigned int beginRun,
316 unsigned int beginLB,
317 unsigned int endLB )
const
320 start.setRunEvent( (
unsigned long)beginRun, (
unsigned long)beginLB );
322 stop.setRunEvent ( (
unsigned long)endRun, (
unsigned long)endLB );
323 std::string
key =
"";
335 const std::string&
tag,
340 start.setTimestamp( beginTime );
344 std::string
key =
"";
356 const std::string&
key,
357 const std::string&
tag,
358 unsigned int beginRun,
360 unsigned int beginLB,
361 unsigned int endLB )
const
364 start.setRunEvent( (
unsigned long)beginRun, (
unsigned long)beginLB );
366 stop.setRunEvent ( (
unsigned long)endRun, (
unsigned long)endLB );
378 const std::string&
key,
379 const std::string&
tag,
384 start.setTimestamp( beginTime );
398 const std::string&
key,
399 const std::string&
folder,
400 const std::string&
tag,
401 unsigned int beginRun,
403 unsigned int beginLB,
404 unsigned int endLB )
const
407 start.setRunEvent( (
unsigned long)beginRun, (
unsigned long)beginLB );
409 stop.setRunEvent ( (
unsigned long)endRun, (
unsigned long)endLB );
422 const std::string&
key,
423 const std::string&
folder,
424 const std::string&
tag,
429 start.setTimestamp( beginTime );
448 const std::string& spec_key,
449 const std::string&
folder,
450 const std::string&
tag,
460 if (spec_key.empty())
466 msg() <<
" spec_key " << spec_key <<
endmsg;
469 <<
" - end time: " <<
stop
474 start.isTimestamp() !=
stop.isTimestamp() ||
475 start.isRunEvent() !=
stop.isRunEvent()) {
477 <<
" isBoth: " <<
start.isBoth() <<
":" <<
stop.isBoth()
478 <<
" isTimestamp: " <<
start.isTimestamp() <<
":" <<
stop.isTimestamp()
479 <<
" isRunEvent: " <<
start.isRunEvent() <<
":" <<
stop.isRunEvent());
480 return( StatusCode::FAILURE);
496 const std::string& spec_key,
498 const std::string&
tag,
512 if (
sc.isFailure()) {
514 return( StatusCode::FAILURE);
532 bool storeRef =
true;
533 bool storeAttrListColl =
false;
534 bool needSGaddr=
false;
535 if (
"AthenaAttributeList" ==
typeName) {
539 if (
"CondAttrListCollection" ==
typeName) {
541 storeAttrListColl =
true;
549 IOpaqueAddress* addr=0;
550 std::string
key = spec_key;
551 std::vector<CLID> symlinks;
559 return( StatusCode::FAILURE);
566 addr =
proxy->address();
571 ATH_MSG_ERROR (
"Could not get proxy for clid " << clid <<
" and key " <<
key);
572 return( StatusCode::FAILURE );
576 addr =
proxy->address();
581 symlinks =
proxy->transientID();
582 auto it =
std::find (symlinks.begin(), symlinks.end(), clid);
583 if (
it != symlinks.end()) {
592 storeAttrListColl =
true;
597 if (
sc.isFailure()) {
598 ATH_MSG_WARNING (
"Could not get string from IOpaqueAddress for clid " << clid
599 <<
" is BAD_STORAGE_TYPE: " << (
sc == IConversionSvc::Status::BAD_STORAGE_TYPE));
600 return( StatusCode::FAILURE);
609 return( StatusCode::FAILURE );
613 if (
"AthenaAttributeList" ==
typeName) {
614 saddr=
"<address_header service_type=\"256\" clid=\"40774348\" /> POOLContainer_AthenaAttributeList][CLID=x";
615 }
else if (
"CondAttrListCollection" ==
typeName) {
616 saddr=
"<address_header service_type=\"256\" clid=\"1238547719\" /> POOLContainer_CondAttrListCollection][CLID=x";
625 <<
" Storing AttrListCollection: " << storeAttrListColl);
630 std::string local_folder;
639 cool::IDatabasePtr
db =
m_iov_db->getDatabase(
false);
642 return(StatusCode::FAILURE);
645 const cool::DatabaseId& dbid=
db->databaseId();
647 bool dbidprod=(dbid.find(
"oracle")!=std::string::npos && (
648 dbid.find(
"ATLAS_COOLONL_")!=std::string::npos ||
649 dbid.find(
"ATLAS_COOLOFL_")!=std::string::npos ||
650 dbid.find(
"ATLAS_COOL_")!=std::string::npos));
652 bool dbidwriter=(dbid.find(
"oracle")!=std::string::npos &&
653 dbid.find(
"_W")!=std::string::npos);
654 ATH_MSG_DEBUG (
"Identified prod/writer " << dbidprod << dbidwriter);
657 ATH_MSG_FATAL (
"Direct update of production Oracle servers from Athena is FORBIDDEN");
658 ATH_MSG_FATAL (
"Please write to SQLite file and then merge with AtlCoolMerge.py");
659 return StatusCode::FAILURE;
667 if (
"CondAttrListCollection"==
typeName) {
672 return StatusCode::FAILURE;
674 }
else if (storeAttrListColl) {
683 << addr <<
" " << attrAddr <<
" " << attrListColl);
685 ATH_MSG_ERROR (
"Could not extract ptr for CondAttrListCollAddress ");
686 return StatusCode::FAILURE;
689 ATH_MSG_ERROR (
"Cannot write out collection of POOLref without streaming them first" );
690 return StatusCode::FAILURE;
694 if (StatusCode::SUCCESS!=
m_detStore->retrieve(attrList,
key)) {
697 return StatusCode::FAILURE;
712 bool createFolders =
false;
714 if(
db->existsFolder(local_folder)) {
718 if (dbidprod || dbidwriter) {
719 ATH_MSG_FATAL (
"Apparent attempt to delete folder on production COOL schema " << dbid);
720 return StatusCode::FAILURE;
723 ATH_MSG_DEBUG (
" Deleting existing COOL Folder " << local_folder);
724 db->dropNode( local_folder );
725 createFolders =
true;
730 folder =
db->getFolder(local_folder);
736 <<
" does not exist - must create it");
737 createFolders =
true;
741 std::string address_header;
742 std::string address_data;
745 if (
sc.isFailure()) {
747 <<
"addr: " << saddr <<
"\n"
748 <<
"hdr: " << address_header <<
"\n"
749 <<
"data " << address_data);
750 return( StatusCode::FAILURE);
753 <<
" hdr: " << address_header <<
endmsg
754 <<
" data: " << address_data <<
endmsg;
760 ATH_MSG_FATAL (
"Apparent attempt to create folder using writer account, dbID is: " << dbid);
761 return StatusCode::FAILURE;
780 std::string mergedNames;
784 if (
sc.isFailure()) {
785 ATH_MSG_ERROR (
"Could not merge towards merged description: "
787 return( StatusCode::FAILURE);
792 if (
sc.isFailure()) {
793 ATH_MSG_ERROR (
"Could not merge towards merged description: "
794 <<
"addrHeader: " << address_header);
795 return( StatusCode::FAILURE);
805 if (
sc.isFailure()) {
806 ATH_MSG_ERROR (
"Could not merge towards merged description: "
808 return( StatusCode::FAILURE);
813 if (!symlinks.empty()) {
814 std::string symlinkTypes;
815 for (
unsigned int i = 0;
i < symlinks.size(); ++
i) {
818 if (
sc.isFailure()) {
821 return( StatusCode::FAILURE);
825 << symlinks[
i] <<
" " <<
type);
827 if (symlinkTypes.size()) symlinkTypes +=
':';
828 symlinkTypes +=
type;
831 if (
sc.isFailure()) {
832 msg() << MSG::ERROR <<
"Could not merge symlinks to merged description: "
833 <<
"symlink types: ";
834 for (
unsigned int i = 0;
i < symlinkTypes.size(); ++
i) {
835 msg() << MSG::ERROR << symlinkTypes[
i] <<
" ";
838 return( StatusCode::FAILURE);
842 << symlinkTypes <<
" " << mergedNames);
849 if (!
start.isValid() ||
851 start.isTimestamp() !=
stop.isTimestamp() ||
852 start.isRunEvent() !=
stop.isRunEvent()) {
853 ATH_MSG_ERROR (
"Invalid times: start isValid/isTimeStamp/isRunEvent "
854 <<
"addrHeader: " << address_header
855 <<
start.isValid() <<
" " <<
start.isTimestamp() <<
" "
856 <<
start.isRunEvent());
857 ATH_MSG_ERROR (
"Invalid times: stop isValid/isTimeStamp/isRunEvent "
858 <<
"addrHeader: " << address_header
859 <<
stop.isValid() <<
" " <<
stop.isTimestamp() <<
" "
860 <<
stop.isRunEvent());
861 return( StatusCode::FAILURE);
863 bool isTimeStamp =
false;
864 if (
start.isTimestamp()) isTimeStamp =
true;
876 if (
sc.isFailure()) {
877 ATH_MSG_ERROR (
"Could not merge timeStamp flag towards merged description. ");
878 return( StatusCode::FAILURE);
881 if (storeAttrListColl && attrListColl!=0 &&
882 attrListColl->
name_size()>0) mergedNames+=
"<named/>";
885 <<
" with description " << mergedNames);
891 cool::RecordSpecification payloadSpec;
896 payloadSpec.extend(
"PoolRef",cool::StorageType::String4k);
901 if (storeAttrListColl) {
905 if (0 == attrListColl) {
907 return( StatusCode::FAILURE);
910 if (0 == attrListColl->
size()) {
912 return( StatusCode::FAILURE);
916 attrListColl->
size());
926 for (coral::AttributeList::const_iterator itr=
927 atr4spec->begin();itr!=atr4spec->end();++itr) {
930 payloadSpec.extend(itr->specification().name(),
932 itr->specification().typeName()));
937 cool::FolderVersioning::MULTI_VERSION;
939 version=cool::FolderVersioning::SINGLE_VERSION;
946 cool::FolderSpecification
folderSpec(
version,payloadSpec,cool::PayloadMode::SEPARATEPAYLOAD);
950 local_folder <<
" done");
953 if (storeAttrListColl && attrListColl!=0 &&
956 " channels in " << local_folder);
959 nitr!=attrListColl->
name_end();++nitr) {
960 folder->createChannel(nitr->first,nitr->second);
967 if (storeAttrListColl) {
969 <<
start <<
" " <<
stop <<
" Note: will be ignored for channels with differnt IOVs " );
976 cool::ValidityKey ivStart =
start.re_time();
977 cool::ValidityKey ivStop =
stop.re_time();
978 if(
start.isTimestamp()) {
979 ivStart =
start.timestamp();
980 ivStop =
stop.timestamp();
985 const cool::RecordSpecification& rspec=
folder->payloadSpecification();
987 if (storeAttrListColl) {
997 ATH_MSG_ERROR (
"Trying to store a ref for a CondAttrListCollection. ");
998 return( StatusCode::FAILURE);
1002 <<
", " <<
tag <<
" )");
1016 cool::ValidityKey ivStart1 = ivStart;
1017 cool::ValidityKey ivStop1 = ivStop;
1019 std::ostringstream attr;
1020 payload.toOutputStream( attr );
1024 if(
range.start().isTimestamp()) {
1025 ivStart1 =
range.start().timestamp();
1026 ivStop1 =
range.stop().timestamp();
1029 ivStart1 =
range.start().re_time();
1030 ivStop1 =
range.stop().re_time();
1033 <<
range.start() <<
" " <<
range.stop() <<
" ");
1041 cool::Record record(rspec,
payload);
1044 folder->storeObject( ivStart1,
1049 folder->storeObject( ivStart1,
1058 cool::Record record(rspec);
1061 record[
"PoolRef"].setValue<std::string>(address_data);
1065 record=cool::Record(rspec,*attrList);
1071 folder->storeObject( ivStart,
1075 folder->storeObject( ivStart,
1081 <<
", " <<
tag <<
" )");
1090 ATH_MSG_DEBUG (
" tag is empty - folder is not being tagged ");
1093 ATH_MSG_INFO (
" Tagging HEAD of folder " << local_folder <<
1094 " with tag " <<
tag);
1098 catch ( cool::TagExists&
e) {
1100 " exists - attempt to delete tag and retag HEAD");
1105 ATH_MSG_ERROR (
"Tag is defined in another folder - tag names must be global");
1106 }
else if (
folder->existsUserTag(
tag)) {
1110 " is already USER tag - cannot mix tagging modes");
1117 catch ( cool::TagNotFound&
e) {
1124 return StatusCode::SUCCESS;
1131 return StatusCode::FAILURE;
1138 const std::string&
parname,
const std::string& coralName)
const {
1140 std::string coralType=coralName;
1145 ATH_MSG_INFO (
"Override default type for attribute " <<
1146 parname <<
" - use " << coralType);
1152 if (coralType==
"bool")
return cool::StorageType::Bool;
1153 if (coralType==
"UChar" || coralType==
"unsigned char")
return cool::StorageType::UChar;
1154 if (coralType==
"Int16")
return cool::StorageType::Int16;
1155 if (coralType==
"UInt16")
return cool::StorageType::UInt16;
1156 if (coralType==
"Int32" || coralType==
"int")
return cool::StorageType::Int32;
1157 if (coralType==
"UInt32" || coralType==
"unsigned int")
return cool::StorageType::UInt32;
1158 if (coralType==
"UInt63" || coralType==
"unsigned long long")
return cool::StorageType::UInt63;
1159 if (coralType==
"Int64" || coralType==
"long long")
return cool::StorageType::Int64;
1160 if (coralType==
"Float" || coralType==
"float")
return cool::StorageType::Float;
1161 if (coralType==
"Double" || coralType==
"double")
return cool::StorageType::Double;
1162 if (coralType==
"String255")
return cool::StorageType::String255;
1163 if (coralType==
"String4k" || coralType==
"string")
return cool::StorageType::String4k;
1164 if (coralType==
"String64k")
return cool::StorageType::String64k;
1165 if (coralType==
"String16M")
return cool::StorageType::String16M;
1166 if (coralType==
"blob" || coralType==
"Blob64k")
1167 return cool::StorageType::Blob64k;
1168 if (coralType==
"Blob16M")
return cool::StorageType::Blob16M;
1171 ATH_MSG_FATAL (
"No COOL mapping defined for CORAL type " << coralName);
1185 return static_cast<uint64_t>(timesec)*1000000000;
1190 const std::string&
value,
1196 return StatusCode::FAILURE;
1199 return StatusCode::SUCCESS;
1203 std::string& address_header,
1204 std::string& address_data )
const {
1210 std::string::size_type p1=
address.find(
" />");
1211 if (p1!=std::string::npos) {
1212 address_header=
address.substr(0,p1+3);
1213 address_data=
address.substr(p1+4);
1214 return StatusCode::SUCCESS;
1216 return StatusCode::FAILURE;