|
ATLAS Offline Software
|
Go to the documentation of this file.
9 #include <boost/uuid/uuid.hpp>
10 #include <boost/uuid/uuid_generators.hpp>
11 #include <boost/uuid/uuid_io.hpp>
12 #include <boost/asio.hpp>
36 : m_root_folder(root_folder), m_isRewrite(rewriteIfExists)
61 std::ifstream ifs(
path);
62 std::stringstream buf;
91 for (
auto i = std::filesystem::directory_iterator(
p);
i != std::filesystem::directory_iterator();
i++)
93 std::string
file =
i->path().filename().string();
96 std::cout <<
file << std::endl;
108 std::string
name =
"";
115 throw CrestException(
"ERROR in CrestFsClient::createGlobalTag: global tag name is not set.");
130 outFile.open(globalTagFile.c_str());
155 "ERROR in CrestFsClient::findGlobalTag: cannot get the global tag " +
name +
" form the file storage.");
174 if (sort ==
"name:ASC")
178 else if (sort ==
"name:DESC")
185 "ERROR in CrestFsClient::listTags: wrong sort parameter." + sort);
191 std::vector<std::string> clearedTaglist;
203 clearedTaglist.push_back(
tag);
208 clearedTaglist.push_back(
tag);
225 "ERROR in CrestFsClient::listGlobalTags: cannot get the tag list.");
284 "ERROR in CrestFsClient::findTag: cannot get the tag " +
name +
" form the file storage.");
303 if (sort ==
"name:ASC")
307 else if (sort ==
"name:DESC")
314 "ERROR in CrestFsClient::listTags: wrong sort parameter." + sort);
320 std::vector<std::string> clearedTaglist;
332 clearedTaglist.push_back(
tag);
337 clearedTaglist.push_back(
tag);
354 "ERROR in CrestFsClient::listTags: cannot get the tag list.");
381 std::string
name =
tag.tagName;
395 outFile.open(tagMetaFile.c_str());
423 "ERROR in CrestFsClient::findTagMeta: cannot get the tag " +
name +
" form the file storage.");
436 std::string
name =
"";
439 name =
static_cast<std::string
>(js[
"globalTagName"]);
443 throw CrestException(
"ERROR in CrestClient::createGlobalTagMap: cannot get the global tag name from JSON.");
450 tagname =
static_cast<std::string
>(js[
"tagName"]);
454 throw CrestException(
"ERROR in CrestClient::createGlobalTagMap: cannot get the tag name from JSON.");
473 throw CrestException(
"ERROR in CrestFsClient::createGlobalTagMap: global tag map file corrupted.");
479 int m = cathalogue.size();
480 for (
int i = 0;
i <
m;
i++)
482 const std::string &tn = cathalogue[
i][
"tagName"];
494 cathalogue.push_back(js);
506 cathalogue.push_back(js);
525 throw CrestException(
"ERROR in " + std::string(method_name) +
" This methods is unsupported for FILESYSTEM mode");
533 if (xCrestMapMode !=
"Trace")
536 "ERROR in CrestFsClient::getGlobalTagMap: not supported value for the parameter xCrestMapMode = " + xCrestMapMode);
553 "ERROR in CrestFsClient::getGlobalTagMap: cannot get the global tag map " +
name +
554 " form the file storage.");
575 for (
int i = 0;
i < niovs;
i++)
590 if (currentS >=
since)
600 throw CrestException(
"ERROR in CrestClient::selectIovsFS : cannot get the iov list form file storage");
604 if (sort ==
"id.since:ASC")
606 else if (sort ==
"id.since:DESC")
611 "ERROR in CrestFsClient::selectIovs: wrong sort parameter." + sort);
638 throw CrestException(
"ERROR in CrestFsClient::findAllIovs : cannot get the iov information form file storage ");
671 const std::string &payloadFormat,
673 const std::string &compressionType,
686 auto it = js_data.find(
"resources");
687 if (
it != js_data.end())
689 res = js_data[
"resources"];
694 for (
auto &kvp :
res)
696 std::string
payload = kvp.value(
"data",
"");
697 int since = kvp.value(
"since", 0);
698 std::string streamer = kvp.value(
"streamerInfo",
"");
706 throw CrestException(
"ERROR in CrestFsClient::storeData cannot store the data in a file");
713 time_t
now = time(0);
717 localtime_r(&
now, &tstruct);
718 strftime(buf,
sizeof(buf),
"%Y-%m-%d %X", &tstruct);
730 const std::string &js,
731 const std::string &payloadFormat,
733 const std::string &compressionType,
735 const std::string &streamerInfo)
740 std::string hashCode;
741 std::string payloadLocalFile;
744 if (payloadFormat ==
"JSON")
751 int found_dots = js.find_first_of(
':');
752 int word_size = js.size();
753 payloadLocalFile = js.substr(found_dots + 3, word_size);
771 std::string tagFile = workDir +
"/payload.json";
773 if (payloadFormat ==
"JSON")
783 std::filesystem::copy_file(payloadLocalFile, tagFile);
785 catch (std::filesystem::filesystem_error &
e)
787 throw CrestException(
"ERROR in CrestFsClient::storePayloadDump cannot not save payload file: " + tagFile +
e.what());
795 {
"checkSum",
"SHA-256"},
799 {
"streamerInfo", streamerInfo},
800 {
"compressionType", compressionType},
804 std::string metaFile = workDir +
"/meta.json";
817 m_data.insert(std::pair<std::string, nlohmann::json>(
tag, jsi));
825 m_data.insert(std::pair<std::string, nlohmann::json>(
tag, jsFree));
830 "ERROR in CrestFsClient::storePayloadDump cannot get data for tag \"" +
tag +
"\" from file storage.");
838 std::string link = hashCode;
844 obj[
"payloadHash"] = link;
860 std::string
filePath = workDir +
"/payload.json";
861 std::string
res =
"";
877 throw CrestException(
"ERROR in CrestFsClient::getPayload cannot get the payload form file storage, " +
message);
897 std::string
res =
"";
915 throw CrestException(
"ERROR in CrestClient::getPayloadMeta cannot get the payload meta info form file storage, " +
message);
942 for (
int i = kmin;
i < kmax;
i++)
944 js.push_back(
data[
i]);
951 std::vector<std::string>
res;
970 for (
int i = kmin;
i < kmax;
i++)
982 for (
auto i = std::filesystem::directory_iterator(
p);
i != std::filesystem::directory_iterator();
i++)
984 std::string
file =
i->path().filename().string();
1002 std::vector<std::string> parlist;
1003 std::map<std::string, nlohmann::json>
m;
1005 int size = js.size();
1006 for (
int i = 0;
i <
size;
i++)
1010 auto res = elem.find(
par);
1012 if (
res != elem.end())
1014 std::string par_val = elem[
par];
1015 parlist.push_back(par_val);
1020 std::sort(parlist.begin(), parlist.end());
1027 for (std::string
item : parlist)
1029 respond.push_back(
m[
item]);
1038 std::string
par =
"since";
1040 std::vector<double> parlist;
1041 std::map<double, nlohmann::json>
m;
1043 int size = js.size();
1044 for (
int i = 0;
i <
size;
i++)
1048 auto res = elem.find(
par);
1050 if (
res != elem.end())
1052 double par_val = elem[
par];
1053 parlist.push_back(par_val);
1058 std::sort(parlist.begin(), parlist.end());
1065 for (
double item : parlist)
1067 respond.push_back(
m[
item]);
1077 return n == word.size();
1080 if (
n == word.size())
1082 for (
long unsigned int i =
m;
i <
pattern.size();
i++)
1114 "ERROR in CrestFsClient::getCrestVersion: cannot get the CREST server version for file storage.");
JetConstituentVector::iterator iterator
static const std::string s_FS_GLOBALTAG_PATH
static const std::string s_FS_TAG_PATH
static IovSetDto from_fs_json(const json &j)
static GlobalTagMapSetDto from_fs_json(const json &j)
char data[hepevt_bytes_allocation_ATLAS]
~CrestFsClient()
CrestClient destructor.
void updateTagMeta(TagMetaDto &tag) override
This method updates a tag meta info on the file storage.
path
python interpreter configuration --------------------------------------—
void createTagMeta(TagMetaDto &tag) override
This method creates a tag meta info on the file storage.
GlobalTagSetDto listGlobalTags(const std::string &name, int size, int page, const std::string &sort) override
This method finds the global tags on the file storage.
std::string m_data_folder
std::string find(const std::string &s)
return a remapped string
TagSetDto listTags(const std::string &name, int size, int page, const std::string &sort) override
This method returns the tag list as TagSetDto.
std::string getFirstLetters(const std::string &str)
This is an auxillary method extract first letters from the string (hash).
nlohmann::json sortIOVJson(nlohmann::json js, bool order)
void getFileList(const std::string &path)
Auxiliary method to get a file list in the given directory.
int getSize(const std::string &tagname) override
This method gets the number of IOVs for the given tag.
Header file for CREST C++ Client Library.
static const std::string s_FS_IOV_FILE
IovSetDto selectIovs(const std::string &name, uint64_t since, uint64_t until, long snapshot, int size, int page, const std::string &sort) override
This method selects IOVs for a given tagname from the file storage.
TagMetaDto findTagMeta(const std::string &name) override
This method gets a tag meta info by the tag name from the file storage.
static TagDto from_json(const json &j)
void flush()
Auxiliary method flush the data to the file system.
std::string getHash(std::string_view str)
This method method calculates the hash for string.
GlobalTagMapSetDto findGlobalTagMap(const std::string &name, const std::string &xCrestMapMode) override
This method searches for tag mappings using the global tag name or tag name on the file storage.
void createTag(TagDto &tag) override
This method creates a tag on the file storage.
static const std::string s_FS_MAP_FILE
bool isMatch(const std::string &word, long unsigned int n, const std::string &pattern, long unsigned int m)
std::vector< std::string > nameList(std::string &folder, bool ascending=true)
static GlobalTagDto from_json(const json &j)
std::string getFileString(const std::string &path)
Auxiliary method to get a file as a string.
std::string m_root_folder
static const std::string s_FS_TAG_FILE
std::string getDateAndTime()
static PayloadDto from_json(const json &j)
The TagDto class It contains all fields of the TagDto class from the CREST API.
CrestFsClient(bool rewriteIfExists, const std::string &root_folder)
CrestFsClient constructor.
std::pair< std::vector< unsigned int >, bool > res
static const int s_FS_PREFIX_LENGTH
void createGlobalTagMap(GlobalTagMapDto &globalTagMap) override
This method creates a global tag map on the file storage.
void checkFsException(const char *method_name)
Auxiliary method to check if the CrestApi library initialized to work with the file system.
nlohmann::json sortJson(nlohmann::json js, const std::string &par, bool order)
std::string getCrestVersion() override
This method returns the full CREST Server version.
std::optional< std::string > datatype
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
outFile
Comment Out Those You do not wish to run.
GlobalTagDto findGlobalTag(const std::string &name) override
This method finds a global tag by name on the file storage.
TagDto findTag(const std::string &name) override
This method finds a tag by the name on the file storage.
void createGlobalTag(GlobalTagDto &globalTag) override
This method creates a global tag on the file storage.
static const std::string s_FS_TAGMETAINFO_FILE
std::vector< std::string > getVectorPage(const std::vector< std::string > &data, int size, int page)
size_t dataSize(TDA::PayloadIterator start)
Size in bytes of the buffer that is needed to decode next fragment data content.
void removeGlobalTagMap(const std::string &name, const std::string &record, const std::string &label, const std::string &tagname) override
This method removes a global tag map from the file storage.
static const std::string s_FS_GLOBALTAG_FILE
IovSetDto selectGroups(const std::string &name, long snapshot, int size, int page, const std::string &sort) override
This method returns IOV groups for a given tagname.
nlohmann::json getPage(nlohmann::json data, int size, int page)
std::map< std::string, nlohmann::json > m_data
void removeGlobalTag(const std::string &name) override
This method removes a global tag.
std::string buildPath(const std::string &path, const std::string &file)
void storePayloadDump(const std::string &tag, uint64_t since, const std::string &js, const std::string &payloadFormat, const std::string &objectType, const std::string &compressionType, const std::string &version, const std::string &streamerInfo)
This auxiliary method stores a single payload (with since time) on the file system.
std::string getHashForFile(const std::string &file)
This method method calculates the hash for a file.
PayloadDto getPayloadMeta(const std::string &hash) override
This method finds a payload meta info for the hash on the file storage.
std::string getPayload(const std::string &hash) override
This method finds a payload resource associated to the hash on the file storage.
void storeData(const std::string &tag, const StoreSetDto &storeSetJson, const std::string &payloadFormat="JSON", const std::string &objectType="none", const std::string &compressionType="none", const std::string &version="1.0", uint64_t endTime=-1) override
This method stores several payloads in batch mode on the file storage.
void removeTag(const std::string &name) override
This method removes a tag from the file storage.
nlohmann::json findAllIovs(const std::string &tagname)
This auxiliary method finds all iovs for a given tag name.