Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:47:23

0001 /****************************************************************************
0002  *
0003  * This is a part of CTPPS offline software.
0004  * Authors:
0005  *   Filip Dej
0006  *   Laurent Forthomme
0007  *
0008  ****************************************************************************/
0009 
0010 #include "CondFormats/PPSObjects/interface/PPSTimingCalibration.h"
0011 #include <ostream>
0012 
0013 //--------------------------------------------------------------------------
0014 
0015 bool PPSTimingCalibration::Key::operator<(const PPSTimingCalibration::Key& rhs) const {
0016   if (db == rhs.db) {
0017     if (sampic == rhs.sampic) {
0018       if (channel == rhs.channel)
0019         return cell < rhs.cell;
0020       return channel < rhs.channel;
0021     }
0022     return sampic < rhs.sampic;
0023   }
0024   return db < rhs.db;
0025 }
0026 
0027 std::ostream& operator<<(std::ostream& os, const PPSTimingCalibration::Key& key) {
0028   return os << key.db << " " << key.sampic << " " << key.channel << " " << key.cell;
0029 }
0030 
0031 //--------------------------------------------------------------------------
0032 
0033 std::vector<double> PPSTimingCalibration::parameters(int key1, int key2, int key3, int key4) const {
0034   Key key{key1, key2, key3, key4};
0035   auto out = parameters_.find(key);
0036   if (out == parameters_.end())
0037     return {};
0038   return out->second;
0039 }
0040 
0041 double PPSTimingCalibration::timeOffset(int key1, int key2, int key3, int key4) const {
0042   Key key{key1, key2, key3, key4};
0043   auto out = timeInfo_.find(key);
0044   if (out == timeInfo_.end())
0045     return 0.;
0046   return out->second.first;
0047 }
0048 
0049 double PPSTimingCalibration::timePrecision(int key1, int key2, int key3, int key4) const {
0050   Key key{key1, key2, key3, key4};
0051   auto out = timeInfo_.find(key);
0052   if (out == timeInfo_.end())
0053     return 0.;
0054   return out->second.second;
0055 }
0056 
0057 std::ostream& operator<<(std::ostream& os, const PPSTimingCalibration& data) {
0058   os << "FORMULA: " << data.formula_ << "\nDB SAMPIC CHANNEL CELL PARAMETERS TIME_OFFSET\n";
0059   for (const auto& kv : data.parameters_) {
0060     os << kv.first << " [";
0061     for (size_t i = 0; i < kv.second.size(); ++i)
0062       os << (i > 0 ? ", " : "") << kv.second.at(i);
0063 
0064     PPSTimingCalibration::Key key = kv.first;
0065     if (data.timeInfo_.find(key) == data.timeInfo_.end())
0066       key = {kv.first.db, kv.first.sampic, kv.first.channel, -1};
0067 
0068     const auto& time = data.timeInfo_.at(key);
0069     os << "] " << time.first << " " << time.second << "\n";
0070   }
0071   return os;
0072 }