DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::snbmodules::GroupMetadata Class Reference

#include <group_metadata.hpp>

Inheritance diagram for dunedaq::snbmodules::GroupMetadata:
[legend]
Collaboration diagram for dunedaq::snbmodules::GroupMetadata:
[legend]

Public Member Functions

void generate_metadata_file (std::filesystem::path dest) override
 Generaete metadata file to dest.
 
void load_metadata_from_meta_file (std::filesystem::path src) override
 Load metadata file from src.
 
std::string export_to_string () override
 Export metadata to string (json format)
 
void from_string (const std::string &) override
 Import metadata from string (json format)
 
status_type::e_status get_group_status () const
 Return a status of the group transfer based on the status of his transfers, The highest status in priority order is returned.
 
 GroupMetadata (std::string group_id, std::string source, const IPFormat &source_ip, protocol_type::e_protocol_type protocol, const nlohmann::json &protocol_options=nlohmann::json(), const std::vector< std::shared_ptr< TransferMetadata > > &transfers_meta=std::vector< std::shared_ptr< TransferMetadata > >())
 Constructor.
 
 GroupMetadata (const std::filesystem::path &src, bool is_path=true)
 Load from file constructor.
 
virtual ~GroupMetadata ()=default
 
bool operator== (MetadataAbstract const &other) const override
 Operator ==.
 
bool operator< (MetadataAbstract const &other) const override
 Operator <.
 
void set_group_id (std::string transfer_id)
 
void set_protocol (protocol_type::e_protocol_type protocol)
 
void set_transfers_meta (std::vector< std::shared_ptr< TransferMetadata > > files_meta)
 
void set_protocol_options (nlohmann::json protocol_options)
 
void set_source_id (std::string source_id)
 
void set_expected_files (std::set< std::string > expected_files)
 
TransferMetadataadd_file (std::shared_ptr< TransferMetadata > meta)
 
void add_expected_file (const std::filesystem::path &file)
 
std::string get_group_id () const
 
protocol_type::e_protocol_type get_protocol () const
 
std::vector< std::shared_ptr< TransferMetadata > > & get_transfers_meta ()
 
const std::vector< std::shared_ptr< TransferMetadata > > & get_transfers_meta () const
 
TransferMetadataget_transfer_meta_from_file_path (const std::string &file_path)
 
const std::set< std::string > & get_expected_files () const
 
nlohmann::json get_protocol_options () const
 
std::string get_source_id () const
 
IPFormat get_source_ip () const
 
std::string to_string () const
 
- Public Member Functions inherited from dunedaq::snbmodules::MetadataAbstract
virtual ~MetadataAbstract ()=default
 

Static Public Attributes

static const std::string m_file_extension = ".gmetadata"
 

Private Attributes

std::string m_group_id
 Unique identifier for the transfer.
 
protocol_type::e_protocol_type m_protocol
 Protocol used for the transfer, every files in the transfer must use the same protocol.
 
nlohmann::json m_protocol_options
 Specific options for the selected protocol.
 
std::vector< std::shared_ptr< TransferMetadata > > m_transfers_meta
 Set of files to transfer.
 
std::set< std::string > m_expected_files
 Set of expected files metadata to add later.
 
std::string m_source_id
 Get source id.
 
IPFormat m_source_ip
 Get source ip.
 

Detailed Description

Definition at line 25 of file group_metadata.hpp.

Constructor & Destructor Documentation

◆ GroupMetadata() [1/2]

dunedaq::snbmodules::GroupMetadata::GroupMetadata ( std::string group_id,
std::string source,
const IPFormat & source_ip,
protocol_type::e_protocol_type protocol,
const nlohmann::json & protocol_options = nlohmann::json(),
const std::vector< std::shared_ptr< TransferMetadata > > & transfers_meta = std::vector<std::shared_ptr<TransferMetadata>>() )
inline

Constructor.

Parameters
protocol
transfers_meta
transfer_id

Definition at line 54 of file group_metadata.hpp.

