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

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

Toy EDAnalyzer for testing purposes only.

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

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

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

#include "CondFormats/DTObjects/test/stubs/DTDeadWrite.h"
#include "CondFormats/DTObjects/interface/DTDeadFlag.h"

namespace edmtest {

  DTDeadWrite::DTDeadWrite(edm::ParameterSet const& p) {}

  DTDeadWrite::DTDeadWrite(int i) {}

  void DTDeadWrite::analyze(const edm::Event& e, const edm::EventSetup& context) {
    std::cout << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
    std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;
  }

  void DTDeadWrite::endJob() {
    std::cout << "DTDeadWrite::analyze " << std::endl;
    edm::Service<cond::service::PoolDBOutputService> dbservice;
    if (!dbservice.isAvailable()) {
      std::cout << "db service unavailable" << std::endl;
      return;
    }

    DTDeadFlag dlist("deadList");

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

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

  void DTDeadWrite::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 DTDeadWrite::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 DTDeadWrite::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 DTDeadWrite::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(DTDeadWrite);
}  // namespace edmtest