-
Notifications
You must be signed in to change notification settings - Fork 650
Expand file tree
/
Copy pathTableHelper.cxx
More file actions
100 lines (92 loc) · 3.75 KB
/
TableHelper.cxx
File metadata and controls
100 lines (92 loc) · 3.75 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
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 TableHelper.cxx
/// \author Nicolò Jacazio nicolo.jacazio@cern.ch
/// \brief Base of utilities to build advanced tasks
///
#include "Common/Core/TableHelper.h"
#include "Framework/InitContext.h"
#include "Framework/RunningWorkflowInfo.h"
#include <string>
/// Function to print the table required in the full workflow
/// @param initContext initContext of the init function
void o2::common::core::printTablesInWorkflow(o2::framework::InitContext& initContext)
{
auto& workflows = initContext.services().get<o2::framework::RunningWorkflowInfo const>();
for (auto const& device : workflows.devices) {
for (auto const& input : device.inputs) {
LOG(info) << "Table: " << input.matcher.binding << " in device: " << device.name;
}
}
}
/// Function to check if a table is required in a workflow
/// @param initContext initContext of the init function
/// @param table name of the table to check for
bool o2::common::core::isTableRequiredInWorkflow(o2::framework::InitContext& initContext, const std::string& table)
{
LOG(debug) << "Checking if table " << table << " is needed";
bool tableNeeded = false;
auto& workflows = initContext.services().get<o2::framework::RunningWorkflowInfo const>();
for (auto const& device : workflows.devices) {
for (auto const& input : device.inputs) {
if (input.matcher.binding == table) {
LOG(debug) << "Table: " << input.matcher.binding << " is needed in device: " << device.name;
tableNeeded = true;
}
}
}
return tableNeeded;
}
/// Function to enable or disable a configurable flag, depending on the fact that a table is needed or not
/// @param initContext initContext of the init function
/// @param table name of the table to check for
/// @param flag bool value of flag to set, if the given value is true it will be kept, disregarding the table usage in the workflow.
void o2::common::core::enableFlagIfTableRequired(o2::framework::InitContext& initContext, const std::string& table, bool& flag)
{
if (flag) {
LOG(info) << "Table enabled: " + table;
return;
}
if (isTableRequiredInWorkflow(initContext, table)) {
flag = true;
LOG(info) << "Auto-enabling table: " + table;
return;
}
LOG(info) << "Table disabled and not required: " + table;
}
/// Function to enable or disable a configurable flag, depending on the fact that a table is needed or not
/// @param initContext initContext of the init function
/// @param table name of the table to check for
/// @param flag int value of flag to set, only if initially set to -1. Initial values of 0 or 1 will be kept disregarding the table usage in the workflow.
void o2::common::core::enableFlagIfTableRequired(o2::framework::InitContext& initContext, const std::string& table, int& flag)
{
if (flag > 0) {
flag = 1;
LOG(info) << "Table enabled: " + table;
return;
}
if (isTableRequiredInWorkflow(initContext, table)) {
if (flag < 0) {
flag = 1;
LOG(info) << "Auto-enabling table: " + table;
return;
}
LOG(warn) << "Table disabled but required: " + table;
} else {
if (flag < 0) {
flag = 0;
LOG(info) << "Auto-disabling table: " + table;
return;
}
LOG(info) << "Table disabled and not required: " + table;
}
}