File indexing completed on 2025-01-18 10:01:40
0001
0002
0003
0004 #pragma once
0005
0006 #include <string>
0007 #include <map>
0008 #include <set>
0009 #include <vector>
0010 #include <tuple>
0011 #include <mutex>
0012 #include <iostream>
0013
0014 #include <JANA/Services/JParameterManager.h>
0015 class JEvent;
0016 class JFactory;
0017 class JObject;
0018
0019 class JInspector {
0020
0021 public:
0022 enum class Format {Table, Json, Tsv};
0023
0024 private:
0025
0026 Format m_format = Format::Table;
0027 const JEvent* m_event;
0028 bool m_indexes_built = false;
0029 std::map<std::string, std::pair<int, const JFactory*>> m_factory_index;
0030 std::vector<JFactory*> m_factories;
0031 std::ostream& m_out = std::cout;
0032 std::istream& m_in = std::cin;
0033 std::set<std::string> m_discrepancies;
0034 bool m_enable_timeout_on_exit = false;
0035 bool m_enable_ticker_on_exit = false;
0036
0037 public:
0038 explicit JInspector(const JEvent* event);
0039
0040 void PrintEvent();
0041 void PrintFactories(int filter_level);
0042 void PrintFactoryDetails(std::string factory_key);
0043 void PrintObjects(std::string factory_key);
0044 void PrintObject(std::string factory_key, int object_idx);
0045 void PrintFactoryParents(std::string factory_key);
0046 void PrintObjectParents(std::string factory_key, int object_idx);
0047 void PrintObjectAncestors(std::string factory_key, int object_idx);
0048 void PrintHelp();
0049 void Loop();
0050 void Reset();
0051
0052 void SetDiscrepancies(std::set<std::string>&& diverging_factory_keys);
0053
0054 static void ToText(const JEvent* event, bool asJson=false, std::ostream& out=std::cout);
0055 void ToText(const std::vector<JFactory*>& factories, const std::set<std::string>& discrepancies, int filter_level, bool asJson=false, std::ostream& out=std::cout);
0056 static void ToText(const JFactory* factory, bool asJson=false, std::ostream& out=std::cout);
0057 static void ToText(std::vector<JObject*> objs, bool as_json, std::ostream& out= std::cout);
0058 static void ToText(const JObject* obj, bool asJson, std::ostream& out=std::cout);
0059
0060 private:
0061 void BuildIndices();
0062 std::string MakeFactoryKey(std::string name, std::string tag);
0063 static std::vector<const JObject*> FindAllAncestors(const JObject*);
0064 static std::tuple<JFactory*, size_t, size_t> LocateObject(const JEvent&, const JObject* obj);
0065 };
0066
0067 template <>
0068 inline std::string JParameterManager::Stringify(const JInspector::Format& value) {
0069 switch (value) {
0070 case JInspector::Format::Table: return "table";
0071 case JInspector::Format::Json: return "json";
0072 case JInspector::Format::Tsv: return "tsv";
0073 default: return "unknown";
0074 }
0075 }
0076
0077 template <>
0078 inline void JParameterManager::Parse(const std::string& value, JInspector::Format& val) {
0079 auto lowered = JParameterManager::ToLower(value);
0080 if (lowered == "table") val = JInspector::Format::Table;
0081 if (lowered == "json") val = JInspector::Format::Json;
0082 if (lowered == "tsv") val = JInspector::Format::Tsv;
0083 else val = JInspector::Format::Table;
0084 }
0085