CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripBadChannelBuilder.cc
Go to the documentation of this file.
1 // system include files
2 #include <vector>
3 #include <memory>
4 #include <iostream>
5 #include <fstream>
6 
7 // user include files
16 
17 #include "CLHEP/Random/RandFlat.h"
18 #include "CLHEP/Random/RandGauss.h"
19 
20 class SiStripBadChannelBuilder : public ConditionDBWriter<SiStripBadStrip> {
21 public:
23  ~SiStripBadChannelBuilder() override;
24 
25 private:
26  std::unique_ptr<SiStripBadStrip> getNewObject() override;
27 
30 
31  typedef std::vector<edm::ParameterSet> Parameters;
33 };
34 
38  printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
39  BadComponentList_ = iConfig.getUntrackedParameter<Parameters>("BadComponentList");
40 }
41 
43 
44 std::unique_ptr<SiStripBadStrip> SiStripBadChannelBuilder::getNewObject() {
45  edm::LogInfo("SiStripBadChannelBuilder") << "... creating dummy SiStripBadStrip Data" << std::endl;
46 
47  auto obj = std::make_unique<SiStripBadStrip>();
48 
49  const auto detInfo = SiStripDetInfoFileReader::read(fp_.fullPath());
50 
51  for (Parameters::iterator iBadComponent = BadComponentList_.begin(); iBadComponent != BadComponentList_.end();
52  ++iBadComponent) {
53  uint32_t BadModule_ = iBadComponent->getParameter<uint32_t>("BadModule");
54  std::vector<uint32_t> BadChannelList_ = iBadComponent->getParameter<std::vector<uint32_t> >("BadChannelList");
55 
56  std::vector<unsigned int> theSiStripVector;
57  unsigned int NStrips = detInfo.getNumberOfApvsAndStripLength(BadModule_).first * 128;
58 
59  uint32_t lastBad = 999;
60  unsigned short firstBadStrip = 0, NconsecutiveBadStrips = 0;
61  unsigned int theBadStripRange;
62 
63  for (std::vector<uint32_t>::const_iterator is = BadChannelList_.begin(); is != BadChannelList_.end(); ++is) {
64  if (*is > NStrips - 1)
65  break;
66  if (*is != lastBad + 1) {
67  //new set
68 
69  if (lastBad != 999) {
70  //save previous set
71  theBadStripRange = obj->encode(firstBadStrip, NconsecutiveBadStrips);
72 
73  if (printdebug_)
74  edm::LogInfo("SiStripBadChannelBuilder")
75  << "detid " << BadModule_ << " \t"
76  << " firstBadStrip " << firstBadStrip << "\t "
77  << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
78  << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
79 
80  theSiStripVector.push_back(theBadStripRange);
81  }
82 
83  firstBadStrip = *is;
84  NconsecutiveBadStrips = 0;
85  }
86  NconsecutiveBadStrips++;
87  lastBad = *is;
88  }
89 
90  theBadStripRange = obj->encode(firstBadStrip, NconsecutiveBadStrips);
91  if (printdebug_)
92  edm::LogInfo("SiStripBadChannelBuilder")
93  << "detid " << BadModule_ << " \t"
94  << " firstBadStrip " << firstBadStrip << "\t "
95  << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
96  << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
97 
98  theSiStripVector.push_back(theBadStripRange);
99 
100  SiStripBadStrip::Range range(theSiStripVector.begin(), theSiStripVector.end());
101  if (!obj->put(BadModule_, range))
102  edm::LogError("SiStripBadChannelBuilder")
103  << "[SiStripBadChannelBuilder::analyze] detid already exists" << std::endl;
104  }
105  //End now write sistripbadChannel data in DB
107 
108  if (mydbservice.isAvailable()) {
109  if (mydbservice->isNewTagRequest("SiStripBadStripRcd")) {
110  mydbservice->createOneIOV<SiStripBadStrip>(*obj, mydbservice->beginOfTime(), "SiStripBadStripRcd");
111  } else {
112  mydbservice->appendOneIOV<SiStripBadStrip>(*obj, mydbservice->currentTime(), "SiStripBadStripRcd");
113  }
114  } else {
115  edm::LogError("SiStripBadStripBuilder") << "Service is unavailable" << std::endl;
116  }
117 
118  return obj;
119 }
120 
123 
T getUntrackedParameter(std::string const &, T const &) const
SiStripBadChannelBuilder(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Error, false > LogError
std::vector< edm::ParameterSet > Parameters
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
const uint16_t range(const Frame &aFrame)
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:40
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
SiStripDetInfo read(std::string filePath)
Log< level::Info, false > LogInfo
std::pair< ContainerIterator, ContainerIterator > Range
std::string fullPath() const
Definition: FileInPath.cc:161
static constexpr char const *const kDefaultFile
~SiStripBadChannelBuilder() override
std::unique_ptr< SiStripBadStrip > getNewObject() override