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

Cleanup of DTRecoUncertainties/DTRecoUncertaintiesRcd #35208

Merged
merged 1 commit into from
Sep 10, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 18 additions & 45 deletions CalibMuon/DTCalibration/test/DBTools/DumpDBToFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "CondFormats/DTObjects/interface/DTDeadFlag.h"
#include "CondFormats/DataRecord/interface/DTReadOutMappingRcd.h"
#include "CondFormats/DTObjects/interface/DTReadOutMapping.h"
#include "CondFormats/DataRecord/interface/DTRecoUncertaintiesRcd.h"
#include "CondFormats/DTObjects/interface/DTRecoUncertainties.h"
#include "CondFormats/DTObjects/interface/DTRecoConditions.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsTtrigRcd.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsVdriftRcd.h"
Expand Down Expand Up @@ -98,15 +96,9 @@ void DumpDBToFile::beginRun(const edm::Run&, const EventSetup& setup) {
setup.get<DTReadOutMappingRcd>().get(channels);
channelsMap = &*channels;
} else if (dbToDump == "RecoUncertDB") {
if (format == "Legacy") {
ESHandle<DTRecoUncertainties> uncerts;
setup.get<DTRecoUncertaintiesRcd>().get(uncerts);
uncertMap = &*uncerts;
} else if (format == "DTRecoConditions") {
ESHandle<DTRecoConditions> h_rconds;
setup.get<DTRecoConditionsUncertRcd>().get(h_rconds);
rconds = &*h_rconds;
}
ESHandle<DTRecoConditions> h_rconds;
setup.get<DTRecoConditionsUncertRcd>().get(h_rconds);
rconds = &*h_rconds;
Comment on lines +99 to +101
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @namapane since you are touching this part of the code, can you please move to the new method with the Tokens?
To use ESGetToken see
https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideHowToGetDataFromES#In_ED_module
To get data with the token see
https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideHowToGetDataFromES#Getting_data_from_EventSetup_wit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK but I may need to change the subject of the PR, since that will amount tomore changes than those targeted here :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also fine if it's done in a separate PR if you prefer that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be great (I started coding but I'd need a moment to test the change for all 7 objects that are consumed here)

}
}

Expand Down Expand Up @@ -302,42 +294,23 @@ void DumpDBToFile::endJob() {

//---------- Uncertainties
} else if (dbToDump == "RecoUncertDB") {
if (format == "Legacy") {
int version = 1;
int type = 2; // par[step]
cout << "RecoUncertDB version: " << uncertMap->version() << endl;
for (DTRecoUncertainties::const_iterator wireAndUncerts = uncertMap->begin();
wireAndUncerts != uncertMap->end();
++wireAndUncerts) {
DTWireId wireId((*wireAndUncerts).first);
vector<float> values = (*wireAndUncerts).second;
// cout << wireId;
// copy(values.begin(), values.end(), ostream_iterator<float>(cout, " cm, "));
// cout << endl;
int nfields = values.size();
vector<float> consts = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, float(version * 1000 + type * 100 + nfields)};
consts.insert(consts.end(), values.begin(), values.end());
theCalibFile->addCell(wireId, consts);
}
} else if (format == "DTRecoConditions") {
int version = rconds->version();
string expr = rconds->getFormulaExpr();
int type = 2; // par[step]
if (version != 1 || expr != "par[step]")
throw cms::Exception("Configuration") << "only version 1, type 2 is presently supported for RecoUncertDB";
int version = rconds->version();
string expr = rconds->getFormulaExpr();
int type = 2; // par[step]
if (version != 1 || expr != "par[step]")
throw cms::Exception("Configuration") << "only version 1, type 2 is presently supported for RecoUncertDB";

cout << "[DumpDBToFile] DTRecoConditions (uncerts) version: " << rconds->version() << " expression: " << expr
<< endl;
cout << "[DumpDBToFile] DTRecoConditions (uncerts) version: " << rconds->version() << " expression: " << expr
<< endl;

for (DTRecoConditions::const_iterator irc = rconds->begin(); irc != rconds->end(); ++irc) {
DTWireId wireId(irc->first);
const vector<double>& data = irc->second;
int nfields = data.size();
vector<float> consts(11 + nfields, -1);
consts[10] = float(version * 1000 + type * 100 + nfields);
std::copy(data.begin(), data.end(), consts.begin() + 11);
theCalibFile->addCell(wireId, consts);
}
for (DTRecoConditions::const_iterator irc = rconds->begin(); irc != rconds->end(); ++irc) {
DTWireId wireId(irc->first);
const vector<double>& data = irc->second;
int nfields = data.size();
vector<float> consts(11 + nfields, -1);
consts[10] = float(version * 1000 + type * 100 + nfields);
std::copy(data.begin(), data.end(), consts.begin() + 11);
theCalibFile->addCell(wireId, consts);
}
}
//Write constants into file
Expand Down
2 changes: 0 additions & 2 deletions CalibMuon/DTCalibration/test/DBTools/DumpDBToFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class DTStatusFlag;
class DTDeadFlag;
class DTCalibrationMap;
class DTReadOutMapping;
class DTRecoUncertainties;
class DTRecoConditions;

