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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
#include "CalibCalorimetry/EcalTPGTools/plugins/EcalTPGDBApp.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <vector>
#include <ctime>

using namespace std;
using namespace oracle::occi;

EcalTPGDBApp::EcalTPGDBApp(string host, string sid, string user, string pass, int port)
    : EcalCondDBInterface(host, sid, user, pass, port) {}

EcalTPGDBApp::EcalTPGDBApp(string sid, string user, string pass) : EcalCondDBInterface(sid, user, pass) {}

int EcalTPGDBApp::writeToConfDB_TPGPedestals(const map<EcalLogicID, FEConfigPedDat>& pedset, int iovId, string tag) {
  int result = 0;

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "******** Inserting Peds in conf-OMDS*****";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";

  edm::LogVerbatim("ECALTPGDBApp") << "creating fe record ";
  FEConfigPedInfo fe_ped_info;
  fe_ped_info.setIOVId(iovId);
  fe_ped_info.setConfigTag(tag);
  insertConfigSet(&fe_ped_info);
  result = fe_ped_info.getID();

  // Insert the dataset, identifying by iov
  edm::LogVerbatim("ECALTPGDBApp") << "*********about to insert peds *********";
  edm::LogVerbatim("ECALTPGDBApp") << " map size = " << pedset.size();
  insertDataArraySet(&pedset, &fe_ped_info);
  edm::LogVerbatim("ECALTPGDBApp") << "*********Done peds            *********";

  return result;
}

int EcalTPGDBApp::writeToConfDB_TPGLinearCoef(const map<EcalLogicID, FEConfigLinDat>& linset,
                                              const map<EcalLogicID, FEConfigLinParamDat>& linparamset,
                                              int iovId,
                                              string tag) {
  int result = 0;

  edm::LogVerbatim("ECALTPGDBApp") << "*********************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "**Inserting Linarization coeff in conf-OMDS**";
  edm::LogVerbatim("ECALTPGDBApp") << "*********************************************";

  edm::LogVerbatim("ECALTPGDBApp") << "creating fe record ";
  FEConfigLinInfo fe_lin_info;
  fe_lin_info.setIOVId(iovId);
  fe_lin_info.setConfigTag(tag);
  insertConfigSet(&fe_lin_info);
  result = fe_lin_info.getID();

  // Insert the dataset, identifying by iov
  edm::LogVerbatim("ECALTPGDBApp") << "*********about to insert linearization coeff *********";
  edm::LogVerbatim("ECALTPGDBApp") << " map size = " << linset.size();
  insertDataArraySet(&linset, &fe_lin_info);
  insertDataArraySet(&linparamset, &fe_lin_info);
  edm::LogVerbatim("ECALTPGDBApp") << "*********Done lineraization coeff            *********";

  return result;
}

int EcalTPGDBApp::writeToConfDB_TPGMain(int ped,
                                        int lin,
                                        int lut,
                                        int fgr,
                                        int sli,
                                        int wei,
                                        int wei2,
                                        int spi,
                                        int tim,
                                        int bxt,
                                        int btt,
                                        int bst,
                                        int cok,
                                        string tag,
                                        int ver) {
  int result = 0;

  edm::LogVerbatim("ECALTPGDBApp") << "*********************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "**Inserting Main FE table in conf-OMDS     **";
  edm::LogVerbatim("ECALTPGDBApp") << "*********************************************";

  edm::LogVerbatim("ECALTPGDBApp") << "creating fe record ";

  FEConfigMainInfo fe_main;
  fe_main.setPedId(ped);
  fe_main.setLinId(lin);
  fe_main.setLUTId(lut);
  fe_main.setFgrId(fgr);
  fe_main.setSliId(sli);
  fe_main.setWeiId(wei);
  fe_main.setWei2Id(wei2);
  fe_main.setSpiId(spi);
  fe_main.setTimId(tim);
  fe_main.setBxtId(bxt);
  fe_main.setBttId(btt);
  fe_main.setBstId(bst);
  fe_main.setCokeId(cok);
  fe_main.setConfigTag(tag);
  fe_main.setVersion(ver);

  insertConfigSet(&fe_main);
  result = fe_main.getId();

  edm::LogVerbatim("ECALTPGDBApp") << "*********Done Main           *********";

  return result;
}

