artdaq  v3_08_00
ArtdaqFragmentNamingService_service.cc
1 #include "artdaq-core/Data/ContainerFragment.hh"
2 #include "artdaq/ArtModules/ArtdaqFragmentNamingService.h"
3 
4 #include "TRACE/tracemf.h"
5 #define TRACE_NAME "ArtdaqFragmentNamingService"
6 
7 ArtdaqFragmentNamingService::ArtdaqFragmentNamingService(fhicl::ParameterSet const& ps, art::ActivityRegistry&)
9 {
10  TLOG(TLVL_DEBUG) << "ArtdaqFragmentNamingService CONSTRUCTOR START";
11  TLOG(TLVL_DEBUG) << "ArtdaqFragmentNamingService CONSTRUCTOR END";
12 }
13 
15 {
16 }
17 
18 std::string ArtdaqFragmentNamingService::GetInstanceNameForType(artdaq::Fragment::type_t type_id)
19 {
20  if (type_map_.count(type_id) > 0) { return type_map_[type_id]; }
22 }
23 
25 {
26  std::set<std::string> output;
27  for (const auto& map_iter : type_map_)
28  {
29  std::string instance_name = map_iter.second;
30  if (!output.count(instance_name))
31  {
32  output.insert(instance_name);
33  TLOG(TLVL_TRACE) << "Adding product instance name \"" << map_iter.second
34  << "\" to list of expected names";
35  }
36  }
37 
38  auto container_type = type_map_.find(artdaq::Fragment::type_t(artdaq::Fragment::ContainerFragmentType));
39  if (container_type != type_map_.end())
40  {
41  std::string container_type_name = container_type->second;
42  std::set<std::string> tmp_copy = output;
43  for (const auto& set_iter : tmp_copy)
44  {
45  output.insert(container_type_name + set_iter);
46  }
47  }
48 
49  return output;
50 }
51 
52 std::pair<bool, std::string>
54 {
55  auto type_map_end = type_map_.end();
56  bool success_code = true;
57  std::string instance_name;
58 
59  auto primary_type = type_map_.find(fragment.type());
60  if (primary_type != type_map_end)
61  {
62  TLOG(TLVL_TRACE) << "Found matching instance name " << primary_type->second << " for Fragment type " << fragment.type();
63  instance_name = primary_type->second;
64  if (fragment.type() == artdaq::Fragment::ContainerFragmentType)
65  {
66  artdaq::ContainerFragment cf(fragment);
67  auto contained_type = type_map_.find(cf.fragment_type());
68  if (contained_type != type_map_end)
69  {
70  instance_name += contained_type->second;
71  }
72  }
73  }
74  else
75  {
76  TLOG(TLVL_TRACE) << "Could not find match for Fragment type " << fragment.type() << ", returning " << unidentified_instance_name_;
77  instance_name = unidentified_instance_name_;
78  success_code = false;
79  }
80 
81  return std::make_pair(success_code, instance_name);
82 }
83 
84 DEFINE_ART_SERVICE_INTERFACE_IMPL(ArtdaqFragmentNamingService, ArtdaqFragmentNamingServiceInterface)
virtual std::pair< bool, std::string > GetInstanceNameForFragment(artdaq::Fragment const &fragment)
Returns the product instance name for the specified fragment, based on the types that have been speci...
virtual std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id)
Returns the basic translation for the specified type. Defaults to the specified unidentified_instance...
virtual std::set< std::string > GetAllProductInstanceNames()
Returns the full set of product instance names which may be present in the data, based on the types t...
ArtdaqFragmentNamingService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
NetMonTransportService Constructor.
std::map< artdaq::Fragment::type_t, std::string > type_map_
Map relating Fragment Type to strings.
ArtdaqFragmentNamingService extends ArtdaqFragmentNamingServiceInterface. This implementation uses th...
virtual ~ArtdaqFragmentNamingService()
DefaultArtdaqFragmentNamingService Destructor.
Interface for ArtdaqFragmentNamingService. This interface is declared to art as part of the required ...
std::string unidentified_instance_name_
The name to use for unknown Fragment types.