61 : m_group_id(std::move(group_id))
62 , m_protocol(protocol)
63 , m_transfers_meta(transfers_meta)
64 , m_expected_files(std::set<std::string>())
65 , m_source_id(std::move(source))
66 , m_source_ip(source_ip)
67 {
68 set_protocol_options(protocol_options);
69 }
std::string m_group_id
Unique identifier for the transfer.
std::set< std::string > m_expected_files
Set of expected files metadata to add later.
std::vector< std::shared_ptr< TransferMetadata > > m_transfers_meta
Set of files to transfer.
std::string m_source_id
Get source id.
void set_protocol_options(nlohmann::json protocol_options)
protocol_type::e_protocol_type m_protocol
Protocol used for the transfer, every files in the transfer must use the same protocol.

◆ GroupMetadata() [2/2]

dunedaq::snbmodules::GroupMetadata::GroupMetadata ( const std::filesystem::path & src,
bool is_path = true )
inlineexplicit

Load from file constructor.

Definition at line 72 of file group_metadata.hpp.

73 {
74 if (is_path) {
76 } else {
77 from_string(src.string());
78 }
79 }
void load_metadata_from_meta_file(std::filesystem::path src) override
Load metadata file from src.
void from_string(const std::string &) override
Import metadata from string (json format)

◆ ~GroupMetadata()

virtual dunedaq::snbmodules::GroupMetadata::~GroupMetadata ( )
virtualdefault

Member Function Documentation

◆ add_expected_file()

void dunedaq::snbmodules::GroupMetadata::add_expected_file ( const std::filesystem::path & file)
inline

Definition at line 115 of file group_metadata.hpp.

116 {
117 // remove all occurences of ./ in the file path
118 std::string file_path_str = file.string();
119 std::string x = "./";
120
121 size_t pos = 0;
122 while (true) {
123 pos = file_path_str.find(x, pos);
124 if (pos == std::string::npos) {
125 break;
126 }
127
128 file_path_str.replace(pos, x.length(), "");
129 }
130
131 m_expected_files.insert(std::filesystem::absolute(file_path_str));
132 }

◆ add_file()

TransferMetadata & dunedaq::snbmodules::GroupMetadata::add_file ( std::shared_ptr< TransferMetadata > meta)

Definition at line 36 of file group_metadata.cpp.

37{
38 if (m_expected_files.find(meta->get_file_path()) != m_expected_files.end()) {
39 m_expected_files.erase(meta->get_file_path());
40 meta->set_group_id(m_group_id);
41
42 return *m_transfers_meta.emplace_back(meta);
43 } else if (meta->get_group_id() == m_group_id) {
44 int pos = -1;
45 int i = 0;
46 for (const auto& m : m_transfers_meta) {
47 if (m == meta) {
48 // Already inserted, update the transfer
49 pos = i;
50 break;
51 }
52 i++;
53 }
54 if (pos != -1) {
55 m_transfers_meta.erase(m_transfers_meta.begin() + pos);
56 }
57 return *m_transfers_meta.emplace_back(std::move(meta));
58 } else {
59 ers::fatal(MetadataNotExpectedInGroupError(ERS_HERE, m_group_id, meta->get_file_name()));
60 return *m_transfers_meta[0]; // To avoid warning
61 }
62}
#define ERS_HERE
void fatal(const Issue &issue)
Definition ers.hpp:88

◆ export_to_string()

std::string dunedaq::snbmodules::GroupMetadata::export_to_string ( )
overridevirtual

Export metadata to string (json format)

Returns
Metadata in string format

Implements dunedaq::snbmodules::MetadataAbstract.

Definition at line 65 of file group_metadata.cpp.

