|
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);
736 const std::string &js,
737 const std::string &payloadFormat,
739 const std::string &compressionType,
741 const std::string &streamerInfo)
746 std::string hashCode;
747 std::string payloadLocalFile;
750 if (payloadFormat ==
"JSON")
757 int found_dots = js.find_first_of(
':');
758 int word_size = js.size();
759 payloadLocalFile = js.substr(found_dots + 3, word_size);
777 std::string tagFile = workDir +
"/payload.json";
779 if (payloadFormat ==
"JSON")
789 std::filesystem::copy_file(payloadLocalFile, tagFile);
791 catch (std::filesystem::filesystem_error &
e)
793 throw CrestException(
"ERROR in CrestFsClient::storePayloadDump cannot not save payload file: " + tagFile +
e.what());
801 {
"checkSum",
"SHA-256"},
805 {
"streamerInfo", streamerInfo},
806 {
"compressionType", compressionType},
810 std::string metaFile = workDir +
"/meta.json";
823 m_data.insert(std::pair<std::string, nlohmann::json>(
tag, jsi));
831 m_data.insert(std::pair<std::string, nlohmann::json>(
tag, jsFree));
836 "ERROR in CrestFsClient::storePayloadDump cannot get data for tag \"" +
tag +
"\" from file storage.");
844 std::string link = hashCode;
850 obj[
"payloadHash"] = link;
858 std::ifstream ifs(
file);
862 "ERROR in CrestFsClient::getHashForFile cannot open file \"" +
file +
"\".");
866 std::vector<char>
buffer(1024 * 1024);
867 while (ifs.read(
buffer.data(),
static_cast<std::streamsize
>(
buffer.size())))
888 std::string
filePath = workDir +
"/payload.json";
889 std::string
res =
"";
905 throw CrestException(
"ERROR in CrestFsClient::getPayload cannot get the payload form file storage, " +
message);
925 std::string
res =
"";
943 throw CrestException(
"ERROR in CrestClient::getPayloadMeta cannot get the payload meta info form file storage, " +
message);
970 for (
int i = kmin;
i < kmax;
i++)
972 js.push_back(
data[
i]);
979 std::vector<std::string>
res;
998 for (
int i = kmin;
i < kmax;
i++)
1010 for (
auto i = std::filesystem::directory_iterator(
p);
i != std::filesystem::directory_iterator();
i++)
1012 std::string
file =
i->path().filename().string();
1030 std::vector<std::string> parlist;
1031 std::map<std::string, nlohmann::json>
m;
1033 int size = js.size();
1034 for (
int i = 0;
i <
size;
i++)
1038 auto res = elem.find(
par);
1040 if (
res != elem.end())
1042 std::string par_val = elem[
par];
1043 parlist.push_back(par_val);
1048 std::sort(parlist.begin(), parlist.end());
1055 for (std::string
item : parlist)
1057 respond.push_back(
m[
item]);
1066 std::string
par =
"since";
1068 std::vector<double> parlist;
1069 std::map<double, nlohmann::json>
m;
1071 int size = js.size();
1072 for (
int i = 0;
i <
size;
i++)
1076 auto res = elem.find(
par);
1078 if (
res != elem.end())
1080 double par_val = elem[
par];
1081 parlist.push_back(par_val);
1086 std::sort(parlist.begin(), parlist.end());
1093 for (
double item : parlist)
1095 respond.push_back(
m[
item]);
1105 return n == word.size();
1108 if (
n == word.size())
1110 for (
long unsigned int i =
m;
i <
pattern.size();
i++)
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 get_hash_hex_string(const hash256_one_by_one &hasher, std::string &hex_str)
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 hash256_hex_string(InIter first, InIter last, std::string &hex_str)
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.
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.
std::string getHash(std::string_view str)
This method method calculates the hash for string.
static const std::string s_FS_MAP_FILE
std::vector< std::string > nameList(std::string &folder, bool ascending=true)
std::string getHashForFile(const std::string &file)
This method method calculates the hash for a file.
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::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.
void process(RaIter first, RaIter last)
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.
std::vector< std::string > getVectorPage(std::vector< std::string > data, int size, int page)
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
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.
bool isMatch(std::string word, long unsigned int n, std::string pattern, long unsigned int m)
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.
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.