CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
SiStripApvGainFromFileBuilder Class Reference

#include <SiStripApvGainFromFileBuilder.cc>

Inheritance diagram for SiStripApvGainFromFileBuilder:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Classes

struct  Summary
 

Public Types

typedef std::map< uint32_t, float > Gain
 
- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
 SiStripApvGainFromFileBuilder (const edm::ParameterSet &iConfig)
 
 ~SiStripApvGainFromFileBuilder () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void format_summary (std::stringstream &line, Summary summary) const
 
bool gain_from_maps (uint32_t det_id, int onlineAPV_id, float &gain)
 
void gain_from_maps (uint32_t det_id, uint16_t totalAPVs, std::vector< std::pair< int, float >> &gain) const
 
Gainget_map (std::vector< Gain *> *maps, int onlineAPV_id)
 
int online2offline (uint16_t onlineAPV_id, uint16_t totalAPVs) const
 
void output_maps (std::vector< Gain *> *maps, const char *basename) const
 
void output_summary () const
 
void read_tickmark (void)
 

Private Attributes

const edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcdcablingToken_
 
const SiStripDetCablingdetCabling_
 
bool doGainNormalization_
 
double dummyAPVGain_
 
std::vector< Summaryex_summary_
 
std::vector< Gain * > gains_
 
double gainThreshold_
 
std::vector< Gain * > negative_gains_
 
std::vector< Gain * > null_gains_
 
bool outputMaps_
 
bool outputSummary_
 
bool putDummyIntoBadChannels_
 
bool putDummyIntoOffChannels_
 
bool putDummyIntoUncabled_
 
bool putDummyIntoUnscanned_
 
std::vector< Summarysummary_
 
edm::FileInPath tfp_
 

Static Private Attributes

static constexpr float k_GainNormalizationFactor = 640.f
 
static constexpr float k_InvalidGain = 999999.f
 

Additional Inherited Members

- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Description: Created SiStripApvGain paylaods from tickmark height input ASCII files coming from SiStrip opto-gain scans.

Definition at line 46 of file SiStripApvGainFromFileBuilder.cc.

Member Typedef Documentation

◆ Gain

typedef std::map<uint32_t, float> SiStripApvGainFromFileBuilder::Gain

Definition at line 50 of file SiStripApvGainFromFileBuilder.cc.

Constructor & Destructor Documentation

◆ SiStripApvGainFromFileBuilder()

SiStripApvGainFromFileBuilder::SiStripApvGainFromFileBuilder ( const edm::ParameterSet iConfig)
explicit

Brief Constructor.

Definition at line 188 of file SiStripApvGainFromFileBuilder.cc.

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")) {}
const edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcd > cablingToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307

◆ ~SiStripApvGainFromFileBuilder()

SiStripApvGainFromFileBuilder::~SiStripApvGainFromFileBuilder ( )
override

Brief Destructor performing the memory cleanup.

Definition at line 182 of file SiStripApvGainFromFileBuilder.cc.

References CleanUp, gains_, negative_gains_, and null_gains_.

182  {
183  for_each(gains_.begin(), gains_.end(), CleanUp);
184  for_each(negative_gains_.begin(), negative_gains_.end(), CleanUp);
185  for_each(null_gains_.begin(), null_gains_.end(), CleanUp);
186 }
static const struct clean_up CleanUp

Member Function Documentation

◆ analyze()

void SiStripApvGainFromFileBuilder::analyze ( const edm::Event evt,
const edm::EventSetup iSetup 
)
overridevirtual

Brief One dummy-event analysis to create the database record.

Implements edm::one::EDAnalyzerBase.

Definition at line 201 of file SiStripApvGainFromFileBuilder.cc.

