Project
Loading...
Searching...
No Matches
FileProducer.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
19
20#include <deque>
21#include <chrono>
22#include <filesystem>
23#include <algorithm>
24#include <climits>
25#include <fmt/core.h>
26#include <fmt/format.h>
27
28using namespace o2::event_visualisation;
29
30using std::chrono::duration_cast;
31using std::chrono::milliseconds;
32using std::chrono::system_clock;
33
34FileProducer::FileProducer(const std::string& path, const std::string& ext, const std::string& name)
35{
36 this->mPath = path;
37 this->mName = name;
38 this->mExt = ext;
39 o2::utils::createDirectoriesIfAbsent(path); // create a folder if not exists (fails if no rights)
40}
41
42void FileProducer::reduceNumberOfFiles(size_t filesInFolder) const
43{
44 const std::vector<std::string> ext = {".json", ".root", ".eve"};
45 DirectoryLoader::reduceNumberOfFiles(this->mPath, DirectoryLoader::load(this->mPath, "_", ext), filesInFolder);
46}
47
48std::string FileProducer::newFileName() const
49{
50 const auto millisec_since_epoch = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
51
52 char hostname[_POSIX_HOST_NAME_MAX];
53 gethostname(hostname, _POSIX_HOST_NAME_MAX);
54
55 const auto pid = getpid();
56 const auto result = fmt::format(fmt::runtime(this->mName),
57 fmt::arg("hostname", hostname),
58 fmt::arg("pid", pid),
59 fmt::arg("timestamp", millisec_since_epoch),
60 fmt::arg("ext", this->mExt));
61 return this->mPath + "/" + result;
62}
Loading content of the Folder and returning sorted.
uint16_t pid
Definition RawData.h:2
static void reduceNumberOfFiles(const std::string &path, const std::deque< std::string > &files, std::size_t filesInFolder)
static std::deque< std::string > load(const std::string &path, const std::string &marker, const std::vector< std::string > &ext)
void reduceNumberOfFiles(size_t filesInFolder) const
FileProducer(const std::string &path, const std::string &ext, const std::string &name="tracks_{timestamp}_{hostname}_{pid}{ext}")
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint const GLchar * name
Definition glcorearb.h:781
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
void createDirectoriesIfAbsent(std::string const &path)