CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CondFormats/DTObjects/src/DTTPGParameters.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2011/01/21 17:24:34 $
00005  *  $Revision: 1.4 $
00006  *  \author Paolo Ronchese INFN Padova
00007  *
00008  */
00009 
00010 //----------------------
00011 // This Class' Header --
00012 //----------------------
00013 #include "CondFormats/DTObjects/interface/DTTPGParameters.h"
00014 
00015 //-------------------------------
00016 // Collaborating Class Headers --
00017 //-------------------------------
00018 //#include "CondFormats/DTObjects/interface/DTDataBuffer.h"
00019 
00020 //---------------
00021 // C++ Headers --
00022 //---------------
00023 #include <iostream>
00024 #include <sstream>
00025 
00026 //-------------------
00027 // Initializations --
00028 //-------------------
00029 
00030 
00031 //----------------
00032 // Constructors --
00033 //----------------
00034 DTTPGParameters::DTTPGParameters():
00035   dataVersion( " " ),
00036   nsPerCount( 25.0 / 32.0 ),
00037   clockLength( 32 ) {
00038   dataList.reserve( 250 );
00039   dBuf = 0;
00040 }
00041 
00042 
00043 DTTPGParameters::DTTPGParameters( const std::string& version ):
00044   dataVersion( version ),
00045   nsPerCount( 25.0 / 32.0 ),
00046   clockLength( 32 ) {
00047   dataList.reserve( 250 );
00048   dBuf = 0;
00049 }
00050 
00051 
00052 DTTPGParametersId::DTTPGParametersId() :
00053     wheelId( 0 ),
00054   stationId( 0 ),
00055    sectorId( 0 ) {
00056 }
00057 
00058 
00059 DTTPGParametersData::DTTPGParametersData() :
00060   nClock( 0 ),
00061   tPhase( 0.0 ) {
00062 }
00063 
00064 
00065 //--------------
00066 // Destructor --
00067 //--------------
00068 DTTPGParameters::~DTTPGParameters() {
00069 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00070   delete dBuf;
00071 }
00072 
00073 
00074 DTTPGParametersId::~DTTPGParametersId() {
00075 }
00076 
00077 
00078 DTTPGParametersData::~DTTPGParametersData() {
00079 }
00080 
00081 
00082 //--------------
00083 // Operations --
00084 //--------------
00085 int DTTPGParameters::get( int   wheelId,
00086                           int stationId,
00087                           int  sectorId,
00088                           int&    nc,
00089                           float&  ph,
00090                           DTTimeUnits::type unit ) const {
00091 
00092   nc = 0;
00093   ph = 0.0;
00094 
00095 //  std::string mName = mapName();
00096 //  DTBufferTree<int,int>* dBuf =
00097 //  DTDataBuffer<int,int>::findBuffer( mName );
00098 //  if ( dBuf == 0 ) {
00099 //    cacheMap();
00100 //    dBuf =
00101 //    DTDataBuffer<int,int>::findBuffer( mName );
00102 //  }
00103   if ( dBuf == 0 ) cacheMap();
00104 
00105   std::vector<int> chanKey;
00106   chanKey.reserve(3);
00107   chanKey.push_back(   wheelId );
00108   chanKey.push_back( stationId );
00109   chanKey.push_back(  sectorId );
00110   int ientry;
00111   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00112   if ( !searchStatus ) {
00113     const DTTPGParametersData& data( dataList[ientry].second );
00114     nc = data.nClock;
00115     ph = data.tPhase;
00116     if ( unit == DTTimeUnits::ns ) {
00117       ph *= nsPerCount;
00118     }
00119   }
00120 
00121   return searchStatus;
00122 
00123 }
00124 
00125 
00126 int DTTPGParameters::get( const DTChamberId& id,
00127                           int&    nc,
00128                           float&  ph,
00129                           DTTimeUnits::type unit ) const {
00130   return get( id.wheel(),
00131               id.station(),
00132               id.sector(),
00133               nc, ph, unit );
00134 }
00135 
00136 
00137 float DTTPGParameters::totalTime( int   wheelId,
00138                                   int stationId,
00139                                   int  sectorId,
00140                                   DTTimeUnits::type unit ) const {
00141   int cl = 0;
00142   float ph = 0.0;
00143   get( wheelId, stationId, sectorId, cl, ph, unit );
00144   if ( unit == DTTimeUnits::ns ) return ( cl * clock() * nsPerCount ) + ph;
00145   else                           return ( cl * clock()              ) + ph;
00146 }
00147 
00148 
00149 float DTTPGParameters::totalTime( const DTChamberId& id,
00150                                   DTTimeUnits::type unit ) const {
00151   return totalTime( id.wheel(),
00152                     id.station(),
00153                     id.sector(),
00154                     unit );
00155 }
00156 
00157 
00158 int DTTPGParameters::clock() const {
00159   return clockLength;
00160 }
00161 
00162 
00163 float DTTPGParameters::unit() const {
00164   return nsPerCount;
00165 }
00166 
00167 
00168 const
00169 std::string& DTTPGParameters::version() const {
00170   return dataVersion;
00171 }
00172 
00173 
00174 std::string& DTTPGParameters::version() {
00175   return dataVersion;
00176 }
00177 
00178 
00179 void DTTPGParameters::clear() {
00180 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00181   delete dBuf;
00182   dBuf = 0;
00183   dataList.clear();
00184   return;
00185 }
00186 
00187 
00188 int DTTPGParameters::set( int   wheelId,
00189                           int stationId,
00190                           int  sectorId,
00191                           int    nc,
00192                           float  ph,
00193                           DTTimeUnits::type unit ) {
00194 
00195   if ( unit == DTTimeUnits::ns ) {
00196     ph /= nsPerCount;
00197   }
00198 
00199 //  std::string mName = mapName();
00200 //  DTBufferTree<int,int>* dBuf =
00201 //  DTDataBuffer<int,int>::findBuffer( mName );
00202 //  if ( dBuf == 0 ) {
00203 //    cacheMap();
00204 //    dBuf =
00205 //    DTDataBuffer<int,int>::findBuffer( mName );
00206 //  }
00207   if ( dBuf == 0 ) cacheMap();
00208   std::vector<int> chanKey;
00209   chanKey.reserve(3);
00210   chanKey.push_back(   wheelId );
00211   chanKey.push_back( stationId );
00212   chanKey.push_back(  sectorId );
00213   int ientry;
00214   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00215 
00216   if ( !searchStatus ) {
00217     DTTPGParametersData& data( dataList[ientry].second );
00218     data.nClock = nc;
00219     data.tPhase = ph;
00220     return -1;
00221   }
00222   else {
00223     DTTPGParametersId key;
00224     key.  wheelId =   wheelId;
00225     key.stationId = stationId;
00226     key. sectorId =  sectorId;
00227     DTTPGParametersData data;
00228     data.nClock = nc;
00229     data.tPhase = ph;
00230     ientry = dataList.size();
00231     dataList.push_back( std::pair<DTTPGParametersId,
00232                                   DTTPGParametersData>( key, data ) );
00233     dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
00234     return 0;
00235   }
00236 
00237   return 99;
00238 
00239 }
00240 
00241 
00242 int DTTPGParameters::set( const DTChamberId& id,
00243                           int    nc,
00244                           float  ph,
00245                           DTTimeUnits::type unit ) {
00246   return set( id.wheel(),
00247               id.station(),
00248               id.sector(),
00249               nc, ph, unit );
00250 }
00251 
00252 
00253 void DTTPGParameters::setClock( int clock ) {
00254   clockLength = clock;
00255 }
00256 
00257 
00258 void DTTPGParameters::setUnit( float unit ) {
00259   nsPerCount = unit;
00260 }
00261 
00262 
00263 DTTPGParameters::const_iterator DTTPGParameters::begin() const {
00264   return dataList.begin();
00265 }
00266 
00267 
00268 DTTPGParameters::const_iterator DTTPGParameters::end() const {
00269   return dataList.end();
00270 }
00271 
00272 
00273 std::string DTTPGParameters::mapName() const {
00274   std::stringstream name;
00275   name << dataVersion << "_map_TTPG" << this;
00276   return name.str();
00277 }
00278 
00279 
00280 void DTTPGParameters::cacheMap() const {
00281 
00282 //  std::string mName = mapName();
00283 //  DTBufferTree<int,int>* dBuf =
00284 //  DTDataBuffer<int,int>::openBuffer( mName );
00285   DTBufferTree<int,int>** pBuf;
00286   pBuf = const_cast<DTBufferTree<int,int>**>( &dBuf );
00287   *pBuf = new DTBufferTree<int,int>;
00288 
00289   int entryNum = 0;
00290   int entryMax = dataList.size();
00291   std::vector<int> chanKey;
00292   chanKey.reserve(3);
00293   while ( entryNum < entryMax ) {
00294 
00295     const DTTPGParametersId& chan = dataList[entryNum].first;
00296 
00297     chanKey.clear();
00298     chanKey.push_back( chan.  wheelId );
00299     chanKey.push_back( chan.stationId );
00300     chanKey.push_back( chan. sectorId );
00301     dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
00302 
00303   }
00304 
00305   return;
00306 
00307 }
00308