27 #include "GaudiKernel/IAddressCreator.h"
28 #include "GaudiKernel/IClassIDSvc.h"
29 #include "GaudiKernel/IConversionSvc.h"
30 #include "GaudiKernel/IOpaqueAddress.h"
31 #include "GaudiKernel/IConverter.h"
41 #include "CoolKernel/IDatabase.h"
42 #include "CoolKernel/IFolder.h"
43 #include "CoolKernel/RecordSpecification.h"
44 #include "CoolKernel/FolderSpecification.h"
45 #include "CoolKernel/Record.h"
54 m_recreateFolders(false),
59 m_beginTime(
IOVTime::MINTIMESTAMP),
63 m_tagDescription(
"Athena IOVRegistrationSvc"),
68 m_payloadTable(false),
69 m_forceGlobalIOV(false),
70 m_iov_db (
"IOVDbSvc",
name ),
71 m_detStore(
"DetectorStore",
name ),
72 m_persSvc (
"EventPersistencySvc",
name ),
73 m_clidSvc (
"ClassIDSvc",
name )
81 declareProperty(
"EndLB",
m_endLB);
84 declareProperty(
"IOVDbTag",
m_tag);
104 return IIOVRegistrationSvc::interfaceID();
114 if (
sc.isFailure() ) {
116 return StatusCode::FAILURE;
123 return StatusCode::FAILURE;
128 if (
sc.isFailure() ) {
130 return StatusCode::FAILURE;
136 if (
sc != StatusCode::SUCCESS ) {
137 ATH_MSG_ERROR (
" Cannot get IAddressCreator interface of the EventPersistencySvc ");
145 if (
sc != StatusCode::SUCCESS ) {
146 ATH_MSG_ERROR (
" Cannot get IClassIDSvc interface of the CLIDSvc " );
170 ATH_MSG_FATAL (
"Inconsistent settings of OverrideNames and OverrideTypes parameters");
171 return StatusCode::FAILURE;
176 return StatusCode::SUCCESS;
184 return StatusCode::SUCCESS;
191 std::string
key =
"";
225 std::string
key =
"";
258 const std::string&
tag )
const
291 const std::string&
tag,
292 unsigned int beginRun,
294 unsigned int beginLB,
295 unsigned int endLB )
const
298 start.setRunEvent( (
unsigned long)beginRun, (
unsigned long)beginLB );
300 stop.setRunEvent ( (
unsigned long)endRun, (
unsigned long)endLB );
301 std::string
key =
"";
313 const std::string&
tag,
318 start.setTimestamp( beginTime );
322 std::string
key =
"";
334 const std::string&
key,
335 const std::string&
tag,
336 unsigned int beginRun,
338 unsigned int beginLB,
339 unsigned int endLB )
const
342 start.setRunEvent( (
unsigned long)beginRun, (
unsigned long)beginLB );
344 stop.setRunEvent ( (
unsigned long)endRun, (
unsigned long)endLB );
356 const std::string&
key,
357 const std::string&
tag,
362 start.setTimestamp( beginTime );
376 const std::string&
key,
377 const std::string&
folder,
378 const std::string&
tag,
379 unsigned int beginRun,
381 unsigned int beginLB,
382 unsigned int endLB )
const
385 start.setRunEvent( (
unsigned long)beginRun, (
unsigned long)beginLB );
387 stop.setRunEvent ( (
unsigned long)endRun, (
unsigned long)endLB );
400 const std::string&
key,
401 const std::string&
folder,
402 const std::string&
tag,
407 start.setTimestamp( beginTime );
426 const std::string& spec_key,
427 const std::string&
folder,
428 const std::string&
tag,
438 if (spec_key.empty())
444 msg() <<
" spec_key " << spec_key <<
endmsg;
447 <<
" - end time: " <<
stop
452 start.isTimestamp() !=
stop.isTimestamp() ||
453 start.isRunEvent() !=
stop.isRunEvent()) {
455 <<
" isBoth: " <<
start.isBoth() <<
":" <<
stop.isBoth()
456 <<
" isTimestamp: " <<
start.isTimestamp() <<
":" <<
stop.isTimestamp()
457 <<
" isRunEvent: " <<
start.isRunEvent() <<
":" <<
stop.isRunEvent());
458 return( StatusCode::FAILURE);
474 const std::string& spec_key,
476 const std::string&
tag,
490 if (
sc.isFailure()) {
492 return( StatusCode::FAILURE);
510 bool storeRef =
true;
511 bool storeAttrListColl =
false;
512 bool needSGaddr=
false;
513 if (
"AthenaAttributeList" ==
typeName) {
517 if (
"CondAttrListCollection" ==
typeName) {
519 storeAttrListColl =
true;
527 IOpaqueAddress* addr=0;
528 std::string
key = spec_key;
529 std::vector<CLID> symlinks;
537 return( StatusCode::FAILURE);
544 addr =
proxy->address();
549 ATH_MSG_ERROR (
"Could not get proxy for clid " << clid <<
" and key " <<
key);
550 return( StatusCode::FAILURE );
554 addr =
proxy->address();
559 symlinks =
proxy->transientID();
560 auto it =
std::find (symlinks.begin(), symlinks.end(), clid);
561 if (
it != symlinks.end()) {
570 storeAttrListColl =
true;
575 if (
sc.isFailure()) {
576 ATH_MSG_WARNING (
"Could not get string from IOpaqueAddress for clid " << clid
577 <<
" is BAD_STORAGE_TYPE: " << (
sc == IConversionSvc::Status::BAD_STORAGE_TYPE));
578 return( StatusCode::FAILURE);
587 return( StatusCode::FAILURE );
591 if (
"AthenaAttributeList" ==
typeName) {
592 saddr=
"<address_header service_type=\"256\" clid=\"40774348\" /> POOLContainer_AthenaAttributeList][CLID=x";
593 }
else if (
"CondAttrListCollection" ==
typeName) {
594 saddr=
"<address_header service_type=\"256\" clid=\"1238547719\" /> POOLContainer_CondAttrListCollection][CLID=x";
603 <<
" Storing AttrListCollection: " << storeAttrListColl);
608 std::string local_folder;
617 cool::IDatabasePtr
db =
m_iov_db->getDatabase(
false);
620 return(StatusCode::FAILURE);
623 const cool::DatabaseId& dbid=
db->databaseId();
625 bool dbidprod=(dbid.find(
"oracle")!=std::string::npos && (
626 dbid.find(
"ATLAS_COOLONL_")!=std::string::npos ||
627 dbid.find(
"ATLAS_COOLOFL_")!=std::string::npos ||
628 dbid.find(
"ATLAS_COOL_")!=std::string::npos));
630 bool dbidwriter=(dbid.find(
"oracle")!=std::string::npos &&
631 dbid.find(
"_W")!=std::string::npos);
632 ATH_MSG_DEBUG (
"Identified prod/writer " << dbidprod << dbidwriter);
635 ATH_MSG_FATAL (
"Direct update of production Oracle servers from Athena is FORBIDDEN");
636 ATH_MSG_FATAL (
"Please write to SQLite file and then merge with AtlCoolMerge.py");
637 return StatusCode::FAILURE;
645 if (
"CondAttrListCollection"==
typeName) {
650 return StatusCode::FAILURE;
652 }
else if (storeAttrListColl) {
661 << addr <<
" " << attrAddr <<
" " << attrListColl);
663 ATH_MSG_ERROR (
"Could not extract ptr for CondAttrListCollAddress ");
664 return StatusCode::FAILURE;
667 ATH_MSG_ERROR (
"Cannot write out collection of POOLref without streaming them first" );
668 return StatusCode::FAILURE;
672 if (StatusCode::SUCCESS!=
m_detStore->retrieve(attrList,
key)) {
675 return StatusCode::FAILURE;
690 bool createFolders =
false;
692 if(
db->existsFolder(local_folder)) {
696 if (dbidprod || dbidwriter) {
697 ATH_MSG_FATAL (
"Apparent attempt to delete folder on production COOL schema " << dbid);
698 return StatusCode::FAILURE;
701 ATH_MSG_DEBUG (
" Deleting existing COOL Folder " << local_folder);
702 db->dropNode( local_folder );
703 createFolders =
true;
708 folder =
db->getFolder(local_folder);
714 <<
" does not exist - must create it");
715 createFolders =
true;
719 std::string address_header;
720 std::string address_data;
723 if (
sc.isFailure()) {
725 <<
"addr: " << saddr <<
"\n"
726 <<
"hdr: " << address_header <<
"\n"
727 <<
"data " << address_data);
728 return( StatusCode::FAILURE);
731 <<
" hdr: " << address_header <<
endmsg
732 <<
" data: " << address_data <<
endmsg;
738 ATH_MSG_FATAL (
"Apparent attempt to create folder using writer account, dbID is: " << dbid);
739 return StatusCode::FAILURE;
758 std::string mergedNames;
762 if (
sc.isFailure()) {
763 ATH_MSG_ERROR (
"Could not merge towards merged description: "
765 return( StatusCode::FAILURE);
770 if (
sc.isFailure()) {
771 ATH_MSG_ERROR (
"Could not merge towards merged description: "
772 <<
"addrHeader: " << address_header);
773 return( StatusCode::FAILURE);
783 if (
sc.isFailure()) {
784 ATH_MSG_ERROR (
"Could not merge towards merged description: "
786 return( StatusCode::FAILURE);
791 if (!symlinks.empty()) {
792 std::string symlinkTypes;
793 for (
unsigned int i = 0;
i < symlinks.size(); ++
i) {
796 if (
sc.isFailure()) {
799 return( StatusCode::FAILURE);
803 << symlinks[
i] <<
" " <<
type);
805 if (symlinkTypes.size()) symlinkTypes +=
':';
806 symlinkTypes +=
type;
809 if (
sc.isFailure()) {
810 msg() << MSG::ERROR <<
"Could not merge symlinks to merged description: "
811 <<
"symlink types: ";
812 for (
unsigned int i = 0;
i < symlinkTypes.size(); ++
i) {
813 msg() << MSG::ERROR << symlinkTypes[
i] <<
" ";
816 return( StatusCode::FAILURE);
820 << symlinkTypes <<
" " << mergedNames);
827 if (!
start.isValid() ||
829 start.isTimestamp() !=
stop.isTimestamp() ||
830 start.isRunEvent() !=
stop.isRunEvent()) {
831 ATH_MSG_ERROR (
"Invalid times: start isValid/isTimeStamp/isRunEvent "
832 <<
"addrHeader: " << address_header
833 <<
start.isValid() <<
" " <<
start.isTimestamp() <<
" "
834 <<
start.isRunEvent());
835 ATH_MSG_ERROR (
"Invalid times: stop isValid/isTimeStamp/isRunEvent "
836 <<
"addrHeader: " << address_header
837 <<
stop.isValid() <<
" " <<
stop.isTimestamp() <<
" "
838 <<
stop.isRunEvent());
839 return( StatusCode::FAILURE);
841 bool isTimeStamp =
false;
842 if (
start.isTimestamp()) isTimeStamp =
true;
854 if (
sc.isFailure()) {
855 ATH_MSG_ERROR (
"Could not merge timeStamp flag towards merged description. ");
856 return( StatusCode::FAILURE);
859 if (storeAttrListColl && attrListColl!=0 &&
860 attrListColl->
name_size()>0) mergedNames+=
"<named/>";
863 <<
" with description " << mergedNames);
869 cool::RecordSpecification payloadSpec;
874 payloadSpec.extend(
"PoolRef",cool::StorageType::String4k);
879 if (storeAttrListColl) {
883 if (0 == attrListColl) {
885 return( StatusCode::FAILURE);
888 if (0 == attrListColl->
size()) {
890 return( StatusCode::FAILURE);
894 attrListColl->
size());
904 for (coral::AttributeList::const_iterator itr=
905 atr4spec->begin();itr!=atr4spec->end();++itr) {
908 payloadSpec.extend(itr->specification().name(),
910 itr->specification().typeName()));
915 cool::FolderVersioning::MULTI_VERSION;
917 version=cool::FolderVersioning::SINGLE_VERSION;
924 cool::FolderSpecification
folderSpec(
version,payloadSpec,cool::PayloadMode::SEPARATEPAYLOAD);
928 local_folder <<
" done");
931 if (storeAttrListColl && attrListColl!=0 &&
934 " channels in " << local_folder);
937 nitr!=attrListColl->
name_end();++nitr) {
938 folder->createChannel(nitr->first,nitr->second);
945 if (storeAttrListColl) {
947 <<
start <<
" " <<
stop <<
" Note: will be ignored for channels with differnt IOVs " );
954 cool::ValidityKey ivStart =
start.re_time();
955 cool::ValidityKey ivStop =
stop.re_time();
956 if(
start.isTimestamp()) {
957 ivStart =
start.timestamp();
958 ivStop =
stop.timestamp();
963 const cool::RecordSpecification& rspec=
folder->payloadSpecification();
965 if (storeAttrListColl) {
975 ATH_MSG_ERROR (
"Trying to store a ref for a CondAttrListCollection. ");
976 return( StatusCode::FAILURE);
980 <<
", " <<
tag <<
" )");
994 cool::ValidityKey ivStart1 = ivStart;
995 cool::ValidityKey ivStop1 = ivStop;
997 std::ostringstream attr;
998 payload.toOutputStream( attr );
1002 if(
range.start().isTimestamp()) {
1003 ivStart1 =
range.start().timestamp();
1004 ivStop1 =
range.stop().timestamp();
1007 ivStart1 =
range.start().re_time();
1008 ivStop1 =
range.stop().re_time();
1011 <<
range.start() <<
" " <<
range.stop() <<
" ");
1019 cool::Record record(rspec,
payload);
1022 folder->storeObject( ivStart1,
1027 folder->storeObject( ivStart1,
1036 cool::Record record(rspec);
1039 record[
"PoolRef"].setValue<std::string>(address_data);
1043 record=cool::Record(rspec,*attrList);
1049 folder->storeObject( ivStart,
1053 folder->storeObject( ivStart,
1059 <<
", " <<
tag <<
" )");
1068 ATH_MSG_DEBUG (
" tag is empty - folder is not being tagged ");
1071 ATH_MSG_INFO (
" Tagging HEAD of folder " << local_folder <<
1072 " with tag " <<
tag);
1076 catch ( cool::TagExists&
e) {
1078 " exists - attempt to delete tag and retag HEAD");
1083 ATH_MSG_ERROR (
"Tag is defined in another folder - tag names must be global");
1084 }
else if (
folder->existsUserTag(
tag)) {
1088 " is already USER tag - cannot mix tagging modes");
1095 catch ( cool::TagNotFound&
e) {
1102 return StatusCode::SUCCESS;
1109 return StatusCode::FAILURE;
1116 const std::string&
parname,
const std::string& coralName)
const {
1118 std::string coralType=coralName;
1123 ATH_MSG_INFO (
"Override default type for attribute " <<
1124 parname <<
" - use " << coralType);
1130 if (coralType==
"bool")
return cool::StorageType::Bool;
1131 if (coralType==
"UChar" || coralType==
"unsigned char")
return cool::StorageType::UChar;
1132 if (coralType==
"Int16")
return cool::StorageType::Int16;
1133 if (coralType==
"UInt16")
return cool::StorageType::UInt16;
1134 if (coralType==
"Int32" || coralType==
"int")
return cool::StorageType::Int32;
1135 if (coralType==
"UInt32" || coralType==
"unsigned int")
return cool::StorageType::UInt32;
1136 if (coralType==
"UInt63" || coralType==
"unsigned long long")
return cool::StorageType::UInt63;
1137 if (coralType==
"Int64" || coralType==
"long long")
return cool::StorageType::Int64;
1138 if (coralType==
"Float" || coralType==
"float")
return cool::StorageType::Float;
1139 if (coralType==
"Double" || coralType==
"double")
return cool::StorageType::Double;
1140 if (coralType==
"String255")
return cool::StorageType::String255;
1141 if (coralType==
"String4k" || coralType==
"string")
return cool::StorageType::String4k;
1142 if (coralType==
"String64k")
return cool::StorageType::String64k;
1143 if (coralType==
"String16M")
return cool::StorageType::String16M;
1144 if (coralType==
"blob" || coralType==
"Blob64k")
1145 return cool::StorageType::Blob64k;
1146 if (coralType==
"Blob16M")
return cool::StorageType::Blob16M;
1149 ATH_MSG_FATAL (
"No COOL mapping defined for CORAL type " << coralName);
1163 return static_cast<uint64_t>(timesec)*1000000000;
1168 const std::string&
value,
1174 return StatusCode::FAILURE;
1177 return StatusCode::SUCCESS;
1181 std::string& address_header,
1182 std::string& address_data )
const {
1188 std::string::size_type
p1=
address.find(
" />");
1189 if (
p1!=std::string::npos) {
1192 return StatusCode::SUCCESS;
1194 return StatusCode::FAILURE;