Skip to content
Merged
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
21 changes: 13 additions & 8 deletions CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class AlignPCLThresholdsHG : public AlignPCLThresholds {
public:
typedef std::unordered_map<std::string, std::vector<float>> param_map;
AlignPCLThresholdsHG() {}

enum FloatParamIndex {
Expand All @@ -22,24 +23,28 @@ class AlignPCLThresholdsHG : public AlignPCLThresholds {
FSIZE = 6
};

void SetFractionCut(const std::string &AlignableId, const coordType &type, const float &cut);
enum IntParamIndex { ISIZE = 0 };
enum StringParamIndex { SSIZE = 0 };

const std::unordered_map<std::string, std::vector<float>> &getFloatMap() const { return floatMap; }
void setFractionCut(const std::string &AlignableId, const coordType &type, const float &cut);

const param_map &getFloatMap() const { return floatMap_; }
const std::vector<float> &getFloatVec(const std::string &AlignableId) const;

float getFractionCut(const std::string &AlignableId, const coordType &type) const;
std::array<float, 6> getFractionCut(const std::string &AlignableId) const;

int payloadVersion() const;
const int payloadVersion() const;

void printAllHG() const;
void printAll() const;

~AlignPCLThresholdsHG() override {}
~AlignPCLThresholdsHG() override = default;

private:
std::unordered_map<std::string, std::vector<float>> floatMap;
std::unordered_map<std::string, std::vector<int>> intMap;
std::unordered_map<std::string, std::vector<std::string>> stringMap;
param_map floatMap_;
// yet unused, but kept for possible extensions
std::unordered_map<std::string, std::vector<int>> intMap_;
std::unordered_map<std::string, std::vector<std::string>> stringMap_;

COND_SERIALIZABLE;
};
Expand Down
127 changes: 83 additions & 44 deletions CondFormats/PCLConfig/plugins/AlignPCLThresholdsReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ namespace edmtest {
edm::LogInfo("AlignPCLThresholdsReader") << "Size " << thresholds->size() << std::endl;
edm::LogInfo("AlignPCLThresholdsReader") << "Content of myThresholds " << std::endl;
// use built-in method in the CondFormat to print the content
if (printdebug_) {
if (thresholds && printdebug_) {
thresholds->printAll();
// print additional thresholds if HG payload is used
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
thresholds->printAllHG();
}
}

FILE* pFile = nullptr;
Expand All @@ -91,45 +87,118 @@ namespace edmtest {
fprintf(pFile, "AlignPCLThresholds::printAll() \n");
fprintf(pFile,
" ======================================================================================================="
"============ \n");
"============\n");
fprintf(pFile, "N records cut: %i \n", thresholds->getNrecords());

AlignPCLThresholds::threshold_map m_thresholds = thresholds->getThreshold_Map();
AlignPCLThresholdsHG::param_map m_floatMap{};

if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
m_floatMap = thresholds->getFloatMap();
}

for (auto it = m_thresholds.begin(); it != m_thresholds.end(); ++it) {
bool hasFractionCut = (m_floatMap.find(it->first) != m_floatMap.end());

fprintf(pFile,
" ====================================================================================================="
"============== \n");
fprintf(pFile, "key : %s \n ", (it->first).c_str());
"==============\n");
fprintf(pFile, "key : %s \n", (it->first).c_str());
fprintf(pFile, "- Xcut : %8.3f um ", (it->second).getXcut());
fprintf(pFile, "| sigXcut : %8.3f ", (it->second).getSigXcut());
fprintf(pFile, "| maxMoveXcut : %8.3f um ", (it->second).getMaxMoveXcut());
fprintf(pFile, "| ErrorXcut : %8.3f um\n ", (it->second).getErrorXcut());
fprintf(pFile, "| ErrorXcut : %8.3f um ", (it->second).getErrorXcut());
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
if (hasFractionCut) {
fprintf(pFile,
"| X_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::X));
} else {
fprintf(pFile, "\n");
}
} else {
fprintf(pFile, "\n");
}

fprintf(pFile, "- thetaXcut : %8.3f urad ", (it->second).getThetaXcut());
fprintf(pFile, "| sigThetaXcut : %8.3f ", (it->second).getSigThetaXcut());
fprintf(pFile, "| maxMoveThetaXcut : %8.3f urad ", (it->second).getMaxMoveThetaXcut());
fprintf(pFile, "| ErrorThetaXcut : %8.3f urad\n ", (it->second).getErrorThetaXcut());
fprintf(pFile, "| ErrorThetaXcut : %8.3f urad ", (it->second).getErrorThetaXcut());
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
if (hasFractionCut) {
fprintf(pFile,
"| thetaX_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_X));
} else {
fprintf(pFile, "\n");
}
} else {
fprintf(pFile, "\n");
}

fprintf(pFile, "- Ycut : %8.3f um ", (it->second).getYcut());
fprintf(pFile, "| sigYcut : %8.3f ", (it->second).getSigXcut());
fprintf(pFile, "| maxMoveYcut : %8.3f um ", (it->second).getMaxMoveYcut());
fprintf(pFile, "| ErrorYcut : %8.3f um\n ", (it->second).getErrorYcut());
fprintf(pFile, "| ErrorYcut : %8.3f um ", (it->second).getErrorYcut());
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
if (hasFractionCut) {
fprintf(pFile,
"| Y_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::Y));
} else {
fprintf(pFile, "\n");
}
} else {
fprintf(pFile, "\n");
}

fprintf(pFile, "- thetaYcut : %8.3f urad ", (it->second).getThetaYcut());
fprintf(pFile, "| sigThetaYcut : %8.3f ", (it->second).getSigThetaYcut());
fprintf(pFile, "| maxMoveThetaYcut : %8.3f urad ", (it->second).getMaxMoveThetaYcut());
fprintf(pFile, "| ErrorThetaYcut : %8.3f urad\n ", (it->second).getErrorThetaYcut());
fprintf(pFile, "| ErrorThetaYcut : %8.3f urad ", (it->second).getErrorThetaYcut());
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
if (hasFractionCut) {
fprintf(pFile,
"| thetaY_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_Y));
} else {
fprintf(pFile, "\n");
}
} else {
fprintf(pFile, "\n");
}

fprintf(pFile, "- Zcut : %8.3f um ", (it->second).getZcut());
fprintf(pFile, "| sigZcut : %8.3f ", (it->second).getSigZcut());
fprintf(pFile, "| maxMoveZcut : %8.3f um ", (it->second).getMaxMoveZcut());
fprintf(pFile, "| ErrorZcut : %8.3f um\n ", (it->second).getErrorZcut());
fprintf(pFile, "| ErrorZcut : %8.3f um ", (it->second).getErrorZcut());
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
if (hasFractionCut) {
fprintf(pFile,
"| Z_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::Z));
} else {
fprintf(pFile, "\n");
}
} else {
fprintf(pFile, "\n");
}

fprintf(pFile, "- thetaZcut : %8.3f urad ", (it->second).getThetaZcut());
fprintf(pFile, "| sigThetaZcut : %8.3f ", (it->second).getSigThetaZcut());
fprintf(pFile, "| maxMoveThetaZcut : %8.3f urad ", (it->second).getMaxMoveThetaZcut());
fprintf(pFile, "| ErrorThetaZcut : %8.3f urad\n ", (it->second).getErrorThetaZcut());
fprintf(pFile, "| ErrorThetaZcut : %8.3f urad ", (it->second).getErrorThetaZcut());
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
if (hasFractionCut) {
fprintf(pFile,
"| thetaZ_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_Z));
} else {
fprintf(pFile, "\n");
}
} else {
fprintf(pFile, "\n");
}

if ((it->second).hasExtraDOF()) {
for (unsigned int j = 0; j < (it->second).extraDOFSize(); j++) {
Expand All @@ -145,36 +214,6 @@ namespace edmtest {
}
}
}

// print additional thresholds for HG payload
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
fprintf(pFile, "AlignPCLThresholdsHG::printAllHG() \n");
fprintf(pFile, " ======================================= \n");
const std::unordered_map<std::string, std::vector<float>>& floatMap = thresholds->getFloatMap();
for (auto it = floatMap.begin(); it != floatMap.end(); ++it) {
fprintf(pFile, " ======================================= \n");

fprintf(pFile, "key : %s \n", (it->first).c_str());
fprintf(pFile,
"- X_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::X));
fprintf(pFile,
"- thetaX_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_X));
fprintf(pFile,
"- Y_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::Y));
fprintf(pFile,
"- thetaY_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_Y));
fprintf(pFile,
"- Z_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::Z));
fprintf(pFile,
"- thetaZ_fractionCut : %8.3f \n",
thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_Z));
}
}
}
}

Expand Down
70 changes: 41 additions & 29 deletions CondFormats/PCLConfig/plugins/AlignPCLThresholdsWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace DOFs {
enum dof { X, Y, Z, thetaX, thetaY, thetaZ, extraDOF };
}

template <typename T>
class AlignPCLThresholdsWriter : public edm::one::EDAnalyzer<> {
public:
explicit AlignPCLThresholdsWriter(const edm::ParameterSet&);
Expand All @@ -50,7 +51,6 @@ class AlignPCLThresholdsWriter : public edm::one::EDAnalyzer<> {
void analyze(const edm::Event&, const edm::EventSetup&) override;
DOFs::dof mapOntoEnum(std::string coord);

template <typename T>
void writePayload(T& myThresholds);
void storeHGthresholds(AlignPCLThresholdsHG& myThresholds, const std::vector<std::string>& alignables);

Expand All @@ -63,7 +63,8 @@ class AlignPCLThresholdsWriter : public edm::one::EDAnalyzer<> {
//
// constructors and destructor
//
AlignPCLThresholdsWriter::AlignPCLThresholdsWriter(const edm::ParameterSet& iConfig)
template <typename T>
AlignPCLThresholdsWriter<T>::AlignPCLThresholdsWriter(const edm::ParameterSet& iConfig)
: m_record(iConfig.getParameter<std::string>("record")),
m_minNrecords(iConfig.getParameter<unsigned int>("minNRecords")),
m_parameters(iConfig.getParameter<std::vector<edm::ParameterSet> >("thresholds")) {}
Expand All @@ -73,7 +74,8 @@ AlignPCLThresholdsWriter::AlignPCLThresholdsWriter(const edm::ParameterSet& iCon
//

// ------------ method called for each event ------------
void AlignPCLThresholdsWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
template <typename T>
void AlignPCLThresholdsWriter<T>::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
// detect if new payload is used
bool newClass = false;
for (auto& thePSet : m_parameters) {
Expand All @@ -83,17 +85,24 @@ void AlignPCLThresholdsWriter::analyze(const edm::Event& iEvent, const edm::Even
}
}

// use templated method depending on new/old payload
if (newClass) {
AlignPCLThresholdsHG myThresholds{};
writePayload(myThresholds);
T myThresholds{};
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
if (newClass) {
this->writePayload(myThresholds);
} else {
throw cms::Exception("AlignPCLThresholdsWriter") << "mismatched configuration";
}
} else {
AlignPCLThresholds myThresholds{};
writePayload(myThresholds);
if (!newClass) {
this->writePayload(myThresholds);
} else {
throw cms::Exception("AlignPCLThresholdsWriter") << "mismatched configuration";
}
}
}

DOFs::dof AlignPCLThresholdsWriter::mapOntoEnum(std::string coord) {
template <typename T>
DOFs::dof AlignPCLThresholdsWriter<T>::mapOntoEnum(std::string coord) {
if (coord == "X") {
return DOFs::X;
} else if (coord == "Y") {
Expand All @@ -113,7 +122,7 @@ DOFs::dof AlignPCLThresholdsWriter::mapOntoEnum(std::string coord) {

// ------------ templated method to write the payload ------------
template <typename T>
void AlignPCLThresholdsWriter::writePayload(T& myThresholds) {
void AlignPCLThresholdsWriter<T>::writePayload(T& myThresholds) {
using namespace edm;

edm::LogInfo("AlignPCLThresholdsWriter") << "Size of AlignPCLThresholds object " << myThresholds.size() << std::endl;
Expand Down Expand Up @@ -207,14 +216,14 @@ void AlignPCLThresholdsWriter::writePayload(T& myThresholds) {
myThresholds.setNRecords(m_minNrecords);
edm::LogInfo("AlignPCLThresholdsWriter") << "Content of AlignPCLThresholds " << std::endl;

// use buil-in method in the CondFormat
myThresholds.printAll();

// additional thresholds for AlignPCLThresholdsHG
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
storeHGthresholds(myThresholds, alignables);
}

// use built-in method in the CondFormat
myThresholds.printAll();

// Form the data here
edm::Service<cond::service::PoolDBOutputService> poolDbService;
if (poolDbService.isAvailable()) {
Expand All @@ -225,8 +234,9 @@ void AlignPCLThresholdsWriter::writePayload(T& myThresholds) {
}

// ------------ method to store additional HG thresholds ------------
void AlignPCLThresholdsWriter::storeHGthresholds(AlignPCLThresholdsHG& myThresholds,
const std::vector<std::string>& alignables) {
template <typename T>
void AlignPCLThresholdsWriter<T>::storeHGthresholds(AlignPCLThresholdsHG& myThresholds,
const std::vector<std::string>& alignables) {
edm::LogInfo("AlignPCLThresholdsWriter")
<< "Found type AlignPCLThresholdsHG, additional thresholds are written" << std::endl;

Expand All @@ -241,24 +251,18 @@ void AlignPCLThresholdsWriter::storeHGthresholds(AlignPCLThresholdsHG& myThresho
if (alignableId == alignable) {
if (thePSet.exists("fractionCut")) {
const double fractionCut(thePSet.getParameter<double>("fractionCut"));
myThresholds.SetFractionCut(alignableId, type, fractionCut);
} else {
myThresholds.SetFractionCut(alignableId, type, -1.); // better way to define default fraction cut??
myThresholds.setFractionCut(alignableId, type, fractionCut);
}
}
}
}

// print additional tresholds
edm::LogInfo("AlignPCLThresholdsWriter") << "Additonal content of AlignPCLThresholdsHG " << std::endl;
myThresholds.printAllHG();
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void AlignPCLThresholdsWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
template <typename T>
void AlignPCLThresholdsWriter<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.setComment("Plugin to write payloads of type AlignPCLThresholds");
desc.add<std::string>("record", "AlignPCLThresholdsRcd");
desc.add<unsigned int>("minNRecords", 25000);
edm::ParameterSetDescription desc_thresholds;

Expand All @@ -268,13 +272,21 @@ void AlignPCLThresholdsWriter::fillDescriptions(edm::ConfigurationDescriptions&
desc_thresholds.add<double>("sigCut");
desc_thresholds.add<double>("maxMoveCut");
desc_thresholds.add<double>("maxErrorCut");
// optional thresholds from new payload version
desc_thresholds.addOptional<double>("fractionCut");
if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
desc.add<std::string>("record", "AlignPCLThresholdsHGRcd");
//optional thresholds from new payload version (not for all the alignables)
desc_thresholds.addOptional<double>("fractionCut");
} else {
desc.add<std::string>("record", "AlignPCLThresholdsRcd");
}

std::vector<edm::ParameterSet> default_thresholds(1);
desc.addVPSet("thresholds", desc_thresholds, default_thresholds);
descriptions.addWithDefaultLabel(desc);
}

//define this as a plug-in
DEFINE_FWK_MODULE(AlignPCLThresholdsWriter);
typedef AlignPCLThresholdsWriter<AlignPCLThresholds> AlignPCLThresholdsLGWriter;
typedef AlignPCLThresholdsWriter<AlignPCLThresholdsHG> AlignPCLThresholdsHGWriter;

DEFINE_FWK_MODULE(AlignPCLThresholdsLGWriter);
DEFINE_FWK_MODULE(AlignPCLThresholdsHGWriter);
Loading