887 std::cout <<
"Copying tag " << sourcetag <<
" of folder " <<
folder <<
888 " to destination tag " << desttag << std::endl;
892 int updatemode=getUpdateMode(destfl->description(),desttag);
893 std::vector<std::string> dtaglist=destfl->listTags();
896 if (updatemode==1 && m_destdb.find(
"oracle")!=std::string::npos &&
897 (!m_getonline || (!m_truncate && !m_alliov))) {
899 std::cout <<
"Folder is online (UPD1) mode but IGNORING PROTECTION"
902 if(
find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()) {
903 std::cout <<
"Folder is online mode (UPD1) and tag already exist - -getonline and -truncate or -alliov options MUST be used" << std::endl;
907 std::cout <<
"Folder is online mode (UPD1), new tag will be created" << std::endl;
913 if (updatemode==4 && m_destdb.find(
"oracle")!=std::string::npos &&
914 (!m_getbulk || (!m_truncate && !m_alliov))) {
916 std::cout <<
"Folder is bulkreco (UPD4) mode but IGNORING PROTECTION"
919 if(
find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()) {
920 std::cout <<
"Folder is bulkreco mode (UPD4) - -getbulk and -truncate or -alliov options MUST be used" << std::endl;
923 std::cout <<
"Folder is bulkreco mode (UPD4), new tag will be created" << std::endl;
932 if (m_checkdesttag) {
933 if (
find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()
934 || (desttag==
"HEAD" && !created)) {
935 std::cout <<
"Destination tag " << desttag <<
936 " already exists in folder " <<
folder <<
" - skip copy" << std::endl;
942 if ((m_applock || (updatemode==1 && m_getonline) || updatemode==2 ||
943 (updatemode==4 && m_getbulk)) &&
944 dvermode==cool::FolderVersioning::MULTI_VERSION) {
946 std::vector<std::string> dtaglist=destfl->listTags();
947 for (std::vector<std::string>::const_iterator itr=dtaglist.begin();
948 itr!=dtaglist.end();++itr) {
953 if (destfl->tagLockStatus(desttag)==cool::HvsTagLock::LOCKED) {
954 std::cout <<
"Unlocking destination tag " << desttag <<
955 " for append or UPDx access" << std::endl;
957 std::cout <<
"Appending according to SV folder rules" << std::endl;
960 "ERROR: Only allowed for UPD3 mode tags" << std::endl;
964 destfl->setTagLockStatus(desttag,cool::HvsTagLock::UNLOCKED);
976 if (dvermode==cool::FolderVersioning::MULTI_VERSION &&
977 desttag!=
"HEAD" && m_usertags)
localtag=desttag;
982 sourceflc->setPrefetchAll(
false);
984 if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
985 sourceitr=sourceflc->browseObjects(
since,
until,m_chansel);
987 sourceitr=sourceflc->browseObjects(
since,
until,m_chansel,sourcetag);
990 std::map<int,int> insertkeymap;
992 while (sourceitr->hasNext()) {
996 (
obj->since()<m_srunemin ||
obj->until()>m_srunemax)) {
1001 if (!m_excludechans.empty()) {
1002 if (
find(m_excludechans.begin(),m_excludechans.end(),
1003 obj->channelId())!=m_excludechans.end()) {
1009 if (m_debug) std::cout <<
1010 "Setup new CoraCool storage buffer at object " << nobj << std::endl;
1011 destflc->setupStorageBuffer();
1013 cool::ValidityKey newsince,newuntil;
1017 if (newsince>=newuntil) {
1018 std::cout <<
"WARNING: Skipping IOV with since " << newsince <<
1019 ">= until" << newuntil << std::endl;
1026 std::map<int,int>::const_iterator ikey=insertkeymap.end();
1027 bool foundkey=
false;
1030 if (
obj->size()>0) {
1031 oldfk=sourceflc->getAttrKey(
1032 (*
obj->begin())[sourceflc->coralFKey()]);
1033 ikey=insertkeymap.find(oldfk);
1036 if (ikey==insertkeymap.end()) {
1038 destflc->storeObject(newsince,newuntil,
obj->begin(),
obj->end(),
1040 (!m_userupdatehead && !
localtag.empty()));
1041 if (foundkey) insertkeymap[oldfk]=newfk;
1043 destflc->referenceObject(newsince,newuntil,ikey->second,
1045 (!m_userupdatehead && !
localtag.empty()));
1050 if (nbuf==m_bufsize) {
1051 if (m_debug) std::cout <<
"Flush buffer after " << nobj <<
"," <<
1052 nbuf <<
" objects " << std::endl;
1054 destflc->flushStorageBuffer();
1055 destflc->setupStorageBuffer();
1061 if (nref>0) std::cout <<
"Reference-to-existing used for " << nref
1062 <<
" payload objects" << std::endl;
1064 if (m_debug) std::cout <<
"Final buffer flush at " << nobj <<
1065 "," << nbuf << std::endl;
1066 destflc->flushStorageBuffer();
1070 cool::IObjectIteratorPtr sourceitr;
1071 if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
1072 sourceitr=sourcefl->browseObjects(
since,
until,m_chansel);
1074 sourceitr=sourcefl->browseObjects(
since,
until,m_chansel,sourcetag);
1076 while (sourceitr->goToNext()) {
1077 const cool::IObject&
obj=sourceitr->currentRef();
1079 if (m_skipout && (
obj.since()<m_srunemin ||
obj.until()>m_srunemax)) {
1084 if (!m_excludechans.empty()) {
1085 if (
find(m_excludechans.begin(),m_excludechans.end(),
1086 obj.channelId())!=m_excludechans.end()) {
1092 if (m_debug) std::cout <<
"Setup new storage buffer at object " <<
1094 destfl->setupStorageBuffer();
1096 cool::ValidityKey newsince;
1097 cool::ValidityKey newuntil;
1101 if (newsince>=newuntil) {
1102 std::cout <<
"WARNING: Skipping IOV with since " << newsince <<
1103 ">= until" << newuntil << std::endl;
1107 if (checkrefs) checkRef(
obj.payload(),
folder,sourcetag);
1113 if (newuntil!=cool::ValidityKeyMax) {
1114 std::cout <<
"New IOVs must have until=cool::ValidityKeyMax" << std::endl;
1115 throw cool::Exception(
"Illegal insert over locked IOV",
1118 cool::IObjectIteratorPtr checkitr=destfl->browseObjects(newsince,
1119 newuntil,
obj.channelId(),desttag);
1120 while (checkitr->goToNext()) {
1121 const cool::IObject& checkobj=checkitr->currentRef();
1122 if (checkobj.since()>=newsince) {
1123 std::cout <<
"ERROR:: Attempt to insert SV overlapping IOV whilst appending to locked tag" << std::endl;
1124 throw cool::Exception(
"Illegal insert over locked IOV",
1127 if (checkobj.until()!=cool::ValidityKeyMax) {
1128 std::cout <<
"Existing IOVs must have until=cool::ValidityKeyMax" << std::endl;
1129 throw cool::Exception(
"Illegal insert over locked IOV",
1134 }
else if (m_applock) {
1136 const unsigned int nexist=
1137 destfl->countObjects(newsince,newuntil,
obj.channelId(),desttag);
1139 std::cout <<
"ERROR: Attempt to insert IOV over " << nexist <<
1140 " objects whilst appending to locked tag" << std::endl;
1141 throw cool::Exception(
"Illegal insert over locked IOV",
1144 }
else if (updatemode==2) {
1148 throw cool::Exception(
1149 "Attempt to insert into locked UPD2 tag with timestamp format",
1151 unsigned int run1=newsince >> 32;
1152 unsigned int run2=(newuntil-1) >> 32;
1153 for (
unsigned int irun=
run1;irun<=
run2;++irun) {
1154 if (!std::binary_search(m_runlist.begin(),m_runlist.end(),irun))
1156 std::cout <<
"Run " << irun <<
" from range [" <<
run1 <<
","
1157 <<
run2 <<
"] not found in runfile list" << std::endl;
1158 throw cool::Exception(
"Illegal insert over locked IOV",
1165 if (paymode==cool::PayloadMode::VECTORPAYLOAD) {
1167 cool::IRecordIterator& pitr=
obj.payloadIterator();
1168 const cool::IRecordVectorPtr vptr=pitr.fetchAllAsVector();
1169 destfl->storeObject(newsince,newuntil,
1171 (!m_userupdatehead && !
localtag.empty()));
1176 destfl->storeObject(newsince,newuntil,
1178 (!m_userupdatehead && !
localtag.empty()));
1182 if (nbuf>=m_bufsize) {
1183 if (m_debug) std::cout <<
"Flush buffer after " << nobj <<
"," <<
1184 nbuf <<
" objects " << std::endl;
1185 destfl->flushStorageBuffer();
1193 if (m_debug) std::cout <<
"Final buffer flush at " << nobj <<
1194 "," << nbuf << std::endl;
1195 destfl->flushStorageBuffer();
1198 std::cout <<
"Folder copied with " << nobj <<
" objects" << std::endl;
1200 " objects were skipped extending outside IOV selection or excluded channel"
1202 if (nbad>0) std::cout << nbad <<
1203 " objects were skipped having zero or negative IOV lengths" << std::endl;
1206 catch (cool::Exception&
e) {
1207 std::cout <<
"Exception thrown from copy loop: " <<
e.what() <<
1210 std::cout <<
"Relocking destination tag " << desttag << std::endl;
1211 destfl->setTagLockStatus(desttag,cool::HvsTagLock::LOCKED);
1217 std::cout <<
"Relocking destination tag " << desttag << std::endl;
1218 destfl->setTagLockStatus(desttag,cool::HvsTagLock::LOCKED);
1221 if (dvermode==cool::FolderVersioning::MULTI_VERSION && desttag!=
"HEAD") {
1224 std::cout <<
"Tag folder with HEAD-style tagging for tag: " << desttag
1227 destfl->tagCurrentHead(desttag,sourcefl->tagDescription(sourcetag));
1229 catch (cool::Exception&
e) {
1230 std::cout <<
"Exception thrown in HEAD-style folder-tag: " <<
1231 e.what() << std::endl;
1236 if (m_copytaginfo) m_cooltagmap.insert(
1238 destfolder,sourcetag,desttag,m_taglabel)));
1240 if (!m_hitagmap.empty()) {
1241 for (HiTagMap::const_iterator imap=m_hitagmap.begin();
1242 imap!=m_hitagmap.end();++imap) {
1244 if (sourcefl->findTagRelation(imap->first)==sourcetag) {
1245 std::cout <<
"Create hierarchical tag between " << desttag <<
1246 " and " << imap->first <<
" in folder " << imap->second <<
1250 std::string etag=destfl->resolveTag(imap->first);
1251 if (etag==desttag) {
1252 std::cout <<
"This relation has already been created" << std::endl;
1254 std::cout <<
"ERROR: Tag in parent already related to " <<
1255 desttag << std::endl;
1258 catch (cool::Exception&
e ) {
1261 destfl->createTagRelation(imap->first,desttag);
1264 if (
find(m_hiparent.begin(),m_hiparent.end(),imap->second)==
1265 m_hiparent.end()) m_hiparent.push_back(imap->second);
1268 if (m_copytaginfo &&
1269 m_cooltagmap.find(imap->first)==m_cooltagmap.end())
1270 m_cooltagmap.insert(CoolTagMap::value_type(imap->first,
1271 CoolTagInfo(m_sourceDbPtr,imap->second,imap->second,
1272 imap->first,imap->first)));
1274 catch (cool::Exception&
e) {
1275 std::cout <<
"Cool exception " <<
e.what() <<
1276 "thrown in hierarchical tag creation" << std::endl;
1282 catch (cool::Exception&
e) {