Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 62167
b: refs/heads/l1tmuon-upgrade-dev
c: 94d82a6
h: refs/heads/l1tmuon-upgrade-dev
i:
  62165: ab473d9
  62163: 9ed05df
  62159: f2963f1
  • Loading branch information
Vasile Mihai Ghete committed Mar 16, 2009

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 92dbe2f commit e62f29a
Showing 4 changed files with 314 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/l1tmuon-upgrade-dev: 63bb98427b0c2ac10389fd34eb9dd23e2e056f1d
refs/heads/l1tmuon-upgrade-dev: 94d82a6e6aa68738f050e288c0b823045fa28aa8
Original file line number Diff line number Diff line change
@@ -20,13 +20,16 @@
// system include files
#include "boost/shared_ptr.hpp"
#include <string>
#include <vector>

// user include files
// base class
#include "CondTools/L1Trigger/interface/L1ConfigOnlineProdBase.h"

#include "CondTools/L1Trigger/interface/OMDSReader.h"
#include "CondFormats/L1TObjects/interface/L1GtPsbSetup.h"
#include "CondFormats/DataRecord/interface/L1GtPsbSetupRcd.h"
#include "CondFormats/L1TObjects/interface/L1GtPsbConfig.h"

// forward declarations

@@ -48,7 +51,44 @@ class L1GtPsbSetupConfigOnlineProd :

private:

///
/// A predicate to filter the column names of GT_SETUP for
/// those that contain foreign keys to GT_PSB_SETUP.
static bool notPsbColumnName(const std::string& columnName);

/// Creates a new PSB object from a GT_PSB_SETUP entry and adds.
void addPsbFromDb(const std::string& psbKey, std::vector<L1GtPsbConfig>& psbSetup) const;

/// Creates a default valued PSB from an empty foreign key in the GT_SETUP table.
void addDefaultPsb(const std::string& psbColumn, std::vector<L1GtPsbConfig>& psbSetup) const;

/// Ensures that result contains exactly one line, returning false otherwise
bool checkOneLineResult(
const l1t::OMDSReader::QueryResults& result, const std::string& queryDescription) const;

/// A wrapper for OMDSReader::QueryResults::fillVariable that throws an
/// exception when the field it accesses was NULL.
template<class T> void getRequiredValue(
const l1t::OMDSReader::QueryResults& result, const std::string& colName, T& value) const {
if (!result.fillVariable(colName, value)) {
throw cms::Exception("NullValue") << "Required field " << colName
<< " is NULL in database!";
}
}

/// A function to extract a vector of booleans from the GT database format (NUMBER(1)
/// columns labeled prefix<nn>suffix).
std::vector<bool> extractBoolVector(
const l1t::OMDSReader::QueryResults& query, const std::string& prefix,
const std::string& suffix, unsigned nColumns) const;

/// Concatenates prefix, number and suffix into a string.
std::string numberedColumnName(
const std::string& prefix, unsigned number, const std::string& suffix) const;

/// Special case for empty suffix
std::string numberedColumnName(const std::string& prefix, unsigned number) const;
unsigned numberFromString(const std::string& aString) const;

};

#endif
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
* <TODO: enter implementation details>
*
* \author: Vasile Mihai Ghete - HEPHY Vienna
* \author: Thomas Themel - HEPHY Vienna
*
* $Date$
* $Revision$
@@ -19,6 +20,7 @@

// system include files
#include "boost/lexical_cast.hpp"
#include <algorithm>

// user include files
#include "FWCore/MessageLogger/interface/MessageLogger.h"
@@ -47,7 +49,260 @@ boost::shared_ptr<L1GtPsbSetup> L1GtPsbSetupConfigOnlineProd::newObject(
boost::shared_ptr<L1GtPsbSetup> pL1GtPsbSetup = boost::shared_ptr<L1GtPsbSetup>(
new L1GtPsbSetup());

const std::string gtSchema = "CMS_GT";

// the setup's contents, to be filled from database
std::vector<L1GtPsbConfig> psbConfigurations;

// SELECT PSB_SLOT_*_SETUP_FK FROM CMS_GT.GT_SETUP WHERE GT_SETUP.ID = MyKey
std::vector<std::string> psbColumns = m_omdsReader.columnNames(gtSchema, "GT_SETUP");

std::vector<std::string>::iterator newEnd = std::remove_if(
psbColumns.begin(), psbColumns.end(), &notPsbColumnName);
psbColumns.erase(newEnd, psbColumns.end());

// select * from CMS_GT.GT_SETUP where GT_SETUP.ID = objectKey
l1t::OMDSReader::QueryResults psbKeys = m_omdsReader.basicQuery(
psbColumns, gtSchema, "GT_SETUP", "GT_SETUP.ID",
m_omdsReader.singleAttribute(objectKey));

// check if query was successful and produced one line only
if (!checkOneLineResult(psbKeys, "GT_SETUP query for PSB keys with ID = " + objectKey)) {
edm::LogError("L1-O2O")
<< "Problem to get content of CMS_GT.GT_SETUP for GT_SETUP.ID key: "
<< objectKey;
return pL1GtPsbSetup;
}

// fill the psbConfigurations vector
for (std::vector<std::string>::const_iterator it = psbColumns.begin(); it != psbColumns.end(); ++it) {

std::string psbKey;
psbKeys.fillVariable(*it, psbKey);

if (psbKey.empty()) {
addDefaultPsb(*it, psbConfigurations);
} else {
addPsbFromDb(psbKey, psbConfigurations);
}
}

// assign to the result object
pL1GtPsbSetup->setGtPsbSetup(psbConfigurations);

if (edm::isDebugEnabled()) {
LogTrace("L1-O2O") << (*pL1GtPsbSetup) << std::endl;
}

return pL1GtPsbSetup;
}

// Return true if columnName does NOT match the pattern
// PSB_SLOT_.*_SETUP_FK
bool L1GtPsbSetupConfigOnlineProd::notPsbColumnName(const std::string& columnName) {

static std::string startMatch("PSB_SLOT_");
static std::string endMatch("_SETUP_FK");

unsigned len = columnName.size();

// it's not a PSB column name if it's too short
return len <= ( startMatch.size() + endMatch.size() ) ||
// or the start doesn't match
columnName.substr(0, startMatch.size()) != startMatch ||
// or the end doesn't match
columnName.substr(len - endMatch.size(), endMatch.size()) != endMatch;
}

