artdaq_core  v3_06_00
FragmentNameHelper.hh
1 #ifndef _artdaq_core_Data_FragmentNameHelper_hh_
2 #define _artdaq_core_Data_FragmentNameHelper_hh_
3 
4 #include <set>
5 #include <string>
6 #include <vector>
7 
8 #include <cetlib/BasicPluginFactory.h>
9 #include <cetlib/compiler_macros.h>
10 
11 #include "artdaq-core/Data/Fragment.hh"
12 
13 #ifndef EXTERN_C_FUNC_DECLARE_START
14 #define EXTERN_C_FUNC_DECLARE_START \
15  extern "C" {
16 #endif
17 
22 #define DEFINE_ARTDAQ_FRAGMENT_NAME_HELPER(klass) \
23  EXTERN_C_FUNC_DECLARE_START \
24  std::shared_ptr<artdaq::FragmentNameHelper> make(std::string unidentified, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> types) \
25  { \
26  return std::shared_ptr<artdaq::FragmentNameHelper>(new klass(unidentified, types)); \
27  } \
28  }
29 
30 namespace artdaq {
32 {
33 public:
37  virtual ~FragmentNameHelper() = default;
38 
47  FragmentNameHelper(std::string unidentified_instance_name, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> extraTypes)
48  : type_map_()
49  , unidentified_instance_name_(unidentified_instance_name)
50  {
52  for (auto it = extraTypes.begin(); it != extraTypes.end(); ++it)
53  {
54  AddExtraType(it->first, it->second);
55  }
56  }
57 
61  void SetBasicTypes(std::map<artdaq::Fragment::type_t, std::string> const& type_map)
62  {
63  for (auto& type_pair : type_map)
64  {
65  type_map_[type_pair.first] = type_pair.second;
66  }
67  }
68 
72  void AddExtraType(artdaq::Fragment::type_t type_id, std::string const& type_name)
73  {
74  type_map_[type_id] = type_name;
75  }
76 
82 
86  virtual std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id) const = 0;
87 
94  virtual std::set<std::string> GetAllProductInstanceNames() const = 0;
95 
103  virtual std::pair<bool, std::string>
104  GetInstanceNameForFragment(artdaq::Fragment const& fragment) const = 0;
105 
106 protected:
107  std::map<artdaq::Fragment::type_t, std::string> type_map_;
109 private:
110  FragmentNameHelper(FragmentNameHelper const&) = default;
112  FragmentNameHelper& operator=(FragmentNameHelper const&) = default;
113  FragmentNameHelper& operator=(FragmentNameHelper&&) = default;
114 };
115 
116 
117 inline std::shared_ptr<FragmentNameHelper>
118 makeNameHelper(std::string const& plugin_name, std::string const& unidentified_instance_name, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> extraTypes)
119 {
120  static cet::BasicPluginFactory bpf("fragmentNameHelper", "make");
121 
122  return bpf.makePlugin<std::shared_ptr<FragmentNameHelper>>(plugin_name, unidentified_instance_name, extraTypes);
123 }
124 
126 {
127 public:
131  virtual ~ArtdaqFragmentNameHelper();
132 
137  ArtdaqFragmentNameHelper(std::string unidentified_instance_name, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> extraTypes);
138 
143  virtual std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id) const;
144 
150  virtual std::set<std::string> GetAllProductInstanceNames() const;
151 
158  virtual std::pair<bool, std::string>
159  GetInstanceNameForFragment(artdaq::Fragment const& fragment) const;
160 
161 private:
164  ArtdaqFragmentNameHelper& operator=(ArtdaqFragmentNameHelper const&) = delete;
165  ArtdaqFragmentNameHelper& operator=(ArtdaqFragmentNameHelper&&) = delete;
166 };
167 } // namespace artdaq
168 
169 #endif //_artdaq_core_Data_FragmentNameHelper_hh_
void AddExtraType(artdaq::Fragment::type_t type_id, std::string const &type_name)
Adds an additional type to be translated.
virtual ~ArtdaqFragmentNameHelper()
DefaultArtdaqFragmentNameHelper Destructor.
std::string unidentified_instance_name_
The name to use for unknown Fragment types.
virtual std::set< std::string > GetAllProductInstanceNames() const =0
Returns the full set of product instance names which may be present in the data, based on the types t...
virtual ~FragmentNameHelper()=default
Default virtual destructor.
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.
FragmentNameHelper(std::string unidentified_instance_name, std::vector< std::pair< artdaq::Fragment::type_t, std::string >> extraTypes)
FragmentNameHelper constructor.
static std::map< type_t, std::string > MakeSystemTypeMap()
Returns a map of the most commonly-used system types.
Definition: Fragment.hh:177
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...
std::string GetUnidentifiedInstanceName() const
Get the configured unidentified_instance_name.
virtual std::pair< bool, std::string > GetInstanceNameForFragment(artdaq::Fragment const &fragment) const =0
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
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::string GetInstanceNameForType(artdaq::Fragment::type_t type_id) const =0
Returns the basic translation for the specified type. Must be implemented by derived classes...
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...