66{
67 nlohmann::json j;
68 j["transfer_id"] = get_group_id();
69 j["source_id"] = get_source_id();
70 j["source_ip"] = get_source_ip().get_ip_port();
72 j["protocol_options"] = get_protocol_options().dump();
73
74 std::vector<std::string> files;
75 for (const auto& file : get_transfers_meta()) {
76 files.push_back(file->get_file_path().string());
77 }
78 j["files"] = files;
79
80 return j.dump();
81}
protocol_type::e_protocol_type get_protocol() const
std::vector< std::shared_ptr< TransferMetadata > > & get_transfers_meta()
nlohmann::json get_protocol_options() const
std::string get_ip_port() const
Get the IP address and the port in the format "ip:port".
Definition ip_format.hpp:57
static std::string protocols_to_string(e_protocol_type e)

◆ from_string()

void dunedaq::snbmodules::GroupMetadata::from_string ( const std::string & s)
overridevirtual

Import metadata from string (json format)

Implements dunedaq::snbmodules::MetadataAbstract.

Definition at line 84 of file group_metadata.cpp.

85{
86 nlohmann::json j = nlohmann::json::parse(str);
87
88 TLOG() << "debug : Loading metadata from string " << str;
89
90 if (j.contains("transfer_id")) {
91 set_group_id(j["transfer_id"].get<std::string>());
92 }
93 if (j.contains("source_id")) {
94 set_source_id(j["source_id"].get<std::string>());
95 }
96 if (j.contains("source_ip")) {
97 m_source_ip = IPFormat(j["source_ip"].get<std::string>());
98 }
99 if (j.contains("protocol")) {
100 set_protocol(protocol_type::string_to_protocols(j["protocol"].get<std::string>()).value());
101 }
102 if (j.contains("protocol_options")) {
103 set_protocol_options(nlohmann::json::parse(j["protocol_options"].get<std::string>()));
104 }
105 if (j.contains("files")) {
106 auto files = j["files"].get<std::vector<std::filesystem::path>>();
107
108 for (const auto& file : files) {
109 add_expected_file(file);
110 }
111 }
112}
void add_expected_file(const std::filesystem::path &file)
void set_protocol(protocol_type::e_protocol_type protocol)
void set_source_id(std::string source_id)
void set_group_id(std::string transfer_id)
#define TLOG(...)
Definition macro.hpp:22
static std::optional< e_protocol_type > string_to_protocols(std::string s)

◆ generate_metadata_file()

void dunedaq::snbmodules::GroupMetadata::generate_metadata_file ( std::filesystem::path dest)
overridevirtual

Generaete metadata file to dest.

Parameters
dest

Implements dunedaq::snbmodules::MetadataAbstract.

Definition at line 115 of file group_metadata.cpp.

116{
117 std::ofstream metadata_file;
118 metadata_file.open(dest.append(get_group_id()).string() + m_file_extension);
119
120 metadata_file << export_to_string();
121
122 metadata_file.close();
123}
std::string export_to_string() override
Export metadata to string (json format)
static const std::string m_file_extension

◆ get_expected_files()

const std::set< std::string > & dunedaq::snbmodules::GroupMetadata::get_expected_files ( ) const
inline

Definition at line 140 of file group_metadata.hpp.

140{ return m_expected_files; }

◆ get_group_id()

std::string dunedaq::snbmodules::GroupMetadata::get_group_id ( ) const
inline

Definition at line 135 of file group_metadata.hpp.

135{ return m_group_id; }

◆ get_group_status()

status_type::e_status dunedaq::snbmodules::GroupMetadata::get_group_status ( ) const
inline

Return a status of the group transfer based on the status of his transfers, The highest status in priority order is returned.

Returns
Status of the group transfer

Definition at line 39 of file group_metadata.hpp.

40 {
42 for (const auto& transfer : get_transfers_meta()) {
43 if (transfer->get_status() > status) {
44 status = transfer->get_status();
45 }
46 }
47 return status;
48 }
e_status
Different type of session status Need to be sorted by priority (highest last)
@ PREPARING
waiting for the transfer to start, can be waiting to receive expected files metadata

◆ get_protocol()

protocol_type::e_protocol_type dunedaq::snbmodules::GroupMetadata::get_protocol ( ) const
inline

Definition at line 136 of file group_metadata.hpp.

