45 inline static const std::map< const string, const string > plugin_multifile_config_defaults =
50 inline static const char *plugin_multifile_prefix =
"ADC_MULTIFILE_PLUGIN_";
52 const std::vector<string> tags;
60 int config(
const string dir,
const string user_rank) {
61 if (mode != pi_config)
63 char hname[HOST_NAME_MAX+1];
64 char uname[L_cuserid+1];
65 if (gethostname(hname, HOST_NAME_MAX+1)) {
68 if (!cuserid(uname)) {
76 char *wfid = getenv(
"ADC_WFID");
79 clock_gettime(CLOCK_BOOTTIME, &ts);
80 ss << dir <<
"/" << uname <<
"/" << ( wfid ? wfid :
"") <<
82 hname <<
"." << pid <<
"." <<
83 ts.tv_sec <<
"." << ts.tv_nsec <<
"." <<
this;
91 const string get(
const std::map< string, string >& m,
94 auto it = m.find(
field);
99 char *ec = getenv(en.c_str());
101 return plugin_multifile_config_defaults.at(
field);
109 multifile_plugin() : vers(
"1.0.0") , tags({
"none"}), state(ok), paused(
false), mode(pi_config) {
110 std::cout <<
"Constructing multifile_plugin" << std::endl;
118 if (mode != pi_pub_or_final)
120 auto header = b->get_section(
"header");
121 auto app = b->get_value(
"application");
127 string fpath = fdir +
"/" +
"multifile.XXXXXX";
128 out.open(fpath, std::ofstream::out | (std::ofstream::trunc));
130 mode = pi_pub_or_final;
138 out <<
"<json>" << b->serialize() <<
"</json>" << std::endl;
139 std::cout <<
"'multifile' wrote" << std::endl;
142 std::cout <<
"failed out.good" << std::endl;
146 int config(
const std::map< std::string, std::string >& m) {
147 return config(m, plugin_multifile_prefix);
150 int config(
const std::map< std::string, std::string >& m, std::string_view env_prefix) {
151 string d = get(m,
"DIRECTORY", env_prefix);
152 string r = get(m,
"RANK", env_prefix);
157 return plugin_multifile_config_defaults;
161 std::map <string, string >m;
164 if (mode != pi_init) {
167 if ( state == err ) {
169 "multifile plugin initialize found pre-existing error"
174 std::filesystem::create_directories(fdir, ec);
175 if (ec.value() != 0 && ec.value() != EEXIST ) {
177 std::cout <<
"unable to create output directory for plugin 'multifile'; "
178 << fdir <<
" : " << ec.message() << std::endl;
181 string testfile = fdir +
"/.XXXXXX";
182 auto ftemplate = std::make_unique<char[]>(testfile.length()+1);
183 ::std::strcpy(ftemplate.get(), testfile.c_str());
184 int fd = mkstemp(ftemplate.get());
188 std::cout <<
"unable to open file in output directory "
189 << fdir <<
" for plugin 'multifile': " <<
190 std::strerror(rc) << std::endl;
194 unlink(ftemplate.get());
200 if (mode == pi_pub_or_final) {
206 std::cout <<
"multifile plugin finalize on non-running plugin" << std::endl;
227 std::cout <<
"Destructing multifile_plugin" << std::endl;
Parallel file output publisher_api implementation. This plugin generates writes each message to the c...
int config(const std::map< std::string, std::string > &m)
Configure the plugin with the options given.
void pause()
Pause publishing until a call to resume. Duplicate calls are allowed.
int config(const std::map< std::string, std::string > &m, std::string_view env_prefix)
Configure the plugin with the options given and the corresponding environment variables.
int publish(std::shared_ptr< builder_api > b)
Publish the content of the builder.
int initialize()
Ready the plugin to publish following the configuration options set or defaulted.
void resume()
Resume publishing Duplicate calls are allowed.
const std::map< const std::string, const std::string > & get_option_defaults()
Look up the settable options and their defaults.
void finalize()
Stop publishing and release any resources held for managing publication.
string_view version() const
Publisher plugin interface.
std::string_view string_view