Skip to content

Commit

Permalink
Furnish sources, processors, unfolders with logger
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Apr 4, 2024
1 parent 548f2bb commit 69aea70
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/examples/TimesliceExample/MyEventProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ struct MyEventProcessor : public JEventProcessor {
m_writer->writeFrame(*(m_ts_frame_in().at(0)), "timeslices");
}

LOG << "MyEventProcessor: Event " << event->GetEventNumber() << " from Timeslice " << ts_nr
LOG_DEBUG(GetLogger())
<< "MyEventProcessor: Event " << event->GetEventNumber() << " from Timeslice " << ts_nr
<< "\nTimeslice-level hits\n"
<< TabulateHits(m_ts_hits_in())
<< "\nTimeslice-level protoclusters\n"
Expand Down
2 changes: 1 addition & 1 deletion src/examples/TimesliceExample/MyTimesliceSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct MyTimesliceSource : public JEventSource {
hits_out->push_back(ExampleHit(ts_nr, 0, 49, 49, 49, 1));
hits_out->push_back(ExampleHit(ts_nr, 0, 7.6, 7.6, 7.6, 2));

LOG << "MyTimesliceSource: Timeslice " << event->GetEventNumber() << "\n"
LOG_DEBUG(GetLogger()) << "MyTimesliceSource: Timeslice " << event->GetEventNumber() << "\n"
<< TabulateHits(hits_out.get())
<< LOG_END;

Expand Down
2 changes: 1 addition & 1 deletion src/examples/TimesliceExample/MyTimesliceUnfolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct MyTimesliceUnfolder : public JEventUnfolder {
event_clusters_out->setSubsetCollection(true);
event_clusters_out->push_back(m_timeslice_clusters_in()->at(child_idx));

LOG << "MyTimesliceUnfolder: Timeslice " << parent.GetEventNumber()
LOG_DEBUG(GetLogger()) << "MyTimesliceUnfolder: Timeslice " << parent.GetEventNumber()
<< ", Event " << child.GetEventNumber()
<< "\nTimeslice clusters in:\n"
<< TabulateClusters(m_timeslice_clusters_in())
Expand Down
1 change: 0 additions & 1 deletion src/libraries/JANA/JApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ void JApplication::Initialize() {
m_params->SetDefaultParameter("jana:extended_report", m_extended_report, "Controls whether the ticker shows simple vs detailed performance metrics");

m_component_manager->initialize();
m_component_manager->resolve_event_sources();

int engine_choice = 0;
m_params->SetDefaultParameter("jana:engine", engine_choice,
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/JANA/Omni/JComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct JComponent {
Status m_status = Status::Uninitialized;
mutable std::mutex m_mutex;
JApplication* m_app = nullptr;
JLogger m_logger;

public:
// ---------------------
Expand All @@ -53,6 +54,8 @@ struct JComponent {
return m_app;
}

JLogger& GetLogger() { return m_logger; }


// ---------------------
// Meant to be called by JANA
Expand All @@ -61,6 +64,8 @@ struct JComponent {

JEventLevel GetLevel() { return m_level; }

std::string GetLoggerName() const { return m_prefix.empty() ? m_type_name : m_prefix; }

std::string GetPluginName() const { return m_plugin_name; }

void SetPluginName(std::string plugin_name) { m_plugin_name = std::move(plugin_name); };
Expand All @@ -74,6 +79,8 @@ struct JComponent {

void SetApplication(JApplication* app) { m_app = app; }

void SetLogger(JLogger logger) { m_logger = logger; }


protected:
struct ParameterBase {
Expand Down
14 changes: 14 additions & 0 deletions src/libraries/JANA/Services/JComponentManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ void JComponentManager::initialize() {
auto parms = m_app->GetJParameterManager();
parms->SetDefaultParameter("record_call_stack", m_enable_call_graph_recording, "Records a trace of who called each factory. Reduces performance but necessary for plugins such as janadot.");
parms->FilterParameters(m_default_tags, "DEFTAG:");

resolve_event_sources();

auto logging_svc = m_app->GetService<JLoggingService>();

for (JEventSource* source : m_evt_srces) {
source->SetLogger(logging_svc->get_logger(source->GetLoggerName()));
}
for (JEventProcessor* proc : m_evt_procs) {
proc->SetLogger(logging_svc->get_logger(proc->GetLoggerName()));
}
for (JEventUnfolder* unfolder : m_unfolders) {
unfolder->SetLogger(logging_svc->get_logger(unfolder->GetLoggerName()));
}
}


Expand Down

0 comments on commit 69aea70

Please sign in to comment.