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 static 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 static 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 static 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
00212 bool FillInfo::isBunchInBeam1( size_t const & bunch ) const {
00213 if( bunch == 0 )
00214 throw std::out_of_range( "0 not allowed" );
00215 return m_bunchConfiguration1.test( bunch );
00216 }
00217
00218 bool FillInfo::isBunchInBeam2( size_t const & bunch ) const {
00219 if( bunch == 0 )
00220 throw std::out_of_range( "0 not allowed" );
00221 return m_bunchConfiguration2.test( bunch );
00222 }
00223
00224
00225 std::vector<unsigned short> FillInfo::bunchConfigurationForBeam1() const {
00226 return bitsetToVector( m_bunchConfiguration1 );
00227 }
00228
00229 std::vector<unsigned short> FillInfo::bunchConfigurationForBeam2() const {
00230 return bitsetToVector( m_bunchConfiguration2 );
00231 }
00232
00233
00234 void FillInfo::setBunchesInBeam1( unsigned short const & bunches ) {
00235 m_bunches1 = bunches;
00236 }
00237
00238 void FillInfo::setBunchesInBeam2( unsigned short const & bunches ) {
00239 m_bunches2 = bunches;
00240 }
00241
00242 void FillInfo::setCollidingBunches( unsigned short const & collidingBunches ) {
00243 m_collidingBunches = collidingBunches;
00244 }
00245
00246 void FillInfo::setTargetBunches( unsigned short const & targetBunches ) {
00247 m_targetBunches = targetBunches;
00248 }
00249
00250 void FillInfo::setFillType( FillInfo::FillTypeId const & fillType ) {
00251 m_fillType = fillType;
00252 }
00253
00254 void FillInfo::setParticleTypeForBeam1( FillInfo::ParticleTypeId const & particleType ) {
00255 m_particles1 = particleType;
00256 }
00257
00258 void FillInfo::setParticleTypeForBeam2( FillInfo::ParticleTypeId const & particleType ) {
00259 m_particles2 = particleType;
00260 }
00261
00262 void FillInfo::setCrossingAngle( float const & angle ) {
00263 m_crossingAngle = angle;
00264 }
00265
00266 void FillInfo::setBetaStar( float const & betaStar ) {
00267 m_betastar = betaStar;
00268 }
00269
00270 void FillInfo::setIntensityForBeam1( float const & intensity ) {
00271 m_intensity1 = intensity;
00272 }
00273
00274 void FillInfo::setIntensityForBeam2( float const & intensity ) {
00275 m_intensity2 = intensity;
00276 }
00277
00278 void FillInfo::setEnergy( float const & energy ) {
00279 m_energy = energy;
00280 }
00281
00282 void FillInfo::setCreationTime( cond::Time_t const & createTime ) {
00283 m_createTime = createTime;
00284 }
00285
00286 void FillInfo::setBeginTime( cond::Time_t const & beginTime ) {
00287 m_beginTime = beginTime;
00288 }
00289
00290 void FillInfo::setEndTime( cond::Time_t const & endTime ) {
00291 m_endTime = endTime;
00292 }
00293
00294 void FillInfo::setInjectionScheme( std::string const & injectionScheme ) {
00295 m_injectionScheme = injectionScheme;
00296 }
00297
00298
00299 void FillInfo::setBeamInfo( unsigned short const & bunches1
00300 ,unsigned short const & bunches2
00301 ,unsigned short const & collidingBunches
00302 ,unsigned short const & targetBunches
00303 ,FillTypeId const & fillType
00304 ,ParticleTypeId const & particleType1
00305 ,ParticleTypeId const & particleType2
00306 ,float const & angle
00307 ,float const & beta
00308 ,float const & intensity1
00309 ,float const & intensity2
00310 ,float const & energy
00311 ,cond::Time_t const & createTime
00312 ,cond::Time_t const & beginTime
00313 ,cond::Time_t const & endTime
00314 ,std::string const & scheme
00315 ,std::bitset<bunchSlots+1> const & bunchConf1
00316 ,std::bitset<bunchSlots+1> const & bunchConf2 ) {
00317 this->setBunchesInBeam1( bunches1 );
00318 this->setBunchesInBeam2( bunches2 );
00319 this->setCollidingBunches( collidingBunches );
00320 this->setTargetBunches( targetBunches );
00321 this->setFillType( fillType );
00322 this->setParticleTypeForBeam1( particleType1 );
00323 this->setParticleTypeForBeam2( particleType2 );
00324 this->setCrossingAngle( angle );
00325 this->setBetaStar( beta );
00326 this->setIntensityForBeam1( intensity1 );
00327 this->setIntensityForBeam2( intensity2 );
00328 this->setEnergy( energy );
00329 this->setCreationTime( createTime );
00330 this->setBeginTime( beginTime );
00331 this->setEndTime( endTime );
00332 this->setInjectionScheme( scheme );
00333 this->setBunchBitsetForBeam1( bunchConf1 );
00334 this->setBunchBitsetForBeam2( bunchConf2 );
00335 }
00336
00337 void FillInfo::print( std::stringstream & ss ) const {
00338 ss << "LHC fill: " << m_lhcFill << std::endl
00339 << "Bunches in Beam 1: " << m_bunches1 << std::endl
00340 << "Bunches in Beam 2: " << m_bunches2 << std::endl
00341 << "Colliding bunches at IP5: " << m_collidingBunches << std::endl
00342 << "Target bunches at IP5: " << m_targetBunches << std::endl
00343 << "Fill type: " << fillTypeToString( m_fillType ) << std::endl
00344 << "Particle type for Beam 1: " << particleTypeToString( m_particles1 ) << std::endl
00345 << "Particle type for Beam 2: " << particleTypeToString( m_particles2 ) << std::endl
00346 << "Crossing angle (urad): " << m_crossingAngle << std::endl
00347 << "Beta star (cm): " << m_betastar << std::endl
00348 << "Average Intensity for Beam 1 (number of charges): " << m_intensity1 << std::endl
00349 << "Average Intensity for Beam 2 (number of charges): " << m_intensity2 << std::endl
00350 << "Energy (GeV): " << m_energy << std::endl
00351 << "Creation time of the fill: " << boost::posix_time::to_iso_extended_string( cond::time::to_boost( m_createTime ) ) << std::endl
00352 << "Begin time of Stable Beam flag: " << boost::posix_time::to_iso_extended_string( cond::time::to_boost( m_beginTime ) ) << std::endl
00353 << "End time of the fill: " << boost::posix_time::to_iso_extended_string( cond::time::to_boost( m_endTime ) ) << std::endl
00354 << "Injection scheme as given by LPC: " << m_injectionScheme << std::endl;
00355 std::vector<unsigned short> bunchVector1 = this->bunchConfigurationForBeam1();
00356 std::vector<unsigned short> bunchVector2 = this->bunchConfigurationForBeam2();
00357 ss << "Bunches filled for Beam 1 (total " << bunchVector1.size() << "): ";
00358 std::copy( bunchVector1.begin(), bunchVector1.end(), std::ostream_iterator<unsigned short>( ss, ", " ) );
00359 ss << std::endl;
00360 ss << "Bunches filled for Beam 2 (total " << bunchVector2.size() << "): ";
00361 std::copy( bunchVector2.begin(), bunchVector2.end(), std::ostream_iterator<unsigned short>( ss, ", " ) );
00362 ss << std::endl;
00363 }
00364
00365
00366 std::bitset<FillInfo::bunchSlots+1> const & FillInfo::bunchBitsetForBeam1() const {
00367 return m_bunchConfiguration1;
00368 }
00369
00370 std::bitset<FillInfo::bunchSlots+1> const & FillInfo::bunchBitsetForBeam2() const {
00371 return m_bunchConfiguration2;
00372 }
00373
00374
00375 void FillInfo::setBunchBitsetForBeam1( std::bitset<FillInfo::bunchSlots+1> const & bunchConfiguration ) {
00376 m_bunchConfiguration1 = bunchConfiguration;
00377 }
00378
00379 void FillInfo::setBunchBitsetForBeam2( std::bitset<FillInfo::bunchSlots+1> const & bunchConfiguration ) {
00380 m_bunchConfiguration2 = bunchConfiguration;
00381 }
00382
00383 std::ostream & operator<<( std::ostream & os, FillInfo fillInfo ) {
00384 std::stringstream ss;
00385 fillInfo.print( ss );
00386 os << ss.str();
00387 return os;
00388 }