void EcalTPGDBApp::readFromConfDB_TPGPedestals(int iconf_req) {
  // now we do something else
  // this is an example for reading the pedestals
  // for a given config iconf_req

  // FC alternatively a config set can be retrieved by the tag and version

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "test readinf fe_ped with id=" << iconf_req;
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";

  FEConfigPedInfo fe_ped_info;
  fe_ped_info.setId(iconf_req);

  fetchConfigSet(&fe_ped_info);

  map<EcalLogicID, FEConfigPedDat> dataset_ped;
  fetchDataSet(&dataset_ped, &fe_ped_info);

  typedef map<EcalLogicID, FEConfigPedDat>::const_iterator CIfeped;
  EcalLogicID ecid_xt;
  FEConfigPedDat rd_ped;

  for (CIfeped p = dataset_ped.begin(); p != dataset_ped.end(); ++p) {
    ecid_xt = p->first;
    rd_ped = p->second;
    //int sm_num=ecid_xt.getID1();
    ecid_xt.getID2();
    rd_ped.getPedMeanG12();
    rd_ped.getPedMeanG6();
    rd_ped.getPedMeanG1();
  }

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "test read done" << iconf_req;
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
}

int EcalTPGDBApp::readFromCondDB_Pedestals(map<EcalLogicID, MonPedestalsDat>& dataset, int runNb) {
  int iovId = 0;

  edm::LogVerbatim("ECALTPGDBApp") << "Retrieving run list from DB from run nb ... " << runNb;
  RunTag my_runtag;
  LocationDef my_locdef;
  RunTypeDef my_rundef;
  my_locdef.setLocation("P5_Co");
  my_rundef.setRunType("PEDESTAL");
  my_runtag.setLocationDef(my_locdef);
  my_runtag.setRunTypeDef(my_rundef);
  my_runtag.setGeneralTag("LOCAL");

  // here we retrieve the Monitoring results
  MonVersionDef monverdef;
  monverdef.setMonitoringVersion("test01");
  MonRunTag montag;
  montag.setMonVersionDef(monverdef);
  montag.setGeneralTag("CMSSW");

  MonRunList mon_list;
  mon_list.setMonRunTag(montag);
  mon_list.setRunTag(my_runtag);

  edm::LogVerbatim("ECALTPGDBApp") << "we are in read ped from condDB and runNb is " << runNb;

  mon_list = fetchMonRunListLastNRuns(my_runtag, montag, runNb, 10);

  edm::LogVerbatim("ECALTPGDBApp") << "we are in read ped from condDB";

  std::vector<MonRunIOV> mon_run_vec = mon_list.getRuns();
  edm::LogVerbatim("ECALTPGDBApp") << "number of ped runs is : " << mon_run_vec.size();
  int mon_runs = mon_run_vec.size();
  //int sm_num = 0;

  if (mon_runs > 0) {
    for (int ii = 0; ii < (int)mon_run_vec.size(); ii++)
      edm::LogVerbatim("ECALTPGDBApp") << "here is the run number: " << mon_run_vec[ii].getRunIOV().getRunNumber();

    // for the first run of the list we retrieve the pedestals
    int run = 0;
    edm::LogVerbatim("ECALTPGDBApp") << " retrieve the data for a given run";
    edm::LogVerbatim("ECALTPGDBApp") << "here is the run number: " << mon_run_vec[run].getRunIOV().getRunNumber();
    iovId = mon_run_vec[run].getID();

    fetchDataSet(&dataset, &mon_run_vec[run]);
  }
  return iovId;
}

