Project
Loading...
Searching...
No Matches
DeviceSpec.cxx
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
#include "../src/WorkflowHelpers.h"
12
#include "
Framework/DeviceSpec.h
"
13
#include "
Framework/WorkflowSpec.h
"
14
#include "
Framework/ChannelMatching.h
"
15
#include "
Framework/DeviceControl.h
"
16
#include <vector>
17
#include <algorithm>
18
#include <unordered_set>
19
20
using namespace
o2::framework
;
21
22
namespace
o2
23
{
24
namespace
framework
25
{
26
27
using
LogicalChannelsMap
= std::map<LogicalChannelRange, size_t>;
28
29
// This calculates the distance between two strings. See:
30
//
31
// https://en.wikipedia.org/wiki/Levenshtein_distance
32
//
33
// For the full description
34
size_t
levenshteinDistance
(
const
char
* s,
int
len_s,
const
char
* t,
int
len_t)
35
{
36
size_t
cost;
37
38
/* base case: empty strings */
39
if
(len_s == 0) {
40
return
len_t;
41
}
42
if
(len_t == 0) {
43
return
len_s;
44
}
45
46
/* test if last characters of the strings match */
47
if
(s[len_s - 1] == t[len_t - 1]) {
48
cost = 0;
49
}
else
{
50
cost = 1;
51
}
52
53
return
std::min(std::min(
levenshteinDistance
(s, len_s - 1, t, len_t) + 1,
54
levenshteinDistance
(s, len_s, t, len_t - 1) + 1),
55
levenshteinDistance
(s, len_s - 1, t, len_t - 1) + cost);
56
}
57
58
std::string
findBestCandidate
(
const
std::string& candidate,
const
LogicalChannelsMap
& map)
59
{
60
std::string
result
;
61
size_t
score = -1;
62
for
(
const
auto
& pair : map) {
63
auto
newScore =
levenshteinDistance
(candidate.c_str(), candidate.size(),
64
pair.first.name.c_str(), pair.first.name.size());
65
if
(newScore < score) {
66
result
= pair.first.name;
67
}
68
}
69
return
result
;
70
}
71
72
}
// namespace framework
73
}
// namespace o2
ChannelMatching.h
DeviceControl.h
DeviceSpec.h
WorkflowSpec.h
result
GLuint64EXT * result
Definition
glcorearb.h:5662
framework
Definition
BunchFilling.h:113
o2::framework
Defining PrimaryVertex explicitly as messageable.
Definition
TFIDInfo.h:20
o2::framework::levenshteinDistance
size_t levenshteinDistance(const char *s, int len_s, const char *t, int len_t)
Definition
DeviceSpec.cxx:34
o2::framework::findBestCandidate
std::string findBestCandidate(const std::string &candidate, const LogicalChannelsMap &map)
Definition
DeviceSpec.cxx:58
o2::framework::LogicalChannelsMap
std::map< LogicalChannelRange, size_t > LogicalChannelsMap
Definition
DeviceSpec.cxx:27
o2
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Definition
BitstreamReader.h:24
Framework
Core
src
DeviceSpec.cxx
Generated on Tue Feb 25 2025 17:03:21 for Project by
1.9.8