Project
Loading...
Searching...
No Matches
CCDBTimeStampUtils.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
12//
13// Created by Sandro Wenzel on 2019-08-20.
14//
16#include "CCDB/CcdbApi.h"
17#include "CCDB/CcdbObjectInfo.h"
18#include <chrono>
19#include <ctime>
20
21namespace o2::ccdb
22{
23
24long getFutureTimestamp(int secondsInFuture)
25{
26 std::chrono::seconds sec(secondsInFuture);
27 auto future = std::chrono::system_clock::now() + sec;
28 auto future_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(future);
29 auto epoch = future_ms.time_since_epoch();
30 auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
31 return value.count();
32}
33
36{
37 auto now = std::chrono::system_clock::now();
38 auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
39 auto epoch = now_ms.time_since_epoch();
40 auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
41 return value.count();
42}
43
45long createTimestamp(int year, int month, int day, int hour, int minutes, int seconds)
46{
47 struct tm timeinfo;
48 timeinfo.tm_year = year;
49 timeinfo.tm_mon = month;
50 timeinfo.tm_mday = day;
51 timeinfo.tm_hour = hour;
52 timeinfo.tm_min = minutes;
53 timeinfo.tm_sec = seconds;
54
55 time_t timeformat = mktime(&timeinfo);
56 return static_cast<long>(timeformat);
57}
58
60{
61 int res = 0;
62 if (infoNew.getStartValidityTimestamp() > 0) {
63 std::map<std::string, std::string> dummyMD, prevHeader;
65 prevHeader = api.retrieveHeaders(infoNew.getPath(), dummyMD, infoNew.getStartValidityTimestamp() - 1); // is there an adjustable object to override?
66 const auto itETag = prevHeader.find("ETag");
67 if (itETag != prevHeader.end() &&
68 prevHeader.find(o2::ccdb::CcdbObjectInfo::AdjustableEOV) != prevHeader.end() &&
69 prevHeader.find(o2::ccdb::CcdbObjectInfo::DefaultObj) == prevHeader.end()) {
70 std::string etag = itETag->second;
71 etag.erase(remove(etag.begin(), etag.end(), '\"'), etag.end());
72 LOGP(info, "Adjusting EOV of previous {}/{}/{} to {} (id:{})", infoNew.getPath(), prevHeader["Valid-From"], prevHeader["Valid-Until"], infoNew.getStartValidityTimestamp() - 1, etag);
73 // equivalent of std::string cmd = fmt::format("sh -c \"curl -X PUT {}{}{}/{}/{}\"", api.getURL(), api.getURL().back() == '/' ? "" : "/", infoNew.getPath(), infoNew.getStartValidityTimestamp() - 1, infoNew.getStartValidityTimestamp());
74 api.updateMetadata(infoNew.getPath(), {}, infoNew.getStartValidityTimestamp() - 1, etag, infoNew.getStartValidityTimestamp());
75 }
76 }
77 return res;
78}
79
80} // namespace o2::ccdb
uint32_t res
Definition RawData.h:0
std::map< std::string, std::string > retrieveHeaders(std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1) const
Definition CcdbApi.cxx:1416
int updateMetadata(std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp, std::string const &id="", long newEOV=0)
Definition CcdbApi.cxx:1599
static constexpr const char * AdjustableEOV
static constexpr const char * DefaultObj
const std::string & getPath() const
long getStartValidityTimestamp() const
GLsizei const GLfloat * value
Definition glcorearb.h:819
information complementary to a CCDB object (path, metadata, startTimeValidity, endTimeValidity etc)
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
long createTimestamp(int year, int month, int day, int hour, int minutes, int seconds)
Converting time into numerical time stamp representation.
int adjustOverriddenEOV(CcdbApi &api, const CcdbObjectInfo &infoNew)
set EOV of overriden objects to SOV-1 of overriding one if it is allowed
long getFutureTimestamp(int secondsInFuture)
returns the timestamp in long corresponding to "now + secondsInFuture"