Skip to content
Snippets Groups Projects
Commit ef301215 authored by Mikhail Mineev's avatar Mikhail Mineev
Browse files

crestCopy utility rewritten

parent a92636dd
Branches
No related tags found
1 merge request!13Upd16
Pipeline #10363863 passed
......@@ -276,7 +276,7 @@ int main(int argc, char *argv[])
catch (const std::exception &e)
{
std::cerr << std::endl
<< "Cannot write tag:" << std::endl;
<< "Cannot create a new tag \"" << NEW_TAG << ":" << std::endl;
std::cerr << e.what() << std::endl;
}
}
......@@ -293,7 +293,7 @@ int main(int argc, char *argv[])
try
{
TagMetaDto tagMetaInfo = crestSource->findTagMeta(TAG_NAME); // NEW
TagMetaDto tagMetaInfo = crestSource->findTagMeta(TAG_NAME);
TagMetaDto newTagMetaInfo = tagMetaInfo;
newTagMetaInfo.setTagName(NEW_TAG);
......@@ -316,27 +316,29 @@ int main(int argc, char *argv[])
std::cerr << e.what() << std::endl;
}
// This code fragment works when one or more time interval limits are set (i.e. since-until).
// It uses selectIovs(TAG_NAME, SINCE, UNTIL) method.
if (FLAG == 1)
{
std::cout << "ALGORITHM 2 (selectIovs):" << std::endl;
int page_number = 0;
int current_page = 0;
int step = 0;
do
{
IovSetDto dto;
try
{
dto = crestSource->selectIovs(TAG_NAME, SINCE, UNTIL, SNAPSHOT, 10000, 0, "id.since:ASC");
dto = crestSource->selectIovs(TAG_NAME, SINCE, UNTIL, SNAPSHOT, PAGE_SIZE, step, "id.since:ASC");
IovSetDto destDto = copyIovSetDto(dto, NEW_TAG);
std::cout << std::endl
<< " IOV list to be copied into TAG " << NEW_TAG << std::endl
<< destDto.toJson().dump(4) << std::endl;
IovSetDto storedDto = crestSource->storeIovs(destDto);
/*
// IOV list printing:
std::cout << std::endl
<< " IOV list copied into TAG " << NEW_TAG << std::endl
<< storedDto.toJson().dump(4) << std::endl;
*/
}
catch (const std::exception &e)
{
......@@ -345,75 +347,27 @@ int main(int argc, char *argv[])
std::cerr << e.what() << std::endl;
exit(0);
}
}
else // without since/until
{
// This code fragment works when the time interval is not set (i.e. since-until).
// It uses findAllIovs method.
// IOVs
nlohmann::json iovList;
auto rpage = dto.getRespPage();
if (rpage)
{
// IOV number:
page_number = rpage -> getTotalPages();
current_page = rpage -> getNumber();
step = current_page + 1;
int iovSize = 0;
try
{
iovSize = crestSource->getSize(TAG_NAME);
std::cout << std::endl
<< " IOV Number for TAG \"" << TAG_NAME << "\" = " << iovSize << std::endl;
std::cout << "total page number = " << page_number << std::endl;
std::cout << "current page number = " << current_page << std::endl;
std::cout << "step = " << current_page << std::endl;
}
catch (const std::exception &e)
else
{
std::cerr << std::endl
<< "Cannot get IOV number for tag with name \"" << TAG_NAME << "\"" << std::endl;
std::cerr << e.what() << std::endl;
<< "Cannot get page information from IOV list for tag \"" << TAG_NAME << "\"" << std::endl;
exit(0);
}
int stepNumber = iovSize / PAGE_SIZE;
int stepsA = iovSize % PAGE_SIZE;
if (stepsA != 0)
stepNumber = stepNumber + 1;
// the data recieved by pages:
for (int i = 0; i < stepNumber; i++)
{
nlohmann::json iovList = nlohmann::json::array();
// DATA_SOURCE == "server"
try
{
std::cout << "ALGORITHM for copying page by page....:" << std::endl;
IovSetDto dto = crestSource->selectIovs(TAG_NAME, 0, -1, SNAPSHOT, PAGE_SIZE, i, "id.since:ASC");
IovSetDto destDto = copyIovSetDto(dto, NEW_TAG);
std::cout << std::endl
<< " IOV list to be copied into TAG " << NEW_TAG << std::endl
<< destDto.toJson().dump(4) << std::endl;
IovSetDto storedDto = crestSource->storeIovs(destDto);
// IOV list printing:
std::cout << std::endl
<< " IOV list copied into TAG " << NEW_TAG << std::endl
<< storedDto.toJson().dump(4) << std::endl;
nlohmann::json iov_data = dto.toJson();
iovList = getResources(iov_data);
} // findAllIovsFs
catch (const std::exception &e)
{
std::cerr << "ERROR: Cannot get an IOV list for the tag \"" << TAG_NAME << "\"" << std::endl;
std::cerr << e.what() << std::endl;
exit(0);
} // findAllIovs
} // i
} while (step < page_number);
std::cout << "The tag " << TAG_NAME << " copied in to tag " << NEW_TAG << std::endl;
} // else (end)
return retv;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment