53 return std::make_pair(
run,
lumi);
92 return vec.at(it - vec.begin() - 1);
97 return vec.at(it - vec.begin() - 1);
102 : m_connectionPool(),
103 m_condDbQuality(iConfig.getParameter<
std::
string>(
"condDBQuality")),
104 m_condDbCabling(iConfig.getParameter<
std::
string>(
"condDBCabling")),
105 m_QualityTagName(iConfig.getParameter<
std::
string>(
"qualityTagName")),
106 m_CablingTagName(iConfig.getParameter<
std::
string>(
"cablingMapTagName")),
107 m_record(iConfig.getParameter<
std::
string>(
"record")),
108 m_output(iConfig.getParameter<
std::
string>(
"output")),
109 m_startTime(iConfig.getParameter<unsigned long long>(
"startIOV")),
110 m_endTime(iConfig.getParameter<unsigned long long>(
"endIOV")),
111 printdebug_(iConfig.getUntrackedParameter<
bool>(
"printDebug",
false)),
112 isMC_(iConfig.getUntrackedParameter<
bool>(
"isMC",
true)),
113 removeEmptyPayloads_(iConfig.getUntrackedParameter<
bool>(
"removeEmptyPayloads",
false)) {
118 myQualities = std::make_unique<SiPixelFEDChannelContainer>();
124 std::stringstream
ss;
128 if (startIov > endIov)
130 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
131 <<
"[FastSiPixelFEDChannelContainerFromQuality::" << __func__ <<
"] " 132 <<
"Set start time " << startIov <<
"\n ... Set end time " << endIov;
135 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
136 <<
"[FastSiPixelFEDChannelContainerFromQuality::" << __func__ <<
"] " 143 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
144 <<
"[FastSiPixelFEDChannelContainerFromQuality::" << __func__ <<
"] " 148 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
149 <<
"[FastSiPixelFEDChannelContainerFromQuality::" << __func__ <<
"] " 156 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
157 <<
"[FastSiPixelFEDChannelContainerFromQuality::" << __func__ <<
"] " 161 std::vector<std::tuple<cond::Time_t, cond::Hash> > m_iovs;
168 std::vector<std::tuple<cond::Time_t, cond::Hash> > m_cabling_iovs;
172 std::vector<unsigned int> listOfIOVs;
175 std::back_inserter(listOfIOVs),
176 [](std::tuple<cond::Time_t, cond::Hash> myIOV) ->
unsigned int {
180 std::vector<unsigned int> listOfCablingIOVs;
182 m_cabling_iovs.end(),
183 std::back_inserter(listOfCablingIOVs),
184 [](std::tuple<cond::Time_t, cond::Hash> myIOV2) ->
unsigned int {
return std::get<0>(myIOV2); });
186 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
187 <<
" Number of SiPixelQuality paloyads to analyze: " << listOfIOVs.size()
188 <<
" Number of SiPixelFedCablngMap payloads: " << listOfCablingIOVs.size() << std::endl;
190 if (listOfCablingIOVs.size() > 1) {
193 throw cms::Exception(
"") <<
" The Pixel FED Cabling map does not cover all the requested SiPixelQuality IOVs in " 194 "the same interval of validity \n";
197 if (listOfIOVs.front() < listOfCablingIOVs.front()) {
198 throw cms::Exception(
"") <<
" The Pixel FED Cabling map does not cover all the requested IOVs \n";
202 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
203 <<
" First run covered by SiPixelQuality tag: " << listOfIOVs.front()
204 <<
" / last run covered by SiPixelQuality tag: " << listOfIOVs.back() << std::endl;
206 edm::LogVerbatim(
"FastSiPixelFEDChannelContainerFromQuality") <<
" SiPixel Cabling Map IOVs in the interval: ";
207 for (
const auto& cb : m_cabling_iovs) {
209 <<
" " << std::setw(6) << std::get<0>(cb) <<
" : " << std::get<1>(cb);
214 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
215 <<
" closest_from_above(listOfCablingIOVs,listOfIOVs.back()): " 217 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
218 <<
" closest_from_below(listOfCablingIOVs,listOfIOVs.front()): " 223 listOfCablingIOVs.begin(), listOfCablingIOVs.end(),
closest_from_below(listOfCablingIOVs, listOfIOVs.front()));
226 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
227 <<
" using the SiPixelFedCablingMap with hash: " << std::get<1>(m_cabling_iovs.at(
index)) << std::endl;
230 auto theCablingTree = (*theCablingMapPayload).cablingTree();
233 "Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
234 printf(
"Translating into SiPixelFEDChannelCollection :");
235 int step = (m_iovs.size() >= 50) ? m_iovs.size() / 50 : 1;
237 for (
const auto& myIOV : m_iovs) {
238 if (niov %
step == 0) {
247 ss << runLS.first <<
"," << runLS.second <<
" (" << std::get<0>(myIOV) <<
")" 248 <<
" [hash: " << std::get<1>(myIOV) <<
"] \n";
253 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
254 <<
"Found IOV:" << runLS.first <<
"(" << runLS.second <<
")" << std::endl;
257 auto theSiPixelFEDChannelCollection =
270 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
271 <<
"[FastSiPixelFEDChannelContainerFromQuality::" << __func__ <<
"] " 273 <<
" corresponding to the specified time interval.\n\n" 277 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
278 <<
"[FastSiPixelFEDChannelContainerFromQuality::" << __func__ <<
"] " <<
ss.str();
302 for (
const auto&
mod : theDisabledModules) {
305 int coded_badRocs =
mod.BadRocs;
306 std::vector<PixelFEDChannel> disabledChannelsDetSet;
307 std::vector<sipixelobjects::CablingPathToDetUnit>
path = theFedCabling.
pathToDetUnit(
mod.DetID);
308 unsigned int nrocs_inLink(0);
314 throw cms::Exception(
"Inconsistent data") <<
"could not find CablingPathToDetUnit for detId:" <<
mod.DetID;
317 std::bitset<16> bad_rocs(coded_badRocs);
318 unsigned int n_ch = bad_rocs.size() / nrocs_inLink;
320 for (
unsigned int i_roc = 0; i_roc < n_ch; ++i_roc) {
321 unsigned int first_idx = nrocs_inLink * i_roc;
322 unsigned int sec_idx = nrocs_inLink * (i_roc + 1) - 1;
323 unsigned int mask =
pow(2, nrocs_inLink) - 1;
324 unsigned int n_setbits = (coded_badRocs >> (i_roc * nrocs_inLink)) &
mask;
326 if (n_setbits == 0) {
330 if (n_setbits !=
mask) {
333 <<
"Mismatch! DetId: " <<
mod.DetID <<
" " << n_setbits <<
" " <<
mask << std::endl;
339 edm::LogVerbatim(
"FastSiPixelFEDChannelContainerFromQuality") <<
"passed" << std::endl;
342 unsigned int link_id = 99999;
343 unsigned int fed_id = 99999;
345 for (
auto const&
p :
path) {
349 unsigned int first_roc =
roc->idInDetUnit();
351 if (first_roc == first_idx) {
360 <<
" " << fed_id <<
" " << link_id <<
" " << first_idx <<
" " << sec_idx << std::endl;
364 disabledChannelsDetSet.push_back(ch);
368 << i_roc <<
" " << coded_badRocs <<
" " << first_idx <<
" " << sec_idx << std::endl;
370 <<
"=======================================" << std::endl;
374 if (!disabledChannelsDetSet.empty()) {
375 theBadChannelCollection[
mod.DetID] = disabledChannelsDetSet;
378 return theBadChannelCollection;
383 desc.setComment(
"Writes payloads of type SiPixelFEDChannelContainer");
384 desc.addUntracked<
bool>(
"printDebug",
false);
385 desc.addUntracked<
bool>(
"removeEmptyPayloads",
false);
387 desc.add<
std::string>(
"condDBQuality",
"frontier://FrontierPrep/CMS_CONDITIONS");
388 desc.add<
std::string>(
"qualityTagName",
"SiPixelQualityOffline_2017_threshold1percent_stuckTBM");
389 desc.add<
std::string>(
"condDBCabling",
"frontier://FrontierProd/CMS_CONDITIONS");
391 desc.add<
unsigned long long>(
"startIOV", 1310841198608821);
392 desc.add<
unsigned long long>(
"endIOV", 1312696624480350);
398 descDBParameters.addUntracked<
int>(
"authenticationSystem", 0);
399 descDBParameters.addUntracked<
std::string>(
"security",
"");
400 descDBParameters.addUntracked<
int>(
"messageLevel", 0);
403 descriptions.
add(
"FastSiPixelFEDChannelContainerFromQuality",
desc);
408 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality")
409 <<
"Size of SiPixelFEDChannelContainer object " <<
myQualities->size() << std::endl
413 edm::LogInfo(
"FastSiPixelFEDChannelContainerFromQuality") <<
"Content of SiPixelFEDChannelContainer " << std::endl;
const TimeTypeSpecs timeTypeSpecs[]
Log< level::Info, true > LogVerbatim
cond::persistency::ConnectionPool m_connectionPool
T getParameter(std::string const &) const
const std::string m_condDbCabling
const PixelFEDLink * link(unsigned int id) const
return link identified by id. Link id's are ranged [1, numberOfLinks]
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
const bool removeEmptyPayloads_
unsigned long long m_startTime
void start(bool readOnly=true)
unsigned int numberOfROCs() const
number of ROCs in fed
const std::string m_condDbQuality
FastSiPixelFEDChannelContainerFromQuality(const edm::ParameterSet &iConfig)
const Time_t kLowMask(0xFFFFFFFF)
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
std::vector< sipixelobjects::CablingPathToDetUnit > pathToDetUnit(uint32_t rawDetId) const final
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Transaction & transaction()
static std::string to_string(const XMLCh *ch)
void setParameters(const edm::ParameterSet &connectionPset)
const std::vector< disabledModuleType > getBadComponentList() const
unsigned long long Time_t
SiPixelFEDChannelContainer::SiPixelFEDChannelCollection createFromSiPixelQuality(const SiPixelQuality &theQuality, const SiPixelFedCablingMap &theFedCabling, const SiPixelFedCablingTree &theCablingTree)
unsigned int closest_from_below(std::vector< unsigned int > const &vec, unsigned int value)
const std::string m_CablingTagName
cond::Time_t currentTime() const
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Session createSession(const std::string &connectionString, bool writeCapable=false)
#define DEFINE_FWK_MODULE(type)
~FastSiPixelFEDChannelContainerFromQuality() override
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
IOVProxy readIov(const std::string &tag)
const std::string m_output
Log< level::Info, false > LogInfo
const std::string m_QualityTagName
const PixelFEDCabling * fed(unsigned int idFed) const
get fed identified by its id
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
IOVArray selectRange(const cond::Time_t &begin, const cond::Time_t &end)
const PixelROC * roc(unsigned int id) const
return ROC identified by id. ROC ids are ranged [1,numberOfROCs]
std::unordered_map< uint32_t, unsigned int > det2fedMap() const final
std::unique_ptr< SiPixelFEDChannelContainer > myQualities
Log< level::Warning, false > LogWarning
unsigned long long m_endTime
T mod(const T &a, const T &b)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
unsigned int closest_from_above(std::vector< unsigned int > const &vec, unsigned int value)
std::map< DetId, std::vector< PixelFEDChannel > > SiPixelFEDChannelCollection
const std::string m_record