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
/****************************************************************************
 *
 * This is a part of CTPPS offline software.
 * Authors:
 *   Filip Dej
 *   Laurent Forthomme
 *
 ****************************************************************************/

#include "CondFormats/PPSObjects/interface/PPSTimingCalibration.h"
#include <ostream>

//--------------------------------------------------------------------------

bool PPSTimingCalibration::Key::operator<(const PPSTimingCalibration::Key& rhs) const {
  if (db == rhs.db) {
    if (sampic == rhs.sampic) {
      if (channel == rhs.channel)
        return cell < rhs.cell;
      return channel < rhs.channel;
    }
    return sampic < rhs.sampic;
  }
  return db < rhs.db;
}

std::ostream& operator<<(std::ostream& os, const PPSTimingCalibration::Key& key) {
  return os << key.db << " " << key.sampic << " " << key.channel << " " << key.cell;
}

//--------------------------------------------------------------------------

std::vector<double> PPSTimingCalibration::parameters(int key1, int key2, int key3, int key4) const {
  Key key{key1, key2, key3, key4};
  auto out = parameters_.find(key);
  if (out == parameters_.end())
    return {};
  return out->second;
}

double PPSTimingCalibration::timeOffset(int key1, int key2, int key3, int key4) const {
  Key key{key1, key2, key3, key4};
  auto out = timeInfo_.find(key);
  if (out == timeInfo_.end())
    return 0.;
  return out->second.first;
}

double PPSTimingCalibration::timePrecision(int key1, int key2, int key3, int key4) const {
  Key key{key1, key2, key3, key4};
  auto out = timeInfo_.find(key);
  if (out == timeInfo_.end())
    return 0.;
  return out->second.second;
}

std::ostream& operator<<(std::ostream& os, const PPSTimingCalibration& data) {
  os << "FORMULA: " << data.formula_ << "\nDB SAMPIC CHANNEL CELL PARAMETERS TIME_OFFSET\n";
  for (const auto& kv : data.parameters_) {
    os << kv.first << " [";
    for (size_t i = 0; i < kv.second.size(); ++i)
      os << (i > 0 ? ", " : "") << kv.second.at(i);

    PPSTimingCalibration::Key key = kv.first;
    if (data.timeInfo_.find(key) == data.timeInfo_.end())
      key = {kv.first.db, kv.first.sampic, kv.first.channel, -1};

    const auto& time = data.timeInfo_.at(key);
    os << "] " << time.first << " " << time.second << "\n";
  }
  return os;
}