00001 #include "CondFormats/RunInfo/interface/FillInfo.h"
00002 #include "CondFormats/Common/interface/TimeConversions.h"
00003 #include <algorithm>
00004 #include <iterator>
00005 #include <stdexcept>
00006
00007
00008 std::vector<unsigned short> bitsetToVector( std::bitset<FillInfo::bunchSlots+1> const & bs ) {
00009 std::vector<unsigned short> vec;
00010
00011 vec.reserve( bs.count() );
00012 for( size_t i = 0; i < bs.size(); ++i ) {
00013 if( bs.test( i ) )
00014 vec.push_back( (unsigned short)i );
00015 }
00016 return vec;
00017 }
00018
00019
00020 std::string fillTypeToString( FillInfo::FillTypeId const & fillType ) {
00021 std::string s_fillType( "UNKNOWN" );
00022 switch( fillType ) {
00023 case FillInfo::UNKNOWN :
00024 s_fillType = std::string( "UNKNOWN" );
00025 break;
00026 case FillInfo::PROTONS :
00027 s_fillType = std::string( "PROTONS" );
00028 break;
00029 case FillInfo::IONS :
00030 s_fillType = std::string( "IONS" );
00031 break;
00032 case FillInfo::COSMICS :
00033 s_fillType = std::string( "COSMICS" );
00034 break;
00035 case FillInfo::GAP :
00036 s_fillType = std::string( "GAP" );
00037 break;
00038 default :
00039 s_fillType = std::string( "UNKNOWN" );
00040 }
00041 return s_fillType;
00042 }
00043
00044
00045 std::string particleTypeToString( FillInfo::ParticleTypeId const & particleType ) {
00046 std::string s_particleType( "NONE" );
00047 switch( particleType ) {
00048 case FillInfo::NONE :
00049 s_particleType = std::string( "NONE" );
00050 break;
00051 case FillInfo::PROTON :
00052 s_particleType = std::string( "PROTON" );
00053 break;
00054 case FillInfo::PB82 :
00055 s_particleType = std::string( "PB82" );
00056 break;
00057 case FillInfo::AR18 :
00058 s_particleType = std::string( "AR18" );
00059 break;
00060 case FillInfo::D :
00061 s_particleType = std::string( "D" );
00062 break;
00063 case FillInfo::XE54 :
00064 s_particleType = std::string( "XE54" );
00065 break;
00066 default :
00067 s_particleType = std::string( "NONE" );
00068 }
00069 return s_particleType;
00070 }
00071
00072 FillInfo::FillInfo(): m_isData( false )
00073 , m_lhcFill( 0 )
00074 , m_bunches1( 0 )
00075 , m_bunches2( 0 )
00076 , m_collidingBunches( 0 )
00077 , m_targetBunches( 0 )
00078 , m_fillType( FillTypeId::UNKNOWN )
00079 , m_particles1( ParticleTypeId::NONE )
00080 , m_particles2( ParticleTypeId::NONE )
00081 , m_crossingAngle( 0. )
00082 , m_betastar( 0. )
00083 , m_intensity1( 0. )
00084 , m_intensity2( 0. )
00085 , m_energy( 0. )
00086 , m_createTime( 0 )
00087 , m_beginTime( 0 )
00088 , m_endTime( 0 )
00089 , m_injectionScheme( "None" )
00090 {}
00091
00092 FillInfo::FillInfo( unsigned short const & lhcFill, bool const & fromData ): m_isData( fromData )
00093 , m_lhcFill( lhcFill )
00094 , m_bunches1( 0 )
00095 , m_bunches2( 0 )
00096 , m_collidingBunches( 0 )
00097 , m_targetBunches( 0 )
00098 , m_fillType( FillTypeId::UNKNOWN )
00099 , m_particles1( ParticleTypeId::NONE )
00100 , m_particles2( ParticleTypeId::NONE )
00101 , m_crossingAngle( 0. )
00102 , m_betastar( 0. )
00103 , m_intensity1( 0. )
00104 , m_intensity2( 0. )
00105 , m_energy( 0. )
00106 , m_createTime( 0 )
00107 , m_beginTime( 0 )
00108 , m_endTime( 0 )
00109 , m_injectionScheme( "None" )
00110 {}
00111
00112 FillInfo::~FillInfo() {}
00113
00114
00115 void FillInfo::setFill( unsigned short const & lhcFill, bool const & fromData ) {
00116 m_isData = fromData;
00117 m_lhcFill = lhcFill;
00118 m_bunches1 = 0;
00119 m_bunches2 = 0;
00120 m_collidingBunches = 0;
00121 m_targetBunches = 0;
00122 m_fillType = FillTypeId::UNKNOWN;
00123 m_particles1 = ParticleTypeId::NONE;
00124 m_particles2 = ParticleTypeId::NONE;
00125 m_crossingAngle = 0.;
00126 m_betastar = 0.;
00127 m_intensity1 = 0;
00128 m_intensity2 = 0;
00129 m_energy = 0.;
00130 m_createTime = 0;
00131 m_beginTime = 0;
00132 m_endTime = 0;
00133 m_injectionScheme = "None";
00134 m_bunchConfiguration1.reset();
00135 m_bunchConfiguration2.reset();
00136 }
00137
00138
00139 unsigned short const & FillInfo::fillNumber() const {
00140 return m_lhcFill;
00141 }
00142
00143 bool const & FillInfo::isData() const {
00144 return m_isData;
00145 }
00146
00147 unsigned short const & FillInfo::bunchesInBeam1() const {
00148 return m_bunches1;
00149 }
00150
00151 unsigned short const & FillInfo::bunchesInBeam2() const {
00152 return m_bunches2;
00153 }
00154
00155 unsigned short const & FillInfo::collidingBunches() const {
00156 return m_collidingBunches;
00157 }
00158
00159 unsigned short const & FillInfo::targetBunches() const {
00160 return m_targetBunches;
00161 }
00162
00163 FillInfo::FillTypeId const & FillInfo::fillType() const {
00164 return m_fillType;
00165 }
00166
00167 FillInfo::ParticleTypeId const & FillInfo::particleTypeForBeam1() const {
00168 return m_particles1;
00169 }
00170
00171 FillInfo::ParticleTypeId const & FillInfo::particleTypeForBeam2() const {
00172 return m_particles2;
00173 }
00174
00175 float const & FillInfo::crossingAngle() const {
00176 return m_crossingAngle;
00177 }
00178
00179 float const & FillInfo::betaStar() const {
00180 return m_betastar;
00181 }
00182
00183 float const & FillInfo::intensityForBeam1() const {
00184 return m_intensity1;
00185 }
00186
00187 float const & FillInfo::intensityForBeam2() const {
00188 return m_intensity2;
00189 }
00190
00191 float const & FillInfo::energy() const {
00192 return m_energy;
00193 }
00194
00195 cond::Time_t const & FillInfo::createTime() const {
00196 return m_createTime;
00197 }
00198
00199 cond::Time_t const & FillInfo::beginTime() const {
00200 return m_beginTime;
00201 }
00202
00203 cond::Time_t const & FillInfo::endTime() const {
00204 return m_endTime;
00205 }
00206
00207 std::string const & FillInfo::injectionScheme() const {
00208 return m_injectionScheme;
00209 }
00210
00211 std::bitset<FillInfo::bunchSlots+1> const & FillInfo::bunchBitsetForBeam1() const {
00212 return m_bunchConfiguration1;
00213 }
00214
00215 std::bitset<FillInfo::bunchSlots+1> const & FillInfo::bunchBitsetForBeam2() const {
00216 return m_bunchConfiguration2;
00217 }
00218
00219
00220 bool FillInfo::isBunchInBeam1( size_t const & bunch ) const {
00221 if( bunch == 0 )
00222 throw std::out_of_range( "0 not allowed" );
00223 return m_bunchConfiguration1.test( bunch );
00224 }
00225
00226 bool FillInfo::isBunchInBeam2( size_t const & bunch ) const {
00227 if( bunch == 0 )
00228 throw std::out_of_range( "0 not allowed" );
00229 return m_bunchConfiguration2.test( bunch );
00230 }
00231
00232
00233 std::vector<unsigned short> FillInfo::bunchConfigurationForBeam1() const {
00234 return bitsetToVector( m_bunchConfiguration1 );
00235 }
00236
00237 std::vector<unsigned short> FillInfo::bunchConfigurationForBeam2() const {
00238 return bitsetToVector( m_bunchConfiguration2 );
00239 }
00240
00241
00242 unsigned short & FillInfo::bunchesInBeam1() {
00243 return m_bunches1;
00244 }
00245
00246 unsigned short & FillInfo::bunchesInBeam2() {
00247 return m_bunches2;
00248 }
00249
00250 unsigned short & FillInfo::collidingBunches() {
00251 return m_collidingBunches;
00252 }
00253
00254 unsigned short & FillInfo::targetBunches() {
00255 return m_targetBunches;
00256 }
00257
00258 FillInfo::FillTypeId & FillInfo::fillType() {
00259 return m_fillType;
00260 }
00261
00262 FillInfo::ParticleTypeId & FillInfo::particleTypeForBeam1() {
00263 return m_particles1;
00264 }
00265
00266 FillInfo::ParticleTypeId & FillInfo::particleTypeForBeam2() {
00267 return m_particles2;
00268 }
00269
00270 float & FillInfo::crossingAngle() {
00271 return m_crossingAngle;
00272 }
00273
00274 float & FillInfo::betaStar() {
00275 return m_betastar;
00276 }
00277
00278 float & FillInfo::intensityForBeam1() {
00279 return m_intensity1;
00280 }
00281
00282 float & FillInfo::intensityForBeam2() {
00283 return m_intensity2;
00284 }
00285
00286 float & FillInfo::energy() {
00287 return m_energy;
00288 }
00289
00290 cond::Time_t & FillInfo::createTime() {
00291 return m_createTime;
00292 }
00293
00294 cond::Time_t & FillInfo::beginTime() {
00295 return m_beginTime;
00296 }
00297
00298 cond::Time_t & FillInfo::endTime() {
00299 return m_endTime;
00300 }
00301
00302 std::string & FillInfo::injectionScheme() {
00303 return m_injectionScheme;
00304 }
00305
00306 std::bitset<FillInfo::bunchSlots+1> & FillInfo::bunchBitsetForBeam1() {
00307 return m_bunchConfiguration1;
00308 }
00309
00310 std::bitset<FillInfo::bunchSlots+1> & FillInfo::bunchBitsetForBeam2() {
00311 return m_bunchConfiguration2;
00312 }
00313
00314
00315 void FillInfo::setBeamInfo( unsigned short const & bunches1
00316 ,unsigned short const & bunches2
00317 ,unsigned short const & collidingBunches
00318 ,unsigned short const & targetBunches
00319 ,FillTypeId const & fillType
00320 ,ParticleTypeId const & particleType1
00321 ,ParticleTypeId const & particleType2
00322 ,float const & angle
00323 ,float const & beta
00324 ,float const & intensity1
00325 ,float const & intensity2
00326 ,float const & energy
00327 ,cond::Time_t const & createTime
00328 ,cond::Time_t const & beginTime
00329 ,cond::Time_t const & endTime
00330 ,std::string const & scheme
00331 ,std::bitset<bunchSlots+1> const & bunchConf1
00332 ,std::bitset<bunchSlots+1> const & bunchConf2 ) {
00333 this->bunchesInBeam1() = bunches1;
00334 this->bunchesInBeam2() = bunches2;
00335 this->collidingBunches() = collidingBunches;
00336 this->targetBunches() = targetBunches;
00337 this->fillType() = fillType;
00338 this->particleTypeForBeam1() = particleType1;
00339 this->particleTypeForBeam2() = particleType2;
00340 this->crossingAngle() = angle;
00341 this->betaStar() = beta;
00342 this->intensityForBeam1() = intensity1;
00343 this->intensityForBeam2() = intensity2;
00344 this->energy() = energy;
00345 this->createTime() = createTime;
00346 this->beginTime() = beginTime;
00347 this->endTime() = endTime;
00348 this->injectionScheme() = scheme;
00349 this->bunchBitsetForBeam1() = bunchConf1;
00350 this->bunchBitsetForBeam2() = bunchConf2;
00351 }
00352
00353 void FillInfo::print( std::stringstream & ss ) const {
00354 ss << "LHC fill: " << m_lhcFill << std::endl
00355 << "Bunches in Beam 1: " << m_bunches1 << std::endl
00356 << "Bunches in Beam 2: " << m_bunches2 << std::endl
00357 << "Colliding bunches at IP5: " << m_collidingBunches << std::endl
00358 << "Target bunches at IP5: " << m_targetBunches << std::endl
00359 << "Fill type: " << fillTypeToString( m_fillType ) << std::endl
00360 << "Particle type for Beam 1: " << particleTypeToString( m_particles1 ) << std::endl
00361 << "Particle type for Beam 2: " << particleTypeToString( m_particles2 ) << std::endl
00362 << "Crossing angle (urad): " << m_crossingAngle << std::endl
00363 << "Beta star (cm): " << m_betastar << std::endl
00364 << "Average Intensity for Beam 1 (number of charges): " << m_intensity1 << std::endl
00365 << "Average Intensity for Beam 2 (number of charges): " << m_intensity2 << std::endl
00366 << "Energy (GeV): " << m_energy << std::endl
00367 << "Creation time of the fill: " << boost::posix_time::to_iso_extended_string( cond::time::to_boost( m_createTime ) ) << std::endl
00368 << "Begin time of Stable Beam flag: " << boost::posix_time::to_iso_extended_string( cond::time::to_boost( m_beginTime ) ) << std::endl
00369 << "End time of the fill: " << boost::posix_time::to_iso_extended_string( cond::time::to_boost( m_endTime ) ) << std::endl
00370 << "Injection scheme as given by LPC: " << m_injectionScheme << std::endl;
00371 std::vector<unsigned short> bunchVector1 = this->bunchConfigurationForBeam1();
00372 std::vector<unsigned short> bunchVector2 = this->bunchConfigurationForBeam2();
00373 ss << "Bunches filled for Beam 1 (total " << bunchVector1.size() << "): ";
00374 std::copy( bunchVector1.begin(), bunchVector1.end(), std::ostream_iterator<unsigned short>( ss, ", " ) );
00375 ss << std::endl;
00376 ss << "Bunches filled for Beam 2 (total " << bunchVector2.size() << "): ";
00377 std::copy( bunchVector2.begin(), bunchVector2.end(), std::ostream_iterator<unsigned short>( ss, ", " ) );
00378 ss << std::endl;
00379 }
00380
00381 std::ostream & operator<<( std::ostream & os, FillInfo fillInfo ) {
00382 std::stringstream ss;
00383 fillInfo.print( ss );
00384 os << ss.str();
00385 return os;
00386 }