CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CondFormats/DTObjects/src/DTMtime.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/01/20 18:20:08 $
00005  *  $Revision: 1.16 $
00006  *  \author Paolo Ronchese INFN Padova
00007  *
00008  */
00009 
00010 //----------------------
00011 // This Class' Header --
00012 //----------------------
00013 #include "CondFormats/DTObjects/interface/DTMtime.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 DTMtime::DTMtime():
00035   dataVersion( " " ),
00036   nsPerCount( 25.0 / 32.0 ) {
00037   dataList.reserve( 1000 );
00038   dBuf = 0;
00039 }
00040 
00041 
00042 DTMtime::DTMtime( const std::string& version ):
00043   dataVersion( version ),
00044   nsPerCount( 25.0 / 32.0 ) {
00045   dataList.reserve( 1000 );
00046   dBuf = 0;
00047 }
00048 
00049 
00050 DTMtimeId::DTMtimeId() :
00051     wheelId( 0 ),
00052   stationId( 0 ),
00053    sectorId( 0 ),
00054        slId( 0 ),
00055     layerId( 0 ),
00056      cellId( 0 ) {
00057 }
00058 
00059 
00060 DTMtimeData::DTMtimeData() :
00061   mTime( 0.0 ),
00062   mTrms( 0.0 ) {
00063 }
00064 
00065 
00066 //--------------
00067 // Destructor --
00068 //--------------
00069 DTMtime::~DTMtime() {
00070 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00071   delete dBuf;
00072 }
00073 
00074 
00075 DTMtimeId::~DTMtimeId() {
00076 }
00077 
00078 
00079 DTMtimeData::~DTMtimeData() {
00080 }
00081 
00082 
00083 //--------------
00084 // Operations --
00085 //--------------
00086 int DTMtime::get( int   wheelId,
00087                   int stationId,
00088                   int  sectorId,
00089                   int      slId,
00090                   float&  mTime,
00091                   float&  mTrms,
00092                   DTTimeUnits::type unit ) const {
00093   return get( wheelId, stationId, sectorId,
00094                  slId,         0,        0,
00095                 mTime, mTrms, unit );
00096 
00097 }
00098 
00099 
00100 int DTMtime::get( int   wheelId,
00101                   int stationId,
00102                   int  sectorId,
00103                   int      slId,
00104                   float&  mTime,
00105                   float&  mTrms,
00106                   DTVelocityUnits::type unit ) const {
00107   return get( wheelId, stationId, sectorId,
00108                  slId,         0,        0,
00109                 mTime, mTrms, unit );
00110 
00111 }
00112 
00113 
00114 int DTMtime::get( int   wheelId,
00115                   int stationId,
00116                   int  sectorId,
00117                   int      slId,
00118                   int   layerId,
00119                   int    cellId,
00120                   float&  mTime,
00121                   float&  mTrms,
00122                   DTTimeUnits::type unit ) const {
00123 
00124   mTime =
00125   mTrms = 0.0;
00126 
00127 //  std::string mName = mapName();
00128 //  DTBufferTree<int,int>* dBuf =
00129 //  DTDataBuffer<int,int>::findBuffer( mName );
00130 //  if ( dBuf == 0 ) {
00131 //    cacheMap();
00132 //    dBuf =
00133 //    DTDataBuffer<int,int>::findBuffer( mName );
00134 //  }
00135   if ( dBuf == 0 ) cacheMap();
00136 
00137   std::vector<int> chanKey;
00138   chanKey.reserve(6);
00139   chanKey.push_back(   wheelId );
00140   chanKey.push_back( stationId );
00141   chanKey.push_back(  sectorId );
00142   chanKey.push_back(      slId );
00143   chanKey.push_back(   layerId );
00144   chanKey.push_back(    cellId );
00145   int ientry;
00146   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00147   if ( !searchStatus ) {
00148     const DTMtimeData& data( dataList[ientry].second );
00149     mTime = data.mTime;
00150     mTrms = data.mTrms;
00151     if ( unit == DTTimeUnits::ns ) {
00152       mTime *= nsPerCount;
00153       mTrms *= nsPerCount;
00154     }
00155   }
00156 
00157   return searchStatus;
00158 
00159 }
00160 
00161 
00162 int DTMtime::get( int   wheelId,
00163                   int stationId,
00164                   int  sectorId,
00165                   int      slId,
00166                   int   layerId,
00167                   int    cellId,
00168                   float&  mTime,
00169                   float&  mTrms,
00170                   DTVelocityUnits::type unit ) const {
00171   int status = get( wheelId, stationId, sectorId,
00172                        slId,   layerId,   cellId,
00173                       mTime, mTrms, DTTimeUnits::counts );
00174   if ( unit == DTVelocityUnits::cm_per_count ) {
00175     mTime  = 2.1 / mTime;
00176     mTrms *= mTime;
00177   }
00178   if ( unit == DTVelocityUnits::cm_per_ns ) {
00179     mTime  = 2.1 / mTime;
00180     mTrms *= mTime;
00181     mTime /= nsPerCount;
00182   }
00183   return status;
00184 }
00185 
00186 
00187 int DTMtime::get( const DTSuperLayerId& id,
00188                   float&  mTime,
00189                   float&  mTrms,
00190                   DTTimeUnits::type unit ) const {
00191   return get( id.wheel(),
00192               id.station(),
00193               id.sector(),
00194               id.superLayer(), 0, 0,
00195               mTime, mTrms, unit );
00196 }
00197 
00198 
00199 int DTMtime::get( const DTSuperLayerId& id,
00200                   float&  mTime,
00201                   float&  mTrms,
00202                   DTVelocityUnits::type unit ) const {
00203   return get( id.wheel(),
00204               id.station(),
00205               id.sector(),
00206               id.superLayer(), 0, 0,
00207               mTime, mTrms, unit );
00208 }
00209 
00210 
00211 int DTMtime::get( const DetId& id,
00212                   float&  mTime,
00213                   float&  mTrms,
00214                   DTTimeUnits::type unit ) const {
00215   DTWireId wireId( id.rawId() );
00216   return get( wireId.wheel(),
00217               wireId.station(),
00218               wireId.sector(),
00219               wireId.superLayer(),
00220               wireId.layer(),
00221               wireId.wire(),
00222               mTime, mTrms, unit );
00223 }
00224 
00225 
00226 int DTMtime::get( const DetId& id,
00227                   float&  mTime,
00228                   float&  mTrms,
00229                   DTVelocityUnits::type unit ) const {
00230   DTWireId wireId( id.rawId() );
00231   return get( wireId.wheel(),
00232               wireId.station(),
00233               wireId.sector(),
00234               wireId.superLayer(),
00235               wireId.layer(),
00236               wireId.wire(),
00237               mTime, mTrms, unit );
00238 }
00239 
00240 
00241 float DTMtime::unit() const {
00242   return nsPerCount;
00243 }
00244 
00245 
00246 const
00247 std::string& DTMtime::version() const {
00248   return dataVersion;
00249 }
00250 
00251 
00252 std::string& DTMtime::version() {
00253   return dataVersion;
00254 }
00255 
00256 
00257 void DTMtime::clear() {
00258 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00259   delete dBuf;
00260   dBuf = 0;
00261   dataList.clear();
00262   return;
00263 }
00264 
00265 
00266 int DTMtime::set( int   wheelId,
00267                   int stationId,
00268                   int  sectorId,
00269                   int      slId,
00270                   float   mTime,
00271                   float   mTrms,
00272                   DTTimeUnits::type unit ) {
00273   return set( wheelId, stationId, sectorId,
00274                  slId,         0,        0,
00275                 mTime, mTrms, unit );
00276 }
00277 
00278 
00279 int DTMtime::set( int   wheelId,
00280                   int stationId,
00281                   int  sectorId,
00282                   int      slId,
00283                   float   mTime,
00284                   float   mTrms,
00285                   DTVelocityUnits::type unit ) {
00286   return set( wheelId, stationId, sectorId,
00287                  slId,         0,        0,
00288                 mTime, mTrms, unit );
00289 }
00290 
00291 
00292 int DTMtime::set( int   wheelId,
00293                   int stationId,
00294                   int  sectorId,
00295                   int      slId,
00296                   int   layerId,
00297                   int    cellId,
00298                   float   mTime,
00299                   float   mTrms,
00300                   DTTimeUnits::type unit ) {
00301 
00302   if ( unit == DTTimeUnits::ns ) {
00303     mTime /= nsPerCount;
00304     mTrms /= nsPerCount;
00305   }
00306 
00307 //  std::string mName = mapName();
00308 //  DTBufferTree<int,int>* dBuf =
00309 //  DTDataBuffer<int,int>::findBuffer( mName );
00310 //  if ( dBuf == 0 ) {
00311 //    cacheMap();
00312 //    dBuf =
00313 //    DTDataBuffer<int,int>::findBuffer( mName );
00314 //  }
00315   if ( dBuf == 0 ) cacheMap();
00316   std::vector<int> chanKey;
00317   chanKey.reserve(6);
00318   chanKey.push_back(   wheelId );
00319   chanKey.push_back( stationId );
00320   chanKey.push_back(  sectorId );
00321   chanKey.push_back(      slId );
00322   chanKey.push_back(   layerId );
00323   chanKey.push_back(    cellId );
00324   int ientry;
00325   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00326 
00327   if ( !searchStatus ) {
00328     DTMtimeData& data( dataList[ientry].second );
00329     data.mTime = mTime;
00330     data.mTrms = mTrms;
00331     return -1;
00332   }
00333   else {
00334     DTMtimeId key;
00335     key.  wheelId =   wheelId;
00336     key.stationId = stationId;
00337     key. sectorId =  sectorId;
00338     key.     slId =      slId;
00339     key.  layerId =   layerId;
00340     key.   cellId =    cellId;
00341     DTMtimeData data;
00342     data.mTime = mTime;
00343     data.mTrms = mTrms;
00344     ientry = dataList.size();
00345     dataList.push_back( std::pair<DTMtimeId,DTMtimeData>( key, data ) );
00346     dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
00347     return 0;
00348   }
00349 
00350   return 99;
00351 
00352 }
00353 
00354 
00355 int DTMtime::set( int   wheelId,
00356                   int stationId,
00357                   int  sectorId,
00358                   int      slId,
00359                   int   layerId,
00360                   int    cellId,
00361                   float   mTime,
00362                   float   mTrms,
00363                   DTVelocityUnits::type unit ) {
00364   if ( unit == DTVelocityUnits::cm_per_count ) {
00365     mTrms /= mTime;
00366     mTime  = 2.1 / mTime;
00367   }
00368   if ( unit == DTVelocityUnits::cm_per_ns ) {
00369     mTime *= nsPerCount;
00370     mTrms /= mTime;
00371     mTime  = 2.1 / mTime;
00372   }
00373   return set( wheelId, stationId, sectorId,
00374                  slId,   layerId,   cellId,
00375                 mTime, mTrms, DTTimeUnits::counts );
00376 
00377 }
00378 
00379 
00380 int DTMtime::set( const DTSuperLayerId& id,
00381                   float   mTime,
00382                   float   mTrms,
00383                   DTTimeUnits::type unit ) {
00384   return set( id.wheel(),
00385               id.station(),
00386               id.sector(),
00387               id.superLayer(), 0, 0,
00388               mTime, mTrms, unit );
00389 }
00390 
00391 
00392 int DTMtime::set( const DTSuperLayerId& id,
00393                   float   mTime,
00394                   float   mTrms,
00395                   DTVelocityUnits::type unit ) {
00396   return set( id.wheel(),
00397               id.station(),
00398               id.sector(),
00399               id.superLayer(), 0, 0,
00400               mTime, mTrms, unit );
00401 }
00402 
00403 
00404 int DTMtime::set( const DetId& id,
00405                   float   mTime,
00406                   float   mTrms,
00407                   DTTimeUnits::type unit ) {
00408   DTWireId wireId( id.rawId() );
00409   return set( wireId.wheel(),
00410               wireId.station(),
00411               wireId.sector(),
00412               wireId.superLayer(),
00413               wireId.layer(),
00414               wireId.wire(),
00415               mTime, mTrms, unit );
00416 }
00417 
00418 
00419 int DTMtime::set( const DetId& id,
00420                   float   mTime,
00421                   float   mTrms,
00422                   DTVelocityUnits::type unit ) {
00423   DTWireId wireId( id.rawId() );
00424   return set( wireId.wheel(),
00425               wireId.station(),
00426               wireId.sector(),
00427               wireId.superLayer(),
00428               wireId.layer(),
00429               wireId.wire(),
00430               mTime, mTrms, unit );
00431 }
00432 
00433 
00434 void DTMtime::setUnit( float unit ) {
00435   nsPerCount = unit;
00436 }
00437 
00438 
00439 DTMtime::const_iterator DTMtime::begin() const {
00440   return dataList.begin();
00441 }
00442 
00443 
00444 DTMtime::const_iterator DTMtime::end() const {
00445   return dataList.end();
00446 }
00447 
00448 
00449 std::string DTMtime::mapName() const {
00450   std::stringstream name;
00451   name << dataVersion << "_map_Mtime" << this;
00452   return name.str();
00453 }
00454 
00455 
00456 void DTMtime::cacheMap() const {
00457 
00458 //  std::string mName = mapName();
00459 //  DTBufferTree<int,int>* dBuf =
00460 //  DTDataBuffer<int,int>::openBuffer( mName );
00461   DTBufferTree<int,int>** pBuf;
00462   pBuf = const_cast<DTBufferTree<int,int>**>( &dBuf );
00463   *pBuf = new DTBufferTree<int,int>;
00464 
00465   int entryNum = 0;
00466   int entryMax = dataList.size();
00467   std::vector<int> chanKey;
00468   chanKey.reserve(6);
00469   while ( entryNum < entryMax ) {
00470 
00471     const DTMtimeId& chan = dataList[entryNum].first;
00472 
00473     chanKey.clear();
00474     chanKey.push_back( chan.  wheelId );
00475     chanKey.push_back( chan.stationId );
00476     chanKey.push_back( chan. sectorId );
00477     chanKey.push_back( chan.     slId );
00478     chanKey.push_back( chan.  layerId );
00479     chanKey.push_back( chan.   cellId );
00480     dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
00481 
00482   }
00483 
00484   return;
00485 
00486 }
00487