CMS 3D CMS Logo

SiStripDetVOffFakeBuilder.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
20 
22 public:
23  explicit SiStripDetVOffFakeBuilder(const edm::ParameterSet& iConfig);
24 
25  ~SiStripDetVOffFakeBuilder() override;
26 
27  virtual void initialize(const edm::EventSetup&);
28 
29  void analyze(const edm::Event&, const edm::EventSetup&) override;
30 
31 private:
34  std::vector<uint32_t> detids;
35 };
36 
37 using namespace std;
38 using namespace cms;
39 
41  : printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)), tkGeomToken_(esConsumes()) {}
42 
44 
46  const auto& tkGeom = iSetup.getData(tkGeomToken_);
47  edm::LogInfo("SiStripDetVOffFakeBuilder") << " There are " << tkGeom.detUnits().size() << " detectors" << std::endl;
48 
49  for (const auto& it : tkGeom.detUnits()) {
50  if (dynamic_cast<StripGeomDetUnit const*>(it) != nullptr) {
51  uint32_t detid = (it->geographicalId()).rawId();
52  const StripTopology& p = dynamic_cast<StripGeomDetUnit const*>(it)->specificTopology();
53  unsigned short Nstrips = p.nstrips();
54  if (Nstrips < 1 || Nstrips > 768) {
55  edm::LogError("SiStripDetVOffFakeBuilder")
56  << " Problem with Number of strips in detector.. " << p.nstrips() << " Exiting program" << endl;
57  exit(1);
58  }
59  detids.push_back(detid);
60  if (printdebug_)
61  edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid " << detid;
62  }
63  }
64 }
65 
67  initialize(iSetup);
68 
69  unsigned int run = evt.id().run();
70 
71  edm::LogInfo("SiStripDetVOffFakeBuilder")
72  << "... creating dummy SiStripDetVOff Data for Run " << run << "\n " << std::endl;
73 
74  SiStripDetVOff SiStripDetVOff_;
75 
76  // std::vector<uint32_t> TheDetIdHVVector;
77 
78  for (std::vector<uint32_t>::const_iterator it = detids.begin(); it != detids.end(); it++) {
79  //Generate HV and LV for each channel, if at least one of the two is off fill the value
80  int hv = rand() % 20;
81  int lv = rand() % 20;
82  if (hv <= 2) {
83  edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid: " << *it << " HV\t OFF" << std::endl;
84  SiStripDetVOff_.put(*it, 1, -1);
85  // TheDetIdHVVector.push_back(*it);
86  }
87  if (lv <= 2) {
88  edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid: " << *it << " LV\t OFF" << std::endl;
89  SiStripDetVOff_.put(*it, -1, 1);
90  // TheDetIdHVVector.push_back(*it);
91  }
92  if (lv <= 2 || hv <= 2)
93  edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid: " << *it << " V\t OFF" << std::endl;
94  }
95 
96  // SiStripDetVOff_.put(TheDetIdHVVector);
97 
98  //End now write DetVOff data in DB
100 
101  if (mydbservice.isAvailable()) {
102  try {
103  if (mydbservice->isNewTagRequest("SiStripDetVOffRcd")) {
104  mydbservice->createOneIOV<SiStripDetVOff>(SiStripDetVOff_, mydbservice->beginOfTime(), "SiStripDetVOffRcd");
105  } else {
106  mydbservice->appendOneIOV<SiStripDetVOff>(SiStripDetVOff_, mydbservice->currentTime(), "SiStripDetVOffRcd");
107  }
108  } catch (const cond::Exception& er) {
109  edm::LogError("SiStripDetVOffFakeBuilder") << er.what() << std::endl;
110  } catch (const std::exception& er) {
111  edm::LogError("SiStripDetVOffFakeBuilder") << "caught std::exception " << er.what() << std::endl;
112  }
113  } else {
114  edm::LogError("SiStripDetVOffFakeBuilder") << "Service is unavailable" << std::endl;
115  }
116 }
117 
120 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Base exception class for the object to relational access.
Definition: Exception.h:11
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
bool put(const uint32_t DetId, const int HVoff, const int LVoff)
Insert information for a single detId.
Log< level::Error, false > LogError
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
bool isNewTagRequest(const std::string &recordName)
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EventID id() const
Definition: EventBase.h:63
Namespace of DDCMS conversion namespace.
void analyze(const edm::Event &, const edm::EventSetup &) override
Log< level::Info, false > LogInfo
RunNumber_t run() const
Definition: EventID.h:38
bool isAvailable() const
Definition: Service.h:40
char const * what() const noexcept override
Definition: Exception.cc:107
virtual void initialize(const edm::EventSetup &)
SiStripDetVOffFakeBuilder(const edm::ParameterSet &iConfig)
~SiStripDetVOffFakeBuilder() override
def exit(msg="")