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
27using namespace o2::event_visualisation;
28
29using std::chrono::duration_cast;
30using std::chrono::milliseconds;
31using std::chrono::system_clock;
32
33FileProducer::FileProducer(const std::string& path, const std::string& ext, int filesInFolder, const std::string& name)
34{
35 this->mFilesInFolder = filesInFolder;
36 this->mPath = path;
37 this->mName = name;
38 this->mExt = ext;
39 o2::utils::createDirectoriesIfAbsent(path); // create folder if not exists (fails if no rights)
40}
41
42std::string FileProducer::newFileName() const
43{
44 const auto millisec_since_epoch = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
45
46 char hostname[_POSIX_HOST_NAME_MAX];
47 gethostname(hostname, _POSIX_HOST_NAME_MAX);
48
49 const auto pid = getpid();
50 const auto result = fmt::format(fmt::runtime(this->mName),
51 fmt::arg("hostname", hostname),
52 fmt::arg("pid", pid),
53 fmt::arg("timestamp", millisec_since_epoch),
54 fmt::arg("ext", this->mExt));
55 const std::vector<std::string> ext = {".json", ".root", ".eve"};
56 DirectoryLoader::reduceNumberOfFiles(this->mPath, DirectoryLoader::load(this->mPath, "_", ext), this->mFilesInFolder);
57
58 return this->mPath + "/" + result;
59}
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)
FileProducer(const std::string &path, const std::string &ext, int filesInFolder=-1, 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)