Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:26

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #pragma once
0006 #include <JANA/Utils/JEventLevel.h>
0007 
0008 #include <string>
0009 #include <vector>
0010 #include <map>
0011 
0012 // Keeping this around for backwards compatibility only
0013 struct JFactorySummary {
0014     JEventLevel level;
0015     std::string plugin_name;
0016     std::string factory_name;
0017     std::string factory_tag;
0018     std::string object_name;
0019 };
0020 
0021 
0022 namespace jana::components {
0023 
0024 class JComponentSummary {
0025 public:
0026 
0027     class Collection;
0028 
0029     class Component {
0030         friend class JComponentSummary;
0031 
0032         std::string m_base_name;
0033         std::string m_prefix;
0034         std::string m_type_name;
0035         JEventLevel m_level;
0036         std::string m_plugin_name;
0037         std::vector<Collection*> m_inputs;
0038         std::vector<Collection*> m_outputs;
0039 
0040     public:
0041         Component(std::string base_name, std::string prefix, std::string type_name, JEventLevel level, std::string plugin_name)
0042             : m_base_name(base_name), m_prefix(prefix), m_type_name(type_name), m_level(level), m_plugin_name(plugin_name) {}
0043         void AddInput(Collection* input) { m_inputs.push_back(input); }
0044         void AddOutput(Collection* output) { m_outputs.push_back(output); }
0045         std::string GetBaseName() const { return m_base_name; }
0046         std::string GetPrefix() const { return m_prefix; }
0047         std::string GetTypeName() const { return m_type_name; }
0048         JEventLevel GetLevel() const { return m_level; }
0049         std::string GetPluginName() const { return m_plugin_name; }
0050         std::vector<const Collection*> GetInputs() const { 
0051             std::vector<const Collection*> results;
0052             for (Collection* c : m_inputs) {
0053                 results.push_back(c);
0054             }
0055             return results;
0056         }
0057         std::vector<const Collection*> GetOutputs() const { 
0058             std::vector<const Collection*> results;
0059             for (Collection* c : m_outputs) {
0060                 results.push_back(c);
0061             }
0062             return results;
0063         }
0064     };
0065 
0066     class Collection {
0067         friend class JComponentSummary;
0068 
0069         std::string m_tag;
0070         std::string m_name;
0071         std::string m_type_name;
0072         JEventLevel m_level;
0073         std::vector<const Component*> m_producers;
0074         std::vector<const Component*> m_consumers;
0075     
0076     public:
0077         Collection(std::string tag, std::string name, std::string type_name, JEventLevel level)
0078             : m_tag(tag), m_name(name), m_type_name(type_name), m_level(level) {}
0079         void AddProducer(const Component* component) { m_producers.push_back(component); }
0080         void AddConsumer(const Component* component) { m_consumers.push_back(component); }
0081         std::string GetTag() const { return m_tag; }
0082         std::string GetName() const { return m_name; }
0083         std::string GetTypeName() const { return m_type_name; }
0084         JEventLevel GetLevel() const { return m_level; }
0085         std::vector<const Component*> GetProducers() const {
0086             return m_producers;
0087         }
0088         std::vector<const Component*> GetConsumers() const {
0089             return m_consumers;
0090         }
0091     };
0092 
0093 private:
0094     std::vector<Component*> m_components;
0095     std::vector<Collection*> m_collections;
0096     std::map<std::string, std::vector<Component*>> m_component_lookups;
0097     std::map<std::string, std::vector<Collection*>> m_collection_lookups;
0098 
0099 public:
0100     JComponentSummary() = default;
0101 
0102     JComponentSummary(const JComponentSummary&) = delete; // Otherwise we have a lot of internal pointers that have to be deep-copied
0103 
0104     ~JComponentSummary() {
0105         for (Component* c : m_components) {
0106             delete c;
0107         }
0108         for (Collection* c : m_collections) {
0109             delete c;
0110         }
0111     }
0112 
0113 
0114 
0115     void Add(Component* component);
0116 
0117     std::vector<const Collection*> GetAllCollections() const { 
0118         std::vector<const Collection*> results;
0119         for (auto* col: m_collections) {
0120             results.push_back(col);
0121         }
0122         return results; 
0123     }
0124     std::vector<const Component*> GetAllComponents() const { 
0125         std::vector<const Component*> results;
0126         for (auto* comp: m_components) {
0127             results.push_back(comp);
0128         }
0129         return results; 
0130     }
0131 
0132     std::vector<const Collection*> FindCollections(std::string collection_name="") const { 
0133         std::vector<const Collection*> results;
0134         auto it = m_collection_lookups.find(collection_name);
0135         if (it != m_collection_lookups.end()) {
0136             for (auto* col: m_collection_lookups.at(collection_name)) {
0137                 results.push_back(col);
0138             }
0139         }
0140         return results;
0141     }
0142 
0143     std::vector<const Component*> FindComponents(std::string component_name="") const { 
0144         std::vector<const Component*> results;
0145         auto it = m_component_lookups.find(component_name);
0146         if (it != m_component_lookups.end()) {
0147             for (auto* comp: m_component_lookups.at(component_name)) {
0148                 results.push_back(comp);
0149             }
0150         }
0151         return results; 
0152     }
0153 
0154 public:
0155     // Kept for backwards compatibility
0156     std::vector<JFactorySummary> factories;
0157 };
0158 
0159 std::ostream& operator<<(std::ostream& os, const JComponentSummary& cs);
0160 std::ostream& operator<<(std::ostream& os, JComponentSummary::Collection const&);
0161 std::ostream& operator<<(std::ostream& os, JComponentSummary::Component const&);
0162 void PrintComponentTable(std::ostream& os, const JComponentSummary&);
0163 void PrintComponentYaml(std::ostream& os, const JComponentSummary&);
0164 void PrintCollectionTable(std::ostream& os, const JComponentSummary&);
0165 
0166 inline bool operator==(const JComponentSummary::Collection& lhs, const JComponentSummary::Collection& rhs) {
0167     return (lhs.GetLevel() == rhs.GetLevel()) && 
0168            (lhs.GetName() == rhs.GetName()) && 
0169            (lhs.GetTag() == rhs.GetTag()) && 
0170            (lhs.GetTypeName() == rhs.GetTypeName());
0171 }
0172 
0173 inline bool operator!=(const JComponentSummary::Collection& lhs, const JComponentSummary::Collection& rhs) { return !(lhs == rhs); }
0174 
0175 } // namespace jana::components
0176 using jana::components::JComponentSummary;