References cond::service::PoolDBOutputService::appendOneIOV(), cond::service::PoolDBOutputService::beginOfTime(), cablingToken_, DMR_cfg::cerr, cond::service::PoolDBOutputService::createOneIOV(), cond::service::PoolDBOutputService::currentTime(), detCabling_, doGainNormalization_, dummyAPVGain_, MillePedeFileConverter_cfg::e, ex_summary_, cppFunctionSkipper::exception, f, l1tstage2_dqm_sourceclient-live_cfg::fedId, PedestalClient_cfi::gain, gain_from_maps(), gains_, gainThreshold_, SiStripDetCabling::getConnections(), edm::EventSetup::getData(), globals_cff::id1, globals_cff::id2, edm::Service< T >::isAvailable(), cond::service::PoolDBOutputService::isNewTagRequest(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, dqmiolumiharvest::j, k_GainNormalizationFactor, k_InvalidGain, SiStripDetInfoFileReader::kDefaultFile, LogTrace, negative_gains_, null_gains_, getGTfromDQMFile::obj, online2offline(), output_maps(), output_summary(), outputMaps_, outputSummary_, putDummyIntoBadChannels_, putDummyIntoOffChannels_, putDummyIntoUncabled_, putDummyIntoUnscanned_, FastTimerService_cff::range, SiStripDetInfoFileReader::read(), read_tickmark(), DQM::reader, edmLumisInFiles::summary, and summary_.

201  {
202  //unsigned int run=evt.id().run();
203 
204  edm::LogInfo("SiStripApvGainFromFileBuilder") << "@SUB=analyze"
205  << "Insert SiStripApvGain Data.";
206  this->read_tickmark();
207 
208  if (outputMaps_) {
209  try {
210  this->output_maps(&gains_, "tickmark_heights");
211  this->output_maps(&negative_gains_, "negative_tickmark");
212  this->output_maps(&null_gains_, "zero_tickmark");
213  } catch (std::exception& e) {
214  std::cerr << e.what() << std::endl;
215  }
216  }
217 
218  // Retrieve the SiStripDetCabling description
219  detCabling_ = &iSetup.getData(cablingToken_);
220 
221  // APV gain record to be filled with gains and delivered into the database.
222  auto obj = std::make_unique<SiStripApvGain>();
223 
224  const auto& reader =
226  const auto& DetInfos = reader.getAllData();
227 
228  LogTrace("SiStripApvGainFromFileBuilder") << " det id |APVOF| CON |APVON| FED |FEDCH|i2cAd|tickGain|" << std::endl;
229 
230  for (const auto& it : DetInfos) {
231  // check if det id is correct and if it is actually cabled in the detector
232  if (it.first == 0 || it.first == 0xFFFFFFFF) {
233  edm::LogError("DetIdNotGood") << "@SUB=analyze"
234  << "Wrong det id: " << it.first << " ... neglecting!";
235  continue;
236  }
237 
238  // For the cabled det_id retrieve the number of APV connected
239  // to the module with the FED cabling
240  uint16_t nAPVs = 0;
241  const std::vector<const FedChannelConnection*> connection = detCabling_->getConnections(it.first);
242  for (unsigned int ca = 0; ca < connection.size(); ca++) {
243  if (connection[ca] != nullptr) {
244  nAPVs += (connection[ca])->nApvs();
245  break;
246  }
247  }
248 
249  // check consistency among FED cabling and ideal cabling, exit on error
250  if (!connection.empty() && nAPVs != (uint16_t)it.second.nApvs) {
251  edm::LogError("SiStripCablingError")
252  << "@SUB=analyze"
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.");
256  }
257 
258  // eventually separate the processing for the module that are fully
259  // uncabled. This is worth only if we decide not tu put the record
260  // in the DB for the uncabled det_id.
261  //if( !detCabling_->IsConnected(it.first) ) {
262  //
263  // continue;
264  //}
265 
266  //Gather the APV online id
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;
274  }
275  }
276  gain_from_maps(it.first, it.second.nApvs, tickmark_for_detId);
277  std::vector<float> theSiStripVector;
278 
279  // Fill the gain in the DB object, apply the logic for the dummy values
280  for (unsigned short j = 0; j < it.second.nApvs; j++) {
282  summary.det_id = it.first;
283  summary.offlineAPV_id = j;
284  summary.onlineAPV_id = tickmark_for_detId.at(j).first;
285  summary.is_connected = false;
286  summary.FED_id = -1;
287  summary.FED_ch = -1;
288  summary.i2cAdd = -1;
289 
290  for (unsigned int ca = 0; ca < connection.size(); ca++) {
291  if (connection[ca] != nullptr && (connection[ca])->i2cAddr(j % 2) % 32 == summary.onlineAPV_id) {
292  summary.is_connected = (connection[ca])->isConnected();
293  summary.FED_id = (connection[ca])->fedId();
294  summary.FED_ch = (connection[ca])->fedCh();
295  summary.i2cAdd = (connection[ca])->i2cAddr(j % 2);
296  }
297  }
298 
299  try {
300  float gain = tickmark_for_detId[j].second;
301  summary.gain_from_scan = gain;
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)
306  << summary.gain_from_scan << std::endl;
307 
308  if (gain != k_InvalidGain) {
309  summary.is_scanned = true;
310  if (gain > gainThreshold_) {
311  if (doGainNormalization_) {
312  // divide the tickmark by the normalization factor (640)
314  }
315  summary.gain_in_db = gain;
316  if (!summary.is_connected)
317  ex_summary_.push_back(summary);
318  else
319  summary_.push_back(summary);
320  } else {
321  if (gain == 0.f) {
322  summary.gain_in_db = (putDummyIntoOffChannels_ ? dummyAPVGain_ : 0.f);
323  ex_summary_.push_back(summary);
324  } else if (gain < 0.f) {
325  summary.gain_in_db = (putDummyIntoBadChannels_ ? dummyAPVGain_ : 0.f);
326  ex_summary_.push_back(summary);
327  }
328  }
329  } else {
330  summary.is_scanned = false;
331  if (!summary.is_connected) {
332  summary.gain_in_db = (putDummyIntoUncabled_ ? dummyAPVGain_ : 0.f);
333  } else {
334  summary.gain_in_db = (putDummyIntoUnscanned_ ? dummyAPVGain_ : 0.f);
335  }
336  ex_summary_.push_back(summary);
337  }
338 
339  theSiStripVector.push_back(summary.gain_in_db);
340  LogTrace("SiStripApvGainFromFileBuilder") << "output gain:" << summary.gain_in_db;
341  } catch (std::exception& e) {
342  std::cerr << e.what() << std::endl;
343  edm::LogError("MappingError") << "@SUB=analyze"
344  << "Job end prematurely.";
345  return;
346  }
347  }
348 
349  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
350  if (!obj->put(it.first, range))
351  edm::LogError("IndexError") << "@SUB=analyze"
352  << "detid already exists.";
353  }
354 
355  if (outputSummary_)
356  output_summary();
357 
358  //End now write sistripnoises data in DB
360 
361  if (mydbservice.isAvailable()) {
362  if (mydbservice->isNewTagRequest("SiStripApvGainRcd")) {
363  mydbservice->createOneIOV<SiStripApvGain>(*obj, mydbservice->beginOfTime(), "SiStripApvGainRcd");
364  } else {
365  mydbservice->appendOneIOV<SiStripApvGain>(*obj, mydbservice->currentTime(), "SiStripApvGainRcd");
366  }
367  } else {
368  edm::LogError("DBServiceNotAvailable") << "@SUB=analyze"
369  << "DB Service is unavailable";
370  }
371 }
const edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcd > cablingToken_
void output_maps(std::vector< Gain *> *maps, const char *basename) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
reader
Definition: DQM.py:105
Log< level::Error, false > LogError
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
#define LogTrace(id)
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
bool isNewTagRequest(const std::string &recordName)
bool gain_from_maps(uint32_t det_id, int onlineAPV_id, float &gain)
std::pair< ContainerIterator, ContainerIterator > Range
double f[11][100]
SiStripDetInfo read(std::string filePath)
Log< level::Info, false > LogInfo
int online2offline(uint16_t onlineAPV_id, uint16_t totalAPVs) const
static constexpr char const *const kDefaultFile
bool isAvailable() const
Definition: Service.h:40

◆ fillDescriptions()

void SiStripApvGainFromFileBuilder::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Brief framework fillDescription

Definition at line 623 of file SiStripApvGainFromFileBuilder.cc.

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, and k_GainNormalizationFactor.

623  {
625  desc.setComment("Conditions Builder for SiStripApvGain Objects (G1 gain) from tickmark height file");
626  desc.add<edm::FileInPath>("tickFile", edm::FileInPath("CondTools/SiStrip/data/tickheight.txt"));
627  desc.add<double>("gainThreshold", 0.)->setComment("threshold to retain the scan vale");
628  desc.add<double>("dummyAPVGain", (690. / k_GainNormalizationFactor)); // from TDR
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");
636  descriptions.addWithDefaultLabel(desc);
637 }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)

◆ format_summary()

void SiStripApvGainFromFileBuilder::format_summary ( std::stringstream &  line,
Summary  summary 
) const
private

Brief Format the output line for the channel summary.

Definition at line 520 of file SiStripApvGainFromFileBuilder.cc.

References getInfo::conn, mps_splice::line, AlCaHLTBitMon_QueryRunRegistry::string, and edmLumisInFiles::summary.

Referenced by output_summary().

520  {
521  std::string conn = (summary.is_connected) ? "CONNECTED" : "NOT_CONNECTED";
522  std::string scan = (summary.is_scanned) ? "IN_SCAN" : "NOT_IN_SCAN";
523 
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 << " "
527  << std::setw(7) << summary.gain_from_scan << " " << std::setw(7) << summary.gain_in_db;
528 }
conn
Definition: getInfo.py:9

