Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cbmroot
Manage
Activity
Members
Labels
Plan
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computing
cbmroot
Commits
d94b4dec
Commit
d94b4dec
authored
Mar 29, 2022
by
Jan de Cuveland
Committed by
Florian Uhlig
Mar 29, 2022
Browse files
Options
Downloads
Patches
Plain Diff
Add convenience functions to convert between ECbmModuleId and std::string
parent
8fcb9dfc
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!774
Add convenience functions to convert between ECbmModuleId and std::string
Pipeline
#16730
failed
Mar 29, 2022
Stage: build
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/data/CbmDefs.cxx
+56
-1
56 additions, 1 deletion
core/data/CbmDefs.cxx
core/data/CbmDefs.h
+6
-1
6 additions, 1 deletion
core/data/CbmDefs.h
with
62 additions
and
2 deletions
core/data/CbmDefs.cxx
+
56
−
1
View file @
d94b4dec
...
...
@@ -4,8 +4,10 @@
#include
"CbmDefs.h"
#include
<algorithm>
#include
<array>
#include
<cctype>
#include
<stdexcept>
// for out_of_range
#include
<string>
// for to_string
// operator ++ for ECbmModuleId for convenient usage in loops
// This operator is tuned for ECbmModuleID. It takes into account non
...
...
@@ -38,6 +40,59 @@ std::ostream& operator<<(std::ostream& strm, const ECbmModuleId& modId)
return
strm
;
}
// conversion functions between ECbmModuleId and std::string
static
const
std
::
array
<
std
::
pair
<
ECbmModuleId
,
std
::
string
>
,
22
>
ModIdStrMap
=
{
{{
ECbmModuleId
::
kRef
,
"Ref"
},
{
ECbmModuleId
::
kMvd
,
"Mvd"
},
{
ECbmModuleId
::
kSts
,
"Sts"
},
{
ECbmModuleId
::
kRich
,
"Rich"
},
{
ECbmModuleId
::
kMuch
,
"Much"
},
{
ECbmModuleId
::
kTrd
,
"Trd"
},
{
ECbmModuleId
::
kTof
,
"Tof"
},
{
ECbmModuleId
::
kEcal
,
"Ecal"
},
{
ECbmModuleId
::
kPsd
,
"Psd"
},
{
ECbmModuleId
::
kHodo
,
"Hodo"
},
{
ECbmModuleId
::
kDummyDet
,
"DummyDet"
},
{
ECbmModuleId
::
kT0
,
"T0"
},
{
ECbmModuleId
::
kTrd2d
,
"Trd2d"
},
{
ECbmModuleId
::
kNofSystems
,
"NofSystems"
},
{
ECbmModuleId
::
kMagnet
,
"Magnet"
},
{
ECbmModuleId
::
kTarget
,
"Target"
},
{
ECbmModuleId
::
kPipe
,
"Pipe"
},
{
ECbmModuleId
::
kShield
,
"Shield"
},
{
ECbmModuleId
::
kPlatform
,
"Platform"
},
{
ECbmModuleId
::
kCave
,
"Cave"
},
{
ECbmModuleId
::
kLastModule
,
"LastModule"
},
{
ECbmModuleId
::
kNotExist
,
"NotExist"
}}};
std
::
string
ToString
(
ECbmModuleId
modId
)
{
auto
result
=
std
::
find_if
(
ModIdStrMap
.
begin
(),
ModIdStrMap
.
end
(),
[
modId
](
std
::
pair
<
ECbmModuleId
,
std
::
string
>
p
)
{
return
p
.
first
==
modId
;
});
if
(
result
==
std
::
end
(
ModIdStrMap
))
{
return
"NotExist"
;
}
return
result
->
second
;
};
ECbmModuleId
ToCbmModuleId
(
std
::
string
modIdStr
)
{
auto
result
=
std
::
find_if
(
ModIdStrMap
.
begin
(),
ModIdStrMap
.
end
(),
[
modIdStr
](
std
::
pair
<
ECbmModuleId
,
std
::
string
>
p
)
{
return
p
.
second
==
modIdStr
;
});
if
(
result
==
std
::
end
(
ModIdStrMap
))
{
return
ECbmModuleId
::
kNotExist
;
}
return
result
->
first
;
};
ECbmModuleId
ToCbmModuleIdCaseInsensitive
(
std
::
string
modIdStr
)
{
auto
result
=
std
::
find_if
(
ModIdStrMap
.
begin
(),
ModIdStrMap
.
end
(),
[
modIdStr
](
std
::
pair
<
ECbmModuleId
,
std
::
string
>
p
)
{
return
p
.
second
.
size
()
==
modIdStr
.
size
()
&&
std
::
equal
(
p
.
second
.
begin
(),
p
.
second
.
end
(),
modIdStr
.
begin
(),
[](
unsigned
char
a
,
unsigned
char
b
)
{
return
std
::
tolower
(
a
)
==
std
::
tolower
(
b
);
});
});
if
(
result
==
std
::
end
(
ModIdStrMap
))
{
return
ECbmModuleId
::
kNotExist
;
}
return
result
->
first
;
};
// operator << for convenient output to std::ostream.
// Converts the enum value to a string which is put in the stream
std
::
ostream
&
operator
<<
(
std
::
ostream
&
strm
,
const
ECbmDataType
&
dataType
)
...
...
...
...
This diff is collapsed.
Click to expand it.
core/data/CbmDefs.h
+
6
−
1
View file @
d94b4dec
...
...
@@ -15,6 +15,7 @@
#include
<type_traits>
// for underlying_type
#include
<iostream>
// for ostream
#include
<string>
// Convert an element of enum class to its underlying intergral type
// since with C++11 the return type can't be deduced automatically it has
...
...
@@ -76,6 +77,10 @@ ECbmModuleId& operator++(ECbmModuleId&);
// Converts the enum value to a string which is put in the stream
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
ECbmModuleId
&
);
// conversion functions between ECbmModuleId and std::string
std
::
string
ToString
(
ECbmModuleId
modId
);
ECbmModuleId
ToCbmModuleId
(
std
::
string
modIdStr
);
ECbmModuleId
ToCbmModuleIdCaseInsensitive
(
std
::
string
modIdStr
);
/** Enumerator for CBM data types **/
enum
class
ECbmDataType
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment