Back to home page

EIC code displayed by LXR

 
 

    


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

0001 
0002 #include "JApplicationInspector.h"
0003 #include "JANA/Components/JComponentSummary.h"
0004 #include "JANA/Topology/JTopologyBuilder.h"
0005 #include <JANA/JApplication.h>
0006 #include <JANA/Engine/JExecutionEngine.h>
0007 
0008 
0009 void PrintMenu() {
0010     std::cout << "  -----------------------------------------" << std::endl;
0011     std::cout << "  Available commands" << std::endl;
0012     std::cout << "  -----------------------------------------" << std::endl;
0013     std::cout << "  icm  InspectComponents" << std::endl;
0014     std::cout << "  icm  InspectComponent component_name" << std::endl;
0015     std::cout << "  icl  InspectCollections" << std::endl;
0016     std::cout << "  icl  InspectCollection collection_name" << std::endl;
0017     std::cout << "  it   InspectTopology" << std::endl;
0018     std::cout << "  ip   InspectPlace arrow_id place_id" << std::endl;
0019     std::cout << "  ie   InspectEvent arrow_id place_id slot_id" << std::endl;
0020     std::cout << "  f    Fire arrow_id" << std::endl;
0021     std::cout << "  r    Resume" << std::endl;
0022     std::cout << "  s    Scale nthreads" << std::endl;
0023     std::cout << "  q    Quit" << std::endl;
0024     std::cout << "  h    Help" << std::endl;
0025     std::cout << "  -----------------------------------------" << std::endl;
0026 }
0027 
0028 void InspectTopology(JApplication* app) {
0029     auto topology = app->GetService<JTopologyBuilder>();
0030     std::cout << topology->print_topology() << std::endl;
0031 }
0032 
0033 void Fire(JApplication* app, int arrow_id) {
0034     auto engine = app->GetService<JExecutionEngine>();
0035     engine->Fire(arrow_id, 0);
0036 }
0037 
0038 void InspectComponents(JApplication* app) {
0039     auto& summary = app->GetComponentSummary();
0040     PrintComponentTable(std::cout, summary);
0041 }
0042 
0043 void InspectComponent(JApplication* app, std::string component_name) {
0044     const auto& summary = app->GetComponentSummary();
0045     auto lookup = summary.FindComponents(component_name);
0046     if (lookup.empty()) {
0047         std::cout << "Component not found!" << std::endl;
0048     }
0049     else {
0050         std::cout << "----------------------------------------------------------" << std::endl;
0051         for (auto* item : lookup) {
0052             std::cout << *item;
0053             std::cout << "----------------------------------------------------------" << std::endl;
0054         }
0055     }
0056 }
0057 
0058 void InspectCollections(JApplication* app) {
0059     const auto& summary = app->GetComponentSummary();
0060     PrintCollectionTable(std::cout, summary);
0061 }
0062 
0063 void InspectCollection(JApplication* app, std::string collection_name) {
0064     const auto& summary = app->GetComponentSummary();
0065     auto lookup = summary.FindCollections(collection_name);
0066     if (lookup.empty()) {
0067         std::cout << "Collection not found!" << std::endl;
0068     }
0069     else {
0070         std::cout << "----------------------------------------------------------" << std::endl;
0071         for (auto* item : lookup) {
0072             std::cout << *item;
0073             std::cout << "----------------------------------------------------------" << std::endl;
0074         }
0075     }
0076 }
0077 
0078 
0079 void InspectApplication(JApplication* app) {
0080     auto engine = app->GetService<JExecutionEngine>();
0081     PrintMenu();
0082 
0083     while (true) {
0084 
0085         std::string user_input;
0086         std::cout << std::endl << "JANA: "; std::cout.flush();
0087         // obtain a single line
0088         std::getline(std::cin, user_input);
0089         // split into tokens
0090         std::stringstream ss(user_input);
0091         std::string token;
0092         ss >> token;
0093         std::vector<std::string> args;
0094         std::string arg;
0095         try {
0096             while (ss >> arg) {
0097                 args.push_back(arg);
0098             }
0099             if ((token == "InspectComponents" || token == "icm") && args.empty()) {
0100                 InspectComponents(app);
0101             }
0102             else if ((token == "InspectComponent" || token == "icm") && (args.size() == 1)) {
0103                 InspectComponent(app, args[0]);
0104             }
0105             else if ((token == "InspectCollections" || token == "icl") && args.empty()) {
0106                 InspectCollections(app);
0107             }
0108             else if ((token == "InspectCollection" || token == "icl") && (args.size() == 1)) {
0109                 InspectCollection(app, args[0]);
0110             }
0111             else if ((token == "InspectTopology" || token == "it") && args.empty()) {
0112                 InspectTopology(app);
0113             }
0114             else if ((token == "InspectPlace" || token == "ip") && args.size() == 2) {
0115                 // InspectPlace(std::stoi(args[0]), std::stoi(args[1]));
0116             }
0117             else if ((token == "InspectEvent" || token == "ie") && (args.size() == 3)) {
0118                 // InspectEvent(std::stoi(args[0])
0119             }
0120             else if ((token == "Fire" || token == "f") && (args.size() == 1)) {
0121                 Fire(app, std::stoi(args[0]));
0122             }
0123             else if (token == "Resume" || token == "r") {
0124                 engine->RunTopology();
0125                 break;
0126             }
0127             else if ((token == "Scale" || token == "s") && (args.size() == 1)) {
0128                 engine->ScaleWorkers(std::stoi(args[0]));
0129                 engine->RunTopology();
0130                 break;
0131             }
0132             else if (token == "Quit" || token == "q") {
0133                 engine->DrainTopology();
0134                 break;
0135             }
0136             else if (token == "Help" || token == "h") {
0137                 PrintMenu();
0138             }
0139             else if (token == "") {
0140                 // Do nothing
0141             }
0142             else {
0143             std::cout << "(Error: Unrecognized command, or wrong argument count)" << std::endl;
0144             }
0145         }
0146         catch (JException& ex) {
0147             std::cout << "(JException: " << ex.GetMessage() << ")" << std::endl;
0148         }
0149         catch (std::invalid_argument&) {
0150             std::cout << "(Parse error: Maybe an argument needs to be an int)" << std::endl;
0151         }
0152         catch (...) {
0153             std::cout << "(Unknown error)" << std::endl;
0154         }
0155 
0156     }
0157 
0158 }