void L1GtPsbSetupConfigOnlineProd::addPsbFromDb(const std::string& psbKey, std::vector<
L1GtPsbConfig>& psbSetup) const {

// SQL> describe gt_psb_setup;
// (heavily pruned to just the stuff we need to set up a GtPsbConfig)
// Name Null? Type
// ----------------------------------------- -------- ----------------------------
// ID NOT NULL VARCHAR2(256)
// BOARD_SLOT NUMBER(3)
// CH0_SEND_LVDS_NOT_DS92LV16 NUMBER(1)
// CH1_SEND_LVDS_NOT_DS92LV16 NUMBER(1)
// ENABLE_TT_LVDS_0 NUMBER(1)
// ENABLE_TT_LVDS_1 NUMBER(1)
// ENABLE_TT_LVDS_2 NUMBER(1)
// ENABLE_TT_LVDS_3 NUMBER(1)
// ENABLE_TT_LVDS_4 NUMBER(1)
// ENABLE_TT_LVDS_5 NUMBER(1)
// ENABLE_TT_LVDS_6 NUMBER(1)
// ENABLE_TT_LVDS_7 NUMBER(1)
// ENABLE_TT_LVDS_8 NUMBER(1)
// ENABLE_TT_LVDS_9 NUMBER(1)
// ENABLE_TT_LVDS_10 NUMBER(1)
// ENABLE_TT_LVDS_11 NUMBER(1)
// ENABLE_TT_LVDS_12 NUMBER(1)
// ENABLE_TT_LVDS_13 NUMBER(1)
// ENABLE_TT_LVDS_14 NUMBER(1)
// ENABLE_TT_LVDS_15 NUMBER(1)
// SERLINK_CH0_REC_ENABLE NUMBER(1)
// SERLINK_CH1_REC_ENABLE NUMBER(1)
// SERLINK_CH2_REC_ENABLE NUMBER(1)
// SERLINK_CH3_REC_ENABLE NUMBER(1)
// SERLINK_CH4_REC_ENABLE NUMBER(1)
// SERLINK_CH5_REC_ENABLE NUMBER(1)
// SERLINK_CH6_REC_ENABLE NUMBER(1)
// SERLINK_CH7_REC_ENABLE NUMBER(1)

const std::string gtSchema = "CMS_GT";

// setup up columns to query
std::vector<std::string> columnNames;

static const std::string lvdPrefix = "ENABLE_TT_LVDS_";
static const std::string lvdSuffix = "";
static const std::string serPrefix = "SERLINK_CH";
static const std::string serSuffix = "_REC_ENABLE";
static const std::string boardSlotColumn = "BOARD_SLOT";
static const std::string ch0FormatColumn = "CH0_SEND_LVDS_NOT_DS92LV16";
static const std::string ch1FormatColumn = "CH1_SEND_LVDS_NOT_DS92LV16";

columnNames.push_back(boardSlotColumn);
columnNames.push_back(ch0FormatColumn);
columnNames.push_back(ch1FormatColumn);

for (unsigned i = 0; i < (unsigned) L1GtPsbConfig::PsbNumberLvdsGroups; ++i) {
columnNames.push_back(numberedColumnName(lvdPrefix, i, lvdSuffix));
}

for (unsigned i = 0; i < (unsigned) L1GtPsbConfig::PsbSerLinkNumberChannels; ++i) {
columnNames.push_back(numberedColumnName(serPrefix, i, serSuffix));
}

// execute database query
l1t::OMDSReader::QueryResults psbQuery = m_omdsReader.basicQuery(
columnNames, gtSchema, "GT_PSB_SETUP", "GT_PSB_SETUP.ID", m_omdsReader.singleAttribute(
psbKey));

// check if query was successful and we get only one line
if (!checkOneLineResult(psbQuery, "GT_PSB_SETUP query for PSB keys with ID = " + psbKey)) {
edm::LogError("L1-O2O")
<< "Problem to get setup for PSB keys with ID = " << psbKey;
return; // FIXME: change method to bool?
}

// extract values
int16_t boardSlot;

getRequiredValue(psbQuery, boardSlotColumn, boardSlot);

bool sendLvds0, sendLvds1;

getRequiredValue(psbQuery, ch0FormatColumn, sendLvds0);
getRequiredValue(psbQuery, ch1FormatColumn, sendLvds1);

const std::vector<bool>& enableRecLvds = extractBoolVector(
psbQuery, lvdPrefix, lvdSuffix, L1GtPsbConfig::PsbNumberLvdsGroups);
const std::vector<bool>& serLinkRecEnable = extractBoolVector(
psbQuery, serPrefix, serSuffix, L1GtPsbConfig::PsbSerLinkNumberChannels);

// create new PSB object with db values
L1GtPsbConfig toAdd;

toAdd.setGtBoardSlot(boardSlot);
toAdd.setGtPsbCh0SendLvds(sendLvds0);
toAdd.setGtPsbCh1SendLvds(sendLvds1);
toAdd.setGtPsbEnableRecLvds(enableRecLvds);
toAdd.setGtPsbEnableRecSerLink(serLinkRecEnable);

// add to vector
psbSetup.push_back(toAdd);
}

