Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Collections and components lookup #312

Merged
merged 10 commits into from
Jul 3, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ docs/latex/*
*.swp
cmake-build*/
.idea/*
.cache

# PODIO generated artifacts
src/examples/PodioExample/datamodel/*
Expand Down
77 changes: 71 additions & 6 deletions src/libraries/JANA/CLI/JMain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ void PrintUsage() {
}

void PrintUsageOptions() {
std::cout << " -v --version Display version information" << std::endl;
std::cout << " -c --configs Display configuration parameters" << std::endl;
std::cout << " -l --loadconfigs <file> Load configuration parameters from file" << std::endl;
std::cout << " -d --dumpconfigs <file> Dump configuration parameters to file" << std::endl;
std::cout << " -b --benchmark Run in benchmark mode" << std::endl;
std::cout << " -Pkey=value Specify a configuration parameter" << std::endl << std::endl;
std::cout << " -Pkey=value Specify a configuration parameter" << std::endl << std::endl;
std::cout << " -v --version Display version information" << std::endl;
std::cout << " -c --configs Display configuration parameters" << std::endl;
std::cout << " -l --loadconfigs <file> Load configuration parameters from file" << std::endl;
std::cout << " -d --dumpconfigs <file> Dump configuration parameters to file" << std::endl;
std::cout << " -b --benchmark Run in benchmark mode" << std::endl;
std::cout << " --inspect-collection <name> Inspect a collection" << std::endl;
std::cout << " --inspect-component <name> Inspect a component" << std::endl;
}

void PrintVersion() {
Expand Down Expand Up @@ -113,6 +115,51 @@ int Execute(JApplication* app, UserOptions &options) {
<< std::endl;
app->GetJParameterManager()->WriteConfigFile(options.dump_config_file);
}
else if (options.flags[InspectCollection]) {
app->Initialize();
const auto& summary = app->GetComponentSummary();
std::cout << "----------------------------------------------------------" << std::endl;
if (options.collection_query.empty()) {
PrintCollectionTable(std::cout, summary);
}
else {
auto lookup = summary.FindCollections(options.collection_query);
std::cout << "Collection query: '" << options.collection_query << "'" << std::endl;
if (lookup.empty()) {
std::cout << "Collection not found!" << std::endl;
}
else {
std::cout << "----------------------------------------------------------" << std::endl;
for (auto* item : lookup) {
std::cout << *item;
std::cout << "----------------------------------------------------------" << std::endl;
}
}
}
}
else if (options.flags[InspectComponent]) {
app->Initialize();
const auto& summary = app->GetComponentSummary();
std::cout << "----------------------------------------------------------" << std::endl;
if (options.component_query.empty()) {
PrintComponentTable(std::cout, summary);
}
else {
auto lookup = summary.FindComponents(options.component_query);
std::cout << "Component query: '" << options.component_query << "'" << std::endl;
if (lookup.empty()) {
std::cout << "Component not found!" << std::endl;
}
else {
std::cout << "----------------------------------------------------------" << std::endl;
for (auto* item : lookup) {
std::cout << *item;
std::cout << "----------------------------------------------------------" << std::endl;
}
}
}
}

else if (options.flags[Benchmark]) {
// Run JANA in benchmark mode
JBenchmarker benchmarker(app); // Benchmarking params override default params
Expand Down Expand Up @@ -160,6 +207,8 @@ UserOptions ParseCommandLineOptions(int nargs, char *argv[], bool expect_extra)
tokenizer["--dumpconfigs"] = DumpConfigs;
tokenizer["-b"] = Benchmark;
tokenizer["--benchmark"] = Benchmark;
tokenizer["--inspect-collection"] = InspectCollection;
tokenizer["--inspect-component"] = InspectComponent;

if (nargs == 1) {
options.flags[ShowUsage] = true;
Expand Down Expand Up @@ -212,6 +261,22 @@ UserOptions ParseCommandLineOptions(int nargs, char *argv[], bool expect_extra)
options.dump_config_file = "jana.config";
}
break;

case InspectCollection:
options.flags[InspectCollection] = true;
if (i + 1 < nargs && argv[i + 1][0] != '-') {
options.collection_query = argv[i + 1];
i += 1;
}
break;

case InspectComponent:
options.flags[InspectComponent] = true;
if (i + 1 < nargs && argv[i + 1][0] != '-') {
options.component_query = argv[i + 1];
i += 1;
}
break;

case Unknown:
if (argv[i][0] == '-' && argv[i][1] == 'P') {
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/JANA/CLI/JMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace jana {

enum Flag {Unknown, ShowUsage, ShowVersion, ShowConfigs, LoadConfigs, DumpConfigs, Benchmark};
enum Flag {Unknown, ShowUsage, ShowVersion, ShowConfigs, LoadConfigs, DumpConfigs, Benchmark, InspectCollection, InspectComponent};

struct UserOptions {
/// Code representation of all user options.
Expand All @@ -18,6 +18,8 @@ struct UserOptions {
std::vector<std::string> eventSources;
std::string load_config_file;
std::string dump_config_file;
std::string collection_query;
std::string component_query;
};

void PrintUsage();
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/JANA/JApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ void JApplication::Initialize() {
// Resolve all event sources now that all plugins have been loaded
component_manager->resolve_event_sources();

// Call Init() for all factories/multifactories. This populates the ParameterManager
component_manager->initialize_factories();
// Call Summarize() and Init() in order to populate JComponentSummary and JParameterManager, respectively
component_manager->initialize_components();

// Set desired nthreads. We parse the 'nthreads' parameter two different ways for backwards compatibility.
m_desired_nthreads = 1;
Expand Down Expand Up @@ -372,7 +372,7 @@ void JApplication::HandleSigint() {

}

JComponentSummary JApplication::GetComponentSummary() {
const JComponentSummary& JApplication::GetComponentSummary() {
/// Returns a data object describing all components currently running
return m_component_manager->get_component_summary();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/JANA/JApplicationFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class JApplication {
float GetIntegratedRate();
float GetInstantaneousRate();

JComponentSummary GetComponentSummary();
const JComponentSummary& GetComponentSummary();

// Parameter config

Expand Down
14 changes: 14 additions & 0 deletions src/libraries/JANA/JEventProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ class JEventProcessor : public jana::omni::JComponent,
}


void Summarize(JComponentSummary& summary) {
auto* result = new JComponentSummary::Component(
JComponentSummary::ComponentType::Processor, GetPrefix(), GetTypeName(), GetLevel(), GetPluginName());

for (const auto* input : m_inputs) {
size_t subinput_count = input->names.size();
for (size_t i=0; i<subinput_count; ++i) {
result->AddInput(new JComponentSummary::Collection("", input->names[i], input->type_name, input->levels[i]));
}
}
summary.Add(result);
}


virtual void Init() {}


Expand Down
19 changes: 19 additions & 0 deletions src/libraries/JANA/JEventSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class JEventSource : public jana::omni::JComponent, public jana::omni::JHasOutpu
}
}

[[deprecated("Replaced by JEventSource::DoOpen()")]]
virtual void DoInitialize() {
DoOpen();
}

virtual void DoOpen(bool with_lock=true) {
if (with_lock) {
std::lock_guard<std::mutex> lock(m_mutex);
Expand Down Expand Up @@ -345,6 +350,20 @@ class JEventSource : public jana::omni::JComponent, public jana::omni::JHasOutpu
}
}

void Summarize(JComponentSummary& summary) {

auto* result = new JComponentSummary::Component(
JComponentSummary::ComponentType::Source, GetPrefix(), GetTypeName(), GetLevel(), GetPluginName());

for (const auto* output : m_outputs) {
size_t suboutput_count = output->collection_names.size();
for (size_t i=0; i<suboutput_count; ++i) {
result->AddOutput(new JComponentSummary::Collection("", output->collection_names[i], output->type_name, GetLevel()));
}
}

summary.Add(result);
}

// Getters and setters

Expand Down
20 changes: 20 additions & 0 deletions src/libraries/JANA/JEventUnfolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ class JEventUnfolder : public jana::omni::JComponent,
m_status = Status::Finalized;
}
}

void Summarize(JComponentSummary& summary) override {
auto* us = new JComponentSummary::Component(
JComponentSummary::ComponentType::Unfolder, GetPrefix(), GetTypeName(), GetLevel(), GetPluginName());

for (const auto* input : m_inputs) {
size_t subinput_count = input->names.size();
for (size_t i=0; i<subinput_count; ++i) {
us->AddInput(new JComponentSummary::Collection("", input->names[i], input->type_name, input->levels[i]));
}
}
for (const auto* output : m_outputs) {
size_t suboutput_count = output->collection_names.size();
for (size_t i=0; i<suboutput_count; ++i) {
us->AddOutput(new JComponentSummary::Collection("", output->collection_names[i], output->type_name, GetLevel()));
}
}
summary.Add(us);
}

};


21 changes: 21 additions & 0 deletions src/libraries/JANA/JFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,24 @@ void JFactory::DoInit() {
mStatus = Status::Unprocessed;
}
}

void JFactory::Summarize(JComponentSummary& summary) {

auto fs = new JComponentSummary::Component(
JComponentSummary::ComponentType::Factory,
GetPrefix(),
GetTypeName(),
GetLevel(),
GetPluginName());

auto coll = new JComponentSummary::Collection(
GetTag(),
GetTag(),
GetObjectName(),
GetLevel());

fs->AddOutput(coll);
summary.Add(fs);
}


1 change: 1 addition & 0 deletions src/libraries/JANA/JFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class JFactory : public jana::omni::JComponent {
/// type of object contained. In order to access these objects when all you have is a JFactory*, use JFactory::GetAs().
virtual void Create(const std::shared_ptr<const JEvent>& event);
void DoInit();
void Summarize(JComponentSummary& summary);


virtual void Set(const std::vector<JObject *> &data) = 0;
Expand Down
16 changes: 0 additions & 16 deletions src/libraries/JANA/JFactorySet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,3 @@ void JFactorySet::Release() {
}
}

/// Summarize() generates a JFactorySummary data object describing each JFactory
/// that this JFactorySet contains. The data is extracted from the JFactory itself.
std::vector<JFactorySummary> JFactorySet::Summarize() const {

std::vector<JFactorySummary> results;
for (auto& pair : mFactories) {
results.push_back({
.level = pair.second->GetLevel(),
.plugin_name = pair.second->GetPluginName(),
.factory_name = pair.second->GetFactoryName(),
.factory_tag = pair.second->GetTag(),
.object_name = pair.second->GetObjectName()
});
}
return results;
}
2 changes: 0 additions & 2 deletions src/libraries/JANA/JFactorySet.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class JFactorySet : public JResettable
std::vector<JMultifactory*> GetAllMultifactories() const;
template<typename T> std::vector<JFactoryT<T>*> GetAllFactories() const;

std::vector<JFactorySummary> Summarize() const;

JEventLevel GetLevel() const { return mLevel; }
void SetLevel(JEventLevel level) { mLevel = level; }

Expand Down
9 changes: 5 additions & 4 deletions src/libraries/JANA/JLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct JLogMessage {
JLogger::Level level;
std::ostringstream builder;


JLogMessage(const JLogger& logger = default_cout_logger,
JLogger::Level level = JLogger::Level::INFO)
: logger(logger), level(level) {
Expand All @@ -84,20 +85,20 @@ struct JLogMessage {
/// Stream operators

template <typename T>
inline JLogMessage&& operator<<(JLogger& l, T t) {
inline JLogMessage operator<<(JLogger& l, const T& t) {
JLogMessage m(l);
m.builder << t;
return std::move(m);
return m;
}

template<typename T>
inline JLogMessage& operator<<(JLogMessage& m, T t) {
inline JLogMessage& operator<<(JLogMessage& m, const T& t) {
m.builder << t;
return m;
}

template<typename T>
inline JLogMessage&& operator<<(JLogMessage&& m, T t) {
inline JLogMessage&& operator<<(JLogMessage&& m, const T& t) {
m.builder << t;
return std::move(m);
}
Expand Down
17 changes: 17 additions & 0 deletions src/libraries/JANA/JMultifactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,21 @@ void JMultifactory::DoInit() {
}
}

void JMultifactory::Summarize(JComponentSummary& summary) {
auto mfs = new JComponentSummary::Component(
JComponentSummary::ComponentType::Factory,
GetPrefix(),
GetTypeName(),
GetLevel(),
GetPluginName());

for (auto* helper : GetHelpers()->GetAllFactories()) {
auto coll = new JComponentSummary::Collection(
helper->GetTag(),
helper->GetFactoryName(),
helper->GetObjectName(),
helper->GetLevel());
mfs->AddOutput(coll);
}
summary.Add(mfs);
}
6 changes: 4 additions & 2 deletions src/libraries/JANA/JMultifactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class JMultifactory : public jana::omni::JComponent,
// IMPLEMENTED BY USERS

virtual void Init() {}
virtual void BeginRun(const std::shared_ptr<const JEvent>&) {}
void BeginRun(const std::shared_ptr<const JEvent>&) override {}
virtual void Process(const std::shared_ptr<const JEvent>&) {}
virtual void EndRun() {}
void EndRun() override {}
virtual void Finish() {}
// I'm tempted to factor out something like JEventCallback from JFactory, JMultifactory, and JEventProcessor.

Expand Down Expand Up @@ -129,6 +129,8 @@ class JMultifactory : public jana::omni::JComponent,
// These are set by JFactoryGeneratorT (just like JFactories) and get propagated to each of the JMultifactoryHelpers
void SetTag(std::string tag) { mTag = std::move(tag); }
void SetFactoryName(std::string factoryName) { mFactoryName = std::move(factoryName); }

void Summarize(JComponentSummary& summary) override;
};


Expand Down
3 changes: 3 additions & 0 deletions src/libraries/JANA/Omni/JComponentFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class JParameterManager;
#include <JANA/Utils/JEventLevel.h>
#include <JANA/JLogger.h>
#include <JANA/JException.h>
#include <JANA/Status/JComponentSummary.h>

#include <vector>
#include <mutex>
Expand Down Expand Up @@ -80,6 +81,8 @@ struct JComponent {

std::string GetTypeName() const { return m_type_name; }

virtual void Summarize(JComponentSummary&) {};

Status GetStatus() const {
std::lock_guard<std::mutex> lock(m_mutex);
return m_status;
Expand Down
Loading
Loading