Skip to content

Commit

Permalink
Introduce a labels namespace for the string constants (key4hep#315)
Browse files Browse the repository at this point in the history
* Move labels int label namespace and deprecated old versions

* Fix internal usage of deprecated labels

---------

Co-authored-by: hegner <[email protected]>
Co-authored-by: Andre Sailer <[email protected]>
  • Loading branch information
3 people authored Jun 17, 2024
1 parent cd24d43 commit f1b2d82
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
39 changes: 28 additions & 11 deletions include/edm4hep/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@

#include <cstdint>

#define DEPRECATED_LABEL(name, newname) \
static constexpr const auto name [[deprecated("Use 'edm4hep::labels::" #newname "' instead")]] = labels::newname

namespace edm4hep {
static constexpr const char* CellIDEncoding = "CellIDEncoding";
static constexpr const char* EventHeaderName = "EventHeader";
static constexpr const char* EventWeights = "EventWeightNames";
static constexpr const char* shapeParameterNames = "shapeParameterNames";
static constexpr const char* EventFilterStats = "EventFilterStats";
namespace labels {
static constexpr const char* CellIDEncoding = "CellIDEncoding";
static constexpr const char* EventHeader = "EventHeader";
static constexpr const char* EventWeightsNames = "EventWeightNames";
static constexpr const char* ShapeParameterNames = "shapeParameterNames";
static constexpr const char* EventFilterStats = "EventFilterStats";

/// The collection parameter name for accessing the names of the parameters for
/// a ParticleID collection
static constexpr const char* PIDParameterNames = "ParameterNames";
static constexpr const char* PIDAlgoName = "AlgoName";
static constexpr const char* PIDAlgoType = "AlgoType";
} // namespace labels

DEPRECATED_LABEL(CellIDEncoding, CellIDEncoding);
DEPRECATED_LABEL(EventHeaderName, EventHeader);
DEPRECATED_LABEL(EventWeights, EventWeightsNames);
DEPRECATED_LABEL(shapeParameterNames, ShapeParameterNames);
DEPRECATED_LABEL(EventFilterStats, EventFilterStats);

DEPRECATED_LABEL(pidParameterNames, PIDParameterNames);
DEPRECATED_LABEL(pidAlgoName, PIDAlgoName);
DEPRECATED_LABEL(pidAlgoType, PIDAlgoType);

// Use 16 bits to encode the dimension
// Could go to 8 bits, but would need a fix in podio first
Expand All @@ -45,12 +66,8 @@ enum class TrackParams : DimType { d0 = 0, phi, omega, z0, tanLambda, time };
/// Enum for accessing the covariance matrix in the TrackerPulse
enum class TrackerPulseDims : DimType { charge = 0, time };

/// The collection parameter name for accessing the names of the parameters for
/// a ParticleID collection
static constexpr const char* pidParameterNames = "ParameterNames";
static constexpr const char* pidAlgoName = "AlgoName";
static constexpr const char* pidAlgoType = "AlgoType";

} // namespace edm4hep

#undef DEPRECATED_LABEL

#endif // EDM4HEP_CONSTANTS_H
25 changes: 14 additions & 11 deletions utils/src/ParticleIDUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,44 @@ void PIDHandler::setAlgoInfo(podio::Frame& metadata, edm4hep::ParticleIDCollecti

void PIDHandler::setAlgoInfo(podio::Frame& metadata, const std::string& collName,
const edm4hep::utils::ParticleIDMeta& pidMetaInfo) {
metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidAlgoName), pidMetaInfo.algoName);
metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidAlgoType), pidMetaInfo.algoType());
metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidParameterNames), pidMetaInfo.paramNames);
metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::labels::PIDAlgoName), pidMetaInfo.algoName);
metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::labels::PIDAlgoType), pidMetaInfo.algoType());
metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::labels::PIDParameterNames),
pidMetaInfo.paramNames);
}

std::optional<edm4hep::utils::ParticleIDMeta> PIDHandler::getAlgoInfo(const podio::Frame& metadata,
const std::string& collName) {

#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0)
auto maybeAlgoName = metadata.getParameter<std::string>(podio::collMetadataParamName(collName, edm4hep::pidAlgoName));
auto maybeAlgoName =
metadata.getParameter<std::string>(podio::collMetadataParamName(collName, edm4hep::labels::PIDAlgoName));
if (!maybeAlgoName.has_value()) {
return std::nullopt;
}

ParticleIDMeta pidInfo{
std::move(maybeAlgoName.value()),
metadata.getParameter<int>(podio::collMetadataParamName(collName, edm4hep::pidAlgoType)).value(),
metadata.getParameter<int>(podio::collMetadataParamName(collName, edm4hep::labels::PIDAlgoType)).value(),
metadata
.getParameter<std::vector<std::string>>(podio::collMetadataParamName(collName, edm4hep::pidParameterNames))
.getParameter<std::vector<std::string>>(
podio::collMetadataParamName(collName, edm4hep::labels::PIDParameterNames))
.value()};

#else

const auto& algoName =
metadata.getParameter<std::string>(podio::collMetadataParamName(collName, edm4hep::pidAlgoName));
metadata.getParameter<std::string>(podio::collMetadataParamName(collName, edm4hep::labels::PIDAlgoName));
// Use the algoName as proxy to see whether we could actually get the
// information from the metadata
if (algoName.empty()) {
return std::nullopt;
}

ParticleIDMeta pidInfo{algoName,
metadata.getParameter<int>(podio::collMetadataParamName(collName, edm4hep::pidAlgoType)),
metadata.getParameter<std::vector<std::string>>(
podio::collMetadataParamName(collName, edm4hep::pidParameterNames))};
ParticleIDMeta pidInfo{
algoName, metadata.getParameter<int>(podio::collMetadataParamName(collName, edm4hep::labels::PIDAlgoType)),
metadata.getParameter<std::vector<std::string>>(
podio::collMetadataParamName(collName, edm4hep::labels::PIDParameterNames))};
#endif

return pidInfo;
Expand Down

0 comments on commit f1b2d82

Please sign in to comment.