Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-17 01:40:44

0001 
0002 /*----------------------------------------------------------------------
0003 
0004 Toy EDAnalyzer for testing purposes only.
0005 
0006 ----------------------------------------------------------------------*/
0007 
0008 #include <stdexcept>
0009 #include <string>
0010 #include <iostream>
0011 #include <fstream>
0012 #include <map>
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 
0016 #include "FWCore/ServiceRegistry/interface/Service.h"
0017 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0018 
0019 #include "CondFormats/DTObjects/test/stubs/DTDeadUpdate.h"
0020 
0021 namespace edmtest {
0022 
0023   DTDeadUpdate::DTDeadUpdate(edm::ParameterSet const& p) : dSum(0), es_token(esConsumes()) {}
0024 
0025   DTDeadUpdate::DTDeadUpdate(int i) : dSum(0) {}
0026 
0027   DTDeadUpdate::~DTDeadUpdate() { delete dSum; }
0028 
0029   void DTDeadUpdate::analyze(const edm::Event& e, const edm::EventSetup& context) {
0030     if (dSum == 0)
0031       dSum = new DTDeadFlag("deadList");
0032     using namespace edm::eventsetup;
0033     // Context is not used.
0034     std::cout << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0035     std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;
0036     const auto& dList = context.getData(es_token);
0037     std::cout << dList.version() << std::endl;
0038     std::cout << std::distance(dList.begin(), dList.end()) << " data in the container" << std::endl;
0039     DTDeadFlag::const_iterator iter = dList.begin();
0040     DTDeadFlag::const_iterator iend = dList.end();
0041     while (iter != iend) {
0042       const std::pair<DTDeadFlagId, DTDeadFlagData>& data = *iter++;
0043       const DTDeadFlagId& id = data.first;
0044       const DTDeadFlagData& st = data.second;
0045       std::cout << id.wheelId << " " << id.stationId << " " << id.sectorId << " " << id.slId << " " << id.layerId << " "
0046                 << id.cellId << " -> " << st.dead_HV << " " << st.dead_TP << " " << st.dead_RO << " " << st.discCat
0047                 << std::endl;
0048       if (st.dead_HV)
0049         dSum->setCellDead_HV(id.wheelId, id.stationId, id.sectorId, id.slId, id.layerId, id.cellId, true);
0050       if (st.dead_TP)
0051         dSum->setCellDead_TP(id.wheelId, id.stationId, id.sectorId, id.slId, id.layerId, id.cellId, true);
0052       if (st.dead_RO)
0053         dSum->setCellDead_RO(id.wheelId, id.stationId, id.sectorId, id.slId, id.layerId, id.cellId, true);
0054       if (st.discCat)
0055         dSum->setCellDiscCat(id.wheelId, id.stationId, id.sectorId, id.slId, id.layerId, id.cellId, true);
0056     }
0057   }
0058   void DTDeadUpdate::endJob() {
0059     std::cout << "DTDeadUpdate::endJob " << std::endl;
0060     edm::Service<cond::service::PoolDBOutputService> dbservice;
0061     if (!dbservice.isAvailable()) {
0062       std::cout << "db service unavailable" << std::endl;
0063       return;
0064     }
0065 
0066     fill_dead_HV("dead_HV_list.txt", dSum);
0067     fill_dead_TP("dead_TP_list.txt", dSum);
0068     fill_dead_RO("dead_RO_list.txt", dSum);
0069     fill_discCat("discCat_list.txt", dSum);
0070 
0071     if (dbservice->isNewTagRequest("DTDeadFlagRcd")) {
0072       dbservice->createOneIOV<DTDeadFlag>(*dSum, dbservice->beginOfTime(), "DTDeadFlagRcd");
0073     } else {
0074       std::cout << "already present tag" << std::endl;
0075       int currentRun = 10;
0076       //      dbservice->appendTillTime<DTDeadFlag>(
0077       dbservice->appendOneIOV<DTDeadFlag>(*dSum, currentRun, "DTDeadFlagRcd");
0078       //      dbservice->appendSinceTime<DTDeadFlag>(
0079       //                 dlist,dbservice->currentTime(),"DTDeadFlagRcd");
0080     }
0081   }
0082 
0083   void DTDeadUpdate::fill_dead_HV(const char* file, DTDeadFlag* deadList) {
0084     int status = 0;
0085     int whe;
0086     int sta;
0087     int sec;
0088     int qua;
0089     int lay;
0090     int cel;
0091     std::ifstream ifile(file);
0092     while (ifile >> whe >> sta >> sec >> qua >> lay >> cel) {
0093       status = deadList->setCellDead_HV(whe, sta, sec, qua, lay, cel, true);
0094       std::cout << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << "  -> ";
0095       std::cout << "insert status: " << status << std::endl;
0096     }
0097     return;
0098   }
0099   void DTDeadUpdate::fill_dead_TP(const char* file, DTDeadFlag* deadList) {
0100     int status = 0;
0101     int whe;
0102     int sta;
0103     int sec;
0104     int qua;
0105     int lay;
0106     int cel;
0107     std::ifstream ifile(file);
0108     while (ifile >> whe >> sta >> sec >> qua >> lay >> cel) {
0109       status = deadList->setCellDead_TP(whe, sta, sec, qua, lay, cel, true);
0110       std::cout << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << "  -> ";
0111       std::cout << "insert status: " << status << std::endl;
0112     }
0113     return;
0114   }
0115   void DTDeadUpdate::fill_dead_RO(const char* file, DTDeadFlag* deadList) {
0116     int status = 0;
0117     int whe;
0118     int sta;
0119     int sec;
0120     int qua;
0121     int lay;
0122     int cel;
0123     std::ifstream ifile(file);
0124     while (ifile >> whe >> sta >> sec >> qua >> lay >> cel) {
0125       status = deadList->setCellDead_RO(whe, sta, sec, qua, lay, cel, true);
0126       std::cout << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << "  -> ";
0127       std::cout << "insert status: " << status << std::endl;
0128     }
0129     return;
0130   }
0131   void DTDeadUpdate::fill_discCat(const char* file, DTDeadFlag* deadList) {
0132     int status = 0;
0133     int whe;
0134     int sta;
0135     int sec;
0136     int qua;
0137     int lay;
0138     int cel;
0139     std::ifstream ifile(file);
0140     while (ifile >> whe >> sta >> sec >> qua >> lay >> cel) {
0141       status = deadList->setCellDiscCat(whe, sta, sec, qua, lay, cel, true);
0142       std::cout << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << "  -> ";
0143       std::cout << "insert status: " << status << std::endl;
0144     }
0145     return;
0146   }
0147 
0148   DEFINE_FWK_MODULE(DTDeadUpdate);
0149 }  // namespace edmtest