artdaq  v3_08_00
ArtdaqFragmentNamingService.h
1 #ifndef artdaq_ArtModules_ArtdaqFragmentNamingService_h
2 #define artdaq_ArtModules_ArtdaqFragmentNamingService_h
3 
4 #include "art/Framework/Services/Registry/ServiceMacros.h"
5 #include "artdaq-core/Data/Fragment.hh"
6 #include "fhiclcpp/types/Atom.h"
7 
12 {
13 public:
17  virtual ~ArtdaqFragmentNamingServiceInterface() = default;
18 
27  ArtdaqFragmentNamingServiceInterface(fhicl::ParameterSet const& ps)
28  : type_map_(), unidentified_instance_name_(ps.get<std::string>("unidentified_instance_name", "unidentified"))
29  {
30  SetBasicTypes(artdaq::Fragment::MakeSystemTypeMap());
31  auto extraTypes = ps.get<std::vector<std::pair<artdaq::Fragment::type_t, std::string>>>("fragment_type_map", std::vector<std::pair<artdaq::Fragment::type_t, std::string>>());
32  for (auto it = extraTypes.begin(); it != extraTypes.end(); ++it)
33  {
34  AddExtraType(it->first, it->second);
35  }
36  }
37 
41  void SetBasicTypes(std::map<artdaq::Fragment::type_t, std::string> const& type_map)
42  {
43  for (auto& type_pair : type_map)
44  {
45  type_map_[type_pair.first] = type_pair.second;
46  }
47  }
48 
52  void AddExtraType(artdaq::Fragment::type_t type_id, std::string type_name)
53  {
54  type_map_[type_id] = type_name;
55  }
56 
62 
66  virtual std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id) = 0;
67 
74  virtual std::set<std::string> GetAllProductInstanceNames() = 0;
75 
83  virtual std::pair<bool, std::string>
84  GetInstanceNameForFragment(artdaq::Fragment const& fragment) = 0;
85 
86 protected:
87  std::map<artdaq::Fragment::type_t, std::string> type_map_;
89 };
90 DECLARE_ART_SERVICE_INTERFACE(ArtdaqFragmentNamingServiceInterface, LEGACY)
91 
92 // ----------------------------------------------------------------------
93 
94 
99 {
100 public:
104  virtual ~ArtdaqFragmentNamingService();
105 
110  ArtdaqFragmentNamingService(fhicl::ParameterSet const& pset, art::ActivityRegistry&);
111 
116  virtual std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id);
117 
123  virtual std::set<std::string> GetAllProductInstanceNames();
124 
131  virtual std::pair<bool, std::string>
132  GetInstanceNameForFragment(artdaq::Fragment const& fragment);
133 
134 private:
135 };
136 
137 DECLARE_ART_SERVICE_INTERFACE_IMPL(ArtdaqFragmentNamingService, ArtdaqFragmentNamingServiceInterface, LEGACY)
138 
139 #endif /* artdaq_ArtModules_ArtdaqFragmentNamingService_h */
140 
141 // Local Variables:
142 // mode: c++
143 // End:
ArtdaqFragmentNamingServiceInterface(fhicl::ParameterSet const &ps)
ArtdaqFragmentNamingServiceInterface constructor.
void SetBasicTypes(std::map< artdaq::Fragment::type_t, std::string > const &type_map)
Sets the basic types to be translated. (Should not include &quot;container&quot; types.)
virtual std::pair< bool, std::string > GetInstanceNameForFragment(artdaq::Fragment const &fragment)=0
Returns the product instance name for the specified fragment, based on the types that have been speci...
void AddExtraType(artdaq::Fragment::type_t type_id, std::string type_name)
Adds an additional type to be translated.
virtual ~ArtdaqFragmentNamingServiceInterface()=default
Default virtual destructor.
virtual std::set< std::string > GetAllProductInstanceNames()=0
Returns the full set of product instance names which may be present in the data, based on the types t...
std::map< artdaq::Fragment::type_t, std::string > type_map_
Map relating Fragment Type to strings.
ArtdaqFragmentNamingService extends ArtdaqFragmentNamingServiceInterface. This implementation uses th...
Interface for ArtdaqFragmentNamingService. This interface is declared to art as part of the required ...
virtual std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id)=0
Returns the basic translation for the specified type. Must be implemented by derived classes...
std::string unidentified_instance_name_
The name to use for unknown Fragment types.
std::string GetUnidentifiedInstanceName()
Get the configured unidentified_instance_name.