artdaq_core_demo  v1_07_01
FragmentType.cc
1 #include "artdaq-core-demo/Overlays/FragmentType.hh"
2 
3 #include <algorithm>
4 #include <cassert>
5 #include <string>
6 #include <vector>
7 
8 demo::FragmentType demo::toFragmentType(std::string t_string)
9 {
10  std::transform(t_string.begin(), t_string.end(), t_string.begin(), toupper);
11  for (auto& it : names)
12  {
13  if (it.second == t_string) return it.first;
14  }
15  return FragmentType::INVALID;
16 }
17 
18 std::string demo::fragmentTypeToString(FragmentType val)
19 {
20  if (names.count(val))
21  {
22  return names.at(val);
23  }
24 
25  return "INVALID/UNKNOWN";
26 }
27 
28 std::map<artdaq::Fragment::type_t, std::string> demo::makeFragmentTypeMap()
29 {
30  auto output = artdaq::Fragment::MakeSystemTypeMap();
31  for (const auto& name : names)
32  {
33  output[name.first] = name.second;
34  }
35  return output;
36 }
std::unordered_map< FragmentType, std::string > const names
List of names (in the order defined below) of the User types defined in artdaq_core_demo.
Definition: FragmentType.hh:34
std::string fragmentTypeToString(FragmentType val)
Look up the name of the given FragmentType.
Definition: FragmentType.cc:18
std::map< artdaq::Fragment::type_t, std::string > makeFragmentTypeMap()
Create a list of all Fragment types defined by this package, in the format that RawInput expects...
Definition: FragmentType.cc:28
FragmentType toFragmentType(std::string t_string)
Lookup the type code for a fragment by its string name.
Definition: FragmentType.cc:8