Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-11 03:56:56

0001 // system include files
0002 #include <memory>
0003 
0004 // user include files
0005 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0006 #include "CondFormats/SiStripObjects/interface/SiStripDetVOff.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0016 #include "Geometry/CommonTopologies/interface/StripTopology.h"
0017 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0018 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0019 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0020 
0021 class SiStripDetVOffFakeBuilder : public edm::one::EDAnalyzer<> {
0022 public:
0023   explicit SiStripDetVOffFakeBuilder(const edm::ParameterSet& iConfig);
0024 
0025   ~SiStripDetVOffFakeBuilder() override;
0026 
0027   virtual void initialize(const edm::EventSetup&);
0028 
0029   void analyze(const edm::Event&, const edm::EventSetup&) override;
0030 
0031 private:
0032   bool printdebug_;
0033   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0034   std::vector<uint32_t> detids;
0035 };
0036 
0037 using namespace std;
0038 using namespace cms;
0039 
0040 SiStripDetVOffFakeBuilder::SiStripDetVOffFakeBuilder(const edm::ParameterSet& iConfig)
0041     : printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)), tkGeomToken_(esConsumes()) {}
0042 
0043 SiStripDetVOffFakeBuilder::~SiStripDetVOffFakeBuilder() = default;
0044 
0045 void SiStripDetVOffFakeBuilder::initialize(const edm::EventSetup& iSetup) {
0046   const auto& tkGeom = iSetup.getData(tkGeomToken_);
0047   edm::LogInfo("SiStripDetVOffFakeBuilder") << " There are " << tkGeom.detUnits().size() << " detectors" << std::endl;
0048 
0049   for (const auto& it : tkGeom.detUnits()) {
0050     if (dynamic_cast<StripGeomDetUnit const*>(it) != nullptr) {
0051       uint32_t detid = (it->geographicalId()).rawId();
0052       const StripTopology& p = dynamic_cast<StripGeomDetUnit const*>(it)->specificTopology();
0053       unsigned short Nstrips = p.nstrips();
0054       if (Nstrips < 1 || Nstrips > 768) {
0055         edm::LogError("SiStripDetVOffFakeBuilder")
0056             << " Problem with Number of strips in detector.. " << p.nstrips() << " Exiting program" << endl;
0057         exit(1);
0058       }
0059       detids.push_back(detid);
0060       if (printdebug_)
0061         edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid " << detid;
0062     }
0063   }
0064 }
0065 
0066 void SiStripDetVOffFakeBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
0067   initialize(iSetup);
0068 
0069   unsigned int run = evt.id().run();
0070 
0071   edm::LogInfo("SiStripDetVOffFakeBuilder")
0072       << "... creating dummy SiStripDetVOff Data for Run " << run << "\n " << std::endl;
0073 
0074   SiStripDetVOff SiStripDetVOff_;
0075 
0076   // std::vector<uint32_t> TheDetIdHVVector;
0077 
0078   for (std::vector<uint32_t>::const_iterator it = detids.begin(); it != detids.end(); it++) {
0079     //Generate HV and LV for each channel, if at least one of the two is off fill the value
0080     int hv = rand() % 20;
0081     int lv = rand() % 20;
0082     if (hv <= 2) {
0083       edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid: " << *it << " HV\t OFF" << std::endl;
0084       SiStripDetVOff_.put(*it, 1, -1);
0085       // TheDetIdHVVector.push_back(*it);
0086     }
0087     if (lv <= 2) {
0088       edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid: " << *it << " LV\t OFF" << std::endl;
0089       SiStripDetVOff_.put(*it, -1, 1);
0090       // TheDetIdHVVector.push_back(*it);
0091     }
0092     if (lv <= 2 || hv <= 2)
0093       edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid: " << *it << " V\t OFF" << std::endl;
0094   }
0095 
0096   // SiStripDetVOff_.put(TheDetIdHVVector);
0097 
0098   //End now write DetVOff data in DB
0099   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0100 
0101   if (mydbservice.isAvailable()) {
0102     try {
0103       if (mydbservice->isNewTagRequest("SiStripDetVOffRcd")) {
0104         mydbservice->createOneIOV<SiStripDetVOff>(SiStripDetVOff_, mydbservice->beginOfTime(), "SiStripDetVOffRcd");
0105       } else {
0106         mydbservice->appendOneIOV<SiStripDetVOff>(SiStripDetVOff_, mydbservice->currentTime(), "SiStripDetVOffRcd");
0107       }
0108     } catch (const cond::Exception& er) {
0109       edm::LogError("SiStripDetVOffFakeBuilder") << er.what() << std::endl;
0110     } catch (const std::exception& er) {
0111       edm::LogError("SiStripDetVOffFakeBuilder") << "caught std::exception " << er.what() << std::endl;
0112     }
0113   } else {
0114     edm::LogError("SiStripDetVOffFakeBuilder") << "Service is unavailable" << std::endl;
0115   }
0116 }
0117 
0118 #include "FWCore/PluginManager/interface/ModuleDef.h"
0119 #include "FWCore/Framework/interface/MakerMacros.h"
0120 
0121 DEFINE_FWK_MODULE(SiStripDetVOffFakeBuilder);