Project
Loading...
Searching...
No Matches
FileMetaData.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
13
17#include <Framework/Logger.h>
18#include <TMD5.h>
19#include <filesystem>
20#include <chrono>
21
22using namespace o2::dataformats;
23
24bool FileMetaData::fillFileData(const std::string& fname, bool fillmd5, const std::string& tmpEnding)
25{
26 // fill metadata for fname, accounting that the fname might be temporary one while the real one is fnameFinal
27 try {
28 lurl = std::filesystem::canonical(fname).string();
29 size = std::filesystem::file_size(lurl);
30 if (fillmd5) {
31 std::unique_ptr<TMD5> md5ptr{TMD5::FileChecksum(fname.c_str())};
32 if (md5ptr) {
33 md5 = md5ptr->AsString();
34 }
35 }
36 ctime = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
37 if (tmpEnding.size()) {
38 o2::utils::Str::rtrim(lurl, tmpEnding);
39 }
40 } catch (std::exception const& e) {
41 LOG(error) << "Failed to fill metadata for file " << fname << ", reason: " << e.what();
42 return false;
43 }
44 return true;
45}
46
47std::string FileMetaData::asString() const
48{
49 std::string ms;
50
51 // obligatory part
52 ms += fmt::format("LHCPeriod: {}\n", LHCPeriod);
53 ms += fmt::format("run: {}\n", run);
54 ms += fmt::format("lurl: {}\n", lurl);
55
56 // optional part
57 if (!type.empty()) {
58 ms += fmt::format("type: {}\n", type);
59 }
60 if (ctime) {
61 ms += fmt::format("ctime: {}\n", ctime);
62 }
63 if (size) {
64 ms += fmt::format("size: {}\n", size);
65 }
66 if (!guid.empty()) {
67 ms += fmt::format("guid: {}\n", guid);
68 }
69 if (!surl.empty()) {
70 ms += fmt::format("surl: {}\n", surl);
71 }
72 if (!curl.empty()) {
73 ms += fmt::format("curl: {}\n", curl);
74 }
75 if (!md5.empty()) {
76 ms += fmt::format("md5: {}\n", md5);
77 }
78 if (!xxhash.empty()) {
79 ms += fmt::format("xxhash: {}\n", xxhash);
80 }
81 if (!seName.empty()) {
82 ms += fmt::format("seName: {}\n", seName);
83 }
84 if (!seioDaemons.empty()) {
85 ms += fmt::format("seioDaemons: {}\n", seioDaemons);
86 }
87 if (!priority.empty()) {
88 ms += fmt::format("priority: {}\n", priority);
89 }
90 if (persistent) {
91 ms += fmt::format("persistent: {}\n", persistent);
92 }
93 if (!detComposition.empty()) {
94 ms += fmt::format("det_composition: {}\n", detComposition);
95 }
96 if (!tfOrbits.empty()) {
97 ms += fmt::format("TFOrbits: {}", tfOrbits[0]);
98 for (size_t i = 1; i < tfOrbits.size(); i++) {
99 ms += fmt::format(",{}", tfOrbits[i]);
100 }
101 ms += "\n";
102 }
103
104 return ms;
105}
106
113
114std::ostream& o2::dataformats::operator<<(std::ostream& stream, const FileMetaData& h)
115{
116 stream << h.asString();
117 return stream;
118}
int32_t i
Class for time synchronization of RawReader instances.
GLsizeiptr size
Definition glcorearb.h:659
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLuint stream
Definition glcorearb.h:1806
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
std::ostream & operator<<(std::ostream &os, const o2::dataformats::MeanVertexObject &o)
std::string asString() const
bool fillFileData(const std::string &fname, bool fillmd5=false, const std::string &tmpEnding="")
std::vector< uint32_t > tfOrbits
void setDataTakingContext(const o2::framework::DataTakingContext &dtc)
std::string lhcPeriod
The current lhc period.
std::string detectors
The list of detectors taking part in the run.
std::string runNumber
The current run number.
static void rtrim(std::string &s)
Definition StringUtils.h:55
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"