Skip to content

Feature Request: print error and throw exception on failed BoostStore::Get #6

@marc1uk

Description

@marc1uk

I find myself typing out things like this:

get_ok = m_data->Stores.at("ANNIEEvent")->Get("recoStatus", recoStatus);
if(not get_ok){
    Log("FindTrackLengthInWater Tool: Failed to retrieve the recoStatus!",v_error,verbosity);
    return false;
}
get_ok = m_data->Stores.at("ANNIEEvent")->Get("TrueNeutrinoEnergy", TrueNeutrinoEnergy);
if(not get_ok){
    Log("FindTrackLengthInWater Tool: Failed to retrieve TrueNeutrinoEnergy!",v_error,verbosity);
    return false;
}
get_ok = m_data->Stores.at("ANNIEEvent")->Get("TrueInteractionType", TrueInteractionType);
if(not get_ok){
    Log("FindTrackLengthInWater Tool: Failed to retrieve the TrueInteractionType!",v_error,verbosity);
    return false;
}

an awful lot, and, as shown above, it ends up being pretty verbose and can quickly result in a whooole lot of code just to retrieve a bunch of variables.
It would be nice if there was a BoostStore::Get verbosity option that could spit out some minimal error on failure. In fact, since the tool may well just return false on failure, and there's evidently some mechanism for handling uncaught exceptions in ToolAnalysis, perhaps it could even be possible to pass a return on failure option or something that would do just that?
So you could reduce it to

   m_data->Stores.at("ANNIEEvent")->Get("recoStatus", recoStatus, verbosity, true);
   m_data->Stores.at("ANNIEEvent")->Get("TrueNeutrinoEnergy", TrueNeutrinoEnergy, verbosity, true);
   m_data->Stores.at("ANNIEEvent")->Get("TrueInteractionType", TrueInteractionType, verbosity, true);

and if the variable didn't exist, it would spit out an error and throw some recognised exception that would return the tool?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions