Skip to content

Commit 183579a

Browse files
DCS config data format (#6446)
* typedef for DCS configuration using std::vector<char> * Change delimiter, improve print clang-format Fix trailing space * Update functions - do not use pointers * update copyright
1 parent 2b6f406 commit 183579a

3 files changed

Lines changed: 97 additions & 0 deletions

File tree

DataFormats/Detectors/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_subdirectory(PHOS)
2525
add_subdirectory(CPV)
2626
add_subdirectory(CTP)
2727
add_subdirectory(GlobalTracking)
28+
add_subdirectory(DCS)
2829
if(ENABLE_UPGRADES)
2930
add_subdirectory(Upgrades)
3031
else()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
o2_add_header_only_library(DataFormatsDCS)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
/// \file DCSConfigObject.h
13+
/// \bried Data format to store DCS configurations
14+
15+
#include <vector>
16+
#include <string>
17+
#include <iostream>
18+
#include <iterator>
19+
#include <regex>
20+
21+
#include <TString.h>
22+
23+
namespace o2
24+
{
25+
namespace dcs
26+
{
27+
28+
typedef std::vector<char> DCSconfigObject_t;
29+
30+
template <typename T>
31+
inline void addConfigItem(DCSconfigObject_t& configVector, std::string key, const T value)
32+
{
33+
std::string keyValue = key + ":" + std::to_string(value) + ",";
34+
std::copy(keyValue.begin(), keyValue.end(), std::back_inserter(configVector));
35+
}
36+
37+
// explicit specialization for std::string
38+
template <>
39+
inline void addConfigItem(DCSconfigObject_t& configVector, std::string key, const std::string value)
40+
{
41+
std::string keyValue = key + ":" + value + ",";
42+
std::copy(keyValue.begin(), keyValue.end(), std::back_inserter(configVector));
43+
}
44+
45+
// explicit specialization for char
46+
template <>
47+
inline void addConfigItem(DCSconfigObject_t& configVector, std::string key, const char value)
48+
{
49+
std::string keyValue = key + ":" + value + ",";
50+
std::copy(keyValue.begin(), keyValue.end(), std::back_inserter(configVector));
51+
}
52+
53+
// explicit specialization for char*
54+
template <>
55+
inline void addConfigItem(DCSconfigObject_t& configVector, std::string key, const char* value)
56+
{
57+
std::string keyValue = key + ":" + value + ",";
58+
std::copy(keyValue.begin(), keyValue.end(), std::back_inserter(configVector));
59+
}
60+
61+
// explicit specialization for TString
62+
template <>
63+
inline void addConfigItem(DCSconfigObject_t& configVector, std::string key, const TString value)
64+
{
65+
std::string keyValue = key + ":" + value.Data() + ",";
66+
std::copy(keyValue.begin(), keyValue.end(), std::back_inserter(configVector));
67+
}
68+
69+
inline void printDCSConfig(const DCSconfigObject_t& configVector)
70+
{
71+
std::string sConfig(configVector.begin(), configVector.end());
72+
std::cout << "string "
73+
<< " --> " << sConfig << std::endl;
74+
auto const re = std::regex{R"(,+)"};
75+
auto vecRe = std::vector<std::string>(std::sregex_token_iterator{begin(sConfig), end(sConfig), re, -1},
76+
std::sregex_token_iterator{});
77+
for (size_t i = 0; i < vecRe.size(); ++i) {
78+
// vecRe[i].erase(vecRe[i].end() - 1);
79+
std::cout << i << " --> " << vecRe[i] << std::endl;
80+
}
81+
}
82+
83+
} // namespace dcs
84+
} // namespace o2

0 commit comments

Comments
 (0)