Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 8 additions & 1 deletion CondCore/CTPPSPlugins/src/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
#include "CondFormats/PPSObjects/interface/PPSAssociationCuts.h"
#include "CondFormats/DataRecord/interface/PPSAssociationCutsRcd.h"

namespace {
struct InitAssociationCuts {
void operator()(PPSAssociationCuts &cuts) { cuts.initialize(); }
};
} // namespace

REGISTER_PLUGIN(CTPPSBeamParametersRcd, CTPPSBeamParameters);
REGISTER_PLUGIN(CTPPSPixelDAQMappingRcd, CTPPSPixelDAQMapping);
REGISTER_PLUGIN(CTPPSPixelAnalysisMaskRcd, CTPPSPixelAnalysisMask);
Expand All @@ -39,4 +45,5 @@ REGISTER_PLUGIN(PPSDirectSimulationDataRcd, PPSDirectSimulationData);
REGISTER_PLUGIN(PPSPixelTopologyRcd, PPSPixelTopology);
REGISTER_PLUGIN(PPSAlignmentConfigRcd, PPSAlignmentConfig);
REGISTER_PLUGIN(PPSAlignmentConfigurationRcd, PPSAlignmentConfiguration);
REGISTER_PLUGIN(PPSAssociationCutsRcd, PPSAssociationCuts);

REGISTER_PLUGIN_INIT(PPSAssociationCutsRcd, PPSAssociationCuts, InitAssociationCuts);
15 changes: 10 additions & 5 deletions CondFormats/PPSObjects/interface/PPSAssociationCuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class PPSAssociationCuts {
double getTiTrMax() const { return ti_tr_max_; }

// build TF1 representations of the mean and threshold functions
// NB: declared as const as it only modifies mutable class fields
void buildFunctions() const;
void buildFunctions();

// returns whether the specified cut is applied
bool isApplied(Quantities quantity) const;
Expand All @@ -52,8 +51,8 @@ class PPSAssociationCuts {
std::vector<std::string> s_thresholds_;

// TF1 representation of the cut parameters - for run time evaluations
mutable std::vector<std::shared_ptr<TF1> > f_means_ COND_TRANSIENT;
mutable std::vector<std::shared_ptr<TF1> > f_thresholds_ COND_TRANSIENT;
std::vector<std::shared_ptr<TF1> > f_means_ COND_TRANSIENT;
std::vector<std::shared_ptr<TF1> > f_thresholds_ COND_TRANSIENT;

// timing-tracking cuts
double ti_tr_min_;
Expand All @@ -70,7 +69,13 @@ class PPSAssociationCuts {

~PPSAssociationCuts() {}

const CutsPerArm &getAssociationCuts(const int sector) const { return association_cuts_.at(sector); }
// builds run-time data members, useful e.g. after loading data from DB
void initialize() {
for (auto &p : association_cuts_)
p.second.buildFunctions();
}

const CutsPerArm &getAssociationCuts(const int sector) const { return association_cuts_.find(sector)->second; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I just want to point out that with this approach a incorrect payload or sector value lead to undefined behavior (crashes at best, silent garbage output at worst).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I am aware. I wonder what the best/recommended solution would be... Possibly we could update the initialize method to validate the content. But what to do if wrong? Throw an exception? Is this allowed/recommended?

Copy link
Contributor

Choose a reason for hiding this comment

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

doing a check and throw (ie abort) at inizialize time is ok.
What is NOT ok is to check validity at each single access

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @VinInn! Then I will push one more commit in an hour or so.


static edm::ParameterSetDescription getDefaultParameters();

Expand Down
13 changes: 4 additions & 9 deletions CondFormats/PPSObjects/src/PPSAssociationCuts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PPSAssociationCuts::CutsPerArm::CutsPerArm(const edm::ParameterSet &iConfig, int

//----------------------------------------------------------------------------------------------------

void PPSAssociationCuts::CutsPerArm::buildFunctions() const {
void PPSAssociationCuts::CutsPerArm::buildFunctions() {
f_means_.clear();
for (const auto &s : s_means_)
f_means_.push_back(std::make_shared<TF1>("f", s.c_str()));
Expand All @@ -46,7 +46,7 @@ void PPSAssociationCuts::CutsPerArm::buildFunctions() const {
//----------------------------------------------------------------------------------------------------

bool PPSAssociationCuts::CutsPerArm::isApplied(Quantities quantity) const {
return (!s_thresholds_.at(quantity).empty()) && (!s_means_.at(quantity).empty());
return (!s_thresholds_[quantity].empty()) && (!s_means_[quantity].empty());
}

//----------------------------------------------------------------------------------------------------
Expand All @@ -57,14 +57,9 @@ bool PPSAssociationCuts::CutsPerArm::isSatisfied(
if (!isApplied(quantity))
return true;

// build functions if not already done
// (this may happen if data (string representation) are loaded from DB and the constructor is not executed)
if (f_means_.size() < s_means_.size())
buildFunctions();

// evaluate mean and threshold
const double mean = evaluateExpression(f_means_.at(quantity), x_near, y_near, xangle);
const double threshold = evaluateExpression(f_thresholds_.at(quantity), x_near, y_near, xangle);
const double mean = evaluateExpression(f_means_[quantity], x_near, y_near, xangle);
const double threshold = evaluateExpression(f_thresholds_[quantity], x_near, y_near, xangle);

// make comparison
return fabs(q_NF_diff - mean) < threshold;
Expand Down