artdaq_core  v3_06_11
Artdaq_fragmentNameHelper.cc
1 #include "artdaq-core/Data/ContainerFragment.hh"
2 #include "artdaq-core/Data/FragmentNameHelper.hh"
3 
4 namespace artdaq {
5 
6 ArtdaqFragmentNameHelper::ArtdaqFragmentNameHelper(std::string unidentified_instance_name, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> extraTypes)
7  : FragmentNameHelper(unidentified_instance_name, extraTypes)
8 {
9  TLOG(TLVL_DEBUG) << "ArtdaqFragmentNameHelper CONSTRUCTOR START";
10  TLOG(TLVL_DEBUG) << "ArtdaqFragmentNameHelper CONSTRUCTOR END";
11 }
12 
14 
16 {
17  if (type_map_.count(type_id) > 0) { return type_map_.at(type_id); }
19 }
20 
22 {
23  std::set<std::string> output;
24  for (const auto& map_iter : type_map_)
25  {
26  std::string instance_name = map_iter.second;
27  if (output.count(instance_name) == 0u)
28  {
29  output.insert(instance_name);
30  TLOG(TLVL_TRACE) << "Adding product instance name \"" << map_iter.second << "\" to list of expected names";
31  }
32  }
33 
34  auto container_type = type_map_.find(artdaq::Fragment::type_t(artdaq::Fragment::ContainerFragmentType));
35  if (container_type != type_map_.end())
36  {
37  std::string container_type_name = container_type->second;
38  std::set<std::string> tmp_copy = output;
39  for (const auto& set_iter : tmp_copy)
40  {
41  output.insert(container_type_name + set_iter);
42  }
43  }
44 
45  return output;
46 }
47 
48 std::pair<bool, std::string>
50 {
51  auto type_map_end = type_map_.end();
52  bool success_code = true;
53  std::string instance_name;
54 
55  auto primary_type = type_map_.find(fragment.type());
56  if (primary_type != type_map_end)
57  {
58  TLOG(TLVL_TRACE) << "Found matching instance name " << primary_type->second << " for Fragment type " << fragment.type();
59  instance_name = primary_type->second;
61  {
62  artdaq::ContainerFragment cf(fragment);
63  auto contained_type = type_map_.find(cf.fragment_type());
64  if (contained_type != type_map_end)
65  {
66  instance_name += contained_type->second;
67  }
68  }
69  }
70  else
71  {
72  TLOG(TLVL_TRACE) << "Could not find match for Fragment type " << fragment.type() << ", returning " << unidentified_instance_name_;
73  instance_name = unidentified_instance_name_;
74  success_code = false;
75  }
76 
77  return std::make_pair(success_code, instance_name);
78 }
79 } // namespace artdaq
80 
81 DEFINE_ARTDAQ_FRAGMENT_NAME_HELPER(artdaq::ArtdaqFragmentNameHelper)
virtual ~ArtdaqFragmentNameHelper()
DefaultArtdaqFragmentNameHelper Destructor.
The artdaq::ContainerFragment class represents a Fragment which contains other Fragments.
std::string unidentified_instance_name_
The name to use for unknown Fragment types.
virtual std::set< std::string > GetAllProductInstanceNames() const
Returns the full set of product instance names which may be present in the data, based on the types t...
Default implementation of FragmentNameHelper.
detail::RawFragmentHeader::type_t type_t
typedef for type_t from RawFragmentHeader
Definition: Fragment.hh:137
std::map< artdaq::Fragment::type_t, std::string > type_map_
Map relating Fragment Type to strings.
Fragment::type_t fragment_type() const
Get the Fragment::type_t of stored Fragment objects.
The FragmentNameHelper translates between Fragments and their instance names (usually by type...
static constexpr type_t ContainerFragmentType
Copy ContainerFragmentType from RawFragmentHeader.
Definition: Fragment.hh:156
type_t type() const
Type of the Fragment, from the Fragment header.
Definition: Fragment.hh:853
virtual std::pair< bool, std::string > GetInstanceNameForFragment(artdaq::Fragment const &fragment) const
Returns the product instance name for the specified fragment, based on the types that have been speci...
A Fragment contains the data from one piece of the DAQ system for one event The artdaq::Fragment is t...
Definition: Fragment.hh:85
ArtdaqFragmentNameHelper(std::string unidentified_instance_name, std::vector< std::pair< artdaq::Fragment::type_t, std::string >> extraTypes)
ArtdaqFragmentNameHelper Constructor.
virtual std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id) const
Returns the basic translation for the specified type. Defaults to the specified unidentified_instance...