int EcalTPGDBApp::writeToConfDB_TPGSliding(const map<EcalLogicID, FEConfigSlidingDat>& sliset, int iovId, string tag) {
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Inserting SLIDING************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  int result = 0;

  FEConfigSlidingInfo fe_info;
  fe_info.setIOVId(iovId);
  fe_info.setConfigTag(tag);
  insertConfigSet(&fe_info);

  //  Tm tdb = fe_lut_info.getDBTime();
  //tdb.dumpTm();

  // Insert the dataset
  insertDataArraySet(&sliset, &fe_info);

  result = fe_info.getId();

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************SLI done*********************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  return result;
}

int EcalTPGDBApp::writeToConfDB_TPGLUT(const map<EcalLogicID, FEConfigLUTGroupDat>& lutgroupset,
                                       const map<EcalLogicID, FEConfigLUTDat>& lutset,
                                       const map<EcalLogicID, FEConfigLUTParamDat>& lutparamset,
                                       int iovId,
                                       string tag) {
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Inserting LUT************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  int result = 0;

  FEConfigLUTInfo fe_lut_info;
  fe_lut_info.setNumberOfGroups(iovId);
  fe_lut_info.setConfigTag(tag);
  insertConfigSet(&fe_lut_info);

  //  Tm tdb = fe_lut_info.getDBTime();
  //tdb.dumpTm();

  // Insert the dataset
  insertDataArraySet(&lutgroupset, &fe_lut_info);
  // Insert the dataset
  insertDataArraySet(&lutset, &fe_lut_info);
  // insert the parameters
  insertDataArraySet(&lutparamset, &fe_lut_info);

  result = fe_lut_info.getId();

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************LUT done*********************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  return result;
}

int EcalTPGDBApp::writeToConfDB_TPGWeight(const map<EcalLogicID, FEConfigWeightGroupDat>& lutgroupset,
                                          const map<EcalLogicID, FEConfigWeightDat>& lutset,
                                          int ngr,
                                          string tag) {
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Inserting weights************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";

  int result = 0;

  FEConfigWeightInfo fe_wei_info;
  fe_wei_info.setNumberOfGroups(ngr);
  fe_wei_info.setConfigTag(tag);
  insertConfigSet(&fe_wei_info);

  //  Tm tdb = fe_lut_info.getDBTime();
  //tdb.dumpTm();

  // Insert the dataset
  insertDataArraySet(&lutgroupset, &fe_wei_info);
  // Insert the dataset
  insertDataArraySet(&lutset, &fe_wei_info);

  result = fe_wei_info.getId();

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************WEIGHT done******************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  return result;
}

int EcalTPGDBApp::writeToConfDB_TPGWeight_doubleWeights(const map<EcalLogicID, FEConfigOddWeightGroupDat>& lutgroupset,
                                                        const map<EcalLogicID, FEConfigOddWeightDat>& lutset,
                                                        const map<EcalLogicID, FEConfigOddWeightModeDat>& tpmode,
                                                        int ngr,
                                                        string tag) {
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Inserting odd weights************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";

  int result = 0;

  FEConfigOddWeightInfo fe_wei_info;
  fe_wei_info.setNumberOfGroups(ngr);
  fe_wei_info.setConfigTag(tag);
  insertConfigSet(&fe_wei_info);

  //  Tm tdb = fe_lut_info.getDBTime();
  //tdb.dumpTm();

  // Insert the dataset
  insertDataArraySet(&lutgroupset, &fe_wei_info);
  // Insert the dataset
  insertDataArraySet(&lutset, &fe_wei_info);
  // Insert the Tpmode
  insertDataSet(&tpmode, &fe_wei_info);

  result = fe_wei_info.getId();

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************ODD WEIGHT + TPmode done******************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  return result;
}

