50 typedef std::map<uint32_t, float>
Gain;
136 Gain*
get_map(std::vector<Gain*>* maps,
int onlineAPV_id);
143 void output_maps(std::vector<Gain*>* maps,
const char* basename)
const;
161 bool gain_from_maps(uint32_t det_id,
int onlineAPV_id,
float& gain);
166 int online2offline(uint16_t onlineAPV_id, uint16_t totalAPVs)
const;
190 tfp_(iConfig.getParameter<edm::FileInPath>(
"tickFile")),
191 gainThreshold_(iConfig.getParameter<double>(
"gainThreshold")),
192 dummyAPVGain_(iConfig.getParameter<double>(
"dummyAPVGain")),
193 doGainNormalization_(iConfig.getParameter<bool>(
"doGainNormalization")),
194 putDummyIntoUncabled_(iConfig.getParameter<bool>(
"putDummyIntoUncabled")),
195 putDummyIntoUnscanned_(iConfig.getParameter<bool>(
"putDummyIntoUnscanned")),
196 putDummyIntoOffChannels_(iConfig.getParameter<bool>(
"putDummyIntoOffChannels")),
197 putDummyIntoBadChannels_(iConfig.getParameter<bool>(
"putDummyIntoBadChannels")),
198 outputMaps_(iConfig.getParameter<bool>(
"outputMaps")),
199 outputSummary_(iConfig.getParameter<bool>(
"outputSummary")) {}
204 edm::LogInfo(
"SiStripApvGainFromFileBuilder") <<
"@SUB=analyze"
205 <<
"Insert SiStripApvGain Data.";
222 auto obj = std::make_unique<SiStripApvGain>();
228 LogTrace(
"SiStripApvGainFromFileBuilder") <<
" det id |APVOF| CON |APVON| FED |FEDCH|i2cAd|tickGain|" << std::endl;
230 for (
const auto& it : DetInfos) {
232 if (it.first == 0 || it.first == 0xFFFFFFFF) {
234 <<
"Wrong det id: " << it.first <<
" ... neglecting!";
242 for (
unsigned int ca = 0; ca < connection.size(); ca++) {
243 if (connection[ca] !=
nullptr) {
244 nAPVs += (connection[ca])->nApvs();
250 if (!connection.empty() && nAPVs != (uint16_t)it.second.nApvs) {
253 <<
"det id " << it.first <<
": APV number from FedCabling (" << nAPVs
254 <<
") is different from the APV number retrieved from the ideal cabling (" << it.second.nApvs <<
").";
255 throw(
"Inconsistency on the number of APVs.");
267 std::vector<std::pair<int, float>> tickmark_for_detId(it.second.nApvs, std::pair<int, float>(-1,
k_InvalidGain));
268 for (
unsigned int ca = 0; ca < connection.size(); ca++) {
269 if (connection[ca] !=
nullptr) {
270 uint16_t id1 = (connection[ca])->i2cAddr(0) % 32;
271 uint16_t id2 = (connection[ca])->i2cAddr(1) % 32;
272 tickmark_for_detId[
online2offline(id1, it.second.nApvs)].first = id1;
273 tickmark_for_detId[
online2offline(id2, it.second.nApvs)].first = id2;
277 std::vector<float> theSiStripVector;
280 for (
unsigned short j = 0;
j < it.second.nApvs;
j++) {
282 summary.
det_id = it.first;
290 for (
unsigned int ca = 0; ca < connection.size(); ca++) {
291 if (connection[ca] !=
nullptr && (connection[ca])->i2cAddr(
j % 2) % 32 == summary.
onlineAPV_id) {
294 summary.
FED_ch = (connection[ca])->fedCh();
295 summary.
i2cAdd = (connection[ca])->i2cAddr(
j % 2);
300 float gain = tickmark_for_detId[
j].second;
302 LogTrace(
"SiStripApvGainFromFileBuilder")
303 << it.first <<
" " << std::setw(3) <<
j <<
" " << std::setw(3) << connection.size() <<
" "
304 << std::setw(3) << summary.
onlineAPV_id <<
" " << std::setw(3) << summary.
FED_id <<
" " << std::setw(3)
305 << summary.
FED_ch <<
" " << std::setw(3) << summary.
i2cAdd <<
" " << std::setw(7)
324 }
else if (gain < 0.
f) {
339 theSiStripVector.push_back(summary.
gain_in_db);
344 <<
"Job end prematurely.";
352 <<
"detid already exists.";
369 <<
"DB Service is unavailable";
376 std::ifstream thickmark_heights(
filename.c_str());
378 if (!thickmark_heights.is_open()) {
380 <<
"File with thickmark height file " <<
filename.c_str() <<
" cannot be opened!";
398 thickmark_heights >> det_id >> APV_id >> tick_h;
400 if (!(thickmark_heights.eof() || thickmark_heights.fail())) {
402 LogTrace(
"Debug") <<
"Reading " <<
filename.c_str() <<
" for gathering the tickmark heights" << std::endl;
403 LogTrace(
"Debug") <<
"| Det Id | APV Id | Tickmark" << std::endl;
404 LogTrace(
"Debug") <<
"+-----------+----------+----------" << std::endl;
406 LogTrace(
"Debug") << std::setw(11) << det_id << std::setw(8) << APV_id << std::setw(14) << tick_h << std::endl;
412 }
else if (tick_h < 0.
f) {
421 std::pair<Gain::iterator, bool>
ret = map->insert(std::pair<uint32_t, float>(det_id, tick_h));
423 if (ret.second ==
false) {
425 <<
"Cannot not insert gain for detector id " << det_id
426 <<
" into the internal map: detector id already in the map.";
430 <<
"Cannot get the online-offline APV mapping!";
432 }
else if (thickmark_heights.eof()) {
433 edm::LogInfo(
"SiStripApvGainFromFileBuilder") <<
"@SUB=read_tickmark"
434 <<
"EOF of " <<
filename.c_str() <<
" reached.";
436 }
else if (thickmark_heights.fail()) {
438 <<
"error while reading " <<
filename.c_str();
443 thickmark_heights.close();
449 if (onlineAPV_id < 0 || onlineAPV_id > 5)
453 map = maps->at(onlineAPV_id);
454 }
catch (
const std::out_of_range&) {
455 if (maps->size() <
static_cast<unsigned int>(onlineAPV_id))
456 maps->resize(onlineAPV_id);
457 maps->insert(maps->begin() + onlineAPV_id,
new Gain());
458 map = (*maps)[onlineAPV_id];
461 if (map ==
nullptr) {
462 (*maps)[onlineAPV_id] =
new Gain();
463 map = (*maps)[onlineAPV_id];
470 for (
unsigned int APV = 0;
APV < maps->size();
APV++) {
472 if (map !=
nullptr) {
474 std::stringstream
name;
475 name << basename <<
"_APV" <<
APV <<
".txt";
477 if (!ofile->is_open())
478 throw "cannot open output file!";
479 for (Gain::const_iterator el = map->begin(); el != map->end(); el++) {
480 (*ofile) << (*el).first <<
" " << (*el).second << std::endl;
490 (*ofile) <<
" det id | APV | isConnected | FED |FEDCH|i2cAd|APVON| is_scanned |tickGain|gainInDB|" << std::endl;
491 (*ofile) <<
"----------+-----+-------------+-----+-----+-----+-----+------------+--------+--------+" << std::endl;
492 for (
unsigned int s = 0;
s <
summary_.size();
s++) {
495 std::stringstream
line;
499 (*ofile) << line.str() << std::endl;
505 (*ofile) <<
" det id | APV | isConnected | FED |FEDCH|i2cAd|APVON| is_scanned |tickGain|gainInDB|" << std::endl;
506 (*ofile) <<
"----------+-----+-------------+-----+-----+-----+-----+------------+--------+--------+" << std::endl;
510 std::stringstream
line;
514 (*ofile) << line.str() << std::endl;
524 line << summary.
det_id <<
" " << std::setw(3) << summary.
offlineAPV_id <<
" " << std::setw(13) << conn <<
" "
525 << std::setw(3) << summary.
FED_id <<
" " << std::setw(3) << summary.
FED_ch <<
" " << std::setw(3)
526 << summary.
i2cAdd <<
" " << std::setw(3) << summary.
onlineAPV_id <<
" " << std::setw(11) << scan <<
" "
535 if (map !=
nullptr) {
536 Gain::const_iterator el = map->find(det_id);
537 if (el != map->end()) {
545 if (map !=
nullptr) {
546 Gain::const_iterator el = map->find(det_id);
547 if (el != map->end()) {
555 if (map !=
nullptr) {
556 Gain::const_iterator el = map->find(det_id);
557 if (el != map->end()) {
569 std::stringstream ex_msg;
570 ex_msg <<
"two APVs with the same online id for det id " << det_id
571 <<
". Please check the tick mark file or the read_tickmark routine." << std::endl;
573 for (
unsigned int i = 0;
i < 6;
i++) {
577 if (map !=
nullptr) {
578 Gain::const_iterator el = map->find(det_id);
579 if (el != map->end()) {
582 gain[offlineAPV_id].second = el->second;
585 }
catch (
const std::out_of_range&) {
591 if (map !=
nullptr) {
592 Gain::const_iterator el = map->find(det_id);
593 if (el != map->end()) {
596 gain[offlineAPV_id].second = el->second;
599 }
catch (
const std::out_of_range&) {
605 if (map !=
nullptr) {
606 Gain::const_iterator el = map->find(det_id);
607 if (el != map->end()) {
610 gain[offlineAPV_id].second = el->second;
613 }
catch (
const std::out_of_range&) {
620 return (onlineAPV_id >= totalAPVs) ? onlineAPV_id - 2 : onlineAPV_id;
625 desc.
setComment(
"Conditions Builder for SiStripApvGain Objects (G1 gain) from tickmark height file");
627 desc.
add<
double>(
"gainThreshold", 0.)->
setComment(
"threshold to retain the scan vale");
629 desc.
add<
bool>(
"doGainNormalization",
false)->setComment(
"normalize the output gain in DB by 640");
630 desc.
add<
bool>(
"putDummyIntoUncabled",
false)->setComment(
"use default gain for uncabled APVs");
631 desc.
add<
bool>(
"putDummyIntoUnscanned",
false)->setComment(
"use default gain for unscanned APVs");
632 desc.
add<
bool>(
"putDummyIntoOffChannels",
false)->setComment(
"use default gain for APVs reading HV off modules");
633 desc.
add<
bool>(
"putDummyIntoBadChannels",
false)->setComment(
"use default gain for bad APV channels");
634 desc.
add<
bool>(
"outputMaps",
false)->setComment(
"prints ouput maps");
635 desc.
add<
bool>(
"outputSummary",
false)->setComment(
"prints output summary");
const edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcd > cablingToken_
std::map< uint32_t, float > Gain
void setComment(std::string const &value)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
tuple ret
prodAgent to be discontinued
std::vector< Gain * > null_gains_
static struct clean_up CleanUp
#define DEFINE_FWK_MODULE(type)
SiStripApvGainFromFileBuilder(const edm::ParameterSet &iConfig)
bool putDummyIntoOffChannels_
std::vector< Gain * > gains_
Log< level::Error, false > LogError
bool doGainNormalization_
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
const uint16_t range(const Frame &aFrame)
bool getData(T &iHolder) const
U second(std::pair< T, U > const &p)
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
const SiStripDetCabling * detCabling_
void setComment(std::string const &value)
void operator()(SiStripApvGainFromFileBuilder::Gain *el)
static constexpr float k_InvalidGain
bool putDummyIntoBadChannels_
bool isNewTagRequest(const std::string &recordName)
bool gain_from_maps(uint32_t det_id, int onlineAPV_id, float &gain)
cond::Time_t beginOfTime() const
std::pair< ContainerIterator, ContainerIterator > Range
Gain * get_map(std::vector< Gain * > *maps, int onlineAPV_id)
SiStripDetInfo read(std::string filePath)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static constexpr float k_GainNormalizationFactor
bool putDummyIntoUncabled_
std::vector< Summary > summary_
Log< level::Info, false > LogInfo
void output_maps(std::vector< Gain * > *maps, const char *basename) const
void output_summary() const
std::vector< Summary > ex_summary_
~SiStripApvGainFromFileBuilder() override
const std::map< uint32_t, DetInfo > & getAllData() const noexcept
bool putDummyIntoUnscanned_
cond::Time_t currentTime() const
std::string fullPath() const
static constexpr char const *const kDefaultFile
void format_summary(std::stringstream &line, Summary summary) const
int online2offline(uint16_t onlineAPV_id, uint16_t totalAPVs) const
void analyze(const edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &)
std::vector< Gain * > negative_gains_