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

Moved exceptions from init and added debug statements to process #1565

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/algorithms/fardetectors/FarDetectorMLReconstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace eicrecon {

// Locate and load the weight file
// TODO - Add functionality to select passed by configuration
bool methodFound = false;
if(!m_cfg.modelPath.empty()){
try{
m_method = dynamic_cast<TMVA::MethodBase*>(m_reader->BookMVA( m_cfg.methodName, m_cfg.modelPath ));
m_initialized = true;
}
catch(std::exception &e){
error(fmt::format("Failed to load method {} from file {}: {}", m_cfg.methodName, m_cfg.modelPath, e.what()));
Expand All @@ -55,6 +55,12 @@ namespace eicrecon {
const auto [inputTracks,beamElectrons] = input;
auto [outputFarDetectorMLTrajectories, outputFarDetectorMLTrackParameters, outputFarDetectorMLTracks] = output;

// Check if the algorithm has been initialized properly
if(!m_initialized){
debug("Initialization did not complete");
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you throw here, the Process will be called over and over.

Suggested change
return;
throw std::runtime_exception("Initialization did not complete");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it not call process over and over anyway? I thought the behaviour we wanted was to flag the error but still return an empty collection so that the reconstruction can be carried out with the limited geometry provided. It would be nicer if upon throwing the exception in init, JANA knows not to try again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not. The exceptions in Process trickle into our JEventProcessorPODIO, where we try to print error messages only once, which is the desired effect. We could do some accounting to disable collections, but, you are right, they don't get disabled from being called currently.

}

//Set beam energy from first MCBeamElectron, using std::call_once
std::call_once(m_initBeamE,[&](){
// Check if beam electrons are present
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/fardetectors/FarDetectorMLReconstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace eicrecon {
float m_beamE{10.0};
std::once_flag m_initBeamE;
float nnInput[4] = {0.0,0.0,0.0,0.0};
bool m_initialized{false};

};

Expand Down
10 changes: 8 additions & 2 deletions src/algorithms/fardetectors/FarDetectorTrackerCluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void FarDetectorTrackerCluster::init() {
m_cellid_converter = algorithms::GeoSvc::instance().cellIDPositionConverter();

if (m_cfg.readout.empty()) {
throw JException("Readout is empty");
error("Config readout field is empty");
}
try {
m_seg = m_detector->readout(m_cfg.readout).segmentation();
Expand All @@ -43,9 +43,9 @@ void FarDetectorTrackerCluster::init() {
m_y_idx = m_id_dec->index(m_cfg.y_field);
debug("Find layer field {}, index = {}", m_cfg.y_field, m_y_idx);
}
m_initialized = true;
} catch (...) {
error("Failed to load ID decoder for {}", m_cfg.readout);
throw JException("Failed to load ID decoder");
}
}

Expand All @@ -55,6 +55,12 @@ void FarDetectorTrackerCluster::process(const FarDetectorTrackerCluster::Input&
const auto [inputHitsCollections] = input;
auto [outputClustersCollection] = output;

// Return if configurations are not set properly
if (!m_initialized) {
debug("Initialization did not complete");
return;
}

// Loop over input and output collections - Any collection should only contain hits from a single
// surface
for (size_t i = 0; i < inputHitsCollections.size(); i++) {
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/fardetectors/FarDetectorTrackerCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class FarDetectorTrackerCluster : public FarDetectorTrackerClusterAlgorithm,
const dd4hep::BitFieldCoder* m_id_dec{nullptr};
const dd4hep::rec::CellIDPositionConverter* m_cellid_converter{nullptr};
dd4hep::Segmentation m_seg;
bool m_initialized{false};

int m_x_idx{0};
int m_y_idx{0};
Expand Down
Loading