forked from AliceO2Group/QualityControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectsManager.cxx
More file actions
142 lines (122 loc) · 4.44 KB
/
ObjectsManager.cxx
File metadata and controls
142 lines (122 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file ObjectsManager.cxx
/// \author Barthelemy von Haller
///
#include "QualityControl/ObjectsManager.h"
#include "QualityControl/QcInfoLogger.h"
#include "QualityControl/ServiceDiscovery.h"
#include <Common/Exceptions.h>
#include <TObjArray.h>
using namespace o2::quality_control::core;
using namespace AliceO2::Common;
using namespace std;
namespace o2::quality_control::core
{
ObjectsManager::ObjectsManager(TaskConfig& taskConfig, bool noDiscovery) : mTaskConfig(taskConfig), mUpdateServiceDiscovery(false)
{
mMonitorObjects = std::make_unique<TObjArray>();
mMonitorObjects->SetOwner(true);
// register with the discovery service
if (!noDiscovery) {
mServiceDiscovery = std::make_unique<ServiceDiscovery>(taskConfig.consulUrl, taskConfig.taskName);
} else {
QcInfoLogger::GetInstance() << "Service Discovery disabled" << infologger::endm;
mServiceDiscovery = nullptr;
}
}
ObjectsManager::~ObjectsManager() = default;
void ObjectsManager::startPublishing(TObject* object)
{
if (mMonitorObjects->FindObject(object->GetName()) != 0) {
QcInfoLogger::GetInstance() << "Object already being published (" << object->GetName() << ")"
<< infologger::endm;
BOOST_THROW_EXCEPTION(DuplicateObjectError() << errinfo_object_name(object->GetName()));
}
auto* newObject = new MonitorObject(object, mTaskConfig.taskName, mTaskConfig.detectorName);
newObject->setIsOwner(false);
mMonitorObjects->Add(newObject);
mUpdateServiceDiscovery = true;
}
void ObjectsManager::updateServiceDiscovery()
{
if (!mUpdateServiceDiscovery || mServiceDiscovery == nullptr) {
return;
}
// prepare the string of comma separated objects and publish it
string objects;
for (auto tobj : *mMonitorObjects) {
MonitorObject* mo = dynamic_cast<MonitorObject*>(tobj);
objects += mo->getPath() + ",";
}
objects.pop_back();
mServiceDiscovery->_register(objects);
mUpdateServiceDiscovery = false;
}
void ObjectsManager::removeAllFromServiceDiscovery()
{
if (mServiceDiscovery == nullptr) {
return;
}
mServiceDiscovery->_register("");
mUpdateServiceDiscovery = true;
}
void ObjectsManager::stopPublishing(TObject* object)
{
stopPublishing(object->GetName());
}
void ObjectsManager::stopPublishing(const string& name)
{
auto* mo = dynamic_cast<MonitorObject*>(mMonitorObjects->FindObject(name.data()));
if (mo == nullptr) {
// TODO: ideally we want to pass the object name to the exception but the implementation
// of AliceO2::Common::ObjectNotFoundError drops additional information. For clarity we
// better skip
// << errinfo_object_name(name));
// until this is fixed
BOOST_THROW_EXCEPTION(ObjectNotFoundError());
}
mMonitorObjects->Remove(mo);
}
MonitorObject* ObjectsManager::getMonitorObject(std::string objectName)
{
TObject* mo = mMonitorObjects->FindObject(objectName.c_str());
if (mo != nullptr) {
return dynamic_cast<MonitorObject*>(mo);
} else {
// TODO: ideally we want to pass the object name to the exception but the implementation
// of AliceO2::Common::ObjectNotFoundError drops additional information. For clarity we
// better skip
// << errinfo_object_name(objectName));
// until this is fixed
BOOST_THROW_EXCEPTION(ObjectNotFoundError());
}
}
TObject* ObjectsManager::getObject(std::string objectName)
{
MonitorObject* mo = getMonitorObject(objectName);
return mo->getObject();
}
TObjArray* ObjectsManager::getNonOwningArray() const
{
return new TObjArray(*mMonitorObjects);
}
void ObjectsManager::addMetadata(const std::string& objectName, const std::string& key, const std::string& value)
{
MonitorObject* mo = getMonitorObject(objectName);
mo->addMetadata(key, value);
QcInfoLogger::GetInstance() << "Added metadata on " << objectName << " : " << key << " -> " << value << infologger::endm;
}
int ObjectsManager::getNumberPublishedObjects()
{
return mMonitorObjects->GetLast() + 1; // GetLast returns the index
}
} // namespace o2::quality_control::core