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

Add possibility to specify GBT Id only to DTC cabling map producer #29443

Merged
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
81 changes: 53 additions & 28 deletions CondTools/SiPhase2Tracker/plugins/DTCCablingMapProducer.cc
Expand Up @@ -43,9 +43,11 @@ Description: [one line class summary]
//

static constexpr const unsigned int gbt_id_minvalue = 0;
static constexpr const unsigned int gbt_id_maxvalue = 72;
static constexpr const unsigned int gbt_id_maxvalue = 71;
static constexpr const unsigned int elink_id_minvalue = 0;
static constexpr const unsigned int elink_id_maxvalue = 7;
static constexpr const unsigned int elink_id_maxvalue = 6;

enum { DUMMY_FILL_DISABLED = 0, DUMMY_FILL_ELINK_ID = 1, DUMMY_FILL_ELINK_ID_AND_GBT_ID = 2 };

//
// SOME HELPER FUNCTIONS
Expand Down Expand Up @@ -82,7 +84,7 @@ class DTCCablingMapProducer : public edm::one::EDAnalyzer<> {
virtual void LoadModulesToDTCCablingMapFromCSV(std::vector<std::string> const&);

private:
bool generate_fake_valid_gbtlink_and_elinkid_;
int dummy_fill_mode_;
int verbosity_;
unsigned csvFormat_ncolumns_;
unsigned csvFormat_idetid_;
Expand All @@ -97,28 +99,43 @@ class DTCCablingMapProducer : public edm::one::EDAnalyzer<> {
void DTCCablingMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.setComment("Stores a TrackerDetToDTCELinkCablingMap object into the database from a CSV file.");
desc.add<bool>("generate_fake_valid_gbtlink_and_elinkid", false);
desc.add<std::string>("dummy_fill_mode", "DUMMY_FILL_DISABLED");
desc.add<int>("verbosity", 0);
desc.add<unsigned>("csvFormat_idetid", 0);
desc.add<unsigned>("csvFormat_ncolumns", 15);
desc.add<unsigned>("csvFormat_idtcid", 10);
desc.add<unsigned>("csvFormat_igbtlinkid", 11);
desc.add<unsigned>("csvFormat_ielinkid", 12);
desc.add<unsigned>("csvFormat_idetid", 0);
desc.add<unsigned>("csvFormat_idtcid", 0);
desc.add<unsigned>("csvFormat_igbtlinkid", 0);
desc.add<unsigned>("csvFormat_ielinkid", 0);
desc.add<long long unsigned int>("iovBeginTime", 1);
desc.add<std::string>("record", "TrackerDTCCablingMapRcd");
desc.add<std::vector<std::string>>("modulesToDTCCablingCSVFileNames", std::vector<std::string>());
descriptions.add("DTCCablingMapProducer", desc);
}

DTCCablingMapProducer::DTCCablingMapProducer(const edm::ParameterSet& iConfig)
: generate_fake_valid_gbtlink_and_elinkid_(iConfig.getParameter<bool>("generate_fake_valid_gbtlink_and_elinkid")),
verbosity_(iConfig.getParameter<int>("verbosity")),
: verbosity_(iConfig.getParameter<int>("verbosity")),
csvFormat_ncolumns_(iConfig.getParameter<unsigned>("csvFormat_ncolumns")),
csvFormat_idetid_(iConfig.getParameter<unsigned>("csvFormat_idetid")),
csvFormat_idtcid_(iConfig.getParameter<unsigned>("csvFormat_idtcid")),
csvFormat_igbtlinkid_(iConfig.getParameter<unsigned>("csvFormat_igbtlinkid")),
csvFormat_ielinkid_(iConfig.getParameter<unsigned>("csvFormat_ielinkid")),
iovBeginTime_(iConfig.getParameter<long long unsigned int>("iovBeginTime")),
pCablingMap_(std::make_unique<TrackerDetToDTCELinkCablingMap>()),
record_(iConfig.getParameter<std::string>("record")) {
std::string const dummy_fill_mode_param = iConfig.getParameter<std::string>("dummy_fill_mode");

// We pass from the easy to use string to an int representation for this mode flag, as it is more efficient in comparisons
if (dummy_fill_mode_param == "DUMMY_FILL_DISABLED")
dummy_fill_mode_ = DUMMY_FILL_DISABLED;
else if (dummy_fill_mode_param == "DUMMY_FILL_ELINK_ID")
dummy_fill_mode_ = DUMMY_FILL_ELINK_ID;
else if (dummy_fill_mode_param == "DUMMY_FILL_ELINK_ID_AND_GBT_ID")
dummy_fill_mode_ = DUMMY_FILL_ELINK_ID_AND_GBT_ID;
else {
throw cms::Exception("InvalidDummyFillMode")
<< "Parameter dummy_fill_mode with invalid value: " << dummy_fill_mode_param;
}

LoadModulesToDTCCablingMapFromCSV(iConfig.getParameter<std::vector<std::string>>("modulesToDTCCablingCSVFileNames"));
}

Expand Down Expand Up @@ -178,30 +195,41 @@ void DTCCablingMapProducer::LoadModulesToDTCCablingMapFromCSV(
uint32_t detIdRaw;

try {
detIdRaw = std::stoi(csvColumn[csvFormat_idetid_]);
detIdRaw = std::stoi(csvColumn.at(csvFormat_idetid_));
} catch (std::exception const& e) {
if (verbosity_ >= 0) {
edm::LogError("CSVParser") << "-- malformed DetId string in CSV file: \"" << csvLine << "\"" << endl;
}
throw e;
}

unsigned const dtc_id = strtoul(csvColumn[csvFormat_idtcid_].c_str(), nullptr, 10);
unsigned const dtc_id = strtoul(csvColumn.at(csvFormat_idtcid_).c_str(), nullptr, 10);
unsigned gbt_id;
unsigned elink_id;

if (generate_fake_valid_gbtlink_and_elinkid_) {
for (gbt_id = gbt_id_minvalue; gbt_id < gbt_id_maxvalue + 1u; ++gbt_id) {
switch (dummy_fill_mode_) {
default:
case DUMMY_FILL_DISABLED:
gbt_id = strtoul(csvColumn.at(csvFormat_igbtlinkid_).c_str(), nullptr, 10);
elink_id = strtoul(csvColumn.at(csvFormat_ielinkid_).c_str(), nullptr, 10);
break;
case DUMMY_FILL_ELINK_ID:
gbt_id = strtoul(csvColumn.at(csvFormat_igbtlinkid_).c_str(), nullptr, 10);
for (elink_id = elink_id_minvalue; elink_id < elink_id_maxvalue + 1u; ++elink_id) {
Copy link
Contributor

@ghugo83 ghugo83 Apr 10, 2020

Choose a reason for hiding this comment

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

Just having a quick diagonal look.

Sorry am not sure I understand this, on the e-link Id:
elink_id_minvalue = 0
elink_id_maxvalue = 7
So here you are looping from 0 to 7 included, while there are always 7 ports max only on a GBT (right?).
Why not:
(elink_id = elink_id_minvalue; elink_id < elink_id_maxvalue; ++elink_id)
only?

Copy link
Author

Choose a reason for hiding this comment

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

Good, you caught it. I will change it!

if (!(pCablingMap_->knowsDTCELinkId(DTCELinkId(dtc_id, gbt_id, elink_id))))
goto gbtlink_and_elinkid_generator_end; //break out of this double loop
break;
}
}
gbtlink_and_elinkid_generator_end:
((void)0); // This is a NOP, it's here just to have a valid (although dummy) instruction after the goto tag
} else {
gbt_id = strtoul(csvColumn[csvFormat_igbtlinkid_].c_str(), nullptr, 10);
elink_id = strtoul(csvColumn[csvFormat_ielinkid_].c_str(), nullptr, 10);
break;
case DUMMY_FILL_ELINK_ID_AND_GBT_ID:
for (gbt_id = gbt_id_minvalue; gbt_id < gbt_id_maxvalue + 1u; ++gbt_id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, but with the GBT id. There are at most 72 GBTs (6 trunk cables x 12 GBTS) connected to 1 DTC.
gbt_id_minvalue = 0;
gbt_id_maxvalue = 72;
So why not
(gbt_id = gbt_id_minvalue; gbt_id < gbt_id_maxvalue; ++gbt_id)

Copy link
Author

Choose a reason for hiding this comment

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

Good, you caught it. I will change it!

for (elink_id = elink_id_minvalue; elink_id < elink_id_maxvalue + 1u; ++elink_id) {
if (!(pCablingMap_->knowsDTCELinkId(DTCELinkId(dtc_id, gbt_id, elink_id))))
goto gbtlink_and_elinkid_generator_end; //break out of this double loop, this is one of the few "proper" uses of goto
}
}
gbtlink_and_elinkid_generator_end:
((void)0); // This is a NOP, it's here just to have a valid (although dummy) instruction after the goto tag
break;
}

DTCELinkId dtcELinkId(dtc_id, gbt_id, elink_id);
Expand All @@ -212,12 +240,9 @@ void DTCCablingMapProducer::LoadModulesToDTCCablingMapFromCSV(
}

if (pCablingMap_->knowsDTCELinkId(dtcELinkId)) {
ostringstream message;
message
<< "Reading CSV file: CRITICAL ERROR, duplicated dtcELinkId entry about (dtc_id, gbt_id, elink_id) = ("
throw cms::Exception("DuplicateDTCELinkIdInCSV")
<< "Reading CSV file: CRITICAL ERROR, duplicate dtcELinkId entry about (dtc_id, gbt_id, elink_id) = ("
<< dtc_id << "," << gbt_id << "," << elink_id << ")";

throw cms::Exception(message.str());
}

pCablingMap_->insert(dtcELinkId, detIdRaw);
Expand All @@ -228,7 +253,7 @@ void DTCCablingMapProducer::LoadModulesToDTCCablingMapFromCSV(
}
}
} else {
throw cms::Exception("DTCCablingMapProducer: Unable to open input CSV file") << csvFilePath << endl;
throw cms::Exception("CSVFileNotFound") << "Unable to open input CSV file" << csvFilePath << endl;
}

csvFile.close();
Expand All @@ -246,7 +271,7 @@ void DTCCablingMapProducer::endJob() {
if (poolDbService.isAvailable()) {
poolDbService->writeOne(pCablingMap_.release(), iovBeginTime_, record_);
} else {
throw cms::Exception("PoolDBService required.");
throw cms::Exception("PoolDBServiceNotFound") << "A running PoolDBService instance is required.";
}
}

Expand Down
14 changes: 9 additions & 5 deletions CondTools/SiPhase2Tracker/test/DTCCablingMapProducer_write.py
Expand Up @@ -30,13 +30,17 @@

process.otdtccablingmap_producer = cms.EDAnalyzer("DTCCablingMapProducer",
record = cms.string('TrackerDetToDTCELinkCablingMapRcd'),
generate_fake_valid_gbtlink_and_elinkid = cms.bool(True),
#dummy_fill_mode = cms.string("DUMMY_FILL_DISABLED"),
#dummy_fill_mode = cms.string("DUMMY_FILL_ELINK_ID"),
modulesToDTCCablingCSVFileNames = cms.vstring(
"CondTools/SiPhase2Tracker/data/TrackerModuleToDTCCablingMap__OT616_200_IT613__T14__OTOnly.csv"
"CondTools/SiPhase2Tracker/TrackerDetToDTCELinkCablingMap__OT614_200_IT404_layer2_10G__T6__OTOnly.csv"
),
csvFormat_ncolumns = cms.uint32( 2),
csvFormat_idetid = cms.uint32( 0),
csvFormat_idtcid = cms.uint32( 1),
dummy_fill_mode = cms.string("DUMMY_FILL_ELINK_ID_AND_GBT_ID"),
csvFormat_ncolumns = cms.uint32( 2),
csvFormat_idetid = cms.uint32( 0),
csvFormat_idtcid = cms.uint32( 1),
csvFormat_igbtlinkid = cms.uint32( 1),
csvFormat_ielinkid = cms.uint32( 1),
verbosity = cms.int32(0),
#loggingOn= cms.untracked.bool(True),
#SinceAppendMode=cms.bool(True),
Expand Down