int EcalTPGDBApp::writeToConfDB_TPGFgr(const map<EcalLogicID, FEConfigFgrGroupDat>& fgrgroupset,
                                       const map<EcalLogicID, FEConfigFgrDat>& fgrset,
                                       const map<EcalLogicID, FEConfigFgrParamDat>& fgrparamset,
                                       const map<EcalLogicID, FEConfigFgrEETowerDat>& dataset3,
                                       const map<EcalLogicID, FEConfigFgrEEStripDat>& dataset4,
                                       int iovId,
                                       string tag) {
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Inserting Fgr************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  int result = 0;

  FEConfigFgrInfo fe_fgr_info;
  fe_fgr_info.setNumberOfGroups(iovId);  // this eventually refers to some other table
  fe_fgr_info.setConfigTag(tag);
  insertConfigSet(&fe_fgr_info);

  //  Tm tdb = fe_fgr_info.getDBTime();
  //tdb.dumpTm();

  // Insert the dataset
  insertDataArraySet(&fgrgroupset, &fe_fgr_info);
  // Insert the dataset
  insertDataArraySet(&fgrset, &fe_fgr_info);
  // Insert the parameters
  insertDataArraySet(&fgrparamset, &fe_fgr_info);
  // Insert the parameters
  insertDataArraySet(&dataset3, &fe_fgr_info);
  // Insert the parameters
  insertDataArraySet(&dataset4, &fe_fgr_info);

  result = fe_fgr_info.getId();

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Fgr done*********************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  return result;
}

int EcalTPGDBApp::writeToConfDB_Spike(const map<EcalLogicID, FEConfigSpikeDat>& spikegroupset, string tag) {
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Inserting Spike************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  int result = 0;

  FEConfigSpikeInfo fe_spike_info;
  fe_spike_info.setConfigTag(tag);
  insertConfigSet(&fe_spike_info);

  //  Tm tdb = fe_fgr_info.getDBTime();
  //tdb.dumpTm();

  // Insert the dataset
  insertDataArraySet(&spikegroupset, &fe_spike_info);

  result = fe_spike_info.getId();

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Spike done*******************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  return result;
}

int EcalTPGDBApp::writeToConfDB_Delay(const map<EcalLogicID, FEConfigTimingDat>& timegroupset, string tag) {
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Inserting Delays************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  int result = 0;

  FEConfigTimingInfo fe_time_info;
  fe_time_info.setConfigTag(tag);
  insertConfigSet(&fe_time_info);

  //  Tm tdb = fe_fgr_info.getDBTime();
  //tdb.dumpTm();

  // Insert the dataset
  insertDataArraySet(&timegroupset, &fe_time_info);

  result = fe_time_info.getId();

  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  edm::LogVerbatim("ECALTPGDBApp") << "************Delays done******************";
  edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
  return result;
}

void EcalTPGDBApp::printTag(const RunTag* tag) const {
  edm::LogVerbatim("ECALTPGDBApp") << "=============RunTag:";
  edm::LogVerbatim("ECALTPGDBApp") << "GeneralTag:         " << tag->getGeneralTag();
  edm::LogVerbatim("ECALTPGDBApp") << "Location:           " << tag->getLocationDef().getLocation();
  edm::LogVerbatim("ECALTPGDBApp") << "Run Type:           " << tag->getRunTypeDef().getRunType();
  edm::LogVerbatim("ECALTPGDBApp") << "====================";
}

void EcalTPGDBApp::printIOV(const RunIOV* iov) const {
  edm::LogVerbatim("ECALTPGDBApp") << "=============RunIOV:";
  RunTag tag = iov->getRunTag();
  printTag(&tag);
  edm::LogVerbatim("ECALTPGDBApp") << "Run Number:         " << iov->getRunNumber();
  edm::LogVerbatim("ECALTPGDBApp") << "Run Start:          " << iov->getRunStart().str();
  edm::LogVerbatim("ECALTPGDBApp") << "Run End:            " << iov->getRunEnd().str();
  edm::LogVerbatim("ECALTPGDBApp") << "====================";
}