artdaq_core  v3_06_01
Artdaq_fragmentNameHelper.cc
1 #include "artdaq-core/Data/FragmentNameHelper.hh"
2 #include "artdaq-core/Data/ContainerFragment.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
31  << "\" to list of expected names";
32  }
33  }
34 
35  auto container_type = type_map_.find(artdaq::Fragment::type_t(artdaq::Fragment::ContainerFragmentType));
36  if (container_type != type_map_.end())
37  {
38  std::string container_type_name = container_type->second;
39  std::set<std::string> tmp_copy = output;
40  for (const auto& set_iter : tmp_copy)
41  {
42  output.insert(container_type_name + set_iter);
43  }
44  }
45 
46  return output;
47 }
48 
49 std::pair<bool, std::string>
51 {
52  auto type_map_end = type_map_.end();
53  bool success_code = true;
54  std::string instance_name;
55 
56  auto primary_type = type_map_.find(fragment.type());
57  if (primary_type != type_map_end)
58  {
59  TLOG(TLVL_TRACE) << "Found matching instance name " << primary_type->second << " for Fragment type " << fragment.type();
60  instance_name = primary_type->second;
62  {
63  artdaq::ContainerFragment cf(fragment);
64  auto contained_type = type_map_.find(cf.fragment_type());
65  if (contained_type != type_map_end)
66  {
67  instance_name += contained_type->second;
68  }
69  }
70  }
71  else
72  {
73  TLOG(TLVL_TRACE) << "Could not find match for Fragment type " << fragment.type() << ", returning " << unidentified_instance_name_;
74  instance_name = unidentified_instance_name_;
75  success_code = false;
76  }
77 
78  return std::make_pair(success_code, instance_name);
79 }
80 } // namespace artdaq
81 
82 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...
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.
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)
NetMonTransportService 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...