1 #ifndef _artdaq_core_Plugins_FragmentNameHelper_hh_
2 #define _artdaq_core_Plugins_FragmentNameHelper_hh_
8 #include <cetlib/BasicPluginFactory.h>
9 #include <cetlib/compiler_macros.h>
11 #include "artdaq-core/Data/ContainerFragment.hh"
12 #include "artdaq-core/Data/Fragment.hh"
14 #ifndef EXTERN_C_FUNC_DECLARE_START
15 #define EXTERN_C_FUNC_DECLARE_START \
23 #define DEFINE_ARTDAQ_FRAGMENT_NAME_HELPER(klass) \
24 EXTERN_C_FUNC_DECLARE_START \
25 std::shared_ptr<artdaq::FragmentNameHelper> make(std::string unidentified, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> types) \
27 return std::shared_ptr<artdaq::FragmentNameHelper>(new klass(unidentified, types)); \
48 FragmentNameHelper(std::string unidentified_instance_name, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> extraTypes)
53 for (
auto it = extraTypes.begin(); it != extraTypes.end(); ++it)
62 void SetBasicTypes(std::map<artdaq::Fragment::type_t, std::string>
const& type_map)
64 for (
auto& type_pair : type_map)
66 type_map_[type_pair.first] = type_pair.second;
101 std::set<std::string> output;
104 std::string instance_name = map_iter.second;
105 if (output.count(instance_name) == 0u)
107 output.insert(instance_name);
108 TLOG(TLVL_DEBUG + 33) <<
"Adding product instance name \"" << map_iter.second <<
"\" to list of expected names";
113 if (container_type != type_map_.end())
115 std::string container_type_name = container_type->second;
116 std::set<std::string> tmp_copy = output;
117 for (
const auto& set_iter : tmp_copy)
119 output.insert(container_type_name + set_iter);
133 virtual std::pair<bool, std::string>
137 bool success_code =
true;
138 std::string instance_name;
141 if (primary_type != type_map_end)
143 TLOG(TLVL_DEBUG + 33) <<
"Found matching instance name " << primary_type->second <<
" for Fragment type " <<
static_cast<int>(fragment.
type());
144 instance_name = primary_type->second;
149 if (contained_type != type_map_end)
151 instance_name += contained_type->second;
157 TLOG(TLVL_DEBUG + 33) <<
"Could not find match for Fragment type " <<
static_cast<int>(fragment.
type()) <<
", returning " <<
unidentified_instance_name_;
159 success_code =
false;
162 return std::make_pair(success_code, instance_name);
166 std::map<artdaq::Fragment::type_t, std::string>
type_map_;
182 inline std::shared_ptr<FragmentNameHelper>
183 makeNameHelper(std::string
const& plugin_name, std::string
const& unidentified_instance_name, std::vector<std::pair<artdaq::Fragment::type_t, std::string>> extraTypes)
185 static cet::BasicPluginFactory bpf(
"fragmentNameHelper",
"make");
187 return bpf.makePlugin<std::shared_ptr<FragmentNameHelper>>(plugin_name, unidentified_instance_name, extraTypes);
191 #endif //_artdaq_core_Plugins_FragmentNameHelper_hh_
void AddExtraType(artdaq::Fragment::type_t type_id, std::string const &type_name)
Adds an additional type to be translated.
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 ~FragmentNameHelper()=default
Default virtual destructor.
detail::RawFragmentHeader::type_t type_t
typedef for type_t from RawFragmentHeader
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.
virtual std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id) const
Returns the basic translation for the specified type. Must be implemented by derived classes...
The FragmentNameHelper translates between Fragments and their instance names (usually by type...
static constexpr type_t ContainerFragmentType
Copy ContainerFragmentType from RawFragmentHeader.
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.
type_t type() const
Type of the Fragment, from the Fragment header.
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.
A Fragment contains the data from one piece of the DAQ system for one event The artdaq::Fragment is t...
void SetBasicTypes(std::map< artdaq::Fragment::type_t, std::string > const &type_map)
Sets the basic types to be translated. (Should not include "container" types.)
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...
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...