888 std::cout <<
"Copying tag " << sourcetag <<
" of folder " <<
folder <<
889 " to destination tag " << desttag << std::endl;
893 int updatemode=getUpdateMode(destfl->description(),desttag);
894 std::vector<std::string> dtaglist=destfl->listTags();
897 if (updatemode==1 && m_destdb.find(
"oracle")!=std::string::npos &&
898 (!m_getonline || (!m_truncate && !m_alliov))) {
900 std::cout <<
"Folder is online (UPD1) mode but IGNORING PROTECTION"
903 if(
find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()) {
904 std::cout <<
"Folder is online mode (UPD1) and tag already exist - -getonline and -truncate or -alliov options MUST be used" << std::endl;
908 std::cout <<
"Folder is online mode (UPD1), new tag will be created" << std::endl;
914 if (updatemode==4 && m_destdb.find(
"oracle")!=std::string::npos &&
915 (!m_getbulk || (!m_truncate && !m_alliov))) {
917 std::cout <<
"Folder is bulkreco (UPD4) mode but IGNORING PROTECTION"
920 if(
find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()) {
921 std::cout <<
"Folder is bulkreco mode (UPD4) - -getbulk and -truncate or -alliov options MUST be used" << std::endl;
924 std::cout <<
"Folder is bulkreco mode (UPD4), new tag will be created" << std::endl;
933 if (m_checkdesttag) {
934 if (
find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()
935 || (desttag==
"HEAD" && !created)) {
936 std::cout <<
"Destination tag " << desttag <<
937 " already exists in folder " <<
folder <<
" - skip copy" << std::endl;
943 if ((m_applock || (updatemode==1 && m_getonline) || updatemode==2 ||
944 (updatemode==4 && m_getbulk)) &&
945 dvermode==cool::FolderVersioning::MULTI_VERSION) {
947 std::vector<std::string> dtaglist=destfl->listTags();
948 for (std::vector<std::string>::const_iterator itr=dtaglist.begin();
949 itr!=dtaglist.end();++itr) {
954 if (destfl->tagLockStatus(desttag)==cool::HvsTagLock::LOCKED) {
955 std::cout <<
"Unlocking destination tag " << desttag <<
956 " for append or UPDx access" << std::endl;
958 std::cout <<
"Appending according to SV folder rules" << std::endl;
961 "ERROR: Only allowed for UPD3 mode tags" << std::endl;
965 destfl->setTagLockStatus(desttag,cool::HvsTagLock::UNLOCKED);
977 if (dvermode==cool::FolderVersioning::MULTI_VERSION &&
978 desttag!=
"HEAD" && m_usertags)
localtag=desttag;
983 sourceflc->setPrefetchAll(
false);
985 if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
986 sourceitr=sourceflc->browseObjects(
since,
until,m_chansel);
988 sourceitr=sourceflc->browseObjects(
since,
until,m_chansel,sourcetag);
991 std::map<int,int> insertkeymap;
993 while (sourceitr->hasNext()) {
997 (
obj->since()<m_srunemin ||
obj->until()>m_srunemax)) {
1002 if (!m_excludechans.empty()) {
1003 if (
find(m_excludechans.begin(),m_excludechans.end(),
1004 obj->channelId())!=m_excludechans.end()) {
1010 if (m_debug) std::cout <<
1011 "Setup new CoraCool storage buffer at object " << nobj << std::endl;
1012 destflc->setupStorageBuffer();
1014 cool::ValidityKey newsince,newuntil;
1018 if (newsince>=newuntil) {
1019 std::cout <<
"WARNING: Skipping IOV with since " << newsince <<
1020 ">= until" << newuntil << std::endl;
1027 std::map<int,int>::const_iterator ikey=insertkeymap.end();
1028 bool foundkey=
false;
1031 if (
obj->size()>0) {
1032 oldfk=sourceflc->getAttrKey(
1033 (*
obj->begin())[sourceflc->coralFKey()]);
1034 ikey=insertkeymap.find(oldfk);
1037 if (ikey==insertkeymap.end()) {
1039 destflc->storeObject(newsince,newuntil,
obj->begin(),
obj->end(),
1041 (!m_userupdatehead && !
localtag.empty()));
1042 if (foundkey) insertkeymap[oldfk]=newfk;
1044 destflc->referenceObject(newsince,newuntil,ikey->second,
1046 (!m_userupdatehead && !
localtag.empty()));
1051 if (nbuf==m_bufsize) {
1052 if (m_debug) std::cout <<
"Flush buffer after " << nobj <<
"," <<
1053 nbuf <<
" objects " << std::endl;
1055 destflc->flushStorageBuffer();
1056 destflc->setupStorageBuffer();
1062 if (nref>0) std::cout <<
"Reference-to-existing used for " << nref
1063 <<
" payload objects" << std::endl;
1065 if (m_debug) std::cout <<
"Final buffer flush at " << nobj <<
1066 "," << nbuf << std::endl;
1067 destflc->flushStorageBuffer();
1071 cool::IObjectIteratorPtr sourceitr;
1072 if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
1073 sourceitr=sourcefl->browseObjects(
since,
until,m_chansel);
1075 sourceitr=sourcefl->browseObjects(
since,
until,m_chansel,sourcetag);
1077 while (sourceitr->goToNext()) {
1078 const cool::IObject&
obj=sourceitr->currentRef();
1080 if (m_skipout && (
obj.since()<m_srunemin ||
obj.until()>m_srunemax)) {
1085 if (!m_excludechans.empty()) {
1086 if (
find(m_excludechans.begin(),m_excludechans.end(),
1087 obj.channelId())!=m_excludechans.end()) {
1093 if (m_debug) std::cout <<
"Setup new storage buffer at object " <<
1095 destfl->setupStorageBuffer();
1097 cool::ValidityKey newsince;
1098 cool::ValidityKey newuntil;
1102 if (newsince>=newuntil) {
1103 std::cout <<
"WARNING: Skipping IOV with since " << newsince <<
1104 ">= until" << newuntil << std::endl;
1108 if (checkrefs) checkRef(
obj.payload(),
folder,sourcetag);
1114 if (newuntil!=cool::ValidityKeyMax) {
1115 std::cout <<
"New IOVs must have until=cool::ValidityKeyMax" << std::endl;
1116 throw cool::Exception(
"Illegal insert over locked IOV",
1119 cool::IObjectIteratorPtr checkitr=destfl->browseObjects(newsince,
1120 newuntil,
obj.channelId(),desttag);
1121 while (checkitr->goToNext()) {
1122 const cool::IObject& checkobj=checkitr->currentRef();
1123 if (checkobj.since()>=newsince) {
1124 std::cout <<
"ERROR:: Attempt to insert SV overlapping IOV whilst appending to locked tag" << std::endl;
1125 throw cool::Exception(
"Illegal insert over locked IOV",
1128 if (checkobj.until()!=cool::ValidityKeyMax) {
1129 std::cout <<
"Existing IOVs must have until=cool::ValidityKeyMax" << std::endl;
1130 throw cool::Exception(
"Illegal insert over locked IOV",
1135 }
else if (m_applock) {
1137 const unsigned int nexist=
1138 destfl->countObjects(newsince,newuntil,
obj.channelId(),desttag);
1140 std::cout <<
"ERROR: Attempt to insert IOV over " << nexist <<
1141 " objects whilst appending to locked tag" << std::endl;
1142 throw cool::Exception(
"Illegal insert over locked IOV",
1145 }
else if (updatemode==2) {
1149 throw cool::Exception(
1150 "Attempt to insert into locked UPD2 tag with timestamp format",
1152 unsigned int run1=newsince >> 32;
1153 unsigned int run2=(newuntil-1) >> 32;
1154 for (
unsigned int irun=
run1;irun<=
run2;++irun) {
1155 if (!std::binary_search(m_runlist.begin(),m_runlist.end(),irun))
1157 std::cout <<
"Run " << irun <<
" from range [" <<
run1 <<
","
1158 <<
run2 <<
"] not found in runfile list" << std::endl;
1159 throw cool::Exception(
"Illegal insert over locked IOV",
1166 if (paymode==cool::PayloadMode::VECTORPAYLOAD) {
1168 cool::IRecordIterator& pitr=
obj.payloadIterator();
1169 const cool::IRecordVectorPtr vptr=pitr.fetchAllAsVector();
1170 destfl->storeObject(newsince,newuntil,
1172 (!m_userupdatehead && !
localtag.empty()));
1177 destfl->storeObject(newsince,newuntil,
1179 (!m_userupdatehead && !
localtag.empty()));
1183 if (nbuf>=m_bufsize) {
1184 if (m_debug) std::cout <<
"Flush buffer after " << nobj <<
"," <<
1185 nbuf <<
" objects " << std::endl;
1186 destfl->flushStorageBuffer();
1194 if (m_debug) std::cout <<
"Final buffer flush at " << nobj <<
1195 "," << nbuf << std::endl;
1196 destfl->flushStorageBuffer();
1199 std::cout <<
"Folder copied with " << nobj <<
" objects" << std::endl;
1201 " objects were skipped extending outside IOV selection or excluded channel"
1203 if (nbad>0) std::cout << nbad <<
1204 " objects were skipped having zero or negative IOV lengths" << std::endl;
1207 catch (cool::Exception&
e) {
1208 std::cout <<
"Exception thrown from copy loop: " <<
e.what() <<
1211 std::cout <<
"Relocking destination tag " << desttag << std::endl;
1212 destfl->setTagLockStatus(desttag,cool::HvsTagLock::LOCKED);
1218 std::cout <<
"Relocking destination tag " << desttag << std::endl;
1219 destfl->setTagLockStatus(desttag,cool::HvsTagLock::LOCKED);
1222 if (dvermode==cool::FolderVersioning::MULTI_VERSION && desttag!=
"HEAD") {
1225 std::cout <<
"Tag folder with HEAD-style tagging for tag: " << desttag
1228 destfl->tagCurrentHead(desttag,sourcefl->tagDescription(sourcetag));
1230 catch (cool::Exception&
e) {
1231 std::cout <<
"Exception thrown in HEAD-style folder-tag: " <<
1232 e.what() << std::endl;
1237 if (m_copytaginfo) m_cooltagmap.insert(
1239 destfolder,sourcetag,desttag,m_taglabel)));
1241 if (!m_hitagmap.empty()) {
1242 for (HiTagMap::const_iterator imap=m_hitagmap.begin();
1243 imap!=m_hitagmap.end();++imap) {
1245 if (sourcefl->findTagRelation(imap->first)==sourcetag) {
1246 std::cout <<
"Create hierarchical tag between " << desttag <<
1247 " and " << imap->first <<
" in folder " << imap->second <<
1251 std::string etag=destfl->resolveTag(imap->first);
1252 if (etag==desttag) {
1253 std::cout <<
"This relation has already been created" << std::endl;
1255 std::cout <<
"ERROR: Tag in parent already related to " <<
1256 desttag << std::endl;
1259 catch (cool::Exception&
e ) {
1262 destfl->createTagRelation(imap->first,desttag);
1265 if (
find(m_hiparent.begin(),m_hiparent.end(),imap->second)==
1266 m_hiparent.end()) m_hiparent.push_back(imap->second);
1269 if (m_copytaginfo &&
1270 m_cooltagmap.find(imap->first)==m_cooltagmap.end())
1271 m_cooltagmap.insert(CoolTagMap::value_type(imap->first,
1272 CoolTagInfo(m_sourceDbPtr,imap->second,imap->second,
1273 imap->first,imap->first)));
1275 catch (cool::Exception&
e) {
1276 std::cout <<
"Cool exception " <<
e.what() <<
1277 "thrown in hierarchical tag creation" << std::endl;
1283 catch (cool::Exception&
e) {