Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

/*----------------------------------------------------------------------

Toy EDAnalyzer for testing purposes only.

----------------------------------------------------------------------*/

#include <stdexcept>
#include <string>
#include <iostream>
#include <fstream>
#include <map>
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"

#include "CondFormats/DTObjects/test/stubs/DTDeadUpdate.h"

namespace edmtest {

  DTDeadUpdate::DTDeadUpdate(edm::ParameterSet const& p) : dSum(0), es_token(esConsumes()) {}

  DTDeadUpdate::DTDeadUpdate(int i) : dSum(0) {}

  DTDeadUpdate::~DTDeadUpdate() { delete dSum; }

  void DTDeadUpdate::analyze(const edm::Event& e, const edm::EventSetup& context) {
    if (dSum == 0)
      dSum = new DTDeadFlag("deadList");
    using namespace edm::eventsetup;
    // Context is not used.
    std::cout << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
    std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;
    const auto& dList = context.getData(es_token);
    std::cout << dList.version() << std::endl;
    std::cout << std::distance(dList.begin(), dList.end()) << " data in the container" << std::endl;
    DTDeadFlag::const_iterator iter = dList.begin();
    DTDeadFlag::const_iterator iend = dList.end();
    while (iter != iend) {
      const std::pair<DTDeadFlagId, DTDeadFlagData>& data = *iter++;
      const DTDeadFlagId& id = data.first;
      const DTDeadFlagData& st = data.second;
      std::cout << id.wheelId << " " << id.stationId << " " << id.sectorId << " " << id.slId << " " << id.layerId << " "
                << id.cellId << " -> " << st.dead_HV << " " << st.dead_TP << " " << st.dead_RO << " " << st.discCat
                << std::endl;
      if (st.dead_HV)
        dSum->setCellDead_HV(id.wheelId, id.stationId, id.sectorId, id.slId, id.layerId, id.cellId, true);
      if (st.dead_TP)
        dSum->setCellDead_TP(id.wheelId, id.stationId, id.sectorId, id.slId, id.layerId, id.cellId, true);
      if (st.dead_RO)
        dSum->setCellDead_RO(id.wheelId, id.stationId, id.sectorId, id.slId, id.layerId, id.cellId, true);
      if (st.discCat)
        dSum->setCellDiscCat(id.wheelId, id.stationId, id.sectorId, id.slId, id.layerId, id.cellId, true);
    }
  }
  void DTDeadUpdate::endJob() {
    std::cout << "DTDeadUpdate::endJob " << std::endl;
    edm::Service<cond::service::PoolDBOutputService> dbservice;
    if (!dbservice.isAvailable()) {
      std::cout << "db service unavailable" << std::endl;
      return;
    }

    fill_dead_HV("dead_HV_list.txt", dSum);
    fill_dead_TP("dead_TP_list.txt", dSum);
    fill_dead_RO("dead_RO_list.txt", dSum);
    fill_discCat("discCat_list.txt", dSum);

    if (dbservice->isNewTagRequest("DTDeadFlagRcd")) {
      dbservice->createOneIOV<DTDeadFlag>(*dSum, dbservice->beginOfTime(), "DTDeadFlagRcd");
    } else {
      std::cout << "already present tag" << std::endl;
      int currentRun = 10;
      //      dbservice->appendTillTime<DTDeadFlag>(
      dbservice->appendOneIOV<DTDeadFlag>(*dSum, currentRun, "DTDeadFlagRcd");
      //      dbservice->appendSinceTime<DTDeadFlag>(
      //                 dlist,dbservice->currentTime(),"DTDeadFlagRcd");
    }
  }

  void DTDeadUpdate::fill_dead_HV(const char* file, DTDeadFlag* deadList) {
    int status = 0;
    int whe;
    int sta;
    int sec;
    int qua;
    int lay;
    int cel;
    std::ifstream ifile(file);
    while (ifile >> whe >> sta >> sec >> qua >> lay >> cel) {
      status = deadList->setCellDead_HV(whe, sta, sec, qua, lay, cel, true);
      std::cout << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << "  -> ";
      std::cout << "insert status: " << status << std::endl;
    }
    return;
  }
  void DTDeadUpdate::fill_dead_TP(const char* file, DTDeadFlag* deadList) {
    int status = 0;
    int whe;
    int sta;
    int sec;
    int qua;
    int lay;
    int cel;
    std::ifstream ifile(file);
    while (ifile >> whe >> sta >> sec >> qua >> lay >> cel) {
      status = deadList->setCellDead_TP(whe, sta, sec, qua, lay, cel, true);
      std::cout << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << "  -> ";
      std::cout << "insert status: " << status << std::endl;
    }
    return;
  }
  void DTDeadUpdate::fill_dead_RO(const char* file, DTDeadFlag* deadList) {
    int status = 0;
    int whe;
    int sta;
    int sec;
    int qua;
    int lay;
    int cel;
    std::ifstream ifile(file);
    while (ifile >> whe >> sta >> sec >> qua >> lay >> cel) {
      status = deadList->setCellDead_RO(whe, sta, sec, qua, lay, cel, true);
      std::cout << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << "  -> ";
      std::cout << "insert status: " << status << std::endl;
    }
    return;
  }
  void DTDeadUpdate::fill_discCat(const char* file, DTDeadFlag* deadList) {
    int status = 0;
    int whe;
    int sta;
    int sec;
    int qua;
    int lay;
    int cel;
    std::ifstream ifile(file);
    while (ifile >> whe >> sta >> sec >> qua >> lay >> cel) {
      status = deadList->setCellDiscCat(whe, sta, sec, qua, lay, cel, true);
      std::cout << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << "  -> ";
      std::cout << "insert status: " << status << std::endl;
    }
    return;
  }

  DEFINE_FWK_MODULE(DTDeadUpdate);
}  // namespace edmtest