void L1GtPsbSetupConfigOnlineProd::addDefaultPsb(const std::string& psbColumn, std::vector<
L1GtPsbConfig>& psbSetup) const {

// deduce the assigned board from the column name
unsigned boardSlot = numberFromString(psbColumn);

// create a default PsbConfig with the appropriate board slot and all links disabled
L1GtPsbConfig toAdd;
static std::vector<bool> allFalseLvds(L1GtPsbConfig::PsbNumberLvdsGroups, false);
static std::vector<bool> allFalseSerLink(L1GtPsbConfig::PsbSerLinkNumberChannels, false);

toAdd.setGtBoardSlot(boardSlot);
toAdd.setGtPsbCh0SendLvds(false);
toAdd.setGtPsbCh1SendLvds(false);
toAdd.setGtPsbEnableRecLvds(allFalseLvds);
toAdd.setGtPsbEnableRecSerLink(allFalseSerLink);

psbSetup.push_back(toAdd);
}

std::vector<bool> L1GtPsbSetupConfigOnlineProd::extractBoolVector(
const l1t::OMDSReader::QueryResults& query, const std::string& prefix,
const std::string& suffix, unsigned nColumns) const {

std::vector<bool> result(nColumns);

for (unsigned i = 0; i < nColumns; ++i) {
bool dbValue;
getRequiredValue(query, numberedColumnName(prefix, i, suffix), dbValue);
result[i] = dbValue;
}

return result;
}

bool L1GtPsbSetupConfigOnlineProd::checkOneLineResult(
const l1t::OMDSReader::QueryResults& result, const std::string& queryDescription) const {

// check if query was successful
if (result.queryFailed()) {
edm::LogError("L1-O2O") << "\n " << queryDescription + " failed: no match found!";
return false;

} else if (result.numberRows() != 1) {
edm::LogError("L1-O2O") << "\nProblem with " << queryDescription << ": "
<< ( result.numberRows() ) << " rows were returned, expected 1.";
return false;
}

return true;
}


std::string L1GtPsbSetupConfigOnlineProd::numberedColumnName(
const std::string& prefix, unsigned number) const {

return numberedColumnName(prefix, number, "");

}

std::string L1GtPsbSetupConfigOnlineProd::numberedColumnName(
const std::string& prefix, unsigned number, const std::string& suffix) const {

std::ostringstream colName;
colName << prefix << number << suffix;

return colName.str();
}

unsigned L1GtPsbSetupConfigOnlineProd::numberFromString(const std::string& aString) const {

std::istringstream stream(aString);
unsigned result;

for (unsigned i = 0; i < aString.size(); ++i) {
if (stream >> result) {
// we got a value
return result;
} else {
// clear error flags from failed >>
stream.clear();
// skip another character
stream.seekg(i);
}
}

// throw here
throw cms::Exception("NumberNotFound") << "Failed to extract numeric value from " << aString;
}

DEFINE_FWK_EVENTSETUP_MODULE( L1GtPsbSetupConfigOnlineProd);
Original file line number Diff line number Diff line change
@@ -112,6 +112,15 @@ std::string L1GtTscObjectKeysOnlineProd::keyL1GtPsbSetup(
const std::string& subsystemKey, const std::string& gtSchema) {

std::string objectKey;

if (!subsystemKey.empty()) {

// no need to query OMDS, one uses the GT_SETUP key to get the individual PSB keys.
// the L1GtPsbSetup key is GT_SETUP key
objectKey = subsystemKey;

}

return objectKey;

}
@@ -141,6 +150,14 @@ void L1GtTscObjectKeysOnlineProd::fillObjectKeys(ReturnType pL1TriggerKey) {
}
}

//
if (m_enableL1GtPsbSetup) {
const std::string& objectKey = keyL1GtPsbSetup(subsystemKey, gtSchema);
if (!objectKey.empty()) {
pL1TriggerKey->add("L1GtPsbSetupRcd", "L1GtPsbSetup", objectKey);
}
}

}

DEFINE_FWK_EVENTSETUP_MODULE( L1GtTscObjectKeysOnlineProd);

0 comments on commit e62f29a

Please sign in to comment.