Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:58

0001 #include <cassert>
0002 #include <math.h>
0003 #include <iostream>
0004 using namespace std;
0005 
0006 #include "MEVarVector.hh"
0007 
0008 ClassImp(MEVarVector);
0009 
0010 MEVarVector::MEVarVector( int size ) : _size(  size )
0011 {
0012 }
0013 
0014 MEVarVector::~MEVarVector() 
0015 {
0016   for( MusEcal::VarVecTimeMap::iterator it=_map.begin(); it!=_map.end(); ++it )
0017     {
0018       delete it->second;
0019     }
0020 }
0021 
0022 void
0023 MEVarVector::addTime( ME::Time t )
0024 {
0025   if( _map.count( t ) !=0 ) return;
0026   MusEcal::VarVec* vec_ = 
0027     new MusEcal::VarVec( _size, make_pair<float,bool>( 0., true ) );
0028   _map[t] = vec_;
0029 }
0030 
0031 void
0032 MEVarVector::setVal( ME::Time t, int ii, float val, bool check )
0033 {
0034   if( check ) addTime( t );
0035   MusEcal::VarVec& vec_ = *(_map[t]);
0036   vec_[ii].first = val;
0037 }
0038 
0039 void
0040 MEVarVector::setFlag( ME::Time t, int ii, bool flag, bool check )
0041 {
0042   if( check ) addTime( t );
0043   MusEcal::VarVec& vec_ = *(_map[t]);
0044   vec_[ii].second = flag;
0045 }
0046 
0047 void
0048 MEVarVector::setValAndFlag( ME::Time t, int ii, float val, bool flag, bool check )
0049 {
0050   setVal( t, ii, val, check );
0051   setFlag( t, ii, flag, check );
0052 }
0053 
0054 void
0055 MEVarVector::getTime( vector< ME::Time >& time, 
0056               const METimeInterval* interval )
0057 {
0058   time.clear();
0059   for( MusEcal::VarVecTimeMap::iterator it=_map.begin(); 
0060        it!=_map.end(); ++it )
0061     {
0062       ME::Time t_ = it->first;
0063       if( interval!=0 )
0064     {
0065       if( t_<interval->firstTime() || t_>interval->lastTime() ) continue;
0066     }
0067       time.push_back( t_ );
0068     }
0069 }
0070 
0071 void
0072 MEVarVector::getValAndFlag( int ii, 
0073                 const vector< ME::Time >& time, 
0074                 vector< float >& val,
0075                 vector< bool >& flag )
0076 {
0077   val.clear();
0078   flag.clear();
0079   for( unsigned int itime=0; itime<time.size(); itime++ )
0080     {
0081       ME::Time t_ = time[itime];
0082       float val_(0.);
0083       bool flag_(true);
0084       assert( getValByTime( t_, ii, val_, flag_ ) );
0085       val.push_back( val_ );
0086       flag.push_back( flag_ );
0087     }
0088 }
0089 
0090 void
0091 MEVarVector::getTimeValAndFlag( int ii, 
0092                 vector< ME::Time >& time, 
0093                 vector< float >& val,
0094                 vector< bool >& flag,
0095                 const METimeInterval* interval )
0096 {
0097   getTime( time, interval );
0098   val.clear();
0099   flag.clear();
0100   getValAndFlag( ii, time, val, flag );
0101 }
0102 
0103 bool
0104 MEVarVector::getValByTime(  ME::Time time, int ii, 
0105                 float& val, bool& flag ) 
0106 {
0107   val=0;
0108   flag=false;
0109   if( _map.count( time )==0 ) return false;
0110   MusEcal::VarVec* vec_ = _map[time];
0111   val=(*vec_)[ii].first;
0112   flag=(*vec_)[ii].second;
0113   return true;
0114 }
0115