◆ gain_from_maps() [1/2]

bool SiStripApvGainFromFileBuilder::gain_from_maps ( uint32_t  det_id,
int  onlineAPV_id,
float &  gain 
)
private

Brief Find the gain value for a pair det_id, APV_id in the internal maps.

Definition at line 530 of file SiStripApvGainFromFileBuilder.cc.

References PedestalClient_cfi::gain, gains_, get_map(), genParticles_cff::map, negative_gains_, and null_gains_.

Referenced by analyze().

530  {
531  Gain* map = nullptr;
532 
533  // search det_id and APV in the good scan map
534  map = get_map(&gains_, onlineAPV_id);
535  if (map != nullptr) {
536  Gain::const_iterator el = map->find(det_id);
537  if (el != map->end()) {
538  gain = el->second;
539  return true;
540  }
541  }
542 
543  // search det_id and APV in the zero gain scan map
544  map = get_map(&negative_gains_, onlineAPV_id);
545  if (map != nullptr) {
546  Gain::const_iterator el = map->find(det_id);
547  if (el != map->end()) {
548  gain = el->second;
549  return true;
550  }
551  }
552 
553  //search det_id and APV in the negative gain scan map
554  map = get_map(&null_gains_, onlineAPV_id);
555  if (map != nullptr) {
556  Gain::const_iterator el = map->find(det_id);
557  if (el != map->end()) {
558  gain = el->second;
559  return true;
560  }
561  }
562 
563  return false;
564 }
Gain * get_map(std::vector< Gain *> *maps, int onlineAPV_id)

◆ gain_from_maps() [2/2]

void SiStripApvGainFromFileBuilder::gain_from_maps ( uint32_t  det_id,
uint16_t  totalAPVs,
std::vector< std::pair< int, float >> &  gain 
) const
private

Definition at line 566 of file SiStripApvGainFromFileBuilder.cc.

References PedestalClient_cfi::gain, gains_, mps_fire::i, k_InvalidGain, genParticles_cff::map, negative_gains_, null_gains_, online2offline(), and edm::second().

568  {
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;
572 
573  for (unsigned int i = 0; i < 6; i++) {
574  int offlineAPV_id = online2offline(i, totalAPVs);
575  try {
576  Gain* map = gains_.at(i);
577  if (map != nullptr) {
578  Gain::const_iterator el = map->find(det_id);
579  if (el != map->end()) {
580  if (gain[offlineAPV_id].second != k_InvalidGain)
581  throw(ex_msg.str());
582  gain[offlineAPV_id].second = el->second;
583  }
584  }
585  } catch (const std::out_of_range&) {
586  // nothing to do, just pass over
587  }
588 
589  try {
590  Gain* map = negative_gains_.at(i);
591  if (map != nullptr) {
592  Gain::const_iterator el = map->find(det_id);
593  if (el != map->end()) {
594  if (gain[offlineAPV_id].second != k_InvalidGain)
595  throw(ex_msg.str());
596  gain[offlineAPV_id].second = el->second;
597  }
598  }
599  } catch (const std::out_of_range&) {
600  // nothing to do, just pass over
601  }
602 
603  try {
604  Gain* map = null_gains_.at(i);
605  if (map != nullptr) {
606  Gain::const_iterator el = map->find(det_id);
607  if (el != map->end()) {
608  if (gain[offlineAPV_id].second != k_InvalidGain)
609  throw(ex_msg.str());
610  gain[offlineAPV_id].second = el->second;
611  }
612  }
613  } catch (const std::out_of_range&) {
614  // nothing to do, just pass over
615  }
616  }
617 }
U second(std::pair< T, U > const &p)
int online2offline(uint16_t onlineAPV_id, uint16_t totalAPVs) const

◆ get_map()

SiStripApvGainFromFileBuilder::Gain * SiStripApvGainFromFileBuilder::get_map ( std::vector< Gain *> *  maps,
int  onlineAPV_id 
)
private

Brief Returns the mapping among channels and gain heights for the APVs. This method searchs the mapping of detector Ids <-> gains provided. If the mapping exists for the requested APV it is returned; if not a new empty mapping is created, inserted and retruned. The methods accepts onlineIDs running from 0 to 5.

Definition at line 446 of file SiStripApvGainFromFileBuilder.cc.

References genParticles_cff::map.

Referenced by gain_from_maps(), and read_tickmark().

447  {
448  Gain* map = nullptr;
449  if (onlineAPV_id < 0 || onlineAPV_id > 5)
450  return map;
451 
452  try {
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];
459  }
460 
461  if (map == nullptr) {
462  (*maps)[onlineAPV_id] = new Gain();
463  map = (*maps)[onlineAPV_id];
464  }
465 
466  return map;
467 }

◆ online2offline()

int SiStripApvGainFromFileBuilder::online2offline ( uint16_t  onlineAPV_id,
uint16_t  totalAPVs 
) const
private

Brief Convert online APV id into offline APV id.

Definition at line 619 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze(), and gain_from_maps().

619  {
620  return (onlineAPV_id >= totalAPVs) ? onlineAPV_id - 2 : onlineAPV_id;
621 }

◆ output_maps()

void SiStripApvGainFromFileBuilder::output_maps ( std::vector< Gain *> *  maps,
const char *  basename 
) const
private

Brief Dumps the internal mapping on a ASCII files. This method dumps the detector id <-> gain maps into acii files separated for each APV. The basenmae of for the acii file has to be provided as a input parameter.

Definition at line 469 of file SiStripApvGainFromFileBuilder.cc.

References sistrip::APV, genParticles_cff::map, Skims_PA_cff::name, and pileupReCalc_HLTpaths::trunc.

Referenced by analyze().

469  {
470  for (unsigned int APV = 0; APV < maps->size(); APV++) {
471  Gain* map = (*maps)[APV];
472  if (map != nullptr) {
473  // open output file
474  std::stringstream name;
475  name << basename << "_APV" << APV << ".txt";
476  std::ofstream* ofile = new std::ofstream(name.str(), std::ofstream::trunc);
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;
481  }
482  ofile->close();
483  delete ofile;
484  }
485  }
486 }

◆ output_summary()

void SiStripApvGainFromFileBuilder::output_summary ( ) const
private

Brief Dump the exceptions summary on a ASCII file. This method dumps the online coordinate of the channels for which there was an exception for filling the database record. Exceptions are the non cabled modules, the channels that were off during the tickmark scan, the channels sending corrupted data duirng the tickmark scan. These exceptions have been solved putting a dummy gain into the DB record or putting a zero gain.

Definition at line 488 of file SiStripApvGainFromFileBuilder.cc.

References ex_summary_, format_summary(), mps_splice::line, alignCSCRings::s, edmLumisInFiles::summary, summary_, and pileupReCalc_HLTpaths::trunc.

Referenced by analyze().

488  {
489  std::ofstream* ofile = new std::ofstream("SiStripApvGainSummary.txt", std::ofstream::trunc);
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++) {
494 
495  std::stringstream line;
496 
498 
499  (*ofile) << line.str() << std::endl;
500  }
501  ofile->close();
502  delete ofile;
503 
504  ofile = new std::ofstream("SiStripApvGainExceptionSummary.txt", std::ofstream::trunc);
505  (*ofile) << " det id | APV | isConnected | FED |FEDCH|i2cAd|APVON| is_scanned |tickGain|gainInDB|" << std::endl;
506  (*ofile) << "----------+-----+-------------+-----+-----+-----+-----+------------+--------+--------+" << std::endl;
507  for (unsigned int s = 0; s < ex_summary_.size(); s++) {
509 
510  std::stringstream line;
511 
513 
514  (*ofile) << line.str() << std::endl;
515  }
516  ofile->close();
517  delete ofile;
518 }
void format_summary(std::stringstream &line, Summary summary) const

◆ read_tickmark()

void SiStripApvGainFromFileBuilder::read_tickmark ( void  )
private

Brief Read the ASCII file containing the tickmark gains. This method reads the ASCII files that contains the tickmark heights for every APV. The heights are first translated into gains, dividing by 640, then are stored into maps to be associated to the detector ids. Maps are created for every APV index. Negative and Zero heights, yielding to a non physical gain, are stored into separate maps. Negative gain: channels sending bad data at the tickmark scan. Zero gain : channels switched off during the tickmark scan.

Definition at line 373 of file SiStripApvGainFromFileBuilder.cc.

References CleanUp, submitPVResolutionJobs::count, f, corrVsCorr::filename, edm::FileInPath::fullPath(), gains_, get_map(), LogTrace, genParticles_cff::map, negative_gains_, null_gains_, runTheMatrix::ret, and tfp_.

Referenced by analyze().

373  {
374  // Connect file for input
375  const auto& filename = tfp_.fullPath();
376  std::ifstream thickmark_heights(filename.c_str());
377 
378  if (!thickmark_heights.is_open()) {
379  edm::LogError("FileNotFound") << "@SUB=read_ticlmark"
380  << "File with thickmark height file " << filename.c_str() << " cannot be opened!";
381  return;
382  }
383 
384  // clear internal maps
385  for_each(gains_.begin(), gains_.end(), CleanUp);
386  for_each(negative_gains_.begin(), negative_gains_.end(), CleanUp);
387  for_each(null_gains_.begin(), null_gains_.end(), CleanUp);
388 
389  // read file and fill internal map
390  uint32_t det_id = 0;
391  uint32_t APV_id = 0;
392  float tick_h = 0.;
393 
394  int count = -1;
395 
396  for (;;) {
397  count++;
398  thickmark_heights >> det_id >> APV_id >> tick_h;
399 
400  if (!(thickmark_heights.eof() || thickmark_heights.fail())) {
401  if (count == 0) {
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;
405  }
406  LogTrace("Debug") << std::setw(11) << det_id << std::setw(8) << APV_id << std::setw(14) << tick_h << std::endl;
407 
408  // retrieve the map corresponding to the gain collection
409  Gain* map = nullptr;
410  if (tick_h > 0.f) {
411  map = get_map(&gains_, APV_id);
412  } else if (tick_h < 0.f) {
413  map = get_map(&negative_gains_, APV_id);
414  } else {
415  // if tick_h == 0.f
416  map = get_map(&null_gains_, APV_id);
417  }
418 
419  // insert the gain value in the map
420  if (map) {
421  std::pair<Gain::iterator, bool> ret = map->insert(std::pair<uint32_t, float>(det_id, tick_h));
422 
423  if (ret.second == false) {
424  edm::LogError("MapError") << "@SUB=read_tickmark"
425  << "Cannot not insert gain for detector id " << det_id
426  << " into the internal map: detector id already in the map.";
427  }
428  } else {
429  edm::LogError("MapError") << "@SUB=read_tickmark"
430  << "Cannot get the online-offline APV mapping!";
431  }
432  } else if (thickmark_heights.eof()) {
433  edm::LogInfo("SiStripApvGainFromFileBuilder") << "@SUB=read_tickmark"
434  << "EOF of " << filename.c_str() << " reached.";
435  break;
436  } else if (thickmark_heights.fail()) {
437  edm::LogError("FileiReadError") << "@SUB=read_tickmark"
438  << "error while reading " << filename.c_str();
439  break;
440  }
441  }
442 
443  thickmark_heights.close();
444 }
std::string fullPath() const
Definition: FileInPath.cc:161
ret
prodAgent to be discontinued
Log< level::Error, false > LogError
#define LogTrace(id)
double f[11][100]
Log< level::Info, false > LogInfo
Gain * get_map(std::vector< Gain *> *maps, int onlineAPV_id)
static const struct clean_up CleanUp

Member Data Documentation

◆ cablingToken_

const edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> SiStripApvGainFromFileBuilder::cablingToken_
private

ES token for the cabling

Definition at line 82 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ detCabling_

const SiStripDetCabling* SiStripApvGainFromFileBuilder::detCabling_
private