136{ return m_protocol; }

◆ get_protocol_options()

nlohmann::json dunedaq::snbmodules::GroupMetadata::get_protocol_options ( ) const
inline

Definition at line 141 of file group_metadata.hpp.

141{ return m_protocol_options; }
nlohmann::json m_protocol_options
Specific options for the selected protocol.

◆ get_source_id()

std::string dunedaq::snbmodules::GroupMetadata::get_source_id ( ) const
inline

Definition at line 142 of file group_metadata.hpp.

142{ return m_source_id; }

◆ get_source_ip()

IPFormat dunedaq::snbmodules::GroupMetadata::get_source_ip ( ) const
inline

Definition at line 143 of file group_metadata.hpp.

143{ return m_source_ip; }

◆ get_transfer_meta_from_file_path()

TransferMetadata & dunedaq::snbmodules::GroupMetadata::get_transfer_meta_from_file_path ( const std::string & file_path)

Definition at line 24 of file group_metadata.cpp.

25{
26 for (std::shared_ptr<TransferMetadata> meta : get_transfers_meta()) {
27 if (meta->get_file_path() == file_path) {
28 return *meta;
29 }
30 }
31 ers::fatal(MetadataNotFoundInGroupError(ERS_HERE, m_group_id, file_path));
32 return *m_transfers_meta[0]; // To avoid warning
33}

◆ get_transfers_meta() [1/2]

std::vector< std::shared_ptr< TransferMetadata > > & dunedaq::snbmodules::GroupMetadata::get_transfers_meta ( )
inline

Definition at line 137 of file group_metadata.hpp.

137{ return m_transfers_meta; }

◆ get_transfers_meta() [2/2]

const std::vector< std::shared_ptr< TransferMetadata > > & dunedaq::snbmodules::GroupMetadata::get_transfers_meta ( ) const
inline

Definition at line 138 of file group_metadata.hpp.

138{ return m_transfers_meta; }

◆ load_metadata_from_meta_file()

void dunedaq::snbmodules::GroupMetadata::load_metadata_from_meta_file ( std::filesystem::path src)
overridevirtual

Load metadata file from src.

Parameters
src

Implements dunedaq::snbmodules::MetadataAbstract.

Definition at line 126 of file group_metadata.cpp.

127{
128 std::ifstream metadata_file;
129 try {
130 metadata_file.open(src.string());
131 } catch (const std::exception& e) {
132 ers::error(MetadataFileNotFoundError(ERS_HERE, e.what()));
133 return;
134 }
135
136 std::stringstream buffer;
137 buffer << metadata_file.rdbuf();
138
139 from_string(buffer.str());
140
141 metadata_file.close();
142}
void error(const Issue &issue)
Definition ers.hpp:81

◆ operator<()

bool dunedaq::snbmodules::GroupMetadata::operator< ( MetadataAbstract const & other) const
inlineoverridevirtual

Operator <.

Parameters
otherOther GroupMetadata to compare
Returns
True if the transfer_id is less than the other transfer_id, false otherwise

Implements dunedaq::snbmodules::MetadataAbstract.

Definition at line 95 of file group_metadata.hpp.

96 {
97 auto o = dynamic_cast<const GroupMetadata&>(other);
98 return m_group_id.compare(o.m_group_id);
99 }
GroupMetadata(std::string group_id, std::string source, const IPFormat &source_ip, protocol_type::e_protocol_type protocol, const nlohmann::json &protocol_options=nlohmann::json(), const std::vector< std::shared_ptr< TransferMetadata > > &transfers_meta=std::vector< std::shared_ptr< TransferMetadata > >())
Constructor.

◆ operator==()

bool dunedaq::snbmodules::GroupMetadata::operator== ( MetadataAbstract const & other) const
inlineoverridevirtual

Operator ==.

Parameters
otherOther GroupMetadata to compare
Returns
True if the transfer_id are equal, false otherwise

Implements dunedaq::snbmodules::MetadataAbstract.

Definition at line 86 of file group_metadata.hpp.

