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;
106 const std::string_view signature=
"node_description\\\":\\\"";
107 const auto signaturePosition = jsonReply.find(signature);
108 if (signaturePosition == std::string::npos)
throw std::runtime_error(
"signature "+std::string(signature)+
" not found");
109 const auto startOfDescription= signaturePosition + signature.size();
110 const std::string_view endSignature =
"\\\",\\\"payload_spec";
111 const auto endOfDescription=jsonReply.find(endSignature);
112 if (endOfDescription == std::string::npos)
throw std::runtime_error(
"end signature "+std::string(endSignature)+
" not found");
113 const auto len=endOfDescription-startOfDescription;
114 description=jsonReply.substr(startOfDescription, len);
116 std::cerr<<__FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the description in "<<jsonReply<<std::endl;
126 std::string jsonReply =
"";
128 TagMetaDto dto = m_crestCl->findTagMeta(
tag);
129 TagInfoDto tag_info_dto = dto.getTagInfoDto();
130 jsonReply = tag_info_dto.getFolderDescription();
136 TagMetaDto dto = m_crestCl->findTagMeta(
tag);
137 TagInfoDto tag_info_dto = dto.getTagInfoDto();
141 std::cerr<<__FILE__<<
":"<<__LINE__<<
": " <<
e.what() <<
" Cannot get a tag meta info " <<
tag << std::endl;
149 TagDto dto = m_crestCl->findTag(
tag);
152 std::cerr<<__FILE__<<
":"<<__LINE__<<
": " <<
e.what() <<
" Cannot get a tag Properties of " <<
tag << std::endl;
159 if (tag_info.contains(
key)){
160 if (
key ==
"channel_list"){
161 return tag_info[
key].dump();
162 }
else if (
key==
"node_description"){
164 tag_info[
key].get_to(
v);
173 std::pair<std::vector<cool::ChannelId> , std::vector<std::string>>
175 std::vector<cool::ChannelId>
list;
176 std::vector<std::string>
names;
180 for (
int i = 0;
i <=
n;
i++) {
182 for (
auto& [
key,
val] : j_object.items()){
183 list.push_back(std::stoll(
key));
189 auto isEmpty=[](
const std::string &
s){
return s.empty();};
191 return std::make_pair(std::move(
list), std::move(
names));
201 std::vector<uint64_t>
203 std::vector<uint64_t>
v;
205 IovSetDto dto = m_crestCl->selectGroups(
tag, 0, 10000, 0,
"id.since:ASC");
206 const std::vector<IovDto> &
res = dto.getResources();
207 for (
const IovDto & item_iov:
res){
208 v.emplace_back(item_iov.getSince());
211 std::cerr<<__FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the IOVs"<<std::endl;
218 std::pair<uint64_t,uint64_t>
222 std::pair<uint64_t,uint64_t> answer = std::make_pair(0,0);
225 std::cerr <<
"Wrong since/until." << std::endl;
230 for (
int i = 0;
i <
N;
i++) {
237 for (
int i = 0;
i <
N;
i++) {
244 answer = std::make_pair(new_since,new_until);
254 std::cerr<<__FILE__<<
":"<<__LINE__<<
": " <<
e.what() <<
" Cannot get the tag size for " <<
tagname << std::endl;
259 std::pair<uint64_t,uint64_t>
261 std::vector<uint64_t>
v = getIovGroups(
tag);
263 return getSinceUntilPair(std::move(
v),
since,
until);
267 std::vector<IovHashPair>
269 std::vector<IovHashPair> iovHashPairs;
270 int iovNumber = getTagSize(
tag);
273 if (iovNumber <=1000) {
274 dto = m_crestCl->selectIovs(
tag, 0, -1, 0, 10000, 0,
"id.since:ASC");
276 const auto &[s_time, u_time] = getIovInterval(
tag,
since,
until);
277 if (s_time == 0 && u_time == 0){
280 dto = m_crestCl->selectIovs(
tag, s_time, u_time, 0, 10000, 0,
"id.since:ASC");
283 std::vector<IovDto>
res = dto.getResources();
284 std::map<uint64_t, std::string> hashmap;
285 for (
const IovDto &
item:
res) {
286 hashmap[
item.getSince()] =
item.getPayloadHash();
288 for (
auto&
t : hashmap){
292 std::cerr<<__FILE__<<
":"<<__LINE__<<
": "<<
e.what()<<
" while trying to find the IOVs"<<std::endl;