441{
442
443
444
445
447
448
449
452 if (
sc.isFailure()) {
453 ATH_MSG_ERROR (
"Could not get clid for typeName " << typeName);
454 return( StatusCode::FAILURE);
455 }
456
457 try {
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472 bool storeRef = true;
473 bool storeAttrListColl = false;
474 bool needSGaddr=false;
475 if ("AthenaAttributeList" == typeName) {
476 storeRef = false;
477 needSGaddr=false;
478 }
479 if ("CondAttrListCollection" == typeName) {
480 storeRef = false;
481 storeAttrListColl = true;
482 needSGaddr=false;
483 }
484
485
486
487
488
489 IOpaqueAddress* addr=0;
490 std::string
key = spec_key;
491 std::vector<CLID> symlinks;
492 SG::DataProxy*
proxy;
494
495
497 if (!proxy) {
499 return( StatusCode::FAILURE);
500 }
501
502
504
505
506 addr =
proxy->address();
507 } else {
508
510 if (!proxy) {
511 ATH_MSG_ERROR (
"Could not get proxy for clid " << clid <<
" and key " << key);
512 return( StatusCode::FAILURE );
513 }
514
515
516 addr =
proxy->address();
517 }
518 std::string saddr;
519 if (addr) {
520
521 symlinks =
proxy->transientID();
522 auto it = std::find (symlinks.begin(), symlinks.end(), clid);
523 if (it != symlinks.end()) {
524 symlinks.erase (it);
525 }
526
527
528
529 CondAttrListCollAddress* collAddr = dynamic_cast<CondAttrListCollAddress*>(addr);
530 if (collAddr) {
531 storeRef = false;
532 storeAttrListColl = true;
533 }
534
535
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);
541 }
543 } else {
544
545
546
547 if (needSGaddr) {
549 return( StatusCode::FAILURE );
550 } else {
552
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";
557 } else {
559 << typeName);
560 }
561 }
562 }
563
565 << " Storing AttrListCollection: " << storeAttrListColl);
566
567
568
569
570 std::string local_folder;
571 if (""==folderName) {
573 } else {
575 }
577
578
579 cool::IDatabasePtr
db =
m_iov_db->getDatabase(
false);
580 if (!db) {
582 return(StatusCode::FAILURE);
583 }
584
585 const cool::DatabaseId& dbid=
db->databaseId();
586
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));
591
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);
595
596 if (dbidprod) {
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;
600 }
601
602
603 const AthenaAttributeList* attrList = 0;
604 const CondAttrListCollection* attrListColl = 0;
605
606 if (!storeRef) {
607 if ("CondAttrListCollection"==typeName) {
611 << key);
612 return StatusCode::FAILURE;
613 }
614 } else if (storeAttrListColl) {
615
616 if (addr) {
617 CondAttrListCollAddress* attrAddr = dynamic_cast<CondAttrListCollAddress*>(addr);
618 if (attrAddr) {
619
623 << addr << " " << attrAddr << " " << attrListColl);
624 } else {
625 ATH_MSG_ERROR (
"Could not extract ptr for CondAttrListCollAddress ");
626 return StatusCode::FAILURE;
627 }
628 } else {
629 ATH_MSG_ERROR (
"Cannot write out collection of POOLref without streaming them first" );
630 return StatusCode::FAILURE;
631 }
632 } else {
633
634 if (StatusCode::SUCCESS!=
m_detStore->retrieve(attrList,key)) {
636 << key);
637 return StatusCode::FAILURE;
638 }
639 }
640
641 }
642
643
645
646
648
649
650
651
652 bool createFolders = false;
653
654 if(
db->existsFolder(local_folder)) {
655
657
658 if (dbidprod || dbidwriter) {
659 ATH_MSG_FATAL (
"Apparent attempt to delete folder on production COOL schema " << dbid);
660 return StatusCode::FAILURE;
661 }
662
663 ATH_MSG_DEBUG (
" Deleting existing COOL Folder " << local_folder);
664 db->dropNode( local_folder );
665 createFolders = true;
666 }
667 else {
668
670 folder =
db->getFolder(local_folder);
671 }
672
673 }
674 else {
676 << " does not exist - must create it");
677 createFolders = true;
678 }
679
680
681 std::string address_header;
682 std::string address_data;
683
685 if (
sc.isFailure()) {
687 << "addr: " << saddr << "\n"
688 << "hdr: " << address_header << "\n"
689 << "data " << address_data);
690 return( StatusCode::FAILURE);
691 }
692 msg() << MSG::DEBUG <<
"split address: " << saddr <<
endmsg
693 <<
" hdr: " << address_header <<
endmsg
694 <<
" data: " << address_data <<
endmsg;
695
696
697 if(createFolders) {
698
699 if (dbidwriter) {
700 ATH_MSG_FATAL (
"Apparent attempt to create folder using writer account, dbID is: " << dbid);
701 return StatusCode::FAILURE;
702 }
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720 std::string mergedNames;
721
723 mergedNames );
724 if (
sc.isFailure()) {
725 ATH_MSG_ERROR (
"Could not merge towards merged description: "
726 << "typeName: " << typeName);
727 return( StatusCode::FAILURE);
728 }
729
731 mergedNames );
732 if (
sc.isFailure()) {
733 ATH_MSG_ERROR (
"Could not merge towards merged description: "
734 << "addrHeader: " << address_header);
735 return( StatusCode::FAILURE);
736 }
737
738
739
740
741
742
745 if (
sc.isFailure()) {
746 ATH_MSG_ERROR (
"Could not merge towards merged description: "
747 << "key: " << key);
748 return( StatusCode::FAILURE);
749 }
750 }
751
752
753 if (!symlinks.empty()) {
754 std::string symlinkTypes;
755 for (
unsigned int i = 0;
i < symlinks.size(); ++
i) {
758 if (
sc.isFailure()) {
760 << symlinks[i]);
761 return( StatusCode::FAILURE);
762 }
763 else {
765 << symlinks[i] <<
" " <<
type);
766 }
767 if (symlinkTypes.size()) symlinkTypes += ':';
768 symlinkTypes +=
type;
769 }
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] <<
" ";
776 }
778 return( StatusCode::FAILURE);
779 }
780 else {
782 << symlinkTypes << " " << mergedNames);
783 }
784 }
785
786
787
788
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);
802 }
803 bool isTimeStamp = false;
804 if (
start.isTimestamp()) isTimeStamp =
true;
805
806 if (isTimeStamp)
807 {
809 mergedNames );
810 }
811 else
812 {
814 mergedNames );
815 }
816 if (
sc.isFailure()) {
817 ATH_MSG_ERROR (
"Could not merge timeStamp flag towards merged description. ");
818 return( StatusCode::FAILURE);
819 }
820
821 if (storeAttrListColl && attrListColl!=0 &&
822 attrListColl->
name_size()>0) mergedNames+=
"<named/>";
823
825 << " with description " << mergedNames);
826
827
828
830
832 if (storeRef) {
833
834
835
836 payloadSpec.extend(
"PoolRef",cool::StorageType::String4k);
837 }
838 else {
839
840 const coral::AttributeList* atr4spec=0;
841 if (storeAttrListColl) {
842
843
844
845 if (0 == attrListColl) {
847 return( StatusCode::FAILURE);
848 }
849
850 if (0 == attrListColl->
size()) {
852 return( StatusCode::FAILURE);
853 }
854
856 attrListColl->
size());
857
858 atr4spec=&((*attrListColl->
begin()).second);
859 } else {
860
861 atr4spec=attrList;
863 }
865
866 for (coral::AttributeList::const_iterator itr=
867 atr4spec->begin();itr!=atr4spec->end();++itr) {
868
869
872 itr->specification().typeName()));
873 }
874 }
875
876 cool::FolderVersioning::Mode
version=
877 cool::FolderVersioning::MULTI_VERSION;
879 version=cool::FolderVersioning::SINGLE_VERSION;
881 << local_folder);
882 }
885 << local_folder);
886 cool::FolderSpecification
folderSpec(version,payloadSpec,cool::PayloadMode::SEPARATEPAYLOAD);
887 folder =
db->createFolder(local_folder,folderSpec,
888 mergedNames,true);
890 local_folder << " done");
891
892
893 if (storeAttrListColl && attrListColl!=0 &&
896 " channels in " << local_folder);
899 nitr!=attrListColl->
name_end();++nitr) {
900 folder->createChannel(nitr->first,nitr->second);
901 }
902 }
903 }
904
905
906
907 if (storeAttrListColl) {
909 << start << " " << stop << " Note: will be ignored for channels with differnt IOVs " );
910 }
911 else {
912 ATH_MSG_DEBUG (
" Start/stop time " << start <<
" " << stop <<
" ");
913 }
914
915
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();
921 }
922
923
924
925 const cool::RecordSpecification& rspec=
folder->payloadSpecification();
926
927 if (storeAttrListColl) {
928
929
930
931
932
933
934
935 if (storeRef) {
936
937 ATH_MSG_ERROR (
"Trying to store a ref for a CondAttrListCollection. ");
938 return( StatusCode::FAILURE);
939 }
940
941 ATH_MSG_DEBUG (
" --> Storing Object( " << start <<
", " << stop
942 << ", " << tag << " )");
944
948
949
950 const coral::AttributeList&
payload = (*first).second;
951
953
954
955
956 cool::ValidityKey ivStart1 = ivStart;
957 cool::ValidityKey ivStop1 = ivStop;
959 std::ostringstream attr;
960 payload.toOutputStream( attr );
961 ATH_MSG_DEBUG (
" --> ChanNum: " << chanNum <<
" Payload: " << attr.str());
963 const IOVRange&
range = (*iovIt).second;
964 if(
range.start().isTimestamp()) {
965 ivStart1 =
range.start().timestamp();
966 ivStop1 =
range.stop().timestamp();
967 }
968 else {
969 ivStart1 =
range.start().re_time();
970 ivStop1 =
range.stop().re_time();
971 }
973 <<
range.start() <<
" " <<
range.stop() <<
" ");
974 }
975 else {
977 << start << " " << stop << " ");
978 }
979
980
981 cool::Record record(rspec,payload);
984 folder->storeObject( ivStart1,
985 ivStop1,
986 record,
988 } else {
989 folder->storeObject( ivStart1,
990 ivStop1,
991 record,
992 chanNum);
993 }
994 }
995 }
996 else {
997
998 cool::Record record(rspec);
999 if (storeRef) {
1000
1001 record["PoolRef"].setValue<std::string>(address_data);
1002 }
1003 else {
1004
1005 record=cool::Record(rspec,*attrList);
1006 }
1007
1008
1011 folder->storeObject( ivStart,
1012 ivStop,
1014 } else {
1015 folder->storeObject( ivStart,
1016 ivStop,
1017 record,0);
1018 }
1019
1020 ATH_MSG_DEBUG (
" --> Stored Object( " << start <<
", " << stop
1021 << ", " << tag << " )");
1023 }
1024
1026
1027
1029 if ("" == tag) {
1030 ATH_MSG_DEBUG (
" tag is empty - folder is not being tagged ");
1031 }
1032 else {
1033 ATH_MSG_INFO (
" Tagging HEAD of folder " << local_folder <<
1034 " with tag " << tag);
1035 try {
1037 }
1038 catch ( cool::TagExists& e) {
1040 " exists - attempt to delete tag and retag HEAD");
1041
1045 ATH_MSG_ERROR (
"Tag is defined in another folder - tag names must be global");
1046 }
else if (
folder->existsUserTag(tag)) {
1047
1048
1050 " is already USER tag - cannot mix tagging modes");
1051 } else {
1052 try {
1056 }
1057 catch ( cool::TagNotFound& e) {
1059 }
1060 }
1061 }
1062 }
1063 }
1064 return StatusCode::SUCCESS;
1065 }
1066
1067 catch (std::exception& e) {
1069
1070
1071 return StatusCode::FAILURE;
1072 }
1073
1074
1075}
#define ATH_MSG_WARNING(x)
uint32_t CLID
The Class ID type.
CondAttrListCollection * attrListColl()
Access to AttributeList.
const_iterator end() const
name_const_iterator name_begin() const
Access to Chan/Name pairs via iterators.
name_size_type name_size() const
number of Chan/Name pairs
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
iov_const_iterator iov_end() const
name_const_iterator name_end() const
size_type size() const
number of Chan/AttributeList pairs
iov_const_iterator chanIOVPair(ChanNum chanNum) const
Access to Chan/IOV pairs via channel number: returns map iterator.
ChanAttrListMap::const_iterator const_iterator
ChanNameMap::const_iterator name_const_iterator
ChanIOVMap::const_iterator iov_const_iterator
Gaudi::Property< bool > m_writeKeyInfo
Gaudi::Property< bool > m_forceGlobalIOV
Gaudi::Property< std::string > m_tagDescription
virtual StatusCode buildDescription(const std::string &identifier, const std::string &value, std::string &description) const
Build the folder description field add in front of the description the value with identifier-markups.
Gaudi::Property< bool > m_userTagsUH
Gaudi::Property< bool > m_userTags
Gaudi::Property< bool > m_payloadTable
Gaudi::Property< bool > m_svFolder
virtual const InterfaceID & type() const
Service type.
cool::StorageType::TypeId coralToCoolType(const std::string &parname, const std::string &coralName) const
StatusCode splitAddress(const std::string &address, std::string &address_header, std::string &address_data) const
Split address in its header and data parts.
std::string find(const std::string &s)
return a remapped string
retrieve(aClass, aKey=None)