87 {
88 auto o = dynamic_cast<const GroupMetadata&>(other);
89 return m_group_id == o.m_group_id;
90 }

◆ set_expected_files()

void dunedaq::snbmodules::GroupMetadata::set_expected_files ( std::set< std::string > expected_files)
inline

Definition at line 113 of file group_metadata.hpp.

113{ m_expected_files = std::move(expected_files); }

◆ set_group_id()

void dunedaq::snbmodules::GroupMetadata::set_group_id ( std::string transfer_id)
inline

Definition at line 102 of file group_metadata.hpp.

102{ m_group_id = std::move(transfer_id); }

◆ set_protocol()

void dunedaq::snbmodules::GroupMetadata::set_protocol ( protocol_type::e_protocol_type protocol)
inline

Definition at line 103 of file group_metadata.hpp.

◆ set_protocol_options()

void dunedaq::snbmodules::GroupMetadata::set_protocol_options ( nlohmann::json protocol_options)
inline

Definition at line 108 of file group_metadata.hpp.

109 {
110 m_protocol_options = std::move(protocol_options);
111 }

◆ set_source_id()

void dunedaq::snbmodules::GroupMetadata::set_source_id ( std::string source_id)
inline

Definition at line 112 of file group_metadata.hpp.

112{ m_source_id = std::move(source_id); }

◆ set_transfers_meta()

void dunedaq::snbmodules::GroupMetadata::set_transfers_meta ( std::vector< std::shared_ptr< TransferMetadata > > files_meta)
inline

Definition at line 104 of file group_metadata.hpp.

105 {
106 m_transfers_meta = std::move(files_meta);
107 }

◆ to_string()

std::string dunedaq::snbmodules::GroupMetadata::to_string ( ) const

Definition at line 145 of file group_metadata.cpp.

146{
147 std::string str;
148 str += "transfer_id " + get_group_id() + " ";
149 str += "protocol " + protocol_type::protocols_to_string(get_protocol()) + "\n";
150
151 for (const auto& file : get_transfers_meta()) {
152 str += "*file " + file->get_file_name() + "\n";
153 }
154 for (const auto& file : get_expected_files()) {
155 str += "*expectedfile " + file + "\n";
156 }
157 return str;
158}
const std::set< std::string > & get_expected_files() const

Member Data Documentation

◆ m_expected_files

std::set<std::string> dunedaq::snbmodules::GroupMetadata::m_expected_files
private

Set of expected files metadata to add later.

Definition at line 160 of file group_metadata.hpp.

◆ m_file_extension

const std::string dunedaq::snbmodules::GroupMetadata::m_file_extension = ".gmetadata"
static

Definition at line 29 of file group_metadata.hpp.

◆ m_group_id

std::string dunedaq::snbmodules::GroupMetadata::m_group_id
private

Unique identifier for the transfer.

Definition at line 148 of file group_metadata.hpp.

◆ m_protocol

protocol_type::e_protocol_type dunedaq::snbmodules::GroupMetadata::m_protocol
private

Protocol used for the transfer, every files in the transfer must use the same protocol.

Definition at line 151 of file group_metadata.hpp.

◆ m_protocol_options

nlohmann::json dunedaq::snbmodules::GroupMetadata::m_protocol_options
private

Specific options for the selected protocol.

Definition at line 154 of file group_metadata.hpp.

◆ m_source_id

std::string dunedaq::snbmodules::GroupMetadata::m_source_id
private

Get source id.

Definition at line 163 of file group_metadata.hpp.

◆ m_source_ip

IPFormat dunedaq::snbmodules::GroupMetadata::m_source_ip
private

Get source ip.

Definition at line 166 of file group_metadata.hpp.

◆ m_transfers_meta

std::vector<std::shared_ptr<TransferMetadata> > dunedaq::snbmodules::GroupMetadata::m_transfers_meta
private

Set of files to transfer.

Definition at line 157 of file group_metadata.hpp.


The documentation for this class was generated from the following files: