artdaq_core  v3_06_10
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 {
35 {
36 public:
40  virtual ~FragmentNameHelper() = default;
41 
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 
123 inline std::shared_ptr<FragmentNameHelper>
124 makeNameHelper(std::string const& plugin_name, std::string const& unidentified_instance_name, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> extraTypes)
125 {
126  static cet::BasicPluginFactory bpf("fragmentNameHelper", "make");
127 
128  return bpf.makePlugin<std::shared_ptr<FragmentNameHelper>>(plugin_name, unidentified_instance_name, extraTypes);
129 }
130 
135 {
136 public:
140  virtual ~ArtdaqFragmentNameHelper();
141 
147  ArtdaqFragmentNameHelper(std::string unidentified_instance_name, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> extraTypes);
148 
153  virtual std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id) const;
154 
160  virtual std::set<std::string> GetAllProductInstanceNames() const;
161 
168  virtual std::pair<bool, std::string>
169  GetInstanceNameForFragment(artdaq::Fragment const& fragment) const;
170 
171 private:
174  ArtdaqFragmentNameHelper& operator=(ArtdaqFragmentNameHelper const&) = delete;
175  ArtdaqFragmentNameHelper& operator=(ArtdaqFragmentNameHelper&&) = delete;
176 };
177 } // namespace artdaq
178 
179 #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...
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.
The FragmentNameHelper translates between Fragments and their instance names (usually by type...
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.
std::shared_ptr< FragmentNameHelper > makeNameHelper(std::string const &plugin_name, std::string const &unidentified_instance_name, std::vector< std::pair< artdaq::Fragment::type_t, std::string >> extraTypes)
Create a FragmentNameHelper.
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)
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...