Description of detector cabling.

Definition at line 94 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ doGainNormalization_

bool SiStripApvGainFromFileBuilder::doGainNormalization_
private

Normalize the tickmark for the APV gain.

Definition at line 86 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ dummyAPVGain_

double SiStripApvGainFromFileBuilder::dummyAPVGain_
private

Dummy value for the APV gain.

Definition at line 85 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ ex_summary_

std::vector<Summary> SiStripApvGainFromFileBuilder::ex_summary_
private

Brief Collection of the exceptions encountered when filling the DB. An exception occur for all the non-cabled channels ( no gain associated in the tikmark file) and for all the channels that were off ( with zero gain associated) or sending corrupted data (with negative values in the tickmark file). At the end of the job the exception summary is dumped in SiStripApvGainExceptionSummary.txt.Collection of DB filling exceptions.

Definition at line 116 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze(), and output_summary().

◆ gains_

std::vector<Gain*> SiStripApvGainFromFileBuilder::gains_
private

Brief Maps [det_id <–> gains] arranged per APV indexes.Mapping channels with positive heights.

Definition at line 98 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze(), gain_from_maps(), read_tickmark(), and ~SiStripApvGainFromFileBuilder().

◆ gainThreshold_

double SiStripApvGainFromFileBuilder::gainThreshold_
private

Threshold for accepting the APV gain in the tickmark scan file.

Definition at line 84 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ k_GainNormalizationFactor

constexpr float SiStripApvGainFromFileBuilder::k_GainNormalizationFactor = 640.f
staticprivate

Definition at line 168 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze(), and fillDescriptions().

◆ k_InvalidGain

constexpr float SiStripApvGainFromFileBuilder::k_InvalidGain = 999999.f
staticprivate

Definition at line 169 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze(), and gain_from_maps().

◆ negative_gains_

std::vector<Gain*> SiStripApvGainFromFileBuilder::negative_gains_
private

Mapping channels sending bad data.

Definition at line 99 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze(), gain_from_maps(), read_tickmark(), and ~SiStripApvGainFromFileBuilder().

◆ null_gains_

std::vector<Gain*> SiStripApvGainFromFileBuilder::null_gains_
private

Mapping channels switched off during the scan.

Definition at line 100 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze(), gain_from_maps(), read_tickmark(), and ~SiStripApvGainFromFileBuilder().

◆ outputMaps_

bool SiStripApvGainFromFileBuilder::outputMaps_
private

Flag for dumping the internal maps on ASCII files.

Definition at line 91 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ outputSummary_

bool SiStripApvGainFromFileBuilder::outputSummary_
private

Flag for dumping the summary of the exceptions during the DB filling.

Definition at line 92 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ putDummyIntoBadChannels_

bool SiStripApvGainFromFileBuilder::putDummyIntoBadChannels_
private

Flag for putting the dummy gain in the channels with negative gains.

Definition at line 90 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ putDummyIntoOffChannels_

bool SiStripApvGainFromFileBuilder::putDummyIntoOffChannels_
private

Flag for putting the dummy gain in the channels that were off during the tickmark scan.

Definition at line 89 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ putDummyIntoUncabled_

bool SiStripApvGainFromFileBuilder::putDummyIntoUncabled_
private

Flag for putting the dummy gain in the channels not actuall cabled.

Definition at line 87 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ putDummyIntoUnscanned_

bool SiStripApvGainFromFileBuilder::putDummyIntoUnscanned_
private

Flag for putting the dummy gain in the chennals not scanned.

Definition at line 88 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze().

◆ summary_

std::vector<Summary> SiStripApvGainFromFileBuilder::summary_
private

Brief Collection of the channels entered in the DB without exceptions. The channels whose APV gain has been input in the DB straight from the tickmark scan are collected in the summary vector. The summary list is dumped in the SiStripApvGainSummary.txt at the end of the job. Collection of channel with no DB filling exceptions.

Definition at line 107 of file SiStripApvGainFromFileBuilder.cc.

Referenced by analyze(), and output_summary().

◆ tfp_

edm::FileInPath SiStripApvGainFromFileBuilder::tfp_
private

File Path for the tickmark scan with the APV gains.

Definition at line 83 of file SiStripApvGainFromFileBuilder.cc.

Referenced by read_tickmark().