Project
Loading...
Searching...
No Matches
Utils.h
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
14
15#ifndef O2_CALIBRATION_CONVENTIONS_H
16#define O2_CALIBRATION_CONVENTIONS_H
17
18#include <typeinfo>
19#include <utility>
20#include <fstream>
21#include <TMemFile.h>
22#include "Headers/DataHeader.h"
25#include "CCDB/CcdbObjectInfo.h"
27#include "CCDB/CcdbApi.h"
28#include <vector>
29
30namespace o2
31{
32namespace calibration
33{
34
35struct Utils {
36
37 enum ValueType { Invalid = 0,
42
43 static constexpr o2::header::DataOrigin gDataOriginCDBPayload{"CLP"}; // generic DataOrigin for calibrations payload
44 static constexpr o2::header::DataOrigin gDataOriginCDBWrapper{"CLW"}; // generic DataOrigin for calibrations wrapper
45 template <typename T>
46 static void prepareCCDBobjectInfo(T& obj, o2::ccdb::CcdbObjectInfo& info, const std::string& path,
47 const std::map<std::string, std::string>& md, long start, long end = -1);
48
49 static std::pair<int, double> findPair(const std::vector<std::pair<uint64_t, double>>& vect, uint64_t timestamp)
50 {
51 // function to find the pair in the vector with the timestamp closest in the past to the one passed as argument
52 // if two entries in the vector have the same timestamp, the first that is found is used
53
54 // let's first check that the elements are sorted in ascending order
55 if (!std::is_sorted(vect.begin(), vect.end(), [](const std::pair<uint64_t, double>& lhs, const std::pair<uint64_t, double>& rhs) -> bool { return lhs.first < rhs.first; })) {
56 LOG(fatal) << "Vector is not sorted, we cannot execute the findPair function";
57 }
58 auto lower = std::lower_bound(vect.begin(), vect.end(), timestamp, [](const std::pair<uint64_t, double>& p, uint64_t value) { return p.first < value; });
59 if ((*lower).first == timestamp) {
60 LOG(debug) << "We found the element for the exact timestamp";
61 return std::make_pair(SameAsRequested, vect[std::distance(vect.begin(), lower)].second);
62 } else if (lower == vect.end()) {
63 LOG(debug) << "All values are smaller than the queried one " << timestamp << ", we return the closest available from below: " << vect.back().first;
64 return std::make_pair(ClosestAvailableFromBelow, vect.back().second);
65 } else if (lower == vect.begin()) {
66 LOG(debug) << "All values are greater that the queried one " << timestamp << ", we return the closest available from above: " << (*vect.begin()).first;
67 return std::make_pair(ClosestAvailableFromAbove, vect.begin()->second);
68 } else {
69 // doing interpolation
70 const auto& p1 = vect[std::distance(vect.begin(), lower) - 1];
71 const auto& p2 = vect[std::distance(vect.begin(), lower)];
72 auto t1 = p1.first;
73 auto t2 = p2.first;
74 auto val1 = p1.second;
75 auto val2 = p2.second;
76 if (t1 == t2) {
77 LOG(debug) << "times are the same, cannot interpolate, returning closest from below";
78 return std::make_pair(ClosestAvailableFromBelow, val1);
79 }
80 // in case values are not ordered in timestamp
81 double val = t2 > t1 ? (timestamp - t1) * (val2 - val1) / (t2 - t1) + val1 : (timestamp - t1) * (val1 - val2) / (t1 - t2) + val1;
82 LOG(debug) << "Doing interpolation between (" << t1 << ", " << val1 << ") and (" << t2 << ", " << val2 << ") for t = " << timestamp << " --> " << val;
83 return std::make_pair(Interpolation, val);
84 }
85 LOG(error) << "Something went wrong!";
86 return std::make_pair(Invalid, 0);
87 }
88};
89
90template <typename T>
91void Utils::prepareCCDBobjectInfo(T& obj, o2::ccdb::CcdbObjectInfo& info, const std::string& path,
92 const std::map<std::string, std::string>& md, long start, long end)
93{
94
95 // prepare all info to be sent to CCDB for object obj
97 auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
98 info.setPath(path);
99 info.setObjectType(clName);
100 info.setFileName(flName);
101 info.setStartValidityTimestamp(start);
102 info.setEndValidityTimestamp(end);
103 info.setMetaData(md);
104}
105
106} // namespace calibration
107} // namespace o2
108
109#endif
std::ostringstream debug
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
constexpr int p2()
constexpr int p1()
constexpr to accelerate the coordinates changing
char error[CURL_ERROR_SIZE]
double lower[3]
static std::string generateFileName(const std::string &inp)
Definition CcdbApi.cxx:905
GLuint GLuint end
Definition glcorearb.h:469
GLint first
Definition glcorearb.h:399
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLuint GLfloat * val
Definition glcorearb.h:1582
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition glcorearb.h:5034
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static void prepareCCDBobjectInfo(T &obj, o2::ccdb::CcdbObjectInfo &info, const std::string &path, const std::map< std::string, std::string > &md, long start, long end=-1)
Definition Utils.h:91
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static std::pair< int, double > findPair(const std::vector< std::pair< uint64_t, double > > &vect, uint64_t timestamp)
Definition Utils.h:49
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
static std::string getClassName(const T &obj)
get the class name of the object
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"