File indexing completed on 2024-04-06 12:04:40
0001 #include "DataFormats/Luminosity/interface/BeamCurrentInfo.h"
0002 #include "DataFormats/Math/interface/libminifloat.h"
0003
0004 #include <iomanip>
0005 #include <ostream>
0006 #include <iostream>
0007
0008 const float BeamCurrentInfo::scaleFactor = 1e10;
0009
0010 float BeamCurrentInfo::getBeam1IntensityBX(int bx) const { return beam1IntensitiesUnpacked_.at(bx); }
0011
0012 const std::vector<float>& BeamCurrentInfo::getBeam1Intensities() const { return beam1IntensitiesUnpacked_; }
0013
0014 float BeamCurrentInfo::getBeam2IntensityBX(int bx) const { return beam2IntensitiesUnpacked_.at(bx); }
0015
0016 const std::vector<float>& BeamCurrentInfo::getBeam2Intensities() const { return beam2IntensitiesUnpacked_; }
0017
0018 bool BeamCurrentInfo::isProductEqual(BeamCurrentInfo const& next) const {
0019 return (beam1IntensitiesPacked_ == next.beam1IntensitiesPacked_ &&
0020 beam2IntensitiesPacked_ == next.beam2IntensitiesPacked_);
0021 }
0022
0023 void BeamCurrentInfo::fillBeamIntensities(const std::vector<float>& beam1Intensities,
0024 const std::vector<float>& beam2Intensities) {
0025 beam1IntensitiesUnpacked_.assign(beam1Intensities.begin(), beam1Intensities.end());
0026 beam2IntensitiesUnpacked_.assign(beam2Intensities.begin(), beam2Intensities.end());
0027 packData();
0028 }
0029
0030 void BeamCurrentInfo::fill(const std::vector<float>& beam1Intensities, const std::vector<float>& beam2Intensities) {
0031 fillBeamIntensities(beam1Intensities, beam2Intensities);
0032 }
0033
0034
0035 void BeamCurrentInfo::packData() {
0036 beam1IntensitiesPacked_.resize(beam1IntensitiesUnpacked_.size());
0037 beam2IntensitiesPacked_.resize(beam2IntensitiesUnpacked_.size());
0038
0039 for (unsigned int i = 0; i < beam1IntensitiesUnpacked_.size(); i++) {
0040 beam1IntensitiesPacked_[i] = MiniFloatConverter::float32to16(beam1IntensitiesUnpacked_[i] / scaleFactor);
0041 }
0042 for (unsigned int i = 0; i < beam2IntensitiesUnpacked_.size(); i++) {
0043 beam2IntensitiesPacked_[i] = MiniFloatConverter::float32to16(beam2IntensitiesUnpacked_[i] / scaleFactor);
0044 }
0045
0046
0047 unpackData();
0048 }
0049
0050
0051 void BeamCurrentInfo::unpackData(const std::vector<uint16_t>& packed, std::vector<float>& unpacked) {
0052 unpacked.resize(packed.size());
0053
0054 for (unsigned int i = 0; i < packed.size(); i++) {
0055 unpacked[i] = MiniFloatConverter::float16to32(packed[i]) * scaleFactor;
0056 }
0057 }
0058
0059 void BeamCurrentInfo::unpackData() {
0060 unpackData(beam1IntensitiesPacked_, beam1IntensitiesUnpacked_);
0061 unpackData(beam2IntensitiesPacked_, beam2IntensitiesUnpacked_);
0062 }
0063
0064 std::ostream& operator<<(std::ostream& s, const BeamCurrentInfo& beamInfo) {
0065 s << std::endl << "Dumping BeamCurrentInfo..." << std::endl;
0066 s << " beam1Intensities = ";
0067 const std::vector<float>& b1int = beamInfo.getBeam1Intensities();
0068 const std::vector<uint16_t>& b1intPacked = beamInfo.getBeam1IntensitiesPacked();
0069 for (unsigned int i = 0; i < 10 && i < b1int.size(); ++i) {
0070 s << b1int[i] << " ";
0071 }
0072 s << "..." << std::endl << " (packed: ";
0073 for (unsigned int i = 0; i < 10 && i < b1intPacked.size(); ++i) {
0074 s << b1intPacked[i] << " ";
0075 }
0076 s << "...)" << std::endl;
0077 s << " beam2Intensities = ";
0078 const std::vector<float>& b2int = beamInfo.getBeam2Intensities();
0079 for (unsigned int i = 0; i < 10 && i < b2int.size(); ++i) {
0080 s << b2int[i] << " ";
0081 }
0082 s << " ..." << std::endl;
0083
0084 return s;
0085 }