10 #include "CrestApi/CrestApi.h"
11 #include "CrestApi/CrestApiFs.h"
22 using namespace Crest;
25 setURLBase(crest_path);
27 const std::string prefix1 =
"http://";
28 const std::string prefix2 =
"https://";
29 if (crest_path.starts_with(prefix1) || crest_path.starts_with(prefix2)){
30 m_crestCl = std::unique_ptr<Crest::CrestApi>(
new Crest::CrestApi(getURLBase()));
33 m_crestCl = std::unique_ptr<Crest::CrestApiFs>(
new Crest::CrestApiFs(
true,getURLBase()));
44 m_CREST_PATH = crest_path;
52 std::string_view signature=
"payloadHash\":\"";
53 auto signaturePosition=jsonReply.rfind(signature);
54 if (signaturePosition == std::string::npos)
throw std::runtime_error(
"signature "+std::string(signature)+
" not found");
55 auto startOfHash=signaturePosition + signature.size();
56 auto endOfHash=jsonReply.find(
'\"',startOfHash);
57 auto len=endOfHash-startOfHash;
58 if (startOfHash > jsonReply.size())
throw std::runtime_error(
"Hash start is beyond end of string");
59 hash=jsonReply.substr(startOfHash, len);
61 std::cerr<<__FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the hash in "<<jsonReply<<std::endl;
71 std::string reply =
"";
74 IovSetDto dto = m_crestCl->selectIovs(
tag, 0, -1, 0, 10000, 0,
"id.since:ASC");
78 reply = iov_list.dump();
80 std::cerr<<__FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the IOVs"<<std::endl;
84 return extractHashFromJson(reply);
89 std::string reply =
"";
92 reply = m_crestCl->getPayload(
hash);
94 std::cerr<<__FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the payload"<<std::endl;
109 std::vector<uint64_t>
111 std::vector<uint64_t>
v;
113 IovSetDto dto = m_crestCl->selectGroups(
tag, 0, 10000, 0,
"id.since:ASC");
114 const std::vector<IovDto> &
res = dto.getResources();
115 for (
const IovDto & item_iov:
res){
116 v.emplace_back(item_iov.getSince());
119 std::cerr<<__FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the IOVs"<<std::endl;
126 std::pair<uint64_t,uint64_t>
130 std::pair<uint64_t,uint64_t> answer = std::make_pair(0,0);
133 std::cerr <<
"Wrong since/until." << std::endl;
138 for (
int i = 0;
i <
N;
i++) {
145 for (
int i = 0;
i <
N;
i++) {
152 answer = std::make_pair(new_since,new_until);
162 std::cerr<<__FILE__<<
":"<<__LINE__<<
": " <<
e.what() <<
" Cannot get the tag size for " <<
tagname << std::endl;
167 std::pair<uint64_t,uint64_t>
169 std::vector<uint64_t>
v = getIovGroups(
tag);
171 return getSinceUntilPair(std::move(
v),
since,
until);
175 std::vector<IovHashPair>
177 std::vector<IovHashPair> iovHashPairs;
178 int iovNumber = getTagSize(
tag);
181 if (iovNumber <=1000) {
182 dto = m_crestCl->selectIovs(
tag, 0, -1, 0, 10000, 0,
"id.since:ASC");
184 const auto &[s_time, u_time] = getIovInterval(
tag,
since,
until);
185 if (s_time == 0 && u_time == 0){
188 dto = m_crestCl->selectIovs(
tag, s_time, u_time, 0, 10000, 0,
"id.since:ASC");
191 std::vector<IovDto>
res = dto.getResources();
192 std::map<uint64_t, std::string> hashmap;
193 for (
const IovDto &
item:
res) {
194 hashmap[
item.getSince()] =
item.getPayloadHash();
196 for (
auto&
t : hashmap){
200 std::cerr<<__FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the IOVs"<<std::endl;