Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:32

0001 #include "CondFormats/RunInfo/interface/FillInfo.h"
0002 #include "CondFormats/Common/interface/TimeConversions.h"
0003 #include <algorithm>
0004 #include <iterator>
0005 #include <stdexcept>
0006 
0007 //helper function: returns the positions of the bits in the bitset that are set (i.e., have a value of 1).
0008 static std::vector<unsigned short> bitsetToVector(std::bitset<FillInfo::bunchSlots + 1> const& bs) {
0009   std::vector<unsigned short> vec;
0010   //reserve space only for the bits in the bitset that are set
0011   vec.reserve(bs.count());
0012   for (size_t i = 0; i < bs.size(); ++i) {
0013     if (bs.test(i))
0014       vec.push_back((unsigned short)i);
0015   }
0016   return vec;
0017 }
0018 
0019 //helper function: returns the enum for fill types in string type
0020 static std::string fillTypeToString(FillInfo::FillTypeId const& fillType) {
0021   std::string s_fillType("UNKNOWN");
0022   switch (fillType) {
0023     case FillInfo::UNKNOWN:
0024       s_fillType = std::string("UNKNOWN");
0025       break;
0026     case FillInfo::PROTONS:
0027       s_fillType = std::string("PROTONS");
0028       break;
0029     case FillInfo::IONS:
0030       s_fillType = std::string("IONS");
0031       break;
0032     case FillInfo::COSMICS:
0033       s_fillType = std::string("COSMICS");
0034       break;
0035     case FillInfo::GAP:
0036       s_fillType = std::string("GAP");
0037       break;
0038     default:
0039       s_fillType = std::string("UNKNOWN");
0040   }
0041   return s_fillType;
0042 }
0043 
0044 //helper function: returns the enum for particle types in string type
0045 static std::string particleTypeToString(FillInfo::ParticleTypeId const& particleType) {
0046   std::string s_particleType("NONE");
0047   switch (particleType) {
0048     case FillInfo::NONE:
0049       s_particleType = std::string("NONE");
0050       break;
0051     case FillInfo::PROTON:
0052       s_particleType = std::string("PROTON");
0053       break;
0054     case FillInfo::PB82:
0055       s_particleType = std::string("PB82");
0056       break;
0057     case FillInfo::AR18:
0058       s_particleType = std::string("AR18");
0059       break;
0060     case FillInfo::D:
0061       s_particleType = std::string("D");
0062       break;
0063     case FillInfo::XE54:
0064       s_particleType = std::string("XE54");
0065       break;
0066     default:
0067       s_particleType = std::string("NONE");
0068   }
0069   return s_particleType;
0070 }
0071 
0072 FillInfo::FillInfo()
0073     : m_isData(false),
0074       m_lhcFill(0),
0075       m_bunches1(0),
0076       m_bunches2(0),
0077       m_collidingBunches(0),
0078       m_targetBunches(0),
0079       m_fillType(FillTypeId::UNKNOWN),
0080       m_particles1(ParticleTypeId::NONE),
0081       m_particles2(ParticleTypeId::NONE),
0082       m_crossingAngle(0.),
0083       m_betastar(0.),
0084       m_intensity1(0.),
0085       m_intensity2(0.),
0086       m_energy(0.),
0087       m_createTime(0),
0088       m_beginTime(0),
0089       m_endTime(0),
0090       m_injectionScheme("None") {}
0091 
0092 FillInfo::FillInfo(unsigned short const& lhcFill, bool const& fromData)
0093     : m_isData(fromData),
0094       m_lhcFill(lhcFill),
0095       m_bunches1(0),
0096       m_bunches2(0),
0097       m_collidingBunches(0),
0098       m_targetBunches(0),
0099       m_fillType(FillTypeId::UNKNOWN),
0100       m_particles1(ParticleTypeId::NONE),
0101       m_particles2(ParticleTypeId::NONE),
0102       m_crossingAngle(0.),
0103       m_betastar(0.),
0104       m_intensity1(0.),
0105       m_intensity2(0.),
0106       m_energy(0.),
0107       m_createTime(0),
0108       m_beginTime(0),
0109       m_endTime(0),
0110       m_injectionScheme("None") {}
0111 
0112 FillInfo::~FillInfo() {}
0113 
0114 //reset instance
0115 void FillInfo::setFill(unsigned short const& lhcFill, bool const& fromData) {
0116   m_isData = fromData;
0117   m_lhcFill = lhcFill;
0118   m_bunches1 = 0;
0119   m_bunches2 = 0;
0120   m_collidingBunches = 0;
0121   m_targetBunches = 0;
0122   m_fillType = FillTypeId::UNKNOWN;
0123   m_particles1 = ParticleTypeId::NONE;
0124   m_particles2 = ParticleTypeId::NONE;
0125   m_crossingAngle = 0.;
0126   m_betastar = 0.;
0127   m_intensity1 = 0;
0128   m_intensity2 = 0;
0129   m_energy = 0.;
0130   m_createTime = 0;
0131   m_beginTime = 0;
0132   m_endTime = 0;
0133   m_injectionScheme = "None";
0134   m_bunchConfiguration1.reset();
0135   m_bunchConfiguration2.reset();
0136 }
0137 
0138 //getters
0139 unsigned short const FillInfo::fillNumber() const { return m_lhcFill; }
0140 
0141 bool const FillInfo::isData() const { return m_isData; }
0142 
0143 unsigned short const FillInfo::bunchesInBeam1() const { return m_bunches1; }
0144 
0145 unsigned short const FillInfo::bunchesInBeam2() const { return m_bunches2; }
0146 
0147 unsigned short const FillInfo::collidingBunches() const { return m_collidingBunches; }
0148 
0149 unsigned short const FillInfo::targetBunches() const { return m_targetBunches; }
0150 
0151 FillInfo::FillTypeId const FillInfo::fillType() const { return m_fillType; }
0152 
0153 FillInfo::ParticleTypeId const FillInfo::particleTypeForBeam1() const { return m_particles1; }
0154 
0155 FillInfo::ParticleTypeId const FillInfo::particleTypeForBeam2() const { return m_particles2; }
0156 
0157 float const FillInfo::crossingAngle() const { return m_crossingAngle; }
0158 
0159 float const FillInfo::betaStar() const { return m_betastar; }
0160 
0161 float const FillInfo::intensityForBeam1() const { return m_intensity1; }
0162 
0163 float const FillInfo::intensityForBeam2() const { return m_intensity2; }
0164 
0165 float const FillInfo::energy() const { return m_energy; }
0166 
0167 cond::Time_t const FillInfo::createTime() const { return m_createTime; }
0168 
0169 cond::Time_t const FillInfo::beginTime() const { return m_beginTime; }
0170 
0171 cond::Time_t const FillInfo::endTime() const { return m_endTime; }
0172 
0173 std::string const& FillInfo::injectionScheme() const { return m_injectionScheme; }
0174 
0175 //returns a boolean, true if the injection scheme has a leading 25ns
0176 //TODO: parse the circulating bunch configuration, instead of the string.
0177 bool FillInfo::is25nsBunchSpacing() const {
0178   const std::string prefix("25ns");
0179   return std::equal(prefix.begin(), prefix.end(), m_injectionScheme.begin());
0180 }
0181 
0182 //returns a boolean, true if the bunch slot number is in the circulating bunch configuration
0183 bool FillInfo::isBunchInBeam1(size_t const& bunch) const {
0184   if (bunch == 0)
0185     throw std::out_of_range("0 not allowed");  //CMS starts counting bunch crossing from 1!
0186   return m_bunchConfiguration1.test(bunch);
0187 }
0188 
0189 bool FillInfo::isBunchInBeam2(size_t const& bunch) const {
0190   if (bunch == 0)
0191     throw std::out_of_range("0 not allowed");  //CMS starts counting bunch crossing from 1!
0192   return m_bunchConfiguration2.test(bunch);
0193 }
0194 
0195 //member functions returning *by value* a vector with all filled bunch slots
0196 std::vector<unsigned short> FillInfo::bunchConfigurationForBeam1() const {
0197   return bitsetToVector(m_bunchConfiguration1);
0198 }
0199 
0200 std::vector<unsigned short> FillInfo::bunchConfigurationForBeam2() const {
0201   return bitsetToVector(m_bunchConfiguration2);
0202 }
0203 
0204 //setters
0205 void FillInfo::setBunchesInBeam1(unsigned short const& bunches) { m_bunches1 = bunches; }
0206 
0207 void FillInfo::setBunchesInBeam2(unsigned short const& bunches) { m_bunches2 = bunches; }
0208 
0209 void FillInfo::setCollidingBunches(unsigned short const& collidingBunches) { m_collidingBunches = collidingBunches; }
0210 
0211 void FillInfo::setTargetBunches(unsigned short const& targetBunches) { m_targetBunches = targetBunches; }
0212 
0213 void FillInfo::setFillType(FillInfo::FillTypeId const& fillType) { m_fillType = fillType; }
0214 
0215 void FillInfo::setParticleTypeForBeam1(FillInfo::ParticleTypeId const& particleType) { m_particles1 = particleType; }
0216 
0217 void FillInfo::setParticleTypeForBeam2(FillInfo::ParticleTypeId const& particleType) { m_particles2 = particleType; }
0218 
0219 void FillInfo::setCrossingAngle(float const& angle) { m_crossingAngle = angle; }
0220 
0221 void FillInfo::setBetaStar(float const& betaStar) { m_betastar = betaStar; }
0222 
0223 void FillInfo::setIntensityForBeam1(float const& intensity) { m_intensity1 = intensity; }
0224 
0225 void FillInfo::setIntensityForBeam2(float const& intensity) { m_intensity2 = intensity; }
0226 
0227 void FillInfo::setEnergy(float const& energy) { m_energy = energy; }
0228 
0229 void FillInfo::setCreationTime(cond::Time_t const& createTime) { m_createTime = createTime; }
0230 
0231 void FillInfo::setBeginTime(cond::Time_t const& beginTime) { m_beginTime = beginTime; }
0232 
0233 void FillInfo::setEndTime(cond::Time_t const& endTime) { m_endTime = endTime; }
0234 
0235 void FillInfo::setInjectionScheme(std::string const& injectionScheme) { m_injectionScheme = injectionScheme; }
0236 
0237 //sets all values in one go
0238 void FillInfo::setBeamInfo(unsigned short const& bunches1,
0239                            unsigned short const& bunches2,
0240                            unsigned short const& collidingBunches,
0241                            unsigned short const& targetBunches,
0242                            FillTypeId const& fillType,
0243                            ParticleTypeId const& particleType1,
0244                            ParticleTypeId const& particleType2,
0245                            float const& angle,
0246                            float const& beta,
0247                            float const& intensity1,
0248                            float const& intensity2,
0249                            float const& energy,
0250                            cond::Time_t const& createTime,
0251                            cond::Time_t const& beginTime,
0252                            cond::Time_t const& endTime,
0253                            std::string const& scheme,
0254                            std::bitset<bunchSlots + 1> const& bunchConf1,
0255                            std::bitset<bunchSlots + 1> const& bunchConf2) {
0256   this->setBunchesInBeam1(bunches1);
0257   this->setBunchesInBeam2(bunches2);
0258   this->setCollidingBunches(collidingBunches);
0259   this->setTargetBunches(targetBunches);
0260   this->setFillType(fillType);
0261   this->setParticleTypeForBeam1(particleType1);
0262   this->setParticleTypeForBeam2(particleType2);
0263   this->setCrossingAngle(angle);
0264   this->setBetaStar(beta);
0265   this->setIntensityForBeam1(intensity1);
0266   this->setIntensityForBeam2(intensity2);
0267   this->setEnergy(energy);
0268   this->setCreationTime(createTime);
0269   this->setBeginTime(beginTime);
0270   this->setEndTime(endTime);
0271   this->setInjectionScheme(scheme);
0272   this->setBunchBitsetForBeam1(bunchConf1);
0273   this->setBunchBitsetForBeam2(bunchConf2);
0274 }
0275 
0276 void FillInfo::print(std::stringstream& ss) const {
0277   ss << "LHC fill: " << m_lhcFill << std::endl
0278      << "Bunches in Beam 1: " << m_bunches1 << std::endl
0279      << "Bunches in Beam 2: " << m_bunches2 << std::endl
0280      << "Colliding bunches at IP5: " << m_collidingBunches << std::endl
0281      << "Target bunches at IP5: " << m_targetBunches << std::endl
0282      << "Fill type: " << fillTypeToString(m_fillType) << std::endl
0283      << "Particle type for Beam 1: " << particleTypeToString(m_particles1) << std::endl
0284      << "Particle type for Beam 2: " << particleTypeToString(m_particles2) << std::endl
0285      << "Crossing angle (urad): " << m_crossingAngle << std::endl
0286      << "Beta star (cm): " << m_betastar << std::endl
0287      << "Average Intensity for Beam 1 (number of charges): " << m_intensity1 << std::endl
0288      << "Average Intensity for Beam 2 (number of charges): " << m_intensity2 << std::endl
0289      << "Energy (GeV): " << m_energy << std::endl
0290      << "Creation time of the fill: " << boost::posix_time::to_iso_extended_string(cond::time::to_boost(m_createTime))
0291      << std::endl
0292      << "Begin time of Stable Beam flag: "
0293      << boost::posix_time::to_iso_extended_string(cond::time::to_boost(m_beginTime)) << std::endl
0294      << "End time of the fill: " << boost::posix_time::to_iso_extended_string(cond::time::to_boost(m_endTime))
0295      << std::endl
0296      << "Injection scheme as given by LPC: " << m_injectionScheme << std::endl;
0297   std::vector<unsigned short> bunchVector1 = this->bunchConfigurationForBeam1();
0298   std::vector<unsigned short> bunchVector2 = this->bunchConfigurationForBeam2();
0299   ss << "Bunches filled for Beam 1 (total " << bunchVector1.size() << "): ";
0300   std::copy(bunchVector1.begin(), bunchVector1.end(), std::ostream_iterator<unsigned short>(ss, ", "));
0301   ss << std::endl;
0302   ss << "Bunches filled for Beam 2 (total " << bunchVector2.size() << "): ";
0303   std::copy(bunchVector2.begin(), bunchVector2.end(), std::ostream_iterator<unsigned short>(ss, ", "));
0304   ss << std::endl;
0305 }
0306 
0307 //protected getters
0308 std::bitset<FillInfo::bunchSlots + 1> const& FillInfo::bunchBitsetForBeam1() const { return m_bunchConfiguration1; }
0309 
0310 std::bitset<FillInfo::bunchSlots + 1> const& FillInfo::bunchBitsetForBeam2() const { return m_bunchConfiguration2; }
0311 
0312 //protected setters
0313 void FillInfo::setBunchBitsetForBeam1(std::bitset<FillInfo::bunchSlots + 1> const& bunchConfiguration) {
0314   m_bunchConfiguration1 = bunchConfiguration;
0315 }
0316 
0317 void FillInfo::setBunchBitsetForBeam2(std::bitset<FillInfo::bunchSlots + 1> const& bunchConfiguration) {
0318   m_bunchConfiguration2 = bunchConfiguration;
0319 }
0320 
0321 std::ostream& operator<<(std::ostream& os, FillInfo fillInfo) {
0322   std::stringstream ss;
0323   fillInfo.print(ss);
0324   os << ss.str();
0325   return os;
0326 }