Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:33

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 #include <iostream>
0006 #include <JANA/Utils/JTablePrinter.h>
0007 #include "JComponentSummary.h"
0008 
0009 namespace jana::components {
0010 
0011 
0012 void JComponentSummary::Add(JComponentSummary::Component* component) {
0013 
0014     m_components.push_back(component);
0015     m_component_lookups[component->GetTypeName()].push_back(component);
0016     m_component_lookups[component->GetPrefix()].push_back(component);
0017 
0018     size_t output_count = component->m_outputs.size();
0019     for (size_t i=0; i<output_count; ++i) {
0020         JComponentSummary::Collection* coll = component->m_outputs[i];
0021         auto lookups = m_collection_lookups[coll->GetName()]; // Auto-create if missing
0022         // See if we already have this collection
0023         bool found = false;
0024         for (JComponentSummary::Collection* existing_coll : lookups) {
0025             if (*existing_coll == *coll) {
0026                 component->m_outputs[i] = existing_coll;
0027                 existing_coll->m_producers.push_back(component);
0028                 delete coll;
0029                 found = true;
0030             }
0031         }
0032         if (!found) {
0033             coll->AddProducer(component);
0034             lookups.push_back(coll);
0035             m_collections.push_back(coll);
0036             m_collection_lookups[coll->GetTypeName()].push_back(coll);
0037         }
0038     }
0039     size_t input_count = component->m_inputs.size();
0040     for (size_t i=0; i<input_count; ++i) {
0041         JComponentSummary::Collection* coll = component->m_inputs[i];
0042         auto lookups = m_collection_lookups[coll->GetName()]; // Auto-create if missing
0043         // See if we already have this collection
0044         bool found = false;
0045         for (JComponentSummary::Collection* existing_coll : lookups) {
0046             if (*existing_coll == *coll) {
0047                 component->m_inputs[i] = existing_coll;
0048                 existing_coll->m_consumers.push_back(component);
0049                 delete coll;
0050                 found = true;
0051             }
0052         }
0053         if (!found) {
0054             coll->AddConsumer(component);
0055             lookups.push_back(coll);
0056             m_collections.push_back(coll);
0057             m_collection_lookups[coll->GetTypeName()].push_back(coll);
0058         }
0059     }
0060 
0061     for (JComponentSummary::Collection* output : component->m_outputs) {
0062         JFactorySummary fac;
0063         fac.level = output->GetLevel();
0064         fac.plugin_name = component->GetPluginName();
0065         fac.factory_name = component->GetTypeName();
0066         fac.factory_tag = output->GetTag().empty() ? output->GetName() : output->GetTag();
0067         fac.object_name = output->GetTypeName();
0068         factories.push_back(std::move(fac));
0069     }
0070 }
0071 
0072 
0073 void PrintCollectionTable(std::ostream& os, const JComponentSummary& cs) {
0074 
0075     JTablePrinter coll_table;
0076     coll_table.AddColumn("Type");
0077     coll_table.AddColumn("Name");
0078     coll_table.AddColumn("Tag");
0079     coll_table.AddColumn("Level");
0080     /*
0081     coll_table.AddColumn("Direction");
0082     coll_table.AddColumn("Factory Type");
0083     coll_table.AddColumn("Factory Prefix");
0084     coll_table.AddColumn("Plugin");
0085     */
0086 
0087     os << "  Collection Summary" << std::endl;
0088 
0089     for (const auto* coll : cs.GetAllCollections()) {
0090         coll_table | coll->GetTypeName() | coll->GetName() | coll->GetTag() | coll->GetLevel();
0091         /*
0092         bool first = true;
0093 
0094         for (const auto* producer : coll->GetProducers()) {
0095             if (!first) {
0096                 coll_table | "" | "" | "" | "";
0097             }
0098             coll_table | "Output" | producer->GetTypeName() | producer->GetPrefix() | producer->GetPluginName();
0099             first = false;
0100         }
0101         for (const auto* consumer : coll->GetConsumers()) {
0102             if (!first) {
0103                 coll_table | "" | "" | "" | "";
0104             }
0105             coll_table | "Input" | consumer->GetTypeName() | consumer->GetPrefix() | consumer->GetPluginName();
0106             first = false;
0107         }
0108         */
0109     }
0110     os << coll_table;
0111 }
0112 
0113 void PrintComponentTable(std::ostream& os, const JComponentSummary& cs) {
0114 
0115 
0116     JTablePrinter comp_table;
0117     comp_table.AddColumn("Base", JTablePrinter::Justify::Left, 12);
0118     comp_table.AddColumn("Type", JTablePrinter::Justify::Left, 40);
0119     comp_table.AddColumn("Prefix", JTablePrinter::Justify::Left, 40);
0120     comp_table.AddColumn("Level", JTablePrinter::Justify::Left, 12);
0121     comp_table.AddColumn("Plugin", JTablePrinter::Justify::Left, 16);
0122 
0123     os << "  Component Summary" << std::endl;
0124 
0125     for (const auto* comp : cs.GetAllComponents()) {
0126         comp_table | comp->GetBaseName() | comp->GetTypeName() | comp->GetPrefix() | comp->GetLevel() | comp->GetPluginName();
0127     }
0128     os << comp_table;
0129 }
0130 
0131 void PrintComponentYaml(std::ostream& os, const JComponentSummary& cs) {
0132     os << "Component Summary" << std::endl;
0133 
0134     for (const auto* comp : cs.GetAllComponents()) {
0135         os << std::endl;
0136         os << " - base:   " << "\"" << comp->GetBaseName() << "\"" << std::endl;
0137         os << "   type:   " << "\"" << comp->GetTypeName() << "\"" << std::endl;
0138         os << "   prefix: " << "\"" << comp->GetPrefix() << "\"" << std::endl;
0139         os << "   level:  " << "\"" << comp->GetLevel() << "\"" << std::endl;
0140         os << "   plugin: " << "\"" << comp->GetPluginName() << "\"" << std::endl;
0141     }
0142 }
0143 
0144 
0145 std::ostream& operator<<(std::ostream& os, JComponentSummary const& cs) {
0146 
0147     PrintComponentYaml(os,cs);
0148     return os;
0149 }
0150 
0151 
0152 std::ostream& operator<<(std::ostream& os, const JComponentSummary::Collection& col) {
0153 
0154     os << "  Type:  " << col.GetTypeName() << std::endl;
0155     os << "  Name:  " << col.GetName() << std::endl;
0156     os << "  Tag:   " << col.GetTag() << std::endl;
0157     os << "  Level: " << col.GetLevel() << std::endl;
0158     os << std::endl;
0159 
0160     if (!col.GetProducers().empty()) {
0161         os << "  Producers:" << std::endl;
0162         JTablePrinter table;
0163         table.AddColumn("Type");
0164         table.AddColumn("Prefix");
0165         table.AddColumn("Level");
0166         table.AddColumn("Plugin");
0167         for (const auto* p : col.GetProducers()) {
0168             table | p->GetTypeName() | p->GetPrefix() | p->GetLevel() | p->GetPluginName();
0169         }
0170         os << table.Render();
0171     }
0172     os << std::endl;
0173 
0174     if (!col.GetConsumers().empty()) {
0175         os << "  Consumers:" << std::endl;
0176         JTablePrinter table;
0177         table.AddColumn("Type");
0178         table.AddColumn("Prefix");
0179         table.AddColumn("Level");
0180         table.AddColumn("Plugin");
0181         for (const auto& c : col.GetConsumers()) {
0182             table | c->GetTypeName() | c->GetPrefix() | c->GetLevel() | c->GetPluginName();
0183         }
0184         os << table.Render();
0185     }
0186     return os;
0187 }
0188 
0189 
0190 std::ostream& operator<<(std::ostream& os, const JComponentSummary::Component& c) {
0191 
0192     os << "  Type:   " << c.GetTypeName() << std::endl;
0193     os << "  Prefix: " << c.GetPrefix() << std::endl;
0194     os << "  Level:  " << c.GetLevel() << std::endl;
0195     os << "  Plugin: " << c.GetPluginName() << std::endl;
0196 
0197     if (!c.GetInputs().empty()) {
0198         os << std::endl;
0199         os << "  Inputs:" << std::endl;
0200         JTablePrinter table;
0201         table.AddColumn("Type");
0202         table.AddColumn("Name");
0203         table.AddColumn("Tag");
0204         table.AddColumn("Level");
0205         for (const auto* col : c.GetInputs()) {
0206             table | col->GetTypeName() | col->GetName() | col->GetTag() | col->GetLevel();
0207         }
0208         os << table.Render();
0209     }
0210 
0211     if (!c.GetOutputs().empty()) {
0212         os << std::endl;
0213         os << "  Outputs:" << std::endl;
0214         JTablePrinter table;
0215         table.AddColumn("Type");
0216         table.AddColumn("Name");
0217         table.AddColumn("Tag");
0218         table.AddColumn("Level");
0219         for (const auto* col : c.GetOutputs()) {
0220             table | col->GetTypeName() | col->GetName() | col->GetTag() | col->GetLevel();
0221         }
0222         os << table.Render();
0223     }
0224     return os;
0225 }
0226 
0227 } // namespace jana::components
0228