ATLAS Offline Software
CrestApi.cxx
Go to the documentation of this file.
1 
9 #include <CrestApi/CrestApi.h>
10 
11 #include <boost/uuid/uuid.hpp> // uuid class
12 #include <boost/uuid/uuid_generators.hpp> // generators
13 #include <boost/uuid/uuid_io.hpp>
14 #include <boost/asio.hpp>
15 
16 #include <fstream>
17 #include <filesystem>
18 #include <iostream>
19 
20 #include <CrestApi/picosha2.h>
21 
22 #include <cstdio>
23 #include <ctime>
24 
25 #include <regex>
26 
27 namespace Crest {
28  CrestClient::CrestClient(bool rewriteIfExists, const std::string& root_folder) : m_mode(FILESYSTEM_MODE),
29  m_root_folder(root_folder), m_isRewrite(rewriteIfExists) {
31  std::filesystem::create_directory(std::filesystem::path(m_root_folder));
32  }
33  m_data_folder = m_root_folder + "/data";
35  std::filesystem::create_directory(std::filesystem::path(m_data_folder));
36  }
37  }
38 
39  CrestClient::CrestClient(const std::string& _host, const std::string& _port, bool check_version) : m_host(_host), m_port(_port), m_mode(
40  SERVER_MODE) {
41  if (check_version == true) {
43  }
44  getProxyPath();
45  }
46 
47  CrestClient::CrestClient(std::string_view url, bool check_version) : m_mode(SERVER_MODE) {
48  size_t found = url.find_first_of(':');
49  size_t n = url.size();
50 
51  std::string_view url_new = url.substr(found + 3); //url_new is the url excluding the http part
52  size_t found1 = url_new.find_first_of(':');
53  size_t found2 = url_new.find_first_of('/');
54 
55  std::string_view host;
56  std::string_view port;
57  std::string_view resources;
58  if (found1 != std::string::npos && found2 != std::string::npos) {
59  host = url_new.substr(0, found1);
60  port = url_new.substr(found1 + 1, found2 - found1 - 1);
61  } else if (found1 != std::string::npos) {
62  host = url_new.substr(0, found1);
63  port = url_new.substr(found1 + 1);
64  } else if (found2 != std::string::npos) {
65  port = "80";
66  host = url_new.substr(0, found2);
67  } else {
68  port = "80";
69  host = url_new;
70  }
71 
72  if (found2 < n - 1){
73  resources = url_new.substr(found2,n - 1);
74  m_PATH = resources;
75  }
76 
77  m_port = std::string(port);
78  m_host = std::string(host);
79 
80  if (check_version == true) {
82  }
83  getProxyPath();
84  }
85 
87  flush();
88  }
89 
90  std::string CrestClient::make_url(const std::string &address) const{
91  std::string str("http://");
92  str += m_host;
93  str += ':';
94  str += m_port;
95  str += address;
96  return str;
97 }
98 
99 //==================================
100 // TAG METHODS
101 //
102 
104  const char* method_name = "CrestClient::listTags";
105 
106  checkFsException(method_name);
107 
108  std::string current_path = m_PATH;
109  current_path += s_TAG_PATH;
110 
111  std::string retv;
112 
113  nlohmann::json js = nullptr;
114  retv = performRequest(current_path, GET, js, method_name);
115 
116  nlohmann::json respond = getJson(retv, method_name);
117 
118  return getResources(respond);
119  }
120 
122  const char* method_name = "CrestClient::listTags";
123 
124  checkFsException(method_name);
125 
126  int size_default = 1000;
127  int page_default = 0;
128  std::string size_param = "";
129  std::string page_param = "";
130  std::string params = "";
131 
132  if (size == size_default && page == page_default) {
133  nlohmann::json respond = listTags();
134  return getResources(respond);
135  }
136 
137  if (size != size_default) {
138  size_param = "size=";
139  size_param += std::to_string(size);
140  params += size_param;
141  }
142  if (page != page_default) {
143  page_param = "page=";
144  page_param += std::to_string(page);
145  if (page_param.empty()) {
146  params += page_param;
147  } else {
148  params += '&';
149  params += page_param;
150  }
151  }
152 
153  std::string current_path = m_PATH;
154  current_path += s_TAG_PATH;
155  current_path += '?';
156  current_path += params;
157  std::string retv;
158 
159  nlohmann::json js = nullptr;
160  retv = performRequest(current_path, GET, js, method_name);
161 
162  nlohmann::json respond = getJson(retv, method_name);
163 
164  return getResources(respond);
165  }
166 
167  nlohmann::json CrestClient::listTags(const std::string& name, int size, int page, const std::string& sort) {
168  const char* method_name = "CrestClient::listTags";
169 
170  checkFsException(method_name);
171 
172  std::string tagname = name;
173 
174  if (tagname.find("%25") == std::string::npos) {
175  replaceSymbols(tagname, "%", "%25");
176  replaceSymbols(tagname, "*", "%25");
177  }
178 
179  std::string current_path = m_PATH;
180  current_path += s_TAG_PATH;
181 
182  if (!name.empty()) {
183  std::string nameString = "?name=";
184  nameString += tagname;
185  current_path += nameString;
186  current_path += "&size=";
187  current_path += std::to_string(size);
188  current_path += "&page=";
189  current_path += std::to_string(page);
190  current_path += "&sort=";
191  current_path += sort;
192  } else {
193  current_path += "?size=";
194  current_path += std::to_string(size);
195  current_path += "&page=";
196  current_path += std::to_string(page);
197  current_path += "&sort=";
198  current_path += sort;
199  }
200 
201  nlohmann::json js = nullptr;
202  std::string retv = performRequest(current_path, GET, js, method_name);
203 
204  nlohmann::json respond = getJson(retv, method_name);
205 
206  return getResources(respond);
207  }
208 
209  void CrestClient::removeTag(const std::string& tagName) {
210  const char* method_name = "removeTag";
211 
212  checkFsException(method_name);
213 
214  std::string current_path = m_PATH;
215  current_path += s_ADMIN_PATH;
216  current_path += s_TAG_PATH;
217  current_path += '/';
218  current_path += tagName;
219  std::string retv;
220 
221  nlohmann::json js = nullptr;
222 
223  retv = performRequest(current_path, DELETE, js, method_name);
224  }
225 
226  nlohmann::json CrestClient::findTag(const std::string& tagName) {
227  const char* method_name = "findTag";
228 
229  if (m_mode == FILESYSTEM_MODE) {
230  return findTagFs(tagName);
231  }
232 
233  std::string current_path = m_PATH + s_TAG_PATH + '/' + tagName;
234 
235  std::string retv;
236 
237  nlohmann::json js = nullptr;
238 
239  retv = performRequest(current_path, GET, js, method_name);
240 
241  nlohmann::json respond = getJson(retv, method_name);
242 
243  return getResources(respond);
244  }
245 
246  void CrestClient::createTag(const std::string& name, const std::string& desc, const std::string& timeType) {
247  nlohmann::json js2 = {{"description", desc}, {"endOfValidity", 0},
248  {"lastValidatedTime", 0}, {"synchronization", "none"}, {"payloadSpec", "json"},
249  {"name", name}, {"timeType", timeType}};
250  createTag(js2);
251  }
252 
253  void CrestClient::createTag(const std::string& name, const std::string& desc, const std::string& timeType,
254  const std::string& payloadSpec) {
255  nlohmann::json js2 = {{"description", desc}, {"endOfValidity", 0},
256  {"lastValidatedTime", 0}, {"synchronization", "none"}, {"payloadSpec", payloadSpec},
257  {"name", name}, {"timeType", timeType}};
258 
259  createTag(js2);
260  }
261 
263  const char* method_name = "CrestClient::createTag";
264 
265  if (m_mode == FILESYSTEM_MODE) {
266  createTagDump(js);
267  return;
268  }
269 
270  std::string current_path = m_PATH;
271  current_path += s_TAG_PATH;
272 
273  std::string retv;
274 
275  retv = performRequest(current_path, POST, js, method_name);
276  }
277 
278  void CrestClient::updateTag(const std::string& tagname, nlohmann::json body) {
279  const char* method_name = "CrestClient::updateTag";
280 
281  checkFsException(method_name);
282 
283  std::string current_path = m_PATH;
284  current_path += s_TAG_PATH;
285  current_path += '/';
286  current_path += tagname;
287 
288  std::string retv;
289 
290  retv = performRequest(current_path, PUT, body, method_name);
291  }
292 
293  void CrestClient::updateTagSpecification(const std::string& tagname, const std::string& objectType) {
294  const char* method_name = "CrestClient::updateTagSpecification";
295 
296  checkFsException(method_name);
297 
298  std::string current_path = m_PATH;
299  current_path += s_TAG_PATH;
300  current_path += '/';
301  current_path += tagname;
302 
303  nlohmann::json body;
304  body["objectType"] = objectType;
305 
306 
307  std::string retv;
308  retv = performRequest(current_path, PUT, body, method_name);
309  }
310 
312  std::string name = js["name"];
313 
314  std::string rootDir = m_root_folder;
315  rootDir += s_FS_TAG_PATH;
317  std::filesystem::create_directory(std::filesystem::path(rootDir));
318  }
319 
320  std::string workDir = m_root_folder;
321  workDir += s_FS_TAG_PATH;
322  workDir += '/';
323  workDir += name;
325  std::filesystem::create_directory(std::filesystem::path(workDir));
326  }
327  if (name.compare(m_currentTag) != 0 && m_isRewrite) {
328  flush();
329  }
330  m_currentTag = name;
331  std::string tagFile = workDir + s_FS_TAG_FILE;
332  std::string iovFile = workDir + s_FS_IOV_FILE;
333 
334  if (m_isRewrite) {
337  }
340  }
341  std::ofstream myfile;
342  myfile.open(tagFile.c_str());
343  myfile << js;
344  myfile.close();
345  }
346  if (m_data.find(name) == m_data.end()) {
347  m_data.insert(std::pair<std::string, nlohmann::json>(name, nlohmann::json(nlohmann::json::value_t::array)));
348  }
349  }
350 
352  if (m_mode == SERVER_MODE) return;
353 
354  for (auto& item : m_data) {
355  nlohmann::json iov = item.second;
356  std::string name = item.first;
357  std::string workDir = m_root_folder + s_FS_TAG_PATH + '/' + name;
358  std::ofstream myfile;
359  std::string tagFile = workDir + s_FS_IOV_FILE;
360  myfile.open(tagFile.c_str());
361  myfile << iov;
362  myfile.close();
363  }
364 
365  m_data.clear();
366  }
367 
368 // IOV methods:
369 
371  const char* method_name = "CrestClient::createIov";
372 
373  checkFsException(method_name);
374 
376  iovList.push_back(js);
377 
378  try{
380  }
381  catch (const std::exception& e) {
382  std::string message = "ERROR in ";
383  message += method_name;
384  message += e.what();
385  throw std::runtime_error(message);
386  }
387 
388  }
389 
391  const char* method_name = "CrestClient::findAllIovs";
392 
393  if (m_mode == FILESYSTEM_MODE) {
394  return findAllIovsFs(tagname);
395  }
396 
397  std::string current_path = m_PATH;
398  current_path += s_IOV_PATH;
399  current_path += "?method=";
400  current_path += s_METHOD_IOVS;
401  current_path += "&tagname=";
402  current_path += tagname;
403 
404  std::string retv;
405 
406  nlohmann::json js = nullptr;
407  retv = performRequest(current_path, GET, js, method_name);
408 
409  nlohmann::json respond = getJson(retv, method_name);
410 
411  auto answer = getResources(respond);
412  return answer;
413  }
414 
415  nlohmann::json CrestClient::findAllIovs(const std::string& tagname, int size, int page, const std::string& sort,
416  const std::string& dateformat) {
417  const char* method_name = "CrestClient::findAllIovs";
418 
419  if (m_mode == FILESYSTEM_MODE) {
420  return findAllIovsFs(tagname);
421  }
422 
423  // http request examples:
424  // http://crest-01.cern.ch:9090/crestapi/iovs?method=IOVS&tagname=MuonAlignMDTBarrelAlign-RUN2-BA_ROLLING_12-BLKP-UPD4-00
425  // http://crest-02.cern.ch:8090/crestapi/tags?size=10&page=2&sort=name:DESC
426 
427  std::string current_path = m_PATH;
428  current_path += s_IOV_PATH;
429  current_path += "?method=";
430  current_path += s_METHOD_IOVS;
431  current_path += "&tagname=";
432  current_path += tagname;
433  current_path += "&size=";
434  current_path += std::to_string(size);
435  current_path += "&page=";
436  current_path += std::to_string(page);
437  current_path += "&sort=";
438  current_path += sort;
439  current_path += "&dateformat=";
440  current_path += dateformat;
441 
442 
443  std::string retv;
444 
445  nlohmann::json js = nullptr;
446 
447  retv = performRequest(current_path, GET, js, method_name);
448 
449  nlohmann::json respond = getJson(retv, method_name);
450 
451  return getResources(respond);
452  }
453 
454  int CrestClient::getSize(const std::string& tagname) {
455  const char* method_name = "CrestClient::getSize";
456 
457  if (m_mode == FILESYSTEM_MODE) {
458  return getSizeFS(tagname);
459  }
460 
461  std::string current_path = m_PATH;
462  current_path += s_IOV_PATH;
463  current_path += s_IOV_SIZE_PATH;
464  current_path += "?tagname=";
465  current_path += tagname;
466 
467  std::string retv;
468 
469  nlohmann::json js = nullptr;
470 
471  retv = performRequest(current_path, GET, js, method_name);
472 
473 
474  nlohmann::json respond = getJson(retv, method_name);
475  nlohmann::json res = getResources(respond)[0];
476 
477  int result = 0;
478 
479  if (respond.find("size") != respond.end()) {
480  int sizeR = respond["size"];
481  if (sizeR == 0) return result;
482  }
483 
484  if (res.find("niovs") != res.end()) {
485  result = res["niovs"];
486  } else {
487  throw std::runtime_error("ERROR in CrestClient::getSize CREST Server JSON response has no \"size\" key.");
488  }
489 
490  return result;
491  }
492 
494  const char* method_name = "CrestClient::selectIovs";
495 
496  checkFsException(method_name);
497 
498  std::string current_path = m_PATH;
499  current_path += s_IOV_PATH;
500  current_path += "?method=";
501  current_path += s_METHOD_IOVS;
502  current_path += "&tagname=";
503 
504  current_path += tagname;
505 
506  std::string retv;
507 
508  nlohmann::json js = nullptr;
509 
510  retv = performRequest(current_path, GET, js, method_name);
511 
512  nlohmann::json respond = getJson(retv, method_name);
513 
514  return getResources(respond);
515  }
516 
517  nlohmann::json CrestClient::selectIovs(const std::string& tagname, long snapshot) {
518  const char* method_name = "CrestClient::selectIovs";
519 
520  checkFsException(method_name);
521 
522  std::string current_path = m_PATH;
523  current_path += s_IOV_PATH;
524 
525  current_path += "?method=";
526  current_path += s_METHOD_IOVS;
527  current_path += "&tagname=";
528 
529  current_path += tagname;
530  current_path += "&snapshot=";
531  current_path += std::to_string(snapshot);
532 
533  std::string retv;
534 
535  nlohmann::json js = nullptr;
536 
537  retv = performRequest(current_path, GET, js, method_name);
538 
539  nlohmann::json respond = getJson(retv, method_name);
540 
541  return getResources(respond);
542  }
543 
544  nlohmann::json CrestClient::selectIovs(const std::string& tagname, long since, long until, long snapshot) {
545  const char* method_name = "CrestClient::selectIovs";
546 
547  checkFsException(method_name);
548 
549  std::string current_path = m_PATH;
550  current_path += s_IOV_PATH;
551 
552  current_path += "?method=";
553  current_path += s_METHOD_IOVS;
554  current_path += "&tagname=";
555 
556  current_path += tagname;
557  current_path += "&since=";
558  current_path += std::to_string(since);
559  current_path += "&until=";
560  if (until == -1) {
561  current_path += "INF";
562  } else {
563  current_path += std::to_string(until);
564  }
565  current_path += "&snapshot=";
566  current_path += std::to_string(snapshot);
567 
568  std::string retv;
569 
570  nlohmann::json js = nullptr;
571 
572  retv = performRequest(current_path, GET, js, method_name);
573 
574  nlohmann::json respond = getJson(retv, method_name);
575 
576  return getResources(respond);
577  }
578 
580  const char* method_name = "CrestClient::selectGroups";
581 
582  checkFsException(method_name);
583 
584  std::string current_path = m_PATH;
585  current_path += s_IOV_PATH;
586 
587  current_path += "?method=";
588  current_path += s_METHOD_GROUPS;
589  current_path += "&tagname=";
590 
591  current_path += tagname;
592 
593  std::string retv;
594 
595  nlohmann::json js = nullptr;
596 
597  retv = performRequest(current_path, GET, js, method_name);
598 
599  nlohmann::json respond = getJson(retv, method_name);
600 
601  return getResources(respond);
602  }
603 
604  nlohmann::json CrestClient::selectGroups(const std::string& tagname, long snapshot) {
605  const char* method_name = "CrestClient::selectGroups";
606 
607  checkFsException(method_name);
608 
609  std::string current_path = m_PATH;
610  current_path += s_IOV_PATH;
611 
612  current_path += "?method=";
613  current_path += s_METHOD_GROUPS;
614  current_path += "&tagname=";
615 
616  current_path += tagname;
617  current_path += "&snapshot=";
618  current_path += std::to_string(snapshot);
619 
620  std::string retv;
621 
622  nlohmann::json js = nullptr;
623  retv = performRequest(current_path, GET, js, method_name);
624 
625  nlohmann::json respond = getJson(retv, method_name);
626 
627  return getResources(respond);
628  }
629 
631  const char* method_name = "CrestClient::storeBatchIOVs";
632 
633  checkFsException(method_name);
634 
635  /*
636 
637  Request Example:
638 
639  curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST
640  http://crest-02.cern.ch:8090/crestapi/iovs/storebatch
641  -d '{"size": 2, "datatype": "iovs", "format": "IovSetDto","resources":
642  [
643  {"payloadHash": "9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0","since": 200,"tagName":
644  "test_MvG10"},
645  {"payloadHash": "3e744b9dc39389baf0c5a0660589b8402f3dbb49b89b3e75f2c9355852a3c677","since": 250,"tagName":
646  "test_MvG10"}
647  ]
648  }'
649  */
650 
651  int n = js.size();
652 
654  {
655  {"size", n},
656  {"datatype", "iovs"},
657  {"format", "IovSetDto"},
658  {"resources", js}
659  };
660 
661 
662  std::string current_path = m_PATH;
663  current_path += s_IOV_PATH;
664 
665  std::string retv;
666 
667  retv = performRequest(current_path, POST, arg, method_name);
668  }
669 
670 // GLOBALTAGS
671 
672  void CrestClient::updateGlobalTag(const std::string& name, nlohmann::json body) {
673  const char* method_name = "CrestClient::updateGlobalTag";
674 
675  checkFsException(method_name);
676 
677  std::string current_path = m_PATH;
678  current_path += s_ADMIN_PATH;
679  current_path += s_GLOBALTAG_PATH;
680  current_path += '/';
681  current_path += name;
682 
683  std::string retv;
684 
685  retv = performRequest(current_path, PUT, body, method_name);
686  }
687 
689  const char* method_name = "CrestClient::createGlobalTag";
690 
691  if (m_mode == FILESYSTEM_MODE) {
692  createGlobalTagFs(js);
693  return;
694  }
695 
696  std::string current_path = m_PATH;
697  current_path += s_GLOBALTAG_PATH;
698  std::string retv;
699  retv = performRequest(current_path, POST, js, method_name);
700  }
701 
702  void CrestClient::createGlobalTag(const std::string& tag) {
703  const char* method_name = "CrestClient::createGlobalTag";
704 
705  nlohmann::json js = getJson(tag, method_name);
706  createGlobalTag(js);
707  }
708 
709  void CrestClient::createGlobalTag(const std::string& tagname, const std::string& description) {
710  nlohmann::json js =
711  {
712  {"name", tagname},
713  {"description", description},
714  {"validity", 0},
715  {"release", 1},
716  {"scenario", "undefined"},
717  {"workflow", "undefined"},
718  {"type", "UPD"}
719  };
720 
721  createGlobalTag(js);
722  }
723 
724  std::string CrestClient::findGlobalTagAsString(const std::string& name) {
725  const char* method_name = "CrestClient::findGlobalTagAsString";
726 
727  if (m_mode == FILESYSTEM_MODE) {
729  std::string s = j.dump();
730  return s;
731  }
732 
733  std::string current_path = m_PATH;
734  current_path += s_GLOBALTAG_PATH;
735  current_path += '/';
736  current_path += name;
737  std::string retv;
738 
739  nlohmann::json js = nullptr;
740  retv = performRequest(current_path, GET, js, method_name);
741 
742  return retv;
743  }
744 
746  const char* method_name = "CrestClient::findGlobalTag";
747 
748  if (m_mode == FILESYSTEM_MODE) {
749  return findGlobalTagFs(name);
750  }
751 
752  std::string retv = findGlobalTagAsString(name);
753  nlohmann::json respond = getJson(retv, method_name);
754 
755  return getResources(respond);
756  }
757 
758  void CrestClient::removeGlobalTag(const std::string& name) {
759  const char* method_name = "CrestClient::removeGlobalTag";
760 
761  checkFsException(method_name);
762 
763  std::string current_path = m_PATH;
764  current_path += s_ADMIN_PATH;
765  current_path += s_GLOBALTAG_PATH;
766  current_path += '/';
767  current_path += name;
768  std::string retv;
769  nlohmann::json js = nullptr;
770  retv = performRequest(current_path, DELETE, js, method_name);
771  }
772 
774  const char* method_name = "CrestClient::listGlobalTags";
775 
776  checkFsException(method_name);
777 
778  std::string current_path = m_PATH;
779  current_path += s_GLOBALTAG_PATH;
780  std::string retv;
781  nlohmann::json js = nullptr;
782  retv = performRequest(current_path, GET, js, method_name);
783  nlohmann::json respond = getJson(retv, method_name);
784 
785  return getResources(respond);
786  }
787 
789  const char* method_name = "CrestClient::listGlobalTagsAsString";
790 
791  checkFsException(method_name);
792 
793  std::string current_path = m_PATH;
794  current_path += s_GLOBALTAG_PATH;
795 
796  std::string retv;
797 
798  nlohmann::json js = nullptr;
799 
800  retv = performRequest(current_path, GET, js, method_name);
801 
802  return retv;
803  }
804 
805  nlohmann::json CrestClient::listGlobalTags(const std::string& name, int size, int page, const std::string& sort) {
806  const char* method_name = "CrestClient::listGlobalTags";
807 
808  checkFsException(method_name);
809 
810  std::string tagname = name;
811 
812  if (tagname.find("%25") == std::string::npos) {
813  replaceSymbols(tagname, "%", "%25");
814  replaceSymbols(tagname, "*", "%25");
815  }
816 
817  std::string current_path = m_PATH;
818  current_path += s_GLOBALTAG_PATH;
819  if (!name.empty()) {
820  std::string nameString = "?name=";
821  nameString += tagname;
822  current_path += nameString;
823  current_path += "&size=";
824  current_path += std::to_string(size);
825  current_path += "&page=";
826  current_path += std::to_string(page);
827  current_path += "&sort=";
828  current_path += sort;
829  } else {
830  current_path += "?size=";
831  current_path += std::to_string(size);
832  current_path += "&page=";
833  current_path += std::to_string(page);
834  current_path += "&sort=";
835  current_path += sort;
836  }
837 
838  std::string retv;
839  nlohmann::json js = nullptr;
840  retv = performRequest(current_path, GET, js, method_name);
841  nlohmann::json respond = getJson(retv, method_name);
842 
843  return getResources(respond);
844  }
845 
846 //=============================
847 // GLOBALTAGM MAPs
848 
850  const char* method_name = "CrestClient::findGlobalTagMap";
851 
852  if (m_mode == FILESYSTEM_MODE) {
853  return findGlobalTagMapFs(name);
854  }
855 
856  std::string current_path = m_PATH;
857  current_path += s_GLOBALTAG_MAP_PATH;
858  current_path += '/';
859  current_path += name;
860 
861  std::string retv;
862 
863  nlohmann::json js = nullptr;
864 
865  retv = performRequest(current_path, GET, js, method_name);
866 
867  nlohmann::json respond = getJson(retv, method_name);
868 
869  return getResources(respond);
870  }
871 
873  const char* method_name = "CrestClient::createGlobalTagMap";
874 
875  if (m_mode == FILESYSTEM_MODE) {
877  return;
878  }
879 
880  std::string current_path = m_PATH;
881  current_path += s_GLOBALTAG_MAP_PATH;
882 
883  std::string retv;
884 
885  retv = performRequest(current_path, POST, js, method_name);
886  }
887 
888  void CrestClient::createGlobalTagMap(const std::string& globaltag, const std::string& tagname,
889  const std::string& record, const std::string& label) {
890  const char* method_name = "CrestClient::createGlobalTagMap";
891 
892  nlohmann::json js =
893  {
894  {"globalTagName", globaltag},
895  {"record", record},
896  {"label", label},
897  {"tagName", tagname}
898  };
899 
900  if (m_mode == FILESYSTEM_MODE) {
902  return;
903  }
904 
905  std::string current_path = m_PATH + s_GLOBALTAG_MAP_PATH;
906 
907  std::string retv;
908 
909  retv = performRequest(current_path, POST, js, method_name);
910  }
911 
912 //==============================
913 //BLOBS & PAYLOADS
914 
915  std::string CrestClient::getBlob(const std::string& hash) {
916  const char* method_name = "CrestClient::getBlob";
917 
918  if (m_mode == FILESYSTEM_MODE) {
919  return getBlobFs(hash);
920  }
921 
922  std::string current_path = m_PATH;
923  current_path += s_PAYLOAD_PATH;
924  current_path += '/';
925  current_path += hash;
926 
927  std::string retv;
928 
929  nlohmann::json js = nullptr;
930 
931  retv = performRequest(current_path, GET, js, method_name);
932 
933  return retv;
934  }
935 
936  std::string CrestClient::getBlobInStream(const std::string& hash, std::ofstream& out) {
937  if (m_mode == FILESYSTEM_MODE) {
938  return getBlobInStreamFs(hash, out);
939  }
940 
941  std::string current_path = m_PATH;
942  current_path += s_PAYLOAD_PATH;
943  current_path += '/';
944  current_path += hash;
945 
946  std::string retv;
947 
948  nlohmann::json js = nullptr;
949  retv = performRequest(current_path, GET, js, out);
950 
951  return retv;
952  }
953 
954 // PAYLOADS
955 
957  const char* method_name = "CrestClient::getPayloadMetaInfo";
958 
959  if (m_mode == FILESYSTEM_MODE) {
961  }
962 
963  std::string current_path = m_PATH;
964  current_path += s_PAYLOAD_PATH;
965  current_path += '/';
966  current_path += hash;
967  current_path += "?format=META";
968 
969  std::string retv;
970 
971  nlohmann::json js = nullptr;
972 
973  retv = performRequest(current_path, GET, js, method_name);
974 
975  nlohmann::json respond = getJson(retv, method_name);
976 
977  return respond;
978  }
979 
980  std::string CrestClient::getPayloadMetaInfoAsString(const std::string& hash) {
981  const char* method_name = "CrestClient::getPayloadMetaInfoAsString";
982 
983  if (m_mode == FILESYSTEM_MODE) {
985  }
986 
987  std::string current_path = m_PATH;
988  current_path += s_PAYLOAD_PATH;
989  current_path += '/';
990  current_path += hash;
991  current_path += "?format=META";
992 
993  std::string retv;
994 
995  nlohmann::json js = nullptr;
996 
997  retv = performRequest(current_path, GET, js, method_name);
998 
999  return retv;
1000  }
1001 
1003  const char* method_name = "CrestClient::getPayloadTagInfo";
1004 
1005  checkFsException(method_name);
1006 
1007  std::string current_path = m_PATH;
1008  current_path += s_MONITORING_PAYLOAD_PATH;
1009  current_path += "?tagname=";
1010  current_path += tagname;
1011 
1012  std::string retv;
1013 
1014  nlohmann::json js = nullptr;
1015 
1016  retv = performRequest(current_path, GET, js, method_name);
1017 
1018  nlohmann::json respond = getJson(retv, method_name);
1019 
1020  return getResources(respond);
1021  }
1022 
1024  const char* method_name = "CrestClient::getPayloadTagInfo";
1025 
1026  checkFsException(method_name);
1027 
1028  std::string current_path = m_PATH;
1029  current_path += s_MONITORING_PAYLOAD_PATH;
1030 
1031  std::string retv;
1032 
1033  nlohmann::json js = nullptr;
1034 
1035  retv = performRequest(current_path, GET, js, method_name);
1036 
1037  nlohmann::json respond = getJson(retv, method_name);
1038 
1039  return getResources(respond);
1040  }
1041 
1043  const char* method_name = "CrestClient::getPayloadAsJson";
1044 
1045  if (m_mode == FILESYSTEM_MODE) {
1046  return getPayloadAsJsonFS(hash);
1047  }
1048 
1049  std::string current_path = m_PATH;
1050  current_path += s_PAYLOAD_PATH;
1051  current_path += '/';
1052  current_path += hash;
1053  current_path += "?format=DTO";
1054 
1055  std::string retv;
1056 
1057  nlohmann::json js = nullptr;
1058 
1059  retv = performRequest(current_path, GET, js, method_name);
1060 
1061  nlohmann::json respond = getJson(retv, method_name);
1062 
1063  return respond;
1064  }
1065 
1066  std::string CrestClient::getPayloadAsString(const std::string& hash) {
1067  const char* method_name = "CrestClient::getPayloadAsString";
1068 
1069  if (m_mode == FILESYSTEM_MODE) {
1070  return getPayloadAsStringFS(hash);
1071  }
1072 
1073  std::string current_path = m_PATH;
1074  current_path += s_PAYLOAD_PATH;
1075  current_path += '/';
1076  current_path += hash;
1077  current_path += "?format=BLOB";
1078 
1079  std::string retv;
1080 
1081  nlohmann::json js = nullptr;
1082 
1083  retv = performRequest(current_path, GET, js, method_name);
1084 
1085  return retv;
1086  }
1087 
1089  const char* method_name = "CrestClient::createPayload";
1090 
1091  checkFsException(method_name);
1092 
1093  std::string current_path = m_PATH + s_PAYLOAD_PATH;
1094 
1095  std::string retv;
1096 
1097  retv = performRequest(current_path, POST, js, method_name);
1098  }
1099 
1100 // METHODS to store the PAYLOADS in BATCH mode
1101 
1102  void CrestClient::storeBatchPayloads(const std::string& tag_name, uint64_t endtime, const std::string& iovsetupload) {
1103  const char* method_name = "CrestClient::storeBatchPayloads";
1104 
1105  nlohmann::json js = getJson(iovsetupload, method_name);
1106  storeBatchPayloads(tag_name, endtime, js);
1107  }
1108 
1109  void CrestClient::storeBatchPayloads(const std::string& tag_name, uint64_t endtime, nlohmann::json& js) {
1110  const char* method_name = "CrestClient::storeBatchPayloads";
1111 
1112  if (m_mode == FILESYSTEM_MODE) {
1113  storeBatchPayloadsFs(tag_name, js);
1114  return;
1115  }
1116  if (!js.is_array()) {
1117  throw std::runtime_error("ERROR in " + std::string(method_name) + " JSON has wrong type (must be array)");
1118  }
1119 
1120  nlohmann::json jsObj = {};
1121  jsObj["datatype"] = "iovs";
1122  jsObj["format"] = "StoreSetDto";
1123  jsObj["size"] = js.size();
1124  jsObj["resources"] = js;
1125  std::string str = jsObj.dump();
1126  std::string retv = storeBatchPayloadRequest(tag_name, endtime, str);
1127 
1128  nlohmann::json respond = getJson(retv, method_name);
1129  }
1130 
1131  void CrestClient::storeBatchPayloads(const std::string& tag_name, const std::string& iovsetupload, uint64_t endtime) {
1132  const char* method_name = "CrestClient::storeBatchPayloads";
1133 
1134  nlohmann::json js = getJson(iovsetupload, method_name);
1135  storeBatchPayloads(tag_name, endtime, js);
1136  }
1137 
1138  void CrestClient::storeBatchPayloads(const std::string& tag_name, nlohmann::json& js, uint64_t endtime) {
1139  const char* method_name = "CrestClient::storeBatchPayloads";
1140 
1141  if (m_mode == FILESYSTEM_MODE) {
1142  storeBatchPayloadsFs(tag_name, js);
1143  return;
1144  }
1145  if (!js.is_array()) {
1146  throw std::runtime_error("ERROR in " + std::string(method_name) + " JSON has wrong type (must be array)");
1147  }
1148 
1149  nlohmann::json jsObj = {};
1150  jsObj["datatype"] = "iovs";
1151  jsObj["format"] = "StoreSetDto";
1152  jsObj["size"] = js.size();
1153  jsObj["resources"] = js;
1154  std::string str = jsObj.dump();
1155  std::string retv = storeBatchPayloadRequest(tag_name, endtime, str);
1156 
1157  nlohmann::json respond = getJson(retv, method_name);
1158  }
1159 
1160 //=========================================
1161 // FOLDERS
1162 
1164  const char* method_name = "CrestClient::listFolders";
1165 
1166  checkFsException(method_name);
1167 
1168  std::string current_path = m_PATH + s_FOLDER_PATH;
1169 
1170  std::string retv;
1171 
1172  nlohmann::json js = nullptr;
1173 
1174  retv = performRequest(current_path, GET, js, method_name);
1175 
1176  nlohmann::json respond = getJson(retv, method_name);
1177 
1178  return getResources(respond);
1179  }
1180 
1182  const char* method_name = "CrestClient::createFolder";
1183 
1184  checkFsException(method_name);
1185 
1186  std::string current_path = m_PATH + s_FOLDER_PATH;
1187 
1188  std::string retv;
1189 
1190  retv = performRequest(current_path, POST, body, method_name);
1191 
1192  return retv;
1193  }
1194 
1195 //==========================================
1196 // RUN INFO
1197 
1199  const char* method_name = "CrestClient::listRunLumiInfo";
1200 
1201  checkFsException(method_name);
1202 
1203  std::string current_path = m_PATH + s_RUNINFO_PATH;
1204 
1205  std::string retv;
1206 
1207  nlohmann::json js = nullptr;
1208 
1209  retv = performRequest(current_path, GET, js, method_name);
1210 
1211  nlohmann::json respond = getJson(retv, method_name);
1212 
1213  return getResources(respond);
1214  }
1215 
1217  const char* method_name = "CrestClient::createRunLumiInfo";
1218 
1219  checkFsException(method_name);
1220 
1221  std::string current_path = m_PATH + s_RUNINFO_PATH;
1222 
1223  std::string retv;
1224 
1225  retv = performRequest(current_path, POST, body, method_name);
1226  }
1227 
1229  const char* method_name = "CrestClient::findRunLumiInfo";
1230 
1231  checkFsException(method_name);
1232 
1233  std::string current_path = m_PATH;
1234  current_path += s_RUNINFO_PATH;
1235  current_path += s_RUNINFO_LIST_PATH;
1236  current_path += '?';
1237  current_path += params.getParams();
1238 
1239  std::string retv;
1240 
1241  nlohmann::json js = nullptr;
1242 
1243  retv = performRequest(current_path, GET, js, method_name);
1244 
1245  nlohmann::json respond = getJson(retv, method_name);
1246 
1247  return getResources(respond);
1248  }
1249 
1250 // REQUEST METHODS
1251 
1252  void CrestClient::storePayload(const std::string& tag, uint64_t since, const std::string& js) {
1253  if (m_mode == FILESYSTEM_MODE) {
1254  storePayloadDump(tag, since, js);
1255  return;
1256  }
1257 
1259  nlohmann::json itemD =
1260  {
1261  {"data", js},
1262  {"since", since}
1263  };
1264 
1265  data.push_back(itemD);
1267  }
1268 
1269  struct data {
1270  char trace_ascii; /* 1 or 0 */
1271  };
1272 
1273  size_t CurlWrite_CallbackFunc_StdString(void* contents, size_t size, size_t nmemb, std::string* s) {
1274  size_t newLength = size * nmemb;
1275 
1276  try
1277  {
1278  s->append((char*) contents, newLength);
1279  }
1280  catch (std::bad_alloc& e)
1281  {
1282  //handle memory problem
1283  return 0;
1284  }
1285  return newLength;
1286  }
1287 
1288 
1289  std::string CrestClient::performRequest(const std::string& current_path, Action action, nlohmann::json& js,
1290  const char* method_name) {
1291  CURL* curl;
1292  CURLcode res;
1293 
1294 
1295  /* Enable tracing of ascii data */
1296  //sanitise the current path
1297  std::string sanitisedPath(current_path);
1298  auto caretPosition = sanitisedPath.find('^');
1299  if (caretPosition != std::string::npos) sanitisedPath.replace(caretPosition, 1, "%5E");
1300  /* get a curl handle */
1301  curl = curl_easy_init();
1302  std::string stt;
1303  struct curl_slist* headers = NULL;
1304  if (curl) {
1305  std::string url = make_url(sanitisedPath);
1306  std::string s;
1307  std::cout << "cURL request to " << url << std::endl;
1308 
1309  if (m_CREST_PROXY) {
1310  // The environment variable exists, and 'socksProxy' now contains its value
1311  std::cout << "SOCKS proxy: " << m_CREST_PROXY << std::endl;
1312  // Set the proxy type (replace with your proxy type details)
1313  curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
1314 
1315  // Set the proxy address and port (replace with your SOCKS proxy details)
1316  curl_easy_setopt(curl, CURLOPT_PROXY, m_CREST_PROXY);
1317  }
1318 
1319  curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
1320  if (js.is_null()) {
1321  if (action == DELETE) curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
1322  } else {
1323  stt = js.dump();
1324 
1325  if (action == PUT) curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
1326  headers = curl_slist_append(headers, "Accept: */*");
1327  headers = curl_slist_append(headers, "Content-Type: application/json");
1328 
1329  headers = curl_slist_append(headers, "Expect:");
1330  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
1331  curl_easy_setopt(curl, CURLOPT_POST, 1L);
1332 
1333  /* set where to read from (on Windows you need to use READFUNCTION too) */
1334  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, stt.c_str());
1335  }
1336 
1337  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_StdString);
1338  curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
1339 
1340 
1341  /* Perform the request, res will get the return code */
1342  res = curl_easy_perform(curl);
1343 
1344 
1345  // data to check the errors in the server response:
1346  long response_code;
1347  curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
1348 
1349  /* always cleanup */
1350  curl_easy_cleanup(curl);
1351  curl_slist_free_all(headers);
1352 
1353  curl_global_cleanup();
1354 
1355  // error checking in the server response:
1356  checkResult(res, response_code, s, method_name);
1357 
1358  return s;
1359  }
1360 
1361  throw std::runtime_error(std::string("ERROR in ") + std::string(method_name) + " | CURL not init");
1362  }
1363 
1364 // REQUEST OLD VERSION
1365 
1366  std::string CrestClient::performRequest(const std::string& current_path, Action action, nlohmann::json& js) {
1367  const char* method = "Unknown";
1368 
1369  return performRequest(current_path, action, js, method);
1370  }
1371 
1372 // REQUEST OLD VERSION (end)
1373 
1374 
1375 //==========================
1376 // REQUEST for STREAM
1377 
1378  std::string CrestClient::performRequest(const std::string& current_path, Action action, nlohmann::json& js,
1379  std::ofstream& out) {
1380  boost::asio::streambuf response;
1381  boost::asio::io_service io_service;
1382 
1383  try {
1384  // Get a list of endpoints corresponding to the server name.
1387  boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
1388 
1389  // Try each endpoint until we successfully establish a connection.
1390  boost::asio::ip::tcp::socket socket(io_service);
1391  boost::asio::connect(socket, endpoint_iterator);
1392 
1393  std::string retv = "Invalid response\n";
1394 
1395  boost::asio::streambuf request;
1396  std::ostream request_stream(&request);
1397 
1398  std::string cmd_line = "";
1399  if (action == GET) cmd_line = "GET";
1400  else if (action == PUT) cmd_line = "PUT";
1401  else if (action == DELETE) cmd_line = "DELETE";
1402 
1403  if (js.is_null()) {
1404  request_stream << cmd_line << " " << current_path << " HTTP/1.0\r\n";
1405  request_stream << "Host: " << m_host << ':' << m_port << " \r\n";
1406  request_stream << "Accept: */*\r\n";
1407  request_stream << "Connection: close\r\n\r\n";
1408  } else {
1409  std::string s = js.dump();
1410  request_stream << action << " " << current_path << " HTTP/1.0\r\n";
1411  request_stream << "Host: " << m_host << ':' << m_port << " \r\n";
1412  request_stream << "Content-Type: application/json; \r\n";
1413  request_stream << "Accept: */*\r\n";
1414  request_stream << "Content-Length: " << s.length() << "\r\n";
1415  request_stream << "Connection: close\r\n\r\n";
1416  request_stream << s;
1417  }
1418 
1419 
1420  //begin request
1421 
1422  // Send the request.
1423  boost::asio::write(socket, request);
1424 
1425  // Read the response status line. The response streambuf will automatically
1426  // grow to accommodate the entire line. The growth may be limited by passing
1427  // a maximum size to the streambuf constructor.
1428 
1429  boost::asio::read_until(socket, response, "\r\n");
1430 
1431 
1432 
1433  boost::asio::read_until(socket, response, "\r\n");
1434 
1435  // Check that response is OK.
1436  std::istream response_stream(&response);
1437  std::string http_version;
1438  response_stream >> http_version;
1439  unsigned int status_code;
1440  response_stream >> status_code;
1441 
1442  std::string status_message;
1443  std::getline(response_stream, status_message);
1444 
1445 
1446  if (!response_stream || http_version.substr(0, 5) != "HTTP/") {
1447  std::cout << "Invalid response" << std::endl;
1448  std::cout << "response_stream : " << status_code << std::endl; // new
1449  return retv;
1450  }
1451  if (status_code != 200) {
1452  std::cout << "Response returned with status code " << status_code << std::endl;
1453 
1454  return retv;
1455  }
1456 
1457  // Read the response headers, which are terminated by a blank line.
1458  boost::asio::read_until(socket, response, "\r\n\r\n");
1459 
1460  // Process the response headers.
1461  std::string header;
1462  while (std::getline(response_stream, header) && header != "\r") {
1463  std::cout << header << std::endl;
1464  }
1465  std::cout << std::endl;
1466 
1467  std::ostringstream txt;
1468 
1469  // Write whatever content we already have to output.
1470  if (response.size() > 0) out << &response;
1471 
1472 
1473  // Read until EOF, writing data to output as we go.
1475  while (boost::asio::read(socket, response,
1476  boost::asio::transfer_at_least(1), error))
1477  out << &response;
1478 
1479  if (error != boost::asio::error::eof) {
1480  std::cerr << "connection error" << std::endl;
1481  std::string st0 = "";
1482  return st0;
1483  }
1484 
1485  retv = status_code;
1486  return retv;
1487 
1488  //end request
1489  }
1490  catch (boost::system::system_error& e) {
1491  std::cerr << e.what() << " | " << e.code() << std::endl;
1492  std::string st0 = "";
1493  return st0;
1494  }
1495  catch (...) {
1496  std::cerr << "connection error" << std::endl;
1497  std::string st0 = "";
1498  return st0;
1499  }
1500  }
1501 
1502 
1503 // Request method to store payloads in batch mode
1504 
1505  std::string CrestClient::storeBatchPayloadRequest(const std::string& tag, uint64_t endtime, const std::string& js) {
1506  std::string current_path = m_PATH;
1507  current_path += s_PAYLOAD_PATH;
1508 
1509  CURL* curl;
1510  CURLcode res;
1511 
1512  // get a curl handle
1513 
1514  curl_global_init(CURL_GLOBAL_DEFAULT);
1515  curl = curl_easy_init();
1516 
1517  struct curl_slist* headers = NULL;
1518  if (curl) {
1519  std::string url = make_url(current_path);
1520  std::string s;
1521 
1522  if (m_CREST_PROXY) {
1523  // The environment variable exists, and 'socksProxy' now contains its value
1524  std::cout << "SOCKS proxy: " << m_CREST_PROXY << std::endl;
1525  // Set the proxy type (replace with your proxy type details)
1526  curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
1527 
1528  // Set the proxy address and port (replace with your SOCKS proxy details)
1529  curl_easy_setopt(curl, CURLOPT_PROXY, m_CREST_PROXY);
1530  }
1531 
1532  // First set the URL that is about to receive our POST. This URL can
1533  // just as well be a https:
1534  // URL if that is what should receive the data.
1535 
1536  curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
1537  headers = curl_slist_append(headers, "X-Crest-PayloadFormat: JSON");
1538  headers = curl_slist_append(headers, "Accept: */*");
1539  headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
1540 
1541  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
1542 
1543  // Create the form for new version
1544 #if LIBCURL_VERSION_MAJOR < 8
1545  struct curl_httppost* formpost = NULL;
1546  struct curl_httppost* lastptr = NULL;
1547  curl_formadd(&formpost,
1548  &lastptr,
1549  CURLFORM_COPYNAME, "tag",
1550  CURLFORM_COPYCONTENTS, tag.c_str(),
1551  CURLFORM_END);
1552 #else
1553  curl_mime* mime = curl_mime_init(curl);
1554  {
1555  curl_mimepart* part = curl_mime_addpart(mime);
1556  curl_mime_name(part, "tag");
1557  curl_mime_data(part, tag.c_str(), tag.size());
1558  }
1559 #endif
1560  if (endtime != 0) {
1561 #if LIBCURL_VERSION_MAJOR < 8
1562  curl_formadd(&formpost,
1563  &lastptr,
1564  CURLFORM_COPYNAME, "endtime",
1565  CURLFORM_COPYCONTENTS, std::to_string(endtime).c_str(),
1566  CURLFORM_END);
1567 #else
1568  std::string endtime_s = std::to_string(endtime);
1569  curl_mimepart* part = curl_mime_addpart(mime);
1570  curl_mime_name(part, "endtime");
1571  curl_mime_data(part, endtime_s.c_str(), endtime_s.size());
1572 #endif
1573  }
1574 #if LIBCURL_VERSION_MAJOR < 8
1575  curl_formadd(&formpost,
1576  &lastptr,
1577  CURLFORM_COPYNAME, "storeset",
1578  CURLFORM_COPYCONTENTS, js.c_str(),
1579  CURLFORM_CONTENTTYPE, "application/json",
1580  CURLFORM_END);
1581  curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
1582 #else
1583  {
1584  curl_mimepart* part = curl_mime_addpart(mime);
1585  curl_mime_name(part, "storeset");
1586  curl_mime_type(part, "application/json");
1587  curl_mime_data(part, js.c_str(), js.size());
1588  }
1589  curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
1590 #endif
1591 
1592  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_StdString);
1593  curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
1594 
1595  // Perform the request, res will get the return code
1596  res = curl_easy_perform(curl);
1597 
1598  // data to check the errors in the server response:
1599  long response_code;
1600  curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
1601  const char* method_name = "CrestClient::storeBatchPayloads";
1602 
1603  /* always cleanup */
1604  curl_easy_cleanup(curl);
1605 #if LIBCURL_VERSION_MAJOR < 8
1606  curl_formfree(formpost);
1607  curl_slist_free_all(headers);
1608 #else
1609  curl_slist_free_all(headers);
1610  curl_mime_free(mime);
1611 #endif
1612 
1613  curl_global_cleanup();
1614 
1615  // error checking in the server response:
1616  checkResult(res, response_code, s, method_name);
1617 
1618  return s;
1619  }
1620  std::string mes = "ERROR in CrestClient::storeBatchPayloads";
1621  throw std::runtime_error(mes + " | CURL not init");
1622  }
1623 
1624 
1625 // end of REQUEST METHODS
1626 
1627 //==============================
1628 // UTILITIES
1629 
1630 
1631  nlohmann::json CrestClient::getJson(const std::string& str, const char* method) {
1632  try {
1634  return js;
1635  }
1636  catch (nlohmann::json::parse_error& e) {
1637  if (method == nullptr || *method == '\0') {
1638  // method name is undefined
1639 
1640  std::string wh = e.what();
1641  throw std::runtime_error("ERROR in JSON conversion: " + wh + " | In string: " + str);
1642  } else {
1643  std::string str2 = ParseXMLOutput(str); // to remove HTML tags use this function
1644  std::string str3 = removeCR(str2); // to remove carridge return
1645  throw std::runtime_error("ERROR in " + std::string(method) + " | CREST Server response : " + str3);
1646  }
1647  }
1648  }
1649 
1651  return getJson(str, "");
1652  }
1653 
1654  // The auxillary method to remove XML/HTML tags from a std::string
1655 
1656  std::string CrestClient::ParseXMLOutput(std::string_view xmlBuffer) {
1657  bool copy = true;
1658 
1659  std::string plainString = "";
1660 
1661  // remove all xml tags
1662  for (long unsigned int i = 0; i < xmlBuffer.length(); i++) {
1663  char convertc = xmlBuffer[i];
1664 
1665  if (convertc == '<') copy = false;
1666  else if (convertc == '>') {
1667  copy = true;
1668  continue;
1669  }
1670 
1671  if (copy) plainString += convertc;
1672  }
1673 
1674  return plainString;
1675  }
1676 
1677  std::string CrestClient::removeCR(const std::string& str) {
1678  std::string str2 = str;
1679  std::replace(str2.begin(), str2.end(), '\n', '|');
1680  char needle = '\r';
1681  size_t pos;
1682  while ((pos = str2.find(needle)) != str2.npos) {
1683  str2.erase(pos, 1);
1684  }
1685  return str2;
1686  }
1687 
1688  bool CrestClient::isJson(const std::string& str) {
1689  try {
1691  return true;
1692  }
1693  catch (nlohmann::json::parse_error& e) {
1694  return false;
1695  }
1696  }
1697 
1698  void CrestClient::checkResult(CURLcode res, const long response_code, const std::string& st,
1699  const char* method_name) {
1700  // Bad HTTP response:
1701 
1702  if (res != CURLE_OK) {
1703  std::string mes = "ERROR in ";
1704  mes += method_name;
1705  mes += " | ";
1706  throw std::runtime_error(mes + std::to_string(response_code));
1707  }
1708 
1709  // Errors, decoded from JSON CREST Server messages:
1710 
1711  if (isJson(st)) {
1712  nlohmann::json respond = getJson(st);
1713  checkErrors(respond, method_name);
1714  }
1715 
1716  // HTTP response code error interval:
1717 
1718  if (response_code >= 400 || response_code == 303) {
1719  std::string s = ParseXMLOutput(st); // to remove HTML tags
1720  s = removeCR(s); // to remove end lines and carridge returns
1721  std::string mes = "ERROR in ";
1722  mes += method_name;
1723  mes += " | ";
1724  throw std::runtime_error(mes + "CREST Server response : " + s);
1725  }
1726  }
1727 
1728 //================================
1729 // METHODS FOR WORKING WITH THE DATA STORED in THE FILE SYSTEM STORAGE
1730 
1731 // UTILITIES
1732 
1733  std::string CrestClient::getFileString(const std::string& path) {
1734  std::ifstream ifs(path);
1735  return std::string((std::istreambuf_iterator<char>(ifs)),
1736  (std::istreambuf_iterator<char>()));
1737  }
1738 
1739  void CrestClient::getFileList(const std::string& path) {
1741  for (auto i = std::filesystem::directory_iterator(p); i != std::filesystem::directory_iterator(); i++) {
1742  std::string file = i->path().filename().string();
1743  if (file != "data") {
1744  std::cout << file << std::endl;
1745  } else continue;
1746  }
1747  }
1748 
1749  std::list<std::string> CrestClient::shortListTagsFs() {
1750  std::list<std::string> tag_list;
1752  for (auto i = std::filesystem::directory_iterator(p); i != std::filesystem::directory_iterator(); i++) {
1753  std::string file = i->path().filename().string();
1754 
1755  if (file != "data") {
1756  tag_list.push_back(file);
1757  } else continue;
1758  }
1759  return tag_list;
1760  }
1761 
1763  nlohmann::json js = nullptr;
1764  std::string file_path = m_root_folder;
1765  file_path += '/';
1767  file_path += '/';
1768  file_path += name;
1770  try{
1771  std::string tag = getFileString(file_path);
1772  js = nlohmann::json::parse(tag);
1773  }
1774  catch (...) {
1775  throw std::runtime_error("ERROR in CrestClient::findTagFs cannot get the tag information form file storage.");
1776  }
1777 
1778  return returnJArray(js);
1779  }
1780 
1782  nlohmann::json js = nullptr;
1783  std::string file_path = m_root_folder;
1784  file_path += '/';
1786  file_path += '/';
1787  file_path += tagname;
1789 
1790  try{
1791  std::string tag = getFileString(file_path);
1792  js = nlohmann::json::parse(tag);
1793  }
1794  catch (...) {
1795  throw std::runtime_error("ERROR in CrestClient::findAllIovsFs : cannot get the iov information form file storage");
1796  }
1797 
1798  return js;
1799  }
1800 
1801 // auxillary method to get a file name from hash
1802  std::string CrestClient::getFileName(const std::string& path) {
1803  int size = path.size();
1804  int pos = path.find(':');
1805 
1806  return path.substr(pos + 3, size);
1807  }
1808 
1809 // this is test only, later it will be deleted
1811  std::string line;
1812 
1813  std::ifstream in("./test-03.txt");
1814  std::ofstream fout("./copy.txt");
1815  if (in.is_open() && fout.is_open()) {
1816  while (getline(in, line)) {
1817  fout << line << std::endl;
1818  }
1819  }
1820  in.close();
1821  }
1822 
1823  //==========================================
1824  // storeBatchPayloadsFs methods
1825 
1826  void CrestClient::storeBatchPayloadsFs(const std::string& tag_name, std::string& iovsetupload) {
1827  const char* method_name = "CrestClient::storeBatchPayloadsFs";
1828 
1829  nlohmann::json js = getJson(iovsetupload, method_name);
1830  if (!js.is_array()) {
1831  throw std::runtime_error("ERROR in CrestClient::storeBatchPayloadsFs: JSON has wrong type (must be array");
1832  }
1833 
1834  storeBatchPayloadsFs(tag_name, js);
1835  }
1836 
1837  void CrestClient::storeBatchPayloadsFs(const std::string& tag_name, nlohmann::json& js) {
1838  const char* method_name = "CrestClient::storeBatchPayloadsFs";
1839 
1840  try {
1841  for (auto& kvp : js) {
1842  std::string payload = kvp.value("data", "");
1843  int since = kvp.value("since", 0);
1844  storePayloadDump(tag_name, since, payload);
1845  }
1846  } // end of try
1847  catch (...) {
1848  throw std::runtime_error("ERROR in " + std::string(method_name) + " cannot store the data in a file");
1849  } // end of catch
1850  flush();
1851  }
1852 
1853 
1854  // Auxillary methods:
1855 
1856  std::string CrestClient::getEnvA(const char* varname) {
1857  std::string respond = "";
1858 
1859  char* pPath;
1860  const char* c = varname;
1861  pPath = std::getenv(c);
1862  if (pPath != NULL) respond = std::string(pPath);
1863  return respond;
1864  }
1865 
1867  const char* varName = "DAT_PATH";
1868 
1869  std::string respond = getEnvA(varName);
1870  respond += "/data/crestapi";
1871 
1872  return respond;
1873  }
1874 
1875  int CrestClient::checkErrors(const nlohmann::json& js, const char* method) {
1876  int result = 0;
1877  auto res = js.find("type");
1878 
1879  // Old format parsing:
1880 
1881  if (res != js.end()) {
1882  std::string type = js.value("type", " unknown type ");
1883  if (type == "error" || type == "info") {
1884  std::string message = js.value("message", " unknown message ");
1885  throw std::runtime_error("ERROR in " + std::string(method) + " | CREST response: " + message);
1886  }
1887  }
1888 
1889  // New format parsing:
1890 
1891  auto r1 = js.find("error");
1892  auto r2 = js.find("message");
1893 
1894  if (r1 != js.end()) {
1895  std::string error = js.value("error", " unknown error ");
1896  if (r2 != js.end()) {
1897  std::string message = js.value("message", "");
1898  if (message == "") {
1899  throw std::runtime_error("ERROR in " + std::string(method) + " | CREST response: " + error);
1900  } else {
1901  throw std::runtime_error("ERROR in " + std::string(method) + " | CREST response: " + message);
1902  }
1903  }
1904  }
1905  return result;
1906  }
1907 
1908  void CrestClient::checkFsException(const char* method_name) {
1909  if (m_mode == FILESYSTEM_MODE) {
1910  throw std::runtime_error("ERROR in " + std::string(
1911  method_name) + " This methods is unsupported for FILESYSTEM mode");
1912  }
1913  return;
1914  }
1915 
1917  nlohmann::json js2 = getJson("[]");
1918  nlohmann::json result = js.value("resources", js2);
1919  return result;
1920  }
1921 
1923  nlohmann::json jNull = getJson("[]");
1924  nlohmann::json res = js.value("resources", jNull);
1926  try {
1927  result = res.at(0);
1928  }
1929  catch (...) {
1930  nlohmann::json result0 = nullptr;
1931  return result0;
1932  }
1933  return result;
1934  }
1935 
1936  std::string CrestClient::getTagMetaInfoElement(const std::string& name, nlohmann::json& js) {
1937  std::string result = "";
1938  int array_length = js.size();
1939  for (int i = 0; i < array_length; i++) {
1940  const nlohmann::json& elem = js[i];
1941  if (auto itr = elem.find(name); itr != elem.end()) {
1942  return *itr;
1943  }
1944  }
1945  return result;
1946  }
1947 
1949  std::string jsName = "tagInfo";
1950  const char* method_name = "CrestClient::convertTagMetaInfo2IOVDbSvc";
1951  nlohmann::json res = getJson(js[jsName], method_name);
1952  return res;
1953  }
1954 
1956  int colsize = 0;
1957 
1958  std::string tagInfo = js.dump();
1959 
1961  result["tagInfo"] = std::move(tagInfo);
1962  result["description"] = "none";
1963 
1964  std::string node_desc = js["node_description"];
1965  std::string payload_spec = js["payload_spec"];
1966  nlohmann::json chan_list = js["channel_list"];
1967  int chan_size = chan_list.size();
1968  result["chansize"] = chan_size;
1969 
1970  try{
1971  colsize = split(payload_spec, ',').size();
1972  }
1973  catch (...) {
1974  colsize = 0;
1975  }
1976 
1977  result["colsize"] = colsize;
1978 
1979  return result;
1980  }
1981 
1982  std::vector<std::string> CrestClient::split(std::string_view str, char delim) {
1983  std::vector<std::string> tokens;
1984  std::size_t prev = 0, pos = 0;
1985  do {
1986  pos = str.find(delim, prev);
1987  if (pos == std::string::npos) pos = str.length();
1988  std::string_view token = str.substr(prev, pos - prev);
1989  if (!token.empty()) tokens.emplace_back(token);
1990  prev = pos + 1;
1991  } while (pos < str.length() && prev < str.length());
1992  return tokens;
1993  }
1994 
1995  //====================================
1996  // Tag Meta Info Methods
1997 
1999  const char* method_name = "CrestClient::createTagMetaInfo";
2000 
2001  if (m_mode == FILESYSTEM_MODE) {
2002  createTagMetaInfoFs(js);
2003  return;
2004  }
2005 
2006  std::string tagname = "";
2007  try{
2008  tagname = static_cast<std::string> (js["tagName"]);
2009  }
2010  catch (...) {
2011  throw std::runtime_error(
2012  "ERROR in CrestClient::createTagMetaInfo cannot get the tag name from tag meta info JSON.");
2013  }
2014 
2015  std::string current_path = m_PATH;
2016  current_path += s_TAG_PATH;
2017  current_path += '/';
2018  current_path += tagname;
2019  current_path += s_META_PATH;
2020 
2021  std::string retv;
2022 
2023  retv = performRequest(current_path, POST, js, method_name);
2024 
2025  nlohmann::json respond = getJson(retv, method_name);
2026  }
2027 
2029  std::string name = js["tagName"];
2030  if (tagname != name) {
2031  throw std::runtime_error("ERROR in CrestClient::createTagMetaInfo tagname in method and in JSON are different.");
2032  }
2033  createTagMetaInfo(js);
2034  return;
2035  }
2036 
2038  const char* method_name = "CrestClient::getTagMetaInfo";
2039 
2040  if (m_mode == FILESYSTEM_MODE) {
2041  return getTagMetaInfoFs(tagname);
2042  }
2043 
2044  std::string current_path = m_PATH;
2045  current_path += s_TAG_PATH;
2046  current_path += '/';
2047  current_path += tagname;
2048  current_path += s_META_PATH;
2049 
2050  std::string retv;
2051 
2052  nlohmann::json js = nullptr;
2053  retv = performRequest(current_path, GET, js, method_name);
2054 
2055  nlohmann::json respond = getJson(retv, method_name);
2056 
2057  return getResources(respond);
2058  }
2059 
2061  const char* method_name = "CrestClient::updateTagMetaInfo";
2062 
2063  std::string tagname = "";
2064  try{
2065  tagname = static_cast<std::string> (js["tagName"]);
2066  }
2067  catch (...) {
2068  throw std::runtime_error(
2069  "ERROR in CrestClient::updateTagMetaInfo cannot get the tag name from tag meta info JSON.");
2070  }
2071 
2072 
2073  if (m_mode == FILESYSTEM_MODE) {
2075  return;
2076  }
2077 
2078  std::string current_path = m_PATH + s_TAG_PATH + '/' + tagname + s_META_PATH;
2079 
2080  std::string retv;
2081 
2082  retv = performRequest(current_path, PUT, js, method_name);
2083  }
2084 
2086  const char* method_name = "CrestClient::updateTagMetaInfo";
2087 
2088  if (m_mode == FILESYSTEM_MODE) {
2089  std::string name = "";
2090  try{
2091  name = static_cast<std::string> (js["tagName"]);
2092  }
2093  catch (...) {
2094  throw std::runtime_error(
2095  "ERROR in CrestClient::updateTagMetaInfo cannot get the tag name from tag meta info JSON.");
2096  }
2097 
2098  if (tagname != name) {
2099  throw std::runtime_error("ERROR in CrestClient::updateTagMetaInfo tagname in method and in JSON are different.");
2100  }
2101 
2103  return;
2104  }
2105 
2106  std::string current_path = m_PATH;
2107  current_path += s_TAG_PATH;
2108  current_path += '/';
2109  current_path += tagname;
2110  current_path += s_META_PATH;
2111 
2112  std::string retv;
2113 
2114  retv = performRequest(current_path, PUT, js, method_name);
2115  }
2116 
2117  //===============================================
2118  // Tag Meta Info Methods (IOVDbSvc format)
2119 
2121  const char* method_name = "CrestClient::updateTagMetaInfo";
2122 
2123  checkFsException(method_name);
2124 
2126 
2127  nlohmann::json resource = js.at(0);
2128 
2130 
2131  return result;
2132  }
2133 
2135  const char* method_name = "CrestClient::createTagMetaInfoIOVDbSvc";
2136 
2137  checkFsException(method_name);
2138 
2140  arg["tagName"] = tagname;
2141 
2143 
2144  return;
2145  }
2146 
2148  const std::string& description) {
2149  const char* method_name = "CrestClient::createTagMetaInfoIOVDbSvc";
2150 
2151  checkFsException(method_name);
2152 
2154  arg["tagName"] = tagname;
2155  arg["description"] = description;
2156 
2158 
2159  return;
2160  }
2161 
2162  //=====================================
2163  // Tag Meta Info methods for FS
2164 
2166  std::string name = "";
2167  try{
2168  name = static_cast<std::string> (js["tagName"]);
2169  }
2170  catch (...) {
2171  throw std::runtime_error(
2172  "ERROR in CrestClient::createTagMetaInfoFs cannot get the tag name from tag meta info JSON.");
2173  }
2174  std::string workDir = m_root_folder;
2175  workDir += s_FS_TAG_PATH;
2176 
2178  std::filesystem::create_directory(std::filesystem::path(workDir));
2179  }
2180 
2181  workDir += '/';
2182  workDir += name;
2183  std::string tagMetaFile = workDir;
2184  tagMetaFile += s_FS_TAGMETAINFO_FILE;
2185 
2187  std::filesystem::create_directory(std::filesystem::path(workDir));
2188  }
2189 
2190  if (m_isRewrite) {
2191  if (std::filesystem::exists(std::filesystem::path(tagMetaFile))) {
2193  }
2194 
2195  std::ofstream myfile;
2196 
2197  myfile.open(tagMetaFile.c_str());
2198  myfile << js;
2199  myfile.close();
2200  }
2201 
2202  return;
2203  }
2204 
2206  nlohmann::json js = nullptr;
2207  std::string file_path = m_root_folder;
2209  file_path += '/';
2210  file_path += name;
2212  try{
2213  std::string tag = getFileString(file_path);
2214  js = nlohmann::json::parse(tag);
2215  }
2216  catch (...) {
2217  throw std::runtime_error(
2218  "ERROR in CrestClient::getTagMetaInfoFs cannot get the tag meta information form file storage.");
2219  }
2220 
2221  return returnJArray(js);
2222  }
2223 
2225  // Check if JSON contains the correct tag name:
2226  auto it = js.find("tagName");
2227 
2228  if (it != js.end()) {
2229  if (js["tagName"] != tagname) {
2230  throw std::runtime_error("ERROR in CrestClient::updateTagMetaInfoFs: JSON contains wrong tag name.");
2231  }
2232  }
2233 
2234  nlohmann::json jstmp;
2235  try{
2236  jstmp = getTagMetaInfoFs(tagname);
2237  }
2238  catch (const std::exception& e) {
2239  throw std::runtime_error(
2240  "ERROR in CrestClient::updateTagMetaInfoFs: the file storage does not contain the tag meta info for the tag " + tagname +
2241  " .");
2242  }
2243 
2244  // Write all keys/values from new JSON to old one:
2245  for (auto it = js.begin(); it != js.end(); it++) {
2246  jstmp[it.key()] = it.value();
2247  }
2248 
2249  try{
2250  createTagMetaInfoFs(jstmp);
2251  }
2252  catch (const std::exception& e) {
2253  throw std::runtime_error(
2254  "ERROR in CrestClient::updateTagMetaInfoFs: cannot write the tag meta info for the tag " + tagname +
2255  " on file storage.");
2256  }
2257 
2258  return;
2259  }
2260 
2261  // Tag Meta Info methods for FS (end)
2262 
2263  //================================================
2264  // Global Tag and Global Tag Maps methods:
2265 
2267  std::string name = "";
2268  try{
2269  name = static_cast<std::string>(js["name"]);
2270  }
2271  catch (...) {
2272  throw std::runtime_error("ERROR in CrestClient::createGlobalTagFs: cannot get the global tag name from JSON.");
2273  }
2274 
2275  std::string gTagDir = m_root_folder;
2276  gTagDir += s_FS_GLOBALTAG_PATH;
2277  std::string workDir = gTagDir;
2278  workDir += '/';
2279  workDir += name;
2280  std::string globalTagFile = workDir;
2281  globalTagFile += s_FS_GLOBALTAG_FILE;
2282 
2283 
2285  std::filesystem::create_directory(std::filesystem::path(gTagDir));
2286  }
2287 
2289  std::filesystem::create_directory(std::filesystem::path(workDir));
2290  }
2291 
2292  if (m_isRewrite) {
2293  if (std::filesystem::exists(std::filesystem::path(globalTagFile))) {
2295  }
2296 
2297  std::ofstream myfile;
2298 
2299  myfile.open(globalTagFile.c_str());
2300  myfile << js;
2301  myfile.close();
2302  }
2303 
2304  return;
2305  }
2306 
2308  nlohmann::json js = nullptr;
2309 
2310  std::string workDir = m_root_folder;
2311  workDir += s_FS_GLOBALTAG_PATH;
2312  workDir += '/';
2313  workDir += name;
2314  std::string file_path = workDir;
2316 
2317  try{
2318  std::string tag = getFileString(file_path);
2319  js = nlohmann::json::parse(tag);
2320  }
2321  catch (...) {
2322  throw std::runtime_error(
2323  "ERROR in CrestClient::getGlobalTagFs: cannot get the global tag " + name + " form the file storage.");
2324  }
2325 
2326  return returnJArray(js);
2327  }
2328 
2330  // global tag name:
2331  std::string name = "";
2332  try{
2333  name = static_cast<std::string>(js["globalTagName"]);
2334  }
2335  catch (...) {
2336  throw std::runtime_error("ERROR in CrestClient::createGlobalTagMapFs: cannot get the global tag name from JSON.");
2337  }
2338 
2339  // tag name:
2340  std::string tagname = "";
2341  try{
2342  tagname = static_cast<std::string>(js["tagName"]);
2343  }
2344  catch (...) {
2345  throw std::runtime_error("ERROR in CrestClient::createGlobalTagMapFs: cannot get the tag name from JSON.");
2346  }
2347 
2348  std::string fname = "/";
2349  fname += tagname;
2350  fname += ".json";
2351 
2352 
2353  std::string gTagDir = m_root_folder + s_FS_GLOBALTAG_PATH;
2354  std::string workDir = gTagDir;
2355  workDir += '/';
2356  workDir += name;
2357 
2358 
2360  std::filesystem::create_directory(std::filesystem::path(workDir));
2361  }
2362 
2364  std::filesystem::create_directory(std::filesystem::path(workDir));
2365  }
2366 
2367 
2368  std::string catalogFile = workDir + s_FS_MAP_FILE;
2369 
2371  // cathalogue file exists:
2372 
2373  std::string array_lst = getFileString(catalogFile);
2374  nlohmann::json cathalogue = getJson(array_lst, "CrestClient::createGlobalTagMapFs");
2375 
2377  // the file storage contains the record of the global tag map:
2378  int m = cathalogue.size();
2379  for (int i = 0; i < m; i++) {
2380  const std::string& tn = cathalogue[i]["tagName"];
2381  if (tn == tagname) {
2382  cathalogue.erase(i);
2383  }
2384  }
2385  } else {
2386  // the file storage does not contain the record of the global tag map:
2387  }
2389  cathalogue.push_back(js);
2390  std::ofstream myfile;
2391 
2392  myfile.open(catalogFile.c_str());
2393  myfile << cathalogue;
2394  myfile.close();
2395  } else {
2396  // cathalogue file does not exist (creation):
2397 
2398  nlohmann::json cathalogue = nlohmann::json::array();
2399  cathalogue.push_back(js);
2400 
2401  std::ofstream myfile;
2402 
2403  myfile.open(catalogFile.c_str());
2404  myfile << cathalogue;
2405  myfile.close();
2406  }
2407 
2408 
2409  return;
2410  }
2411 
2413  nlohmann::json js = nullptr;
2414 
2415  std::string workDir = m_root_folder + s_FS_GLOBALTAG_PATH;
2416  std::string file_path = workDir;
2417  file_path += '/';
2418  file_path += name;
2420 
2421  try{
2422  std::string tag = getFileString(file_path);
2423  js = nlohmann::json::parse(tag);
2424  }
2425  catch (...) {
2426  throw std::runtime_error(
2427  "ERROR in CrestClient::getGlobalTagMapFs: cannot get the global tag map " + name +
2428  " form the file storage.");
2429  }
2430 
2431  return js;
2432  }
2433 
2434  // Global Tag and Global Tag Maps methods (end)
2435 
2436 
2437  //=====================================
2438  // Store Payload FS methods:
2439 
2440 
2441  std::string CrestClient::getHash(std::string_view str) {
2442  std::string hash_hex_str = picosha2::hash256_hex_string(str.begin(), str.end());
2443  return hash_hex_str;
2444  }
2445 
2446  void CrestClient::storePayloadDump(const std::string& tag, uint64_t since, const std::string& js) {
2447  std::ofstream myfile;
2448 
2449  // payload file:
2450  std::string hashCode = getHash(js);
2451  std::string workDir = m_data_folder;
2452  workDir += '/';
2453  workDir += getFirstLetters(hashCode);
2455  std::filesystem::create_directory(std::filesystem::path(workDir));
2456  }
2457  workDir += '/';
2458  workDir += hashCode;
2460  std::filesystem::create_directory(std::filesystem::path(workDir));
2461  }
2462 
2463  std::string tagFile = workDir + "/payload.json";
2464 
2465  myfile.open(tagFile);
2466  myfile << js;
2467  myfile.close();
2468 
2469  /*
2470  // meta info data example:
2471  {
2472  "hash": "9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0",
2473  "insertionTime": "2020-12-08",
2474  "objectType": "JSON",
2475  "size": 3,
2476  "streamerInfo":
2477  "eyJmaWxlbmFtZSI6Ijk4MzQ4NzZkY2ZiMDVjYjE2N2E1YzI0OTUzZWJhNThjNGFjODliMWFkZjU3ZjI4ZjJmOWQwOWFmMTA3ZWU4ZjAiLCJmb3JtYXQiOiJKU09OIiwiaW5zZXJ0aW9uRGF0ZSI6IlR1ZSBEZWMgMDggMTE6MTg6NTAgR01UIDIwMjAifQ==",
2478  "version": "default"
2479  }
2480  */
2481 
2482  nlohmann::json jsn =
2483  {
2484  {"hash", hashCode},
2485  {"objectType", "JSON"},
2486  {"version", "default"},
2487  {"size", js.size()},
2488  {"streamerInfo", "none"},
2489  {"insertionTime", getDateAndTime()}
2490  };
2491 
2492 
2493  // payload meta info file:
2494  std::string metaFile = workDir + "/meta.json";
2495 
2496  myfile.open(metaFile);
2497  myfile << jsn.dump();
2498  myfile.close();
2499 
2500  // check if data exists
2501 
2502  if (m_data.find(tag) == m_data.end()) {
2503  try{
2505  m_data.insert(std::pair<std::string, nlohmann::json>(tag, jsi));
2506  }
2507  catch (...) {
2508  try { // tag exists, but there are no IOVs
2509  nlohmann::json tagJS = findTag(tag);
2511  m_data.insert(std::pair<std::string, nlohmann::json>(tag, jsFree));
2512  }
2513  catch (...) {
2514  throw std::runtime_error(
2515  "ERROR in CrestClient::storePayloadDump cannot get data for tag \"" + tag + "\" from file storage.");
2516  }
2517  }
2518  }
2519 
2521  if (it != m_data.end()) {
2522  std::string link = hashCode;
2523  nlohmann::json iovs = it->second;
2525  obj["tagName"] = tag;
2526  obj["since"] = since;
2527  obj["insertionTime"] = 0;
2528  obj["payloadHash"] = link;
2529  iovs.push_back(obj);
2530  m_data[it->first] = iovs;
2531  }
2532  }
2533 
2535  time_t now = time(0);
2536  struct tm tstruct;
2537  char buf[80];
2538 
2539  localtime_r(&now, &tstruct);
2540  strftime(buf, sizeof(buf), "%Y-%m-%d %X", &tstruct);
2541  return buf;
2542  }
2543 
2544  //==========================================
2545  // Payload methods for File Storage
2546 
2547  std::string CrestClient::getPayloadAsStringFS(const std::string& hash) {
2548  std::string workDir = m_data_folder;
2549  workDir += '/';
2550  workDir += getFirstLetters(hash);
2551  workDir += '/';
2552  workDir += hash;
2553  std::string filePath = workDir + "/payload.json";
2554  std::string res = "";
2555 
2556  try{
2558  }
2559  catch (...) {
2560  throw std::runtime_error("ERROR in CrestClient::getPayloadAsStringFS cannot get the payload form file storage.");
2561  }
2562 
2563  return res;
2564  }
2565 
2567  std::string res = getPayloadAsStringFS(hash);
2568  nlohmann::json respond = getJson(res, "getPayloadAsJsonFS");
2569  return respond;
2570  }
2571 
2572  std::string CrestClient::getPayloadMetaInfoAsStringFS(const std::string& hash) {
2573  std::string workDir = m_data_folder;
2574  workDir += '/';
2575  workDir += getFirstLetters(hash);
2576  workDir += '/';
2577  workDir += hash;
2578 
2579  std::string filePath = workDir;
2580  filePath += "/meta.json";
2581 
2582  std::string res = "";
2583 
2584  try{
2586  }
2587  catch (...) {
2588  throw std::runtime_error("ERROR in CrestClient::getPayloadAsStringFS cannot get the payload form file storage.");
2589  }
2590 
2591  return res;
2592  }
2593 
2595  std::string res = getPayloadMetaInfoAsStringFS(hash);
2596  nlohmann::json respond = getJson(res, "getPayloadAsJsonFS");
2597  return returnJArray(respond);
2598  }
2599 
2600  std::string CrestClient::getBlobFs(const std::string& hash) {
2601  try{
2602  std::string str = getPayloadAsStringFS(hash);
2603  return str;
2604  }
2605  catch (...) {
2606  throw std::runtime_error("ERROR in CrestClient::getBlobFs : cannot get the blob information form file storage");
2607  }
2608  }
2609 
2610  std::string CrestClient::getBlobInStreamFs(const std::string& hash, std::ofstream& out) {
2611  std::string line;
2612  std::string str = "";
2613 
2614  std::string workDir = m_data_folder;
2615  workDir += '/';
2616  workDir += getFirstLetters(hash);
2617  workDir += '/';
2618  workDir += hash;
2619 
2620  std::string file_path = workDir;
2621  file_path += "/payload.json";
2622 
2623  std::ifstream in(file_path);
2624 
2625  if (in.is_open() && out.is_open()) {
2626 
2627  while (getline(in, line)) {
2628  out << line << std::endl;
2629  }
2630  } else {
2631  throw std::runtime_error(
2632  "ERROR in CrestClient::getBlobInStreamFs : cannot get the blob information form file storage");
2633  }
2634  in.close();
2635 
2636  return str;
2637  }
2638 
2641  result.push_back(js);
2642  return result;
2643  }
2644 
2645  int CrestClient::getSizeFS(const std::string& tagname) {
2646  int res = 0;
2647 
2648  try {
2650  int length = iovs.size();
2651  return length;
2652  }
2653  catch (...) {
2654  return res;
2655  }
2656 
2657  return res;
2658  }
2659 
2660  //==========================================
2661  // IOV List Methods for File Storage
2662 
2663 
2666  int dataSize = getSizeFS(tagname);
2667 
2668  if (dataSize == 0) return js; // the data is absent
2669 
2670  // index interval to load the data from JSON array:
2671  int kmin = size * page;
2672  int kmax = size * (page + 1);
2673 
2674  // check if the interval is correct:
2675  if (kmin > dataSize - 1) return js; // out of range
2676 
2677  if (kmax > dataSize - 1) { // this step is not full
2678  kmax = dataSize;
2679  }
2680 
2682 
2683  for (int i = kmin; i < kmax; i++) {
2684  js.push_back(data[i]);
2685  }
2686  return js;
2687  }
2688 
2689  nlohmann::json CrestClient::selectIovsFS(const std::string& tagname, long since, long until) {
2691 
2692  try{
2694  int niovs = iovList.size();
2695  for (int i = 0; i < niovs; i++) {
2696  if (iovList[i].find("since") != iovList[i].end()) {
2697  ;
2698  long currentS = iovList[i]["since"];
2699  if (currentS >= since && currentS <= until) {
2700  js.push_back(iovList[i]);
2701  }
2702  }
2703  }
2704  }
2705  catch (...) {
2706  throw std::runtime_error("ERROR in CrestClient::selectIovsFS : cannot get the iov list form file storage");
2707  }
2708 
2709  return js;
2710  }
2711 
2712  void CrestClient::getTagDataInfo(const std::string& tagname) {
2713  std::cout << std::endl << "test: getTagDataInfo" << std::endl;
2714 
2715  try {
2716  int info = getSizeFS(tagname);
2717  std::cout << std::endl << "IOV Number (" << tagname << ") = "
2718  << info << std::endl;
2719  }
2720  catch (const std::exception& e) {
2721  std::cout << std::endl << "test: getTagDataInfo (failed)" << std::endl;
2722  std::cout << e.what() << std::endl;
2723  }
2724 
2725  try {
2727  int niovs = iovList.size();
2728  std::list <std::string> hashList;
2729 
2730  for (int i = 0; i < niovs; i++) {
2731  if (iovList[i].find("payloadHash") != iovList[i].end()) {
2732  std::string hash = iovList[i]["payloadHash"];
2733  std :: list < std::string > :: iterator pos;
2734  pos = find(hashList.begin(), hashList.end(), hash);
2735  if (pos != hashList.end()) {
2736  } else {
2737  hashList.push_back(hash);
2738  }
2739  }
2740  }
2741 
2742  int hashNumber = hashList.size();
2743  std::cout << "Hash Number (" << tagname << ") = "
2744  << hashNumber << std::endl;
2745  }
2746  catch (const std::exception& e) {
2747  std::cout << std::endl << "ERROR getTagDataInfo: cannot get IOV List" << std::endl;
2748  std::cout << e.what() << std::endl;
2749  }
2750 
2751  std::string path = m_root_folder + s_FS_DATA_PATH;
2752  int dirNumber = 0;
2753 
2754  for (auto it : std::filesystem::directory_iterator(path)) {
2755  dirNumber = dirNumber + 1;
2756  }
2757  std::cout << "Directory Number (" << tagname << ") = "
2758  << dirNumber << std::endl;
2759  }
2760 
2761 
2762  std::string CrestClient::getFirstLetters(const std::string& str) {
2763  std::string result = str.substr(0, s_FS_PREFIX_LENGTH);
2764  return result;
2765  }
2766 
2768  const char* method_name = "getMgmtInfo";
2769 
2770  checkFsException(method_name);
2771 
2772  std::string current_path = s_MGMT_PATH + s_MGMT_INFO_PATH;
2773  std::string retv;
2774  nlohmann::json js = nullptr;
2775 
2776  retv = performRequest(current_path, GET, js, method_name);
2777 
2778  nlohmann::json respond = getJson(retv, method_name);
2779 
2780  return respond;
2781  }
2782 
2784  const char* method_name = "getCrestVersion";
2785  checkFsException(method_name);
2786 
2787  std::string version = "";
2789 
2790  auto subjectIdIter1 = info.find("build");
2791  if (subjectIdIter1 != info.end()){
2792  nlohmann::json build = info["build"];
2793  auto subjectIdIter2 = build.find("version");
2794  if (subjectIdIter2 != build.end()){
2795  version = build["version"];
2796  }
2797  else {
2798  throw std::runtime_error("ERROR in CrestClient::" + (std::string) method_name + ": CREST Server response has no \"version\" key.");
2799  } // iterator 2
2800 
2801  }
2802  else {
2803  throw std::runtime_error("ERROR in CrestClient::" + (std::string) method_name + ": CREST Server response has no \"build\" key.");
2804  } // iterator 1
2805 
2806  return version;
2807  }
2808 
2810  return s_CREST_CLIENT_VERSION;
2811  }
2812 
2814  int v = -1;
2815  int n = str.find('.');
2816 
2817  if (n < 1) {
2818  throw std::runtime_error("ERROR in CrestClient::getMajorVersion: string \"" + str + "\" does not contain major version.");
2819  }
2820 
2821  std::string vers = str.substr(0,n);
2822 
2823  try {
2824  v = std::stoi( str );
2825  }
2826  catch (const std::exception& e) {
2827  throw std::runtime_error("ERROR in CrestClient::getMajorVersion: string \"" + str + "\" does not contain major version.");
2828  }
2829 
2830  return v;
2831  }
2832 
2834  std::string client = getClientVersion();
2835  std::string server = getCrestVersion();
2836 
2837  int clientVersion = getMajorVersion(client);
2838  int serverVersion = getMajorVersion(server);
2839 
2840  if (clientVersion != serverVersion) {
2841  throw std::runtime_error("ERROR in CrestClient::checkCrestVersion: CrestApi version \"" + client + "\" does not correspond to the server version \"" + server + "\".");
2842  }
2843  }
2844 
2845  // V4 version:
2846 
2848  const char* method_name = "getMgmtInfo2";
2849 
2850  checkFsException(method_name);
2851 
2852  std::string current_path = s_MGMT_INFO_PATH_2;
2853  std::string retv;
2854  nlohmann::json js = nullptr;
2855 
2856  retv = performRequest(current_path, GET, js, method_name);
2857 
2858  nlohmann::json respond = getJson(retv, method_name);
2859 
2860  return respond;
2861  }
2862 
2864  const char* method_name = "getCrestVersion";
2865  checkFsException(method_name);
2866 
2867  std::string version = "";
2869 
2870  auto subjectIdIter1 = info.find("build");
2871  if (subjectIdIter1 != info.end()){
2872  nlohmann::json build = info["build"];
2873  auto subjectIdIter2 = build.find("version");
2874  if (subjectIdIter2 != build.end()){
2875  version = build["version"];
2876  }
2877  else {
2878  throw std::runtime_error("ERROR in CrestClient::" + (std::string) method_name + ": CREST Server response has no \"version\" key.");
2879  } // iterator 2
2880 
2881  }
2882  else {
2883  throw std::runtime_error("ERROR in CrestClient::" + (std::string) method_name + ": CREST Server response has no \"build\" key.");
2884  } // iterator 1
2885 
2886  return version;
2887  }
2888 
2890  std::string client = getClientVersion();
2891  std::string server = getCrestVersion2();
2892 
2893  int clientVersion = getMajorVersion(client);
2894  int serverVersion = getMajorVersion(server);
2895 
2896  if (clientVersion != serverVersion) {
2897  throw std::runtime_error("ERROR in CrestClient::checkCrestVersion: CrestApi version \"" + client + "\" does not correspond to the server version \"" + server + "\".");
2898  }
2899  }
2900 
2901 
2902  void CrestClient::removeTagFromGlobalTagMap(const std::string& global_tag,const std::string& tag,const std::string& label){
2903 
2904  const char* method_name = "CrestClient::removeTagFromGlobalTagMap";
2905 
2906  checkFsException(method_name);
2907 
2908  std::string current_path = m_PATH;
2909  current_path += s_GLOBALTAG_MAP_PATH;
2910  current_path += '/';
2911  current_path += global_tag;
2912  current_path += '?';
2913  current_path += "tagname=";
2914  current_path += tag;
2915  current_path += "&label=";
2916  current_path += label;
2917 
2918  std::string retv;
2919 
2920  nlohmann::json js = nullptr;
2921 
2922  retv = performRequest(current_path, DELETE, js, method_name);
2923  }
2924 
2925  void CrestClient::storeBatchPayloadsFiles(const std::string& tag_name, uint64_t endtime, nlohmann::json& js) {
2926  const char* method_name = "CrestClient::storeBatchPayloads";
2927 
2928  if (m_mode == FILESYSTEM_MODE) {
2929  storeBatchPayloadsFs(tag_name, js);
2930  return;
2931  }
2932  if (!js.is_array()) {
2933  throw std::runtime_error("ERROR in " + std::string(method_name) + " JSON has wrong type (must be array)");
2934  }
2935 
2936  nlohmann::json jsObj = {};
2937  jsObj["datatype"] = "iovs";
2938  jsObj["format"] = "StoreSetDto";
2939  jsObj["size"] = js.size();
2940  jsObj["resources"] = js;
2941  std::string str = jsObj.dump();
2942  std::string retv = storeBatchPayloadFilesRequest(tag_name, endtime, str);
2943 
2944  nlohmann::json respond = getJson(retv, method_name);
2945  }
2946 
2947 
2948  std::string CrestClient::storeBatchPayloadFilesRequest(const std::string& tag, uint64_t endtime, const std::string& js) {
2949  std::string current_path = m_PATH;
2950  current_path += s_PAYLOAD_PATH;
2951 
2952  nlohmann::json json0 = getJson(js);
2953  nlohmann::json resources = nullptr;
2954 
2955  auto subjectIdIter1 = json0.find("resources");
2956  if (subjectIdIter1 != json0.end()){
2957  resources = json0["resources"];
2958  }
2959 
2960  int partN = resources.size();
2961 
2962  CURL* curl;
2963  CURLcode res;
2964 
2965  // get a curl handle
2966 
2967  curl_global_init(CURL_GLOBAL_DEFAULT);
2968  curl = curl_easy_init();
2969 
2970  struct curl_slist* headers = NULL;
2971  if (curl) {
2972  std::string url = make_url(current_path);
2973  std::string s;
2974 
2975  if (m_CREST_PROXY) {
2976  // The environment variable exists, and 'socksProxy' now contains its value
2977  std::cout << "SOCKS proxy: " << m_CREST_PROXY << std::endl;
2978  // Set the proxy type (replace with your proxy type details)
2979  curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
2980 
2981  // Set the proxy address and port (replace with your SOCKS proxy details)
2982  curl_easy_setopt(curl, CURLOPT_PROXY, m_CREST_PROXY);
2983  }
2984 
2985  // First set the URL that is about to receive our POST. This URL can
2986  // just as well be a https:
2987  // URL if that is what should receive the data.
2988 
2989  curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
2990 
2991  headers = curl_slist_append(headers, "X-Crest-PayloadFormat: FILE"); // MvG
2992  headers = curl_slist_append(headers, "Accept: */*");
2993  headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
2994 
2995  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
2996 
2997  // Create the form for new version
2998 #if LIBCURL_VERSION_MAJOR < 8
2999  struct curl_httppost* formpost = NULL;
3000  struct curl_httppost* lastptr = NULL;
3001  curl_formadd(&formpost,
3002  &lastptr,
3003  CURLFORM_COPYNAME, "tag",
3004  CURLFORM_COPYCONTENTS, tag.c_str(),
3005  CURLFORM_END);
3006 #else
3007  curl_mime* mime = curl_mime_init(curl);
3008  {
3009  curl_mimepart* part = curl_mime_addpart(mime);
3010  curl_mime_name(part, "tag");
3011  curl_mime_data(part, tag.c_str(), tag.size());
3012  }
3013 #endif
3014  if (endtime != 0) {
3015 #if LIBCURL_VERSION_MAJOR < 8
3016  curl_formadd(&formpost,
3017  &lastptr,
3018  CURLFORM_COPYNAME, "endtime",
3019  CURLFORM_COPYCONTENTS, std::to_string(endtime).c_str(),
3020  CURLFORM_END);
3021 #else
3022  std::string endtime_s = std::to_string(endtime);
3023  curl_mimepart* part = curl_mime_addpart(mime);
3024  curl_mime_name(part, "endtime");
3025  curl_mime_data(part, endtime_s.c_str(), endtime_s.size());
3026 #endif
3027  }
3028 #if LIBCURL_VERSION_MAJOR < 8
3029  curl_formadd(&formpost,
3030  &lastptr,
3031  CURLFORM_COPYNAME, "storeset",
3032  CURLFORM_COPYCONTENTS, js.c_str(),
3033  CURLFORM_END);
3034 
3035  for (int i = 0; i < partN; i++){
3036  nlohmann::json element = resources[i];
3037  std::string file_param;
3038 
3039  auto subjectIdIter1 = element.find("data");
3040  if (subjectIdIter1 != element.end()){
3041  file_param = element["data"];
3042  }
3043 
3044  int found_dots = file_param.find_first_of(':');
3045  int word_size = file_param.size();
3046  std::string data_file = file_param.substr(found_dots + 3, word_size);
3047 
3048  curl_formadd(&formpost, &lastptr,
3049  CURLFORM_COPYNAME, "files",
3050  CURLFORM_FILE, data_file.c_str(),
3051  CURLFORM_END);
3052 
3053  } // i
3054 
3055  curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
3056 #else
3057  {
3058  curl_mimepart* part = curl_mime_addpart(mime);
3059  curl_mime_name(part, "storeset");
3060  curl_mime_data(part, js.c_str(), js.size());
3061  }
3062 
3063  for (int i = 0; i < partN; i++){
3064  nlohmann::json element = resources[i];
3065  std::string file_param;
3066 
3067  auto subjectIdIter1 = element.find("data");
3068  if (subjectIdIter1 != element.end()){
3069  file_param = element["data"];
3070  }
3071 
3072  int found_dots = file_param.find_first_of(':');
3073  int word_size = file_param.size();
3074  std::string data_file = file_param.substr(found_dots + 3, word_size);
3075 
3076  {
3077  curl_mimepart* part = curl_mime_addpart(mime);
3078  curl_mime_name(part, "files");
3079  curl_mime_filedata(part, data_file.c_str());
3080  }
3081 
3082  } // i
3083 
3084  curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
3085 #endif
3086 
3087  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_StdString);
3088  curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
3089 
3090  // Perform the request, res will get the return code
3091  res = curl_easy_perform(curl);
3092 
3093  // data to check the errors in the server response:
3094  long response_code;
3095  curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
3096  const char* method_name = "CrestClient::storeBatchPayloads";
3097 
3098  /* always cleanup */
3099  curl_easy_cleanup(curl);
3100 #if LIBCURL_VERSION_MAJOR < 8
3101  curl_formfree(formpost);
3102  curl_slist_free_all(headers);
3103 #else
3104  curl_slist_free_all(headers);
3105  curl_mime_free(mime);
3106 #endif
3107 
3108  curl_global_cleanup();
3109 
3110  // error checking in the server response:
3111  checkResult(res, response_code, s, method_name);
3112 
3113  return s;
3114  }
3115  std::string mes = "ERROR in CrestClient::storeBatchPayloads";
3116  throw std::runtime_error(mes + " | CURL not init");
3117  }
3118 
3119  void CrestClient::storeData(const std::string& tag, uint64_t endtime, uint64_t since, const std::string& file){
3120  const char* method_name = "CrestClient::storePayloadAsFile";
3121  checkFsException(method_name);
3122  std::string d = "file://" + file;
3123 
3124  std::string str = "[{\"data\":\"" + d + "\",\"since\":" + std::to_string(since) + "}]";
3125  nlohmann::json js = getJson(str);
3126 
3127  storeBatchPayloadsFiles(tag, endtime, js);
3128  }
3129 
3130  void CrestClient::storeDataArray(const std::string& tag, uint64_t endtime, std::map<uint64_t, std::string> m){
3131  nlohmann::json payload_data = nlohmann::json::array();
3132 
3133  std::map<uint64_t, std::string> :: iterator it;
3134  for(it=m.begin();it !=m.end();++it){
3135  std::string file_name = "file://" + it->second;
3136 
3137  nlohmann::json js_element =
3138  {
3139  {"since", it->first},
3140  {"data", file_name}
3141  };
3142 
3143  payload_data.push_back(js_element);
3144  }
3145 
3146  storeBatchPayloadsFiles(tag, endtime, payload_data);
3147  }
3148 
3150  char * val = getenv( m_CREST_PROXY_VAR );
3151  if (val != NULL){
3152  m_CREST_PROXY = val;
3153  }
3154  }
3155 
3156  void CrestClient::replaceSymbols(std::string& subject, const std::string& search,
3157  const std::string& replace) {
3158  size_t pos = 0;
3159  while((pos = subject.find(search, pos)) != std::string::npos) {
3160  subject.replace(pos, search.length(), replace);
3161  pos += replace.length();
3162  }
3163  }
3164 
3165 } // namespace
RunTileTBRec.method
method
Definition: RunTileTBRec.py:73
grepfile.info
info
Definition: grepfile.py:38
Crest::CrestClient::checkFsException
void checkFsException(const char *method_name)
Auxillary method to check if the CrestApi library initialized to work with the file system.
Definition: CrestApi.cxx:1908
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
Crest::CrestClient::getPayloadAsJsonFS
nlohmann::json getPayloadAsJsonFS(const std::string &hash)
This auxillary method finds a payload resource associated to the hash in the local file storage.
Definition: CrestApi.cxx:2566
Crest::CrestClient::s_TAG_PATH
static const std::string s_TAG_PATH
Definition: CrestApi.h:77
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
Crest::CrestClient::m_root_folder
std::string m_root_folder
Definition: CrestApi.h:68
Crest::CrestClient::isJson
bool isJson(const std::string &str)
This method checks if a string is in the JSON format.
Definition: CrestApi.cxx:1688
Crest::CrestClient::getBlob
std::string getBlob(const std::string &hash)
This method finds payload data by hash; the payload object contains the real BLOB.
Definition: CrestApi.cxx:915
Crest::CrestClient::getFileName
std::string getFileName(const std::string &path)
Auxillary method to extract the file name from iov hash (the hash is a path in the file storage).
Definition: CrestApi.cxx:1802
covarianceTool.headers
headers
Definition: covarianceTool.py:537
Crest::CrestClient::s_FS_IOV_FILE
static const std::string s_FS_IOV_FILE
Definition: CrestApi.h:106
Crest::CrestClient::getBlobInStreamFs
std::string getBlobInStreamFs(const std::string &hash, std::ofstream &out)
This method finds payload data by hash; the payload object contains the real BLOB.
Definition: CrestApi.cxx:2610
Crest::CrestClient::m_currentTag
std::string m_currentTag
Definition: CrestApi.h:72
Crest::CrestClient::selectIovs
nlohmann::json selectIovs(const std::string &tagname)
Select iovs for a given tagname.
Definition: CrestApi.cxx:493
checkFileSG.line
line
Definition: checkFileSG.py:75
Crest::CrestClient::findGlobalTagMapFs
nlohmann::json findGlobalTagMapFs(const std::string &name)
The auxillary method to find a global tag by name for the file storage.
Definition: CrestApi.cxx:2412
Crest::CrestClient::findAllIovs
nlohmann::json findAllIovs(const std::string &tagname)
This method finds all iovs for a given tag name.
Definition: CrestApi.cxx:390
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Crest::CrestClient::s_MGMT_INFO_PATH
static const std::string s_MGMT_INFO_PATH
Definition: CrestApi.h:121
Crest::CrestClient::m_mode
int m_mode
Definition: CrestApi.h:67
Crest::CrestClient::m_CREST_PROXY_VAR
const char * m_CREST_PROXY_VAR
Definition: CrestApi.h:76
get_generator_info.result
result
Definition: get_generator_info.py:21
dqt_zlumi_alleff_HIST.iov
iov
Definition: dqt_zlumi_alleff_HIST.py:119
header
Definition: hcg.cxx:526
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Crest::CrestClient::getTagDataInfo
void getTagDataInfo(const std::string &tagname)
This is an auxillary method for checking how many unique IOVs(hashcodes) are in an IOV list.
Definition: CrestApi.cxx:2712
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
Crest::CrestClient::getProxyPath
void getProxyPath()
Definition: CrestApi.cxx:3149
Crest::CrestClient::getDateAndTime
std::string getDateAndTime()
The auxillary method to get a current data and time.
Definition: CrestApi.cxx:2534
Crest::CrestClient::createTagMetaInfoIOVDbSvc
void createTagMetaInfoIOVDbSvc(const std::string &tagname, nlohmann::json &js)
This method creates a tag meta info in the CREST database.
Definition: CrestApi.cxx:2134
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Crest::CrestClient::getPayloadMetaInfoAsJsonFS
nlohmann::json getPayloadMetaInfoAsJsonFS(const std::string &hash)
This auxillary method finds a payload resource associated to the hash in the local file storage.
Definition: CrestApi.cxx:2594
Crest::CrestClient::getJson
nlohmann::json getJson(const std::string &str)
Auxillary method to convert string in to JSON object.
Definition: CrestApi.cxx:1650
json
nlohmann::json json
Definition: HistogramDef.cxx:9
Crest::CrestClient::createTag
void createTag(nlohmann::json &js)
This method creates a tag in the CREST database.
Definition: CrestApi.cxx:262
Crest::CrestClient::getFileString
std::string getFileString(const std::string &path)
Auxillary method to get a file as a string.
Definition: CrestApi.cxx:1733
response
MDT_Response response
Definition: MDT_ResponseTest.cxx:28
Crest::CrestClient::s_ADMIN_PATH
static const std::string s_ADMIN_PATH
Definition: CrestApi.h:78
find_tgc_unfilled_channelids.iovs
iovs
Definition: find_tgc_unfilled_channelids.py:12
Crest::CrestClient::s_FS_TAGMETAINFO_FILE
static const std::string s_FS_TAGMETAINFO_FILE
Definition: CrestApi.h:107
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
Crest::CrestClient::getBlobInStream
std::string getBlobInStream(const std::string &hash, std::ofstream &out)
This method finds payload data by hash; the payload object contains the real BLOB.
Definition: CrestApi.cxx:936
hist_file_dump.d
d
Definition: hist_file_dump.py:137
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
Crest::CrestClient::findTagFs
nlohmann::json findTagFs(const std::string &name)
This method finds a tag by the tag name in the file storage.
Definition: CrestApi.cxx:1762
Crest::CrestClient::m_data
std::map< std::string, nlohmann::json > m_data
Definition: CrestApi.h:70
Crest::CrestClient::getTagMetaInfo
nlohmann::json getTagMetaInfo(const std::string &tagname)
This method gets a tag meta info from the CREST database.
Definition: CrestApi.cxx:2037
Crest::CrestClient::findGlobalTagMap
nlohmann::json findGlobalTagMap(const std::string &name)
This method search for mappings using the global tag name.
Definition: CrestApi.cxx:849
Crest::CrestClient::s_IOV_PATH
static const std::string s_IOV_PATH
Definition: CrestApi.h:79
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:983
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
Crest::CrestClient::createGlobalTag
void createGlobalTag(nlohmann::json &js)
Create a global tag in the database.
Definition: CrestApi.cxx:688
picosha2::hash256_hex_string
void hash256_hex_string(InIter first, InIter last, std::string &hex_str)
Definition: picosha2.h:353
Crest::CrestClient::s_FS_TAG_PATH
static const std::string s_FS_TAG_PATH
Definition: CrestApi.h:101
Crest::CrestClient::findRunLumiInfo
nlohmann::json findRunLumiInfo(const urlParameters &params)
Finds a run/lumi information lists using parameters.
Definition: CrestApi.cxx:1228
Crest::CrestClient::s_METHOD_IOVS
static const std::string s_METHOD_IOVS
Definition: CrestApi.h:94
skel.it
it
Definition: skel.GENtoEVGEN.py:423
Crest::CrestClient::PUT
@ PUT
Definition: CrestApi.h:129
Crest::CrestClient::selectIovsFS
nlohmann::json selectIovsFS(const std::string &tagname, long since, long until)
This method selects all iovs for a given tag name and for the selected time interval (since-until).
Definition: CrestApi.cxx:2689
Crest::CrestClient::storeData
void storeData(const std::string &tag, uint64_t endtime, uint64_t since, const std::string &file)
This method stores a payload from a file in the database, associated to a given IOV since and tag nam...
Definition: CrestApi.cxx:3119
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
Crest::CrestClient::s_GLOBALTAG_MAP_PATH
static const std::string s_GLOBALTAG_MAP_PATH
Definition: CrestApi.h:84
Crest::CrestClient::getTagMetaInfoElement
std::string getTagMetaInfoElement(const std::string &name, nlohmann::json &js)
Auxillary method to get an element by name from the Tag Meta Info.
Definition: CrestApi.cxx:1936
Crest::CrestClient::getSize
int getSize(const std::string &tagname)
This metghod gets the number of iovs for the given tag.
Definition: CrestApi.cxx:454
get_generator_info.build
build
Definition: get_generator_info.py:33
python.sizes.txt
string txt
Definition: sizes.py:141
Crest::CrestClient::streamTest
void streamTest()
this is test only, later it will be deleted (The old method name is streamtest)
Definition: CrestApi.cxx:1810
Crest::CrestClient::FILESYSTEM_MODE
@ FILESYSTEM_MODE
Definition: CrestApi.h:126
Crest::CrestClient::m_host
std::string m_host
Definition: CrestApi.h:65
Crest::CrestClient::findGlobalTag
nlohmann::json findGlobalTag(const std::string &name)
Finds a global tag by name.
Definition: CrestApi.cxx:745
Crest::CrestClient::m_PATH
std::string m_PATH
Definition: CrestApi.h:74
LArConditionsTestConfig.catalogFile
catalogFile
Definition: LArConditionsTestConfig.py:83
WriteCaloSwCorrections.tag_list
tag_list
Definition: WriteCaloSwCorrections.py:28
Crest::CrestClient::getHash
std::string getHash(std::string_view str)
The auxillary method to calculate a hash code for a given string.
Definition: CrestApi.cxx:2441
Crest::CrestClient::listGlobalTags
nlohmann::json listGlobalTags()
This method finds a global tag lists.
Definition: CrestApi.cxx:773
Crest::CrestClient::updateGlobalTag
void updateGlobalTag(const std::string &name, nlohmann::json body)
This method allows to update a GlobalTag.Arguments: the name has to uniquely identify a global tag.
Definition: CrestApi.cxx:672
Crest::CrestClient::POST
@ POST
Definition: CrestApi.h:129
Crest::CrestClient::DELETE
@ DELETE
Definition: CrestApi.h:129
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
Crest::CrestClient::checkCrestVersion2
void checkCrestVersion2()
This method is a CREST version test.
Definition: CrestApi.cxx:2889
Crest::CrestClient::performRequest
std::string performRequest(const std::string &current_path, Action action, nlohmann::json &js)
General auxiliary method to make request to the CREST Server.
Definition: CrestApi.cxx:1366
Crest::CrestClient::getPayloadMetaInfo
nlohmann::json getPayloadMetaInfo(const std::string &hash)
This method finds a payload resource associated to the hash.
Definition: CrestApi.cxx:956
Crest::CrestClient::storeDataArray
void storeDataArray(const std::string &tag, uint64_t endtime, std::map< uint64_t, std::string > m)
This method stores several payloads from files in batch mode.
Definition: CrestApi.cxx:3130
Crest
Definition: CrestApi.h:29
Crest::CrestClient::s_RUNINFO_PATH
static const std::string s_RUNINFO_PATH
Definition: CrestApi.h:91
Crest::CrestClient::~CrestClient
~CrestClient()
Definition: CrestApi.cxx:86
Crest::CrestClient::updateTagMetaInfoFs
void updateTagMetaInfoFs(const std::string &tagname, nlohmann::json &js)
This auxillary method updates a tag meta info in local file storage.
Definition: CrestApi.cxx:2224
Crest::CrestClient::getTagMetaInfoFs
nlohmann::json getTagMetaInfoFs(const std::string &name)
This is an auxillary method, it gets a tag meta info from file system storage.
Definition: CrestApi.cxx:2205
Crest::CrestClient::getPayloadAsStringFS
std::string getPayloadAsStringFS(const std::string &hash)
This auxillary method finds a payload resource associated to the hash in the local file storage.
Definition: CrestApi.cxx:2547
ReweightUtils.message
message
Definition: ReweightUtils.py:15
physics_parameters.url
string url
Definition: physics_parameters.py:27
search
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
Definition: hcg.cxx:738
Crest::CrestClient::s_FS_GLOBALTAG_PATH
static const std::string s_FS_GLOBALTAG_PATH
Definition: CrestApi.h:102
Crest::CrestClient::s_MONITORING_PAYLOAD_PATH
static const std::string s_MONITORING_PAYLOAD_PATH
Definition: CrestApi.h:86
Crest::CrestClient::removeTagFromGlobalTagMap
void removeTagFromGlobalTagMap(const std::string &global_tag, const std::string &tag, const std::string &label)
This method removes a tag with the name tag and the label from the global tag map with name global_ta...
Definition: CrestApi.cxx:2902
CrestApi.h
Header file for CREST C++ Client Library.
Crest::CrestClient::getBlobFs
std::string getBlobFs(const std::string &hash)
This method finds payload data by hash in the file storage; the payload object contains the real BLOB...
Definition: CrestApi.cxx:2600
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
hotSpotInTAG.objectType
objectType
Definition: hotSpotInTAG.py:107
Crest::CrestClient::removeCR
std::string removeCR(const std::string &str)
This method removes all end of line and carriage return symbols from a string.
Definition: CrestApi.cxx:1677
Crest::CrestClient::storeBatchPayloadsFs
void storeBatchPayloadsFs(const std::string &tag_name, std::string &iovsetupload)
This auxillary method stores several payloads in batch mode in the file storage.
Definition: CrestApi.cxx:1826
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
rerun_display.client
client
Definition: rerun_display.py:31
Crest::CrestClient::convertTagMetaInfo2IOVDbSvc
nlohmann::json convertTagMetaInfo2IOVDbSvc(nlohmann::json &js)
Auxillary method to convert a Tag Meta Info from the JSON CREST Server format in to IOVDbSvc format.
Definition: CrestApi.cxx:1948
Crest::CrestClient::createTagMetaInfoFs
void createTagMetaInfoFs(nlohmann::json &js)
This is an auxillary method, it creates a tag meta info on the file system storage.
Definition: CrestApi.cxx:2165
dq_defect_copy_defect_database.until
def until
Definition: dq_defect_copy_defect_database.py:55
query
Definition: query.py:1
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
physics_parameters.file_name
string file_name
Definition: physics_parameters.py:32
Crest::CrestClient::s_GLOBALTAG_PATH
static const std::string s_GLOBALTAG_PATH
Definition: CrestApi.h:83
Crest::CrestClient::convertTagMetaInfo2CREST
nlohmann::json convertTagMetaInfo2CREST(nlohmann::json &js)
Auxillary method to convert a Tag Meta Info from the JSON IOVDbSvc format in CREST Server format.
Definition: CrestApi.cxx:1955
Crest::CrestClient::storeBatchPayloadsFiles
void storeBatchPayloadsFiles(const std::string &tag_name, uint64_t endtime, nlohmann::json &js)
This method stores several payloads from files in batch mode.
Definition: CrestApi.cxx:2925
Crest::CrestClient::createPayload
void createPayload(nlohmann::json &js)
This method creates a payload in the CREST DB.
Definition: CrestApi.cxx:1088
Crest::CrestClient::split
std::vector< std::string > split(std::string_view str, char delim)
Auxillary method to split a string.
Definition: CrestApi.cxx:1982
Crest::CrestClient::listTags
nlohmann::json listTags(void)
This method returns the tag list.
Definition: CrestApi.cxx:103
Crest::CrestClient::s_MGMT_INFO_PATH_2
static const std::string s_MGMT_INFO_PATH_2
Definition: CrestApi.h:123
python.handimod.now
now
Definition: handimod.py:675
Crest::CrestClient::s_META_PATH
static const std::string s_META_PATH
Definition: CrestApi.h:87
defineDB.tagname
string tagname
Definition: JetTagCalibration/share/defineDB.py:19
Crest::CrestClient::updateTag
void updateTag(const std::string &tagname, nlohmann::json body)
This method allows to update tag record in the CREST DB.
Definition: CrestApi.cxx:278
Crest::CrestClient::storeBatchPayloads
void storeBatchPayloads(const std::string &tag_name, uint64_t endtime, const std::string &iovsetupload)
This method stores several payloads in batch mode.
Definition: CrestApi.cxx:1102
CaloCondBlobAlgs_fillNoiseFromASCII.desc
desc
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:54
Crest::CrestClient::getPayloadAsString
std::string getPayloadAsString(const std::string &hash)
This method finds a payload resource associated to the hash.
Definition: CrestApi.cxx:1066
Crest::CurlWrite_CallbackFunc_StdString
size_t CurlWrite_CallbackFunc_StdString(void *contents, size_t size, size_t nmemb, std::string *s)
Definition: CrestApi.cxx:1273
Crest::CrestClient::s_METHOD_GROUPS
static const std::string s_METHOD_GROUPS
Definition: CrestApi.h:95
lumiFormat.i
int i
Definition: lumiFormat.py:92
Crest::CrestClient::getCrestVersion
std::string getCrestVersion()
This method returns the full CREST Server version.
Definition: CrestApi.cxx:2783
Crest::CrestClient::s_MGMT_PATH
static const std::string s_MGMT_PATH
Definition: CrestApi.h:120
beamspotman.n
n
Definition: beamspotman.py:731
PixelAthClusterMonAlgCfg.varName
string varName
end cluster ToT and charge
Definition: PixelAthClusterMonAlgCfg.py:117
Crest::CrestClient::createGlobalTagMapFs
void createGlobalTagMapFs(nlohmann::json &js)
The auxillary method to create a global tag map in file storage.
Definition: CrestApi.cxx:2329
dqt_zlumi_alleff_HIST.fout
fout
Definition: dqt_zlumi_alleff_HIST.py:59
Crest::CrestClient::storeBatchPayloadFilesRequest
std::string storeBatchPayloadFilesRequest(const std::string &tag, uint64_t endtime, const std::string &js)
This is an auxilary method to make an request to store several payloads from files in the batch mode.
Definition: CrestApi.cxx:2948
Crest::CrestClient::returnJArray
nlohmann::json returnJArray(nlohmann::json js)
This auxillary method creates a JSON array from a JSON object.
Definition: CrestApi.cxx:2639
Crest::CrestClient::ParseXMLOutput
std::string ParseXMLOutput(std::string_view xmlBuffer)
This method removes all XML/HTML tags from a string.
Definition: CrestApi.cxx:1656
Crest::CrestClient::SERVER_MODE
@ SERVER_MODE
Definition: CrestApi.h:126
python.ByteStreamConfig.write
def write
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:248
calibdata.exception
exception
Definition: calibdata.py:496
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
Crest::CrestClient::m_CREST_PROXY
char * m_CREST_PROXY
Definition: CrestApi.h:75
athena.file_path
file_path
Definition: athena.py:92
Crest::CrestClient::s_FS_MAP_FILE
static const std::string s_FS_MAP_FILE
Definition: CrestApi.h:113
file
TFile * file
Definition: tile_monitor.h:29
parseDir.wh
wh
Definition: parseDir.py:46
Crest::CrestClient::getSizeFS
int getSizeFS(const std::string &tagname)
This metghod gets the number of iovs for the given tag.
Definition: CrestApi.cxx:2645
Crest::CrestClient::s_FS_PREFIX_LENGTH
static const int s_FS_PREFIX_LENGTH
Definition: CrestApi.h:117
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
Crest::CrestClient::findTag
nlohmann::json findTag(const std::string &name)
This method finds a tag by the name.
Definition: CrestApi.cxx:226
dumpTgcDigiDeadChambers.resolver
resolver
Definition: dumpTgcDigiDeadChambers.py:16
Crest::data
Definition: CrestApi.cxx:1269
Crest::CrestClient::s_FS_DATA_PATH
static const std::string s_FS_DATA_PATH
Definition: CrestApi.h:103
Crest::CrestClient::createGlobalTagMap
void createGlobalTagMap(nlohmann::json &gt)
Method to create a global tag map.
Definition: CrestApi.cxx:872
Crest::CrestClient::GET
@ GET
Definition: CrestApi.h:129
Crest::CrestClient::getResFirst
nlohmann::json getResFirst(nlohmann::json &js)
Auxillary method to get the first element from resources of the new CREST server response.
Definition: CrestApi.cxx:1922
Crest::CrestClient::getPayloadMetaInfoAsStringFS
std::string getPayloadMetaInfoAsStringFS(const std::string &hash)
This auxillary method finds a payload resource associated to the hash in the local file storage.
Definition: CrestApi.cxx:2572
Crest::CrestClient::getCrestVersion2
std::string getCrestVersion2()
This method returns the full CREST Server version.
Definition: CrestApi.cxx:2863
contents
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
Definition: computils.cxx:319
Crest::CrestClient::shortListTagsFs
std::list< std::string > shortListTagsFs()
This method returns a tag list stored in the file storage.
Definition: CrestApi.cxx:1749
Crest::CrestClient::s_CREST_CLIENT_VERSION
static const std::string s_CREST_CLIENT_VERSION
Definition: CrestApi.h:122
Crest::CrestClient::CrestClient
CrestClient(bool rewriteIfExists, const std::string &root_folder="/tmp/crest_dump")
CrestClient constructor for file storage mode.
Definition: CrestApi.cxx:28
Crest::CrestClient::Action
Action
Definition: CrestApi.h:128
query_example.query
query
Definition: query_example.py:15
CheckTagAssociation.globaltag
globaltag
Definition: CheckTagAssociation.py:18
Crest::CrestClient::flush
void flush()
Auxillary method to write all the data at the end of a session.
Definition: CrestApi.cxx:351
Crest::CrestClient::storePayloadDump
void storePayloadDump(const std::string &tag, uint64_t since, const std::string &js)
Method to store a payload in the local file system.
Definition: CrestApi.cxx:2446
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
lumiFormat.array
array
Definition: lumiFormat.py:98
Crest::CrestClient::listPayloadTagInfo
nlohmann::json listPayloadTagInfo()
This method retrieves monitoring information on all payloads as a list of payload tag information.
Definition: CrestApi.cxx:1023
Crest::CrestClient::getResources
nlohmann::json getResources(nlohmann::json &js)
Auxillary method to get a resources parameter from new CREST server response.
Definition: CrestApi.cxx:1916
Crest::CrestClient::getFirstLetters
std::string getFirstLetters(const std::string &str)
This is an auxillary method extract first letters from the string (hash).
Definition: CrestApi.cxx:2762
Crest::CrestClient::getClientVersion
std::string getClientVersion()
This method returns the full CrestApi version.
Definition: CrestApi.cxx:2809
Crest::CrestClient::m_isRewrite
bool m_isRewrite
Definition: CrestApi.h:71
Crest::CrestClient::updateTagMetaInfo
void updateTagMetaInfo(nlohmann::json &js)
This method updates a tag meta info in the CREST database.
Definition: CrestApi.cxx:2060
Crest::CrestClient::checkErrors
int checkErrors(const nlohmann::json &js, const char *method)
Auxillary method to check if the JSON object contain an error message.
Definition: CrestApi.cxx:1875
hancool.filePath
string filePath
Definition: hancool.py:28
Crest::CrestClient::storePayload
void storePayload(const std::string &tag, uint64_t since, const std::string &js)
Create a payload in the database, associated to a given iov since and tag name.
Definition: CrestApi.cxx:1252
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Crest::CrestClient::s_PAYLOAD_PATH
static const std::string s_PAYLOAD_PATH
Definition: CrestApi.h:85
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Crest::CrestClient::updateTagSpecification
void updateTagSpecification(const std::string &tagname, const std::string &objectType)
This method cahnges object type specification.
Definition: CrestApi.cxx:293
PayloadHelpers::dataSize
size_t dataSize(TDA::PayloadIterator start)
Size in bytes of the buffer that is needed to decode next fragment data content.
Definition: TriggerEDMDeserialiserAlg.cxx:188
Crest::CrestClient::checkCrestVersion
void checkCrestVersion()
This method is a CREST version test.
Definition: CrestApi.cxx:2833
Crest::CrestClient::listFolders
nlohmann::json listFolders()
This method returns the folder list on CREST DB.
Definition: CrestApi.cxx:1163
Crest::CrestClient::getMgmtInfo
nlohmann::json getMgmtInfo()
This is an auxillary method to read the CREST Server properties.
Definition: CrestApi.cxx:2767
item
Definition: ItemListSvc.h:43
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
Crest::CrestClient::findGlobalTagAsString
std::string findGlobalTagAsString(const std::string &name)
Finds a global tag by name.
Definition: CrestApi.cxx:724
Crest::CrestClient::storeBatchIOVs
void storeBatchIOVs(nlohmann::json &js)
This method stores an IOV set on the CREST server.
Definition: CrestApi.cxx:630
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
MyPlots.page
page
Definition: MyPlots.py:234
python.PyAthena.v
v
Definition: PyAthena.py:157
get_generator_info.version
version
Definition: get_generator_info.py:33
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
Crest::CrestClient::m_port
std::string m_port
Definition: CrestApi.h:66
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
Crest::data::trace_ascii
char trace_ascii
Definition: CrestApi.cxx:1270
Crest::CrestClient::createIov
void createIov(nlohmann::json &iov)
This method creates an iov for a given tag in the CREST DB for the created payload.
Definition: CrestApi.cxx:370
Crest::CrestClient::getDataPath
std::string getDataPath()
Auxillary method to get an environment variable DAT_PATH.
Definition: CrestApi.cxx:1866
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
Crest::CrestClient::selectGroups
nlohmann::json selectGroups(const std::string &tagname)
Select groups for a given tagname.
Definition: CrestApi.cxx:579
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Crest::CrestClient::createTagMetaInfo
void createTagMetaInfo(nlohmann::json &js)
This method creates a tag meta info in the CREST database.
Definition: CrestApi.cxx:1998
Crest::CrestClient::replaceSymbols
void replaceSymbols(std::string &str, const std::string &from, const std::string &to)
This auxilary method replaces the substring from by the substring to.
Definition: CrestApi.cxx:3156
Crest::CrestClient::getMajorVersion
int getMajorVersion(std::string &str)
This is an auxillary method to extract a major version number from full version string.
Definition: CrestApi.cxx:2813
picosha2.h
LArHVGainsPredictor.error_code
error_code
Definition: LArHVGainsPredictor.py:229
Crest::CrestClient::removeTag
void removeTag(const std::string &tagName)
This method allows to remove a Tag.
Definition: CrestApi.cxx:209
tagname
Definition: tagname.h:29
pickleTool.object
object
Definition: pickleTool.py:30
PlotCalibFromCool.iovList
iovList
Definition: PlotCalibFromCool.py:351
str
Definition: BTagTrackIpAccessor.cxx:11
Crest::CrestClient::listRunLumiInfo
nlohmann::json listRunLumiInfo()
This method gets full list of run/lumi information data.
Definition: CrestApi.cxx:1198
calibdata.copy
bool copy
Definition: calibdata.py:27
Crest::CrestClient::getFileList
void getFileList(const std::string &path)
Auxillary method to get a file list in the given directory.
Definition: CrestApi.cxx:1739
Crest::CrestClient::s_FOLDER_PATH
static const std::string s_FOLDER_PATH
Definition: CrestApi.h:90
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
Crest::CrestClient::getPayloadAsJson
nlohmann::json getPayloadAsJson(const std::string &hash)
This method finds a payload resource associated to the hash.
Definition: CrestApi.cxx:1042
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
Crest::CrestClient::getTagMetaInfoIOVDbSvc
nlohmann::json getTagMetaInfoIOVDbSvc(const std::string &tagname)
This method gets a tag meta info from the CREST database in IOVDbSvc format.
Definition: CrestApi.cxx:2120
Crest::CrestClient::createFolder
std::string createFolder(nlohmann::json &body)
Method to create a folder.
Definition: CrestApi.cxx:1181
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
Crest::CrestClient::s_FS_TAG_FILE
static const std::string s_FS_TAG_FILE
Definition: CrestApi.h:105
python.html.AtlRunQueryDQSummary.server
server
Definition: AtlRunQueryDQSummary.py:22
makeTOC.header
header
Definition: makeTOC.py:28
get_generator_info.error
error
Definition: get_generator_info.py:40
Crest::CrestClient::s_FS_GLOBALTAG_FILE
static const std::string s_FS_GLOBALTAG_FILE
Definition: CrestApi.h:112
Crest::CrestClient::getPayloadMetaInfoAsString
std::string getPayloadMetaInfoAsString(const std::string &hash)
This method finds a payload resource associated to the hash.
Definition: CrestApi.cxx:980
Crest::CrestClient::storeBatchPayloadRequest
std::string storeBatchPayloadRequest(const std::string &tag, uint64_t endtime, const std::string &js)
This is an auxillary method to make an request to store several payloads in the batch mode.
Definition: CrestApi.cxx:1505
python.PyAthena.obj
obj
Definition: PyAthena.py:135
Crest::CrestClient::s_RUNINFO_LIST_PATH
static const std::string s_RUNINFO_LIST_PATH
Definition: CrestApi.h:92
Crest::CrestClient::checkResult
void checkResult(CURLcode res, long response_code, const std::string &st, const char *method_name)
This auxillary method checks the CURL response.
Definition: CrestApi.cxx:1698
error
Definition: IImpactPoint3dEstimator.h:70
Crest::CrestClient::createRunLumiInfo
void createRunLumiInfo(nlohmann::json &body)
This method creates an entry for run information.
Definition: CrestApi.cxx:1216
Crest::CrestClient::findGlobalTagFs
nlohmann::json findGlobalTagFs(const std::string &name)
The auxillary method to find a global tag by name stored in file storage.
Definition: CrestApi.cxx:2307
Crest::urlParameters
Definition: CrestApi.h:33
python.compressB64.c
def c
Definition: compressB64.py:93
Crest::CrestClient::m_data_folder
std::string m_data_folder
Definition: CrestApi.h:69
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
Crest::CrestClient::getEnvA
std::string getEnvA(const char *varname)
Auxillary method to get an environment variable.
Definition: CrestApi.cxx:1856
Crest::CrestClient::createGlobalTagFs
void createGlobalTagFs(nlohmann::json &js)
The auxillary method to create a global tag in file storage.
Definition: CrestApi.cxx:2266
Crest::CrestClient::removeGlobalTag
void removeGlobalTag(const std::string &name)
This method allows to remove a Global Tag form CREST DB.
Definition: CrestApi.cxx:758
Crest::CrestClient::findAllIovsFs
nlohmann::json findAllIovsFs(const std::string &tagname)
This method finds all iovs by the tag name in the file storage.
Definition: CrestApi.cxx:1781
Crest::CrestClient::createTagDump
void createTagDump(nlohmann::json &js)
Method to store a tag in the local file system.
Definition: CrestApi.cxx:311
Crest::CrestClient::make_url
std::string make_url(const std::string &address) const
Definition: CrestApi.cxx:90
Crest::CrestClient::getMgmtInfo2
nlohmann::json getMgmtInfo2()
This is an auxillary method to read the CREST Server properties.
Definition: CrestApi.cxx:2847
Crest::CrestClient::listGlobalTagsAsString
std::string listGlobalTagsAsString()
This method finds a global tag lists.
Definition: CrestApi.cxx:788
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88
Crest::CrestClient::s_IOV_SIZE_PATH
static const std::string s_IOV_SIZE_PATH
Definition: CrestApi.h:81