CMS 3D CMS Logo

BeamCurrentInfo.cc
Go to the documentation of this file.
3 
4 #include <iomanip>
5 #include <ostream>
6 #include <iostream>
7 
8 const float BeamCurrentInfo::scaleFactor = 1e10;
9 
11 
12 const std::vector<float>& BeamCurrentInfo::getBeam1Intensities() const { return beam1IntensitiesUnpacked_; }
13 
15 
16 const std::vector<float>& BeamCurrentInfo::getBeam2Intensities() const { return beam2IntensitiesUnpacked_; }
17 
19  return (beam1IntensitiesPacked_ == next.beam1IntensitiesPacked_ &&
20  beam2IntensitiesPacked_ == next.beam2IntensitiesPacked_);
21 }
22 
23 void BeamCurrentInfo::fillBeamIntensities(const std::vector<float>& beam1Intensities,
24  const std::vector<float>& beam2Intensities) {
25  beam1IntensitiesUnpacked_.assign(beam1Intensities.begin(), beam1Intensities.end());
26  beam2IntensitiesUnpacked_.assign(beam2Intensities.begin(), beam2Intensities.end());
27  packData();
28 }
29 
30 void BeamCurrentInfo::fill(const std::vector<float>& beam1Intensities, const std::vector<float>& beam2Intensities) {
31  fillBeamIntensities(beam1Intensities, beam2Intensities);
32 }
33 
34 // Convert unpacked data to packed data (when it is filled).
38 
39  for (unsigned int i = 0; i < beam1IntensitiesUnpacked_.size(); i++) {
41  }
42  for (unsigned int i = 0; i < beam2IntensitiesUnpacked_.size(); i++) {
44  }
45 
46  // Re-unpack the data so that it matches the packed data.
47  unpackData();
48 }
49 
50 // Convert packed data to unpacked data when reading back data
51 void BeamCurrentInfo::unpackData(const std::vector<uint16_t>& packed, std::vector<float>& unpacked) {
52  unpacked.resize(packed.size());
53 
54  for (unsigned int i = 0; i < packed.size(); i++) {
55  unpacked[i] = MiniFloatConverter::float16to32(packed[i]) * scaleFactor;
56  }
57 }
58 
62 }
63 
64 std::ostream& operator<<(std::ostream& s, const BeamCurrentInfo& beamInfo) {
65  s << std::endl << "Dumping BeamCurrentInfo..." << std::endl;
66  s << " beam1Intensities = ";
67  const std::vector<float>& b1int = beamInfo.getBeam1Intensities();
68  const std::vector<uint16_t>& b1intPacked = beamInfo.getBeam1IntensitiesPacked();
69  for (unsigned int i = 0; i < 10 && i < b1int.size(); ++i) {
70  s << b1int[i] << " ";
71  }
72  s << "..." << std::endl << " (packed: ";
73  for (unsigned int i = 0; i < 10 && i < b1intPacked.size(); ++i) {
74  s << b1intPacked[i] << " ";
75  }
76  s << "...)" << std::endl;
77  s << " beam2Intensities = ";
78  const std::vector<float>& b2int = beamInfo.getBeam2Intensities();
79  for (unsigned int i = 0; i < 10 && i < b2int.size(); ++i) {
80  s << b2int[i] << " ";
81  }
82  s << " ..." << std::endl;
83 
84  return s;
85 }
const std::vector< float > & getBeam1Intensities() const
static const float scaleFactor
std::vector< float > beam2IntensitiesUnpacked_
std::vector< float > beam1IntensitiesUnpacked_
void fillBeamIntensities(const std::vector< float > &beam1Intensities, const std::vector< float > &beam2Intensities)
static float float16to32(uint16_t h)
Definition: libminifloat.h:13
float getBeam2IntensityBX(int bx) const
static uint16_t float32to16(float x)
Definition: libminifloat.h:17
float getBeam1IntensityBX(int bx) const
void fill(const std::vector< float > &beam1Intensities, const std::vector< float > &beam2Intensities)
std::vector< uint16_t > beam1IntensitiesPacked_
const std::vector< uint16_t > & getBeam1IntensitiesPacked() const
const std::vector< float > & getBeam2Intensities() const
std::ostream & operator<<(std::ostream &s, const BeamCurrentInfo &beamInfo)
bool isProductEqual(BeamCurrentInfo const &next) const
std::vector< uint16_t > beam2IntensitiesPacked_