Line data Source code
1 : #ifndef artdaq_ArtModules_ArtdaqFragmentNamingService_h
2 : #define artdaq_ArtModules_ArtdaqFragmentNamingService_h
3 :
4 : #include "art/Framework/Services/Registry/ServiceDeclarationMacros.h"
5 : #include "artdaq-core/Plugins/FragmentNameHelper.hh"
6 :
7 : namespace fhicl {
8 : class ParameterSet;
9 : }
10 :
11 : /**
12 : * \brief Interface for ArtdaqFragmentNamingService. This interface is declared to art as part of the required registration of an art Service
13 : */
14 : class ArtdaqFragmentNamingServiceInterface
15 : {
16 : public:
17 : /**
18 : * \brief Default virtual destructor
19 : */
20 0 : virtual ~ArtdaqFragmentNamingServiceInterface() = default;
21 :
22 : /**
23 : * \brief ArtdaqFragmentNamingServiceInterface constructor
24 : * \param ps ParameterSet used to configure ArtdaqFragmentNamingServiceInterface
25 : *
26 : * ArtdaqFragmentNamingServiceInterface accepts the following Parameters:
27 : * "unidentified_instance_name" (Default: "unidentified"): Name to use for any Fragments which are not successfully translated by the ArtdaqFragmentNamingServiceInterface
28 : * "fragment_type_map" (Default: []): A list of Fragment type_t to string pairs for additional types to register with the ArtdaqFragmentNamingServiceInterface
29 : * "helper_plugin" (Default: "Artdaq"): The name of the FragmentNameHelper plugin to use for resolving Fragment names
30 : * "enabled_fragment_types" (Default: []): A list of Fragment instance names which are allowed to be used. If empty, all types are allowed.
31 : */
32 0 : ArtdaqFragmentNamingServiceInterface(fhicl::ParameterSet const& ps)
33 0 : : nameHelper_(nullptr)
34 : {
35 0 : auto unidentified_instance_name = ps.get<std::string>("unidentified_instance_name", "unidentified");
36 0 : 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>>());
37 0 : auto fragmentNameHelperPluginType = ps.get<std::string>("helper_plugin", "Artdaq");
38 :
39 0 : enabled_fragment_names_ = ps.get<std::vector<std::string>>("enabled_fragment_types", std::vector<std::string>());
40 :
41 0 : nameHelper_ = artdaq::makeNameHelper(fragmentNameHelperPluginType, unidentified_instance_name, extraTypes);
42 0 : }
43 :
44 : /**
45 : * \brief Returns the basic translation for the specified type. Must be implemented by derived classes
46 : */
47 0 : std::string GetInstanceNameForType(artdaq::Fragment::type_t type_id) const
48 : {
49 0 : auto name = nameHelper_->GetInstanceNameForType(type_id);
50 0 : if (!enabled_fragment_names_.empty() && std::find(enabled_fragment_names_.begin(), enabled_fragment_names_.end(), name) == enabled_fragment_names_.end())
51 : {
52 0 : TLOG(TLVL_WARNING, "ArtdaqFragmentNamingServiceInterface") << "DisabledFragmentType: The product instance name mapping for fragment type \"" << name
53 0 : << "\" is not enabled. Fragments of this "
54 0 : << "type will be stored in the event with an instance name of \"" << nameHelper_->GetUnidentifiedInstanceName() << "\".";
55 0 : return nameHelper_->GetUnidentifiedInstanceName();
56 : }
57 0 : return name;
58 0 : }
59 :
60 : /**
61 : * \brief Returns the full set of product instance names which may be present in the data, based on
62 : * the types that have been specified in the SetBasicTypes() and AddExtraType() methods. This
63 : * *does* include "container" types, if the container type mapping is part of the basic types.
64 : * Must be implemented by derived classes
65 : */
66 0 : std::set<std::string> GetAllProductInstanceNames() const
67 : {
68 0 : if (!enabled_fragment_names_.empty())
69 : {
70 0 : std::set<std::string> names;
71 0 : for (const auto& name : enabled_fragment_names_)
72 : {
73 0 : names.insert(name);
74 : }
75 0 : return names;
76 0 : }
77 0 : return nameHelper_->GetAllProductInstanceNames();
78 : }
79 :
80 : /**
81 : * \brief Returns the product instance name for the specified fragment, based on the types that have
82 : * been specified in the SetBasicTypes() and AddExtraType() methods. This *does* include the
83 : * use of "container" types, if the container type mapping is part of the basic types. If no
84 : * mapping is found, the specified unidentified_instance_name is returned.
85 : * Must be implemented by derived classes
86 : */
87 : std::pair<bool, std::string>
88 0 : GetInstanceNameForFragment(artdaq::Fragment const& fragment) const
89 : {
90 0 : auto name_pair = nameHelper_->GetInstanceNameForFragment(fragment);
91 0 : if (!enabled_fragment_names_.empty() && std::find(enabled_fragment_names_.begin(), enabled_fragment_names_.end(), name_pair.second) == enabled_fragment_names_.end())
92 : {
93 0 : TLOG(TLVL_WARNING, "ArtdaqFragmentNamingServiceInterface") << "DisabledFragmentType: The product instance name mapping for fragment type \"" << name_pair.second
94 0 : << "\" is not enabled. Fragments of this "
95 0 : << "type will be stored in the event with an instance name of \"" << nameHelper_->GetUnidentifiedInstanceName() << "\".";
96 0 : return std::make_pair(false, nameHelper_->GetUnidentifiedInstanceName());
97 : }
98 0 : return name_pair;
99 0 : }
100 :
101 : /**
102 : * @brief Get the name used for unidentified Fragment types
103 : * @return The name used for unidentified Fragment types
104 : */
105 0 : std::string GetUnidentifiedInstanceName() const { return nameHelper_->GetUnidentifiedInstanceName(); }
106 :
107 : protected:
108 : std::shared_ptr<artdaq::FragmentNameHelper> nameHelper_; ///< FragmentNameHelper plugin used to resolve Fragment names
109 : std::vector<std::string> enabled_fragment_names_{};
110 :
111 : private:
112 : ArtdaqFragmentNamingServiceInterface(ArtdaqFragmentNamingServiceInterface const&) = delete;
113 : ArtdaqFragmentNamingServiceInterface(ArtdaqFragmentNamingServiceInterface&&) = delete;
114 : ArtdaqFragmentNamingServiceInterface& operator=(ArtdaqFragmentNamingServiceInterface const&) = delete;
115 : ArtdaqFragmentNamingServiceInterface& operator=(ArtdaqFragmentNamingServiceInterface&&) = delete;
116 : };
117 0 : DECLARE_ART_SERVICE_INTERFACE(ArtdaqFragmentNamingServiceInterface, LEGACY)
118 :
119 : #endif /* artdaq_ArtModules_ArtdaqFragmentNamingService_h */
120 :
121 : // Local Variables:
122 : // mode: c++
123 : // End:
|