Skip to content

Commit 1aec2e6

Browse files
pnwkwdavidrohr
authored andcommitted
Include in the JSON filename the hostname and pid of the workflow
1 parent 5bb3d25 commit 1aec2e6

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

EventVisualisation/Workflow/include/EveWorkflow/FileProducer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ class FileProducer
3434

3535
public:
3636
explicit FileProducer(const std::string& path, int filesInFolder = 10,
37-
const std::string& name = "tracks{}.json");
37+
const std::string& name = "tracks_{hostname}_{pid}_{timestamp}.json");
3838

3939
[[nodiscard]] std::string newFileName() const;
4040
};
4141

4242
} // namespace event_visualisation
4343
} // namespace o2
4444

45-
#endif //ALICE_O2_EVENTVISUALISATION_WORKFLOW_FILEPRODUCER_H
45+
#endif // ALICE_O2_EVENTVISUALISATION_WORKFLOW_FILEPRODUCER_H

EventVisualisation/Workflow/src/FileProducer.cxx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,21 @@
1717
#include "CommonUtils/FileSystemUtils.h"
1818

1919
#include <deque>
20-
#include <iostream>
2120
#include <chrono>
22-
#include <cstdio>
2321
#include <filesystem>
2422
#include <algorithm>
23+
#include <climits>
24+
#include <fmt/core.h>
2525

26-
using namespace std;
2726
using namespace o2::event_visualisation;
2827

29-
using std::cout;
30-
using std::endl;
3128
using std::chrono::duration_cast;
3229
using std::chrono::milliseconds;
33-
using std::chrono::seconds;
3430
using std::chrono::system_clock;
3531

3632
std::deque<std::string> FileProducer::load(const std::string& path)
3733
{
38-
deque<string> result;
34+
std::deque<std::string> result;
3935

4036
for (const auto& entry : std::filesystem::directory_iterator(path)) {
4137
if (entry.path().extension() == ".json") {
@@ -55,15 +51,20 @@ FileProducer::FileProducer(const std::string& path, int filesInFolder, const std
5551

5652
std::string FileProducer::newFileName() const
5753
{
58-
string pholder = "{}";
59-
string result = this->mName;
6054
auto millisec_since_epoch = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
61-
string stamp = std::to_string(millisec_since_epoch);
62-
result.replace(result.find(pholder), pholder.length(), stamp);
55+
56+
char hostname[_POSIX_HOST_NAME_MAX];
57+
gethostname(hostname, _POSIX_HOST_NAME_MAX);
58+
59+
auto pid = getpid();
60+
61+
auto result = fmt::format(this->mName, fmt::arg("hostname", hostname), fmt::arg("pid", pid), fmt::arg("timestamp", millisec_since_epoch));
62+
6363
auto files = this->load(this->mPath);
6464
std::sort(files.begin(), files.end());
65+
6566
while (files.size() >= this->mFilesInFolder) {
66-
string front = files.front();
67+
auto front = files.front();
6768
files.pop_front();
6869
std::remove((this->mPath + "/" + front).c_str()); // delete file
6970
}

0 commit comments

Comments
 (0)