class DumpDBToFile : public edm::EDAnalyzer {
Expand All @@ -47,7 +46,6 @@ class DumpDBToFile : public edm::EDAnalyzer {
const DTStatusFlag *statusMap;
const DTDeadFlag *deadMap;
const DTReadOutMapping *channelsMap;
const DTRecoUncertainties *uncertMap;
const DTRecoConditions *rconds;

DTCalibrationMap *theCalibFile;
Expand Down
57 changes: 20 additions & 37 deletions CalibMuon/DTCalibration/test/DBTools/DumpFileToDB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "CondFormats/DTObjects/interface/DTStatusFlag.h"
#include "CondFormats/DTObjects/interface/DTDeadFlag.h"
#include "CondFormats/DTObjects/interface/DTReadOutMapping.h"
#include "CondFormats/DTObjects/interface/DTRecoUncertainties.h"
#include "CondFormats/DTObjects/interface/DTRecoConditions.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsTtrigRcd.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsVdriftRcd.h"
Expand Down Expand Up @@ -268,43 +267,27 @@ void DumpFileToDB::endJob() {
//---------- Uncertainties
} else if (dbToDump == "RecoUncertDB") { // Write the Uncertainties

if (format == "Legacy") {
DTRecoUncertainties* uncert = new DTRecoUncertainties();
int version = 1; // Uniform uncertainties per SL and step; parameters 0-3 are for steps 1-4.
uncert->setVersion(version);
// Loop over file entries
for (DTCalibrationMap::const_iterator keyAndCalibs = theCalibFile->keyAndConsts_begin();
keyAndCalibs != theCalibFile->keyAndConsts_end();
++keyAndCalibs) {
vector<float> values = (*keyAndCalibs).second;
vector<float> uncerts(values.begin() + 11, values.end());
uncert->set((*keyAndCalibs).first, uncerts);
}
DTCalibDBUtils::writeToDB<DTRecoUncertainties>("DTRecoUncertaintiesRcd", uncert);

} else if (format == "DTRecoConditions") {
DTRecoConditions* conds = new DTRecoConditions();
conds->setFormulaExpr("par[step]");
int version = 1; // Uniform uncertainties per SL and step; parameters 0-3 are for steps 1-4.
conds->setVersion(version);

for (DTCalibrationMap::const_iterator keyAndCalibs = theCalibFile->keyAndConsts_begin();
keyAndCalibs != theCalibFile->keyAndConsts_end();
++keyAndCalibs) {
vector<float> values = (*keyAndCalibs).second;
int fversion = int(values[10] / 1000);
int type = (int(values[10]) % 1000) / 100;
int nfields = int(values[10]) % 100;
if (type != 2)
throw cms::Exception("IncorrectSetup") << "Only type==2 supported for uncertainties DB";
if (values.size() != unsigned(nfields + 11))
throw cms::Exception("IncorrectSetup") << "Inconsistent number of fields";
if (fversion != version)
throw cms::Exception("IncorrectSetup") << "Inconsistent version of file";
DTRecoConditions* conds = new DTRecoConditions();
conds->setFormulaExpr("par[step]");
int version = 1; // Uniform uncertainties per SL and step; parameters 0-3 are for steps 1-4.
conds->setVersion(version);

vector<double> params(values.begin() + 11, values.begin() + 11 + nfields);
conds->set((*keyAndCalibs).first, params);
}
for (DTCalibrationMap::const_iterator keyAndCalibs = theCalibFile->keyAndConsts_begin();
keyAndCalibs != theCalibFile->keyAndConsts_end();
++keyAndCalibs) {
vector<float> values = (*keyAndCalibs).second;
int fversion = int(values[10] / 1000);
int type = (int(values[10]) % 1000) / 100;
int nfields = int(values[10]) % 100;
if (type != 2)
throw cms::Exception("IncorrectSetup") << "Only type==2 supported for uncertainties DB";
if (values.size() != unsigned(nfields + 11))
throw cms::Exception("IncorrectSetup") << "Inconsistent number of fields";
if (fversion != version)
throw cms::Exception("IncorrectSetup") << "Inconsistent version of file";

vector<double> params(values.begin() + 11, values.begin() + 11 + nfields);
conds->set((*keyAndCalibs).first, params);
DTCalibDBUtils::writeToDB<DTRecoConditions>("DTRecoConditionsUncertRcd", conds);
}
}
Expand Down
4 changes: 2 additions & 2 deletions CalibMuon/DTCalibration/test/DumpDBToFile_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
if TYPE=="TTrigDB" : RECORD = "DTTtrigRcd"
if TYPE=="VDriftDB" : RECORD = "DTMtimeRcd"
if TYPE=="UncertDB" :
RECORD = "DTRecoUncertaintiesRcd"
print('\nWARNING, Legacy RecoUncertDB is deprecated, as it is no longer used in reconstruction code')
RECORD = ""
print('\nERROR, Legacy RecoUncertDB is no longer supported')
elif DBFORMAT=="DTRecoConditions" :
if TYPE=="TTrigDB" : RECORD = "DTRecoConditionsTtrigRcd"
if TYPE=="VDriftDB" : RECORD = "DTRecoConditionsVdriftRcd"
Expand Down
4 changes: 2 additions & 2 deletions CalibMuon/DTCalibration/test/DumpFileToDB_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
if TYPE=="TTrigDB" : RECORD = "DTTtrigRcd"
if TYPE=="VDriftDB" : RECORD = "DTMtimeRcd"
if TYPE=="UncertDB" :
RECORD = "DTRecoUncertaintiesRcd"
print('\nWARNING, Legacy RecoUncertDB is deprecated, as it is no longer used in reconstruction code')
RECORD = ""
print('\nERROR, Legacy RecoUncertDB is no longer supported')
elif DBFORMAT=="DTRecoConditions" :
if TYPE=="TTrigDB" : RECORD = "DTRecoConditionsTtrigRcd"
if TYPE=="VDriftDB" : RECORD = "DTRecoConditionsVdriftRcd"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
## Uncertainty DB
if uncertDB != "" :
process.GlobalTag.toGet = cms.VPSet(
cms.PSet(record = cms.string("DTRecoUncertaintiesRcd"),
tag = cms.string("DTRecoUncertainties_test"),
cms.PSet(record = cms.string("DTRecoConditionsUncertRcd"),
tag = cms.string("UncertDB"),
connect = cms.untracked.string("sqlite_file:"+uncertDB))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what's happening here, there is a local sqlite file that's read here? DTRecoConditionsUncertRcd is still kept in the GT, right? So why not just use what's in the GT instead of a specification here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This snippet (which is for local tests, i.e. for running manually for testing purposes) allows also, optionally, to take alternate configurations from a .db file (we sometime need to test stuff before we put it them in GTs...)

)

Expand Down