892 std::cout <<
"Copying tag " << sourcetag <<
" of folder " <<
folder <<
893 " to destination tag " << desttag << std::endl;
897 int updatemode=getUpdateMode(destfl->description(),desttag);
898 std::vector<std::string> dtaglist=destfl->listTags();
901 if (updatemode==1 && m_destdb.find(
"oracle")!=std::string::npos &&
902 (!m_getonline || (!m_truncate && !m_alliov))) {
904 std::cout <<
"Folder is online (UPD1) mode but IGNORING PROTECTION"
907 if(
find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()) {
908 std::cout <<
"Folder is online mode (UPD1) and tag already exist - -getonline and -truncate or -alliov options MUST be used" << std::endl;
912 std::cout <<
"Folder is online mode (UPD1), new tag will be created" << std::endl;
918 if (updatemode==4 && m_destdb.find(
"oracle")!=std::string::npos &&
919 (!m_getbulk || (!m_truncate && !m_alliov))) {
921 std::cout <<
"Folder is bulkreco (UPD4) mode but IGNORING PROTECTION"
924 if(
find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()) {
925 std::cout <<
"Folder is bulkreco mode (UPD4) - -getbulk and -truncate or -alliov options MUST be used" << std::endl;
928 std::cout <<
"Folder is bulkreco mode (UPD4), new tag will be created" << std::endl;
937 if (m_checkdesttag) {
938 if (
find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()
939 || (desttag==
"HEAD" && !created)) {
940 std::cout <<
"Destination tag " << desttag <<
941 " already exists in folder " <<
folder <<
" - skip copy" << std::endl;
947 if ((m_applock || (updatemode==1 && m_getonline) || updatemode==2 ||
948 (updatemode==4 && m_getbulk)) &&
949 dvermode==cool::FolderVersioning::MULTI_VERSION) {
951 std::vector<std::string> dtaglist=destfl->listTags();
952 for (std::vector<std::string>::const_iterator itr=dtaglist.begin();
953 itr!=dtaglist.end();++itr) {
958 if (destfl->tagLockStatus(desttag)==cool::HvsTagLock::LOCKED) {
959 std::cout <<
"Unlocking destination tag " << desttag <<
960 " for append or UPDx access" << std::endl;
962 std::cout <<
"Appending according to SV folder rules" << std::endl;
965 "ERROR: Only allowed for UPD3 mode tags" << std::endl;
969 destfl->setTagLockStatus(desttag,cool::HvsTagLock::UNLOCKED);
981 if (dvermode==cool::FolderVersioning::MULTI_VERSION &&
982 desttag!=
"HEAD" && m_usertags)
localtag=desttag;
987 sourceflc->setPrefetchAll(
false);
989 if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
990 sourceitr=sourceflc->browseObjects(
since,
until,m_chansel);
992 sourceitr=sourceflc->browseObjects(
since,
until,m_chansel,sourcetag);
995 std::map<int,int> insertkeymap;
997 while (sourceitr->hasNext()) {
1001 (
obj->since()<m_srunemin ||
obj->until()>m_srunemax)) {
1006 if (!m_excludechans.empty()) {
1007 if (
find(m_excludechans.begin(),m_excludechans.end(),
1008 obj->channelId())!=m_excludechans.end()) {
1014 if (m_debug) std::cout <<
1015 "Setup new CoraCool storage buffer at object " << nobj << std::endl;
1016 destflc->setupStorageBuffer();
1018 cool::ValidityKey newsince,newuntil;
1022 if (newsince>=newuntil) {
1023 std::cout <<
"WARNING: Skipping IOV with since " << newsince <<
1024 ">= until" << newuntil << std::endl;
1031 std::map<int,int>::const_iterator ikey=insertkeymap.end();
1032 bool foundkey=
false;
1035 if (
obj->size()>0) {
1036 oldfk=sourceflc->getAttrKey(
1037 (*
obj->begin())[sourceflc->coralFKey()]);
1038 ikey=insertkeymap.find(oldfk);
1041 if (ikey==insertkeymap.end()) {
1043 destflc->storeObject(newsince,newuntil,
obj->begin(),
obj->end(),
1045 (!m_userupdatehead && !
localtag.empty()));
1046 if (foundkey) insertkeymap[oldfk]=newfk;
1048 destflc->referenceObject(newsince,newuntil,ikey->second,
1050 (!m_userupdatehead && !
localtag.empty()));
1055 if (nbuf==m_bufsize) {
1056 if (m_debug) std::cout <<
"Flush buffer after " << nobj <<
"," <<
1057 nbuf <<
" objects " << std::endl;
1059 destflc->flushStorageBuffer();
1060 destflc->setupStorageBuffer();
1066 if (nref>0) std::cout <<
"Reference-to-existing used for " << nref
1067 <<
" payload objects" << std::endl;
1069 if (m_debug) std::cout <<
"Final buffer flush at " << nobj <<
1070 "," << nbuf << std::endl;
1071 destflc->flushStorageBuffer();
1075 cool::IObjectIteratorPtr sourceitr;
1076 if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
1077 sourceitr=sourcefl->browseObjects(
since,
until,m_chansel);
1079 sourceitr=sourcefl->browseObjects(
since,
until,m_chansel,sourcetag);
1081 while (sourceitr->goToNext()) {
1082 const cool::IObject&
obj=sourceitr->currentRef();
1084 if (m_skipout && (
obj.since()<m_srunemin ||
obj.until()>m_srunemax)) {
1089 if (!m_excludechans.empty()) {
1090 if (
find(m_excludechans.begin(),m_excludechans.end(),
1091 obj.channelId())!=m_excludechans.end()) {
1097 if (m_debug) std::cout <<
"Setup new storage buffer at object " <<
1099 destfl->setupStorageBuffer();
1101 cool::ValidityKey newsince;
1102 cool::ValidityKey newuntil;
1106 if (newsince>=newuntil) {
1107 std::cout <<
"WARNING: Skipping IOV with since " << newsince <<
1108 ">= until" << newuntil << std::endl;
1112 if (checkrefs) checkRef(
obj.payload(),
folder,sourcetag);
1118 if (newuntil!=cool::ValidityKeyMax) {
1119 std::cout <<
"New IOVs must have until=cool::ValidityKeyMax" << std::endl;
1120 throw cool::Exception(
"Illegal insert over locked IOV",
1123 cool::IObjectIteratorPtr checkitr=destfl->browseObjects(newsince,
1124 newuntil,
obj.channelId(),desttag);
1125 while (checkitr->goToNext()) {
1126 const cool::IObject& checkobj=checkitr->currentRef();
1127 if (checkobj.since()>=newsince) {
1128 std::cout <<
"ERROR:: Attempt to insert SV overlapping IOV whilst appending to locked tag" << std::endl;
1129 throw cool::Exception(
"Illegal insert over locked IOV",
1132 if (checkobj.until()!=cool::ValidityKeyMax) {
1133 std::cout <<
"Existing IOVs must have until=cool::ValidityKeyMax" << std::endl;
1134 throw cool::Exception(
"Illegal insert over locked IOV",
1139 }
else if (m_applock) {
1141 const unsigned int nexist=
1142 destfl->countObjects(newsince,newuntil,
obj.channelId(),desttag);
1144 std::cout <<
"ERROR: Attempt to insert IOV over " << nexist <<
1145 " objects whilst appending to locked tag" << std::endl;
1146 throw cool::Exception(
"Illegal insert over locked IOV",
1149 }
else if (updatemode==2) {
1153 throw cool::Exception(
1154 "Attempt to insert into locked UPD2 tag with timestamp format",
1156 unsigned int run1=newsince >> 32;
1157 unsigned int run2=(newuntil-1) >> 32;
1158 for (
unsigned int irun=
run1;irun<=
run2;++irun) {
1159 if (!std::binary_search(m_runlist.begin(),m_runlist.end(),irun))
1161 std::cout <<
"Run " << irun <<
" from range [" <<
run1 <<
","
1162 <<
run2 <<
"] not found in runfile list" << std::endl;
1163 throw cool::Exception(
"Illegal insert over locked IOV",
1170 if (paymode==cool::PayloadMode::VECTORPAYLOAD) {
1172 cool::IRecordIterator& pitr=
obj.payloadIterator();
1173 const cool::IRecordVectorPtr vptr=pitr.fetchAllAsVector();
1174 destfl->storeObject(newsince,newuntil,
1176 (!m_userupdatehead && !
localtag.empty()));
1181 destfl->storeObject(newsince,newuntil,
1183 (!m_userupdatehead && !
localtag.empty()));
1187 if (nbuf>=m_bufsize) {
1188 if (m_debug) std::cout <<
"Flush buffer after " << nobj <<
"," <<
1189 nbuf <<
" objects " << std::endl;
1190 destfl->flushStorageBuffer();
1198 if (m_debug) std::cout <<
"Final buffer flush at " << nobj <<
1199 "," << nbuf << std::endl;
1200 destfl->flushStorageBuffer();
1203 std::cout <<
"Folder copied with " << nobj <<
" objects" << std::endl;
1205 " objects were skipped extending outside IOV selection or excluded channel"
1207 if (nbad>0) std::cout << nbad <<
1208 " objects were skipped having zero or negative IOV lengths" << std::endl;
1211 catch (cool::Exception&
e) {
1212 std::cout <<
"Exception thrown from copy loop: " <<
e.what() <<
1215 std::cout <<
"Relocking destination tag " << desttag << std::endl;
1216 destfl->setTagLockStatus(desttag,cool::HvsTagLock::LOCKED);
1222 std::cout <<
"Relocking destination tag " << desttag << std::endl;
1223 destfl->setTagLockStatus(desttag,cool::HvsTagLock::LOCKED);
1226 if (dvermode==cool::FolderVersioning::MULTI_VERSION && desttag!=
"HEAD") {
1229 std::cout <<
"Tag folder with HEAD-style tagging for tag: " << desttag
1232 destfl->tagCurrentHead(desttag,sourcefl->tagDescription(sourcetag));
1234 catch (cool::Exception&
e) {
1235 std::cout <<
"Exception thrown in HEAD-style folder-tag: " <<
1236 e.what() << std::endl;
1241 if (m_copytaginfo) m_cooltagmap.insert(
1243 destfolder,sourcetag,desttag,m_taglabel)));
1245 if (!m_hitagmap.empty()) {
1246 for (HiTagMap::const_iterator imap=m_hitagmap.begin();
1247 imap!=m_hitagmap.end();++imap) {
1249 if (sourcefl->findTagRelation(imap->first)==sourcetag) {
1250 std::cout <<
"Create hierarchical tag between " << desttag <<
1251 " and " << imap->first <<
" in folder " << imap->second <<
1255 std::string etag=destfl->resolveTag(imap->first);
1256 if (etag==desttag) {
1257 std::cout <<
"This relation has already been created" << std::endl;
1259 std::cout <<
"ERROR: Tag in parent already related to " <<
1260 desttag << std::endl;
1263 catch (cool::Exception&
e ) {
1266 destfl->createTagRelation(imap->first,desttag);
1269 if (
find(m_hiparent.begin(),m_hiparent.end(),imap->second)==
1270 m_hiparent.end()) m_hiparent.push_back(imap->second);
1273 if (m_copytaginfo &&
1274 m_cooltagmap.find(imap->first)==m_cooltagmap.end())
1275 m_cooltagmap.insert(CoolTagMap::value_type(imap->first,
1276 CoolTagInfo(m_sourceDbPtr,imap->second,imap->second,
1277 imap->first,imap->first)));
1279 catch (cool::Exception&
e) {
1280 std::cout <<
"Cool exception " <<
e.what() <<
1281 "thrown in hierarchical tag creation" << std::endl;
1287 catch (cool::Exception&
e) {