CMS 3D CMS Logo

PPSTimingCalibrationLUTESSource.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of CTPPS offline software.
4  * Authors:
5  * Edoardo Bossini
6  * Filip Dej
7  * Laurent Forthomme
8  * Christopher Misan
9  *
10  * NOTE:
11  * Given implementation handles calibration files in JSON format,
12  *
13  ****************************************************************************/
14 
21 
23 
26 
27 #include <boost/property_tree/json_parser.hpp>
28 #include <boost/property_tree/ptree.hpp>
29 
30 namespace pt = boost::property_tree;
31 
32 //------------------------------------------------------------------------------
33 
35 public:
37 
39 
41 
42 private:
44  const edm::IOVSyncValue&,
45  edm::ValidityInterval&) override;
46 
48  std::unique_ptr<PPSTimingCalibrationLUT> parsePPSDiamondLUTJsonFile() const;
49 
51 };
52 
53 //------------------------------------------------------------------------------
54 
56  : filename_(iConfig.getParameter<edm::FileInPath>("calibrationFile").fullPath()) {
57  setWhatProduced(this);
58  findingRecord<PPSTimingCalibrationLUTRcd>();
59 }
60 
61 //------------------------------------------------------------------------------
62 
66 }
67 
68 //------------------------------------------------------------------------------
69 
71  const edm::IOVSyncValue&,
72  edm::ValidityInterval& oValidity) {
74 }
75 
76 //------------------------------------------------------------------------------
77 
78 std::unique_ptr<PPSTimingCalibrationLUT> PPSTimingCalibrationLUTESSource::parsePPSDiamondLUTJsonFile() const {
79  pt::ptree mother_node;
80  pt::read_json(filename_, mother_node);
81 
83  for (pt::ptree::value_type& node : mother_node.get_child("calib")) {
85 
86  key.sector = node.second.get<int>("sector");
87  key.station = node.second.get<int>("station");
88  key.plane = node.second.get<int>("plane");
89  key.channel = node.second.get<int>("channel");
90  std::vector<double> values;
91  for (pt::ptree::value_type& sample : node.second.get_child("samples")) {
92  values.emplace_back(std::stod(sample.second.data(), nullptr));
93  binMap[key] = values;
94  }
95  }
96  return std::make_unique<PPSTimingCalibrationLUT>(binMap);
97 }
98 
101  desc.add<edm::FileInPath>("calibrationFile", edm::FileInPath())->setComment("file with calibrations");
102 
103  descriptions.add("ppsTimingCalibrationLUTESSource", desc);
104 }
105 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
edm::ESProducts< std::unique_ptr< PPSTimingCalibrationLUT > > produce(const PPSTimingCalibrationLUTRcd &)
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
std::map< Key, std::vector< double > > BinMap
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
Helper structure for indexing calibration data.
PPSTimingCalibrationLUTESSource(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &)
std::unique_ptr< PPSTimingCalibrationLUT > parsePPSDiamondLUTJsonFile() const
Extract calibration data from JSON file (PPS horizontal diamond)