otsdaq  v2_05_02_indev
FragmentType.cc
1 #include "artdaq-ots/Overlays/FragmentType.hh"
2 
3 #include <algorithm>
4 #include <cassert>
5 #include <string>
6 #include <vector>
7 
8 ots::FragmentType ots::toFragmentType(std::string t_string)
9 {
10  std::transform(t_string.begin(), t_string.end(), t_string.begin(), toupper);
11  auto it = std::find(names.begin(), names.end(), t_string);
12  return (it == names.end()) ? FragmentType::INVALID : static_cast<FragmentType>(artdaq::Fragment::FirstUserFragmentType + (it - names.begin()));
13 }
14 
15 std::string ots::fragmentTypeToString(FragmentType val)
16 {
17  if(val < FragmentType::INVALID)
18  {
19  return names[val - FragmentType::MISSED];
20  }
21  else
22  {
23  return "INVALID/UNKNOWN";
24  }
25 }
26 
27 std::map<artdaq::Fragment::type_t, std::string> ots::makeFragmentTypeMap()
28 {
29  auto output = artdaq::Fragment::MakeSystemTypeMap();
30  for(auto name : names)
31  {
32  output[toFragmentType(name)] = name;
33  }
34  return output;
35 }