Skip to content

Commit c35a448

Browse files
Initializing dcs-proxy from CCDB (#5456)
* Initializing dcs-proxy from CCDB clang * Update README.md * Install macro Co-authored-by: Ruben Shahoyan <shahor02@users.noreply.github.com>
1 parent 979df75 commit c35a448

File tree

7 files changed

+129
-13
lines changed

7 files changed

+129
-13
lines changed

Detectors/DCS/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ if(BUILD_TESTING)
5858
COMPONENT_NAME dcs
5959
LABELS "dcs"
6060
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
61+
add_subdirectory(testWorkflow/macros)
6162
endif()
6263

6364
add_subdirectory(testWorkflow)

Detectors/DCS/testWorkflow/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co
5151

5252
A concrete example can be found in the `Detectors/TOF/calibration/testWorkflow` dir : `tof-calibration-dcs-sim-workflow`.
5353

54+
# dcs-proxy
55+
56+
It is the proxy to connect to the DCS machine.
57+
For test purposes, you can run with either hard-coded DPs (--test-mode), or reading a configuration entry from CCDB, which can be created with `testWorkflow/macros/makeCCDBEntryForDCS.C`. To validate the retrieval of data, you can attach the workflow `o2-dcs-data-client`, e.g.:
58+
59+
```
60+
o2-dcs-proxy --dcs-proxy '--channel-config "name=dcs-proxy,type=pull,method=connect,address=tcp://10.11.28.22:60000,rateLogging=1,transport=zeromq"' --ccdb-url http://localhost:8080 --detector-list COMMON,COMMON1 -b | o2-dcs-data-client -b
61+
```
62+
5463

5564

5665

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright CERN and copyright holders of ALICE O2. This software is distributed
2+
# under the terms of the GNU General Public License v3 (GPL Version 3), copied
3+
# verbatim in the file "COPYING".
4+
#
5+
# See http://alice-o2.web.cern.ch/license for full licensing information.
6+
#
7+
# In applying this license CERN does not waive the privileges and immunities
8+
# granted to it by virtue of its status as an Intergovernmental Organization or
9+
# submit itself to any jurisdiction.
10+
11+
o2_add_test_root_macro(
12+
makeCCDBEntryForDCS.C
13+
PUBLIC_LINK_LIBRARIES O2::DetectorsDCS O2::CCDB)
14+
15+
install(FILES makeCCDBEntryForDCS.C
16+
DESTINATION share/macro/)
17+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include <vector>
12+
#include <string>
13+
#include "TFile.h"
14+
#include "CCDB/CcdbApi.h"
15+
#include "DetectorsDCS/AliasExpander.h"
16+
#include "DetectorsDCS/DeliveryType.h"
17+
#include "DetectorsDCS/DataPointIdentifier.h"
18+
19+
#include <unordered_map>
20+
#include <chrono>
21+
22+
using DPID = o2::dcs::DataPointIdentifier;
23+
24+
int makeCCDBEntryForDCS(const std::string url = "http://localhost:8080")
25+
{
26+
27+
// std::string url(argv[0]);
28+
// macro to populate CCDB for TOF with the configuration for DCS
29+
std::unordered_map<DPID, std::string> dpid2DataDesc_Common;
30+
std::unordered_map<DPID, std::string> dpid2DataDesc_Common_1;
31+
std::vector<std::string> aliasesCommonStr = {"ADAPOS_LG/TEST_000100", "ADAPOS_LG/TEST_000110"};
32+
std::vector<std::string> aliasesCommon_1_Int = {"ADAPOS_LG/TEST_000240"};
33+
std::vector<std::string> aliasesCommon_1_Str = {"ADAPOS_LG/TEST_000200"};
34+
35+
DPID dpidtmp;
36+
for (size_t i = 0; i < aliasesCommonStr.size(); ++i) {
37+
DPID::FILL(dpidtmp, aliasesCommonStr[i], o2::dcs::DeliveryType::RAW_STRING);
38+
dpid2DataDesc_Common[dpidtmp] = "COMMON";
39+
}
40+
for (size_t i = 0; i < aliasesCommon_1_Int.size(); ++i) {
41+
DPID::FILL(dpidtmp, aliasesCommon_1_Int[i], o2::dcs::DeliveryType::RAW_INT);
42+
dpid2DataDesc_Common_1[dpidtmp] = "COMMON1";
43+
}
44+
for (size_t i = 0; i < aliasesCommon_1_Str.size(); ++i) {
45+
DPID::FILL(dpidtmp, aliasesCommon_1_Str[i], o2::dcs::DeliveryType::RAW_STRING);
46+
dpid2DataDesc_Common_1[dpidtmp] = "COMMON1";
47+
}
48+
49+
o2::ccdb::CcdbApi api;
50+
api.init(url); // or http://localhost:8080 for a local installation
51+
std::map<std::string, std::string> md;
52+
long ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
53+
api.storeAsTFileAny(&dpid2DataDesc_Common, "COMMON/DCSconfig", md, ts);
54+
api.storeAsTFileAny(&dpid2DataDesc_Common_1, "COMMON1/DCSconfig", md, ts);
55+
56+
return 0;
57+
}

Detectors/DCS/testWorkflow/src/dcs-proxy.cxx

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,27 @@
2323
#include "DetectorsDCS/DataPointValue.h"
2424
#include "DetectorsDCS/DeliveryType.h"
2525
#include "DCStoDPLconverter.h"
26+
#include "CCDB/BasicCCDBManager.h"
27+
#include "CCDB/CcdbApi.h"
2628
#include <vector>
2729
#include <unordered_map>
30+
#include <regex>
31+
#include <string>
32+
#include <unistd.h>
2833

2934
using namespace o2::framework;
3035
using DPID = o2::dcs::DataPointIdentifier;
3136
using DPVAL = o2::dcs::DataPointValue;
3237
using DeliveryType = o2::dcs::DeliveryType;
38+
using CcdbManager = o2::ccdb::BasicCCDBManager;
3339

3440
// we need to add workflow options before including Framework/runDataProcessing
3541
void customize(std::vector<ConfigParamSpec>& workflowOptions)
3642
{
37-
workflowOptions.push_back(
38-
ConfigParamSpec{"verbose", VariantType::Bool, false, {"verbose output"}});
43+
workflowOptions.push_back(ConfigParamSpec{"verbose", VariantType::Bool, false, {"verbose output"}});
44+
workflowOptions.push_back(ConfigParamSpec{"test-mode", VariantType::Bool, false, {"test mode"}});
45+
workflowOptions.push_back(ConfigParamSpec{"ccdb-url", VariantType::String, "http://ccdb-test.cern.ch:8080", {"url of CCDB to get the detectors DPs configuration"}});
46+
workflowOptions.push_back(ConfigParamSpec{"detector-list", VariantType::String, "TOF, MCH", {"list of detectors for which to process DCS"}});
3947
}
4048

4149
#include "Framework/runDataProcessing.h"
@@ -44,17 +52,41 @@ WorkflowSpec defineDataProcessing(ConfigContext const& config)
4452
{
4553

4654
bool verbose = config.options().get<bool>("verbose");
47-
DPID dpidtmp;
55+
bool testMode = config.options().get<bool>("test-mode");
56+
std::string url = config.options().get<std::string>("ccdb-url");
57+
std::string detectorList = config.options().get<std::string>("detector-list");
4858

4959
std::unordered_map<DPID, o2h::DataDescription> dpid2DataDesc;
50-
DPID::FILL(dpidtmp, "ADAPOS_LG/TEST_000100", DeliveryType::RAW_STRING);
51-
dpid2DataDesc[dpidtmp] = "COMMON"; // i.e. this will go to {DCS/COMMON/0} OutputSpec
52-
DPID::FILL(dpidtmp, "ADAPOS_LG/TEST_000110", DeliveryType::RAW_STRING);
53-
dpid2DataDesc[dpidtmp] = "COMMON";
54-
DPID::FILL(dpidtmp, "ADAPOS_LG/TEST_000200", DeliveryType::RAW_STRING);
55-
dpid2DataDesc[dpidtmp] = "COMMON1";
56-
DPID::FILL(dpidtmp, "ADAPOS_LG/TEST_000240", DeliveryType::RAW_INT);
57-
dpid2DataDesc[dpidtmp] = "COMMON1";
60+
61+
if (testMode) {
62+
DPID dpidtmp;
63+
DPID::FILL(dpidtmp, "ADAPOS_LG/TEST_000100", DeliveryType::RAW_STRING);
64+
dpid2DataDesc[dpidtmp] = "COMMON"; // i.e. this will go to {DCS/COMMON/0} OutputSpec
65+
DPID::FILL(dpidtmp, "ADAPOS_LG/TEST_000110", DeliveryType::RAW_STRING);
66+
dpid2DataDesc[dpidtmp] = "COMMON";
67+
DPID::FILL(dpidtmp, "ADAPOS_LG/TEST_000200", DeliveryType::RAW_STRING);
68+
dpid2DataDesc[dpidtmp] = "COMMON1";
69+
DPID::FILL(dpidtmp, "ADAPOS_LG/TEST_000240", DeliveryType::RAW_INT);
70+
dpid2DataDesc[dpidtmp] = "COMMON1";
71+
}
72+
73+
else {
74+
auto& mgr = CcdbManager::instance();
75+
mgr.setURL(url); // http://ccdb-test.cern.ch:8080 or http://localhost:8080 for a local installation
76+
long ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
77+
std::regex re("[\\s,-]+");
78+
std::sregex_token_iterator it(detectorList.begin(), detectorList.end(), re, -1);
79+
std::sregex_token_iterator reg_end;
80+
for (; it != reg_end; ++it) {
81+
LOG(INFO) << "DCS DPs configured for detector " << it->str();
82+
std::unordered_map<DPID, std::string>* dpid2Det = mgr.getForTimeStamp<std::unordered_map<DPID, std::string>>(it->str() + "/DCSconfig", ts);
83+
for (auto& el : *dpid2Det) {
84+
o2::header::DataDescription tmpd;
85+
tmpd.runtimeInit(el.second.c_str(), el.second.size());
86+
dpid2DataDesc[el.first] = tmpd;
87+
}
88+
}
89+
}
5890

5991
// RS: here we should complete the attribution of different DPs to different outputs
6092
// ...

Detectors/TOF/calibration/macros/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
# submit itself to any jurisdiction.
1010

1111
o2_add_test_root_macro(
12-
makeCCDBEntryForDCS.C
12+
makeTOFCCDBEntryForDCS.C
1313
PUBLIC_LINK_LIBRARIES O2::DetectorsDCS O2::CCDB)

Detectors/TOF/calibration/macros/makeCCDBEntryForDCS.C renamed to Detectors/TOF/calibration/macros/makeTOFCCDBEntryForDCS.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
using DPID = o2::dcs::DataPointIdentifier;
2323

24-
int makeCCDBEntryForDCS(const std::string url = "http://localhost:8080")
24+
int makeTOFCCDBEntryForDCS(const std::string url = "http://localhost:8080")
2525
{
2626

2727
// std::string url(argv[0]);

0 commit comments

Comments
 (0)