CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/CondFormats/DTObjects/src/DTRangeT0.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.11 $
00006  *  \author Paolo Ronchese INFN Padova
00007  *
00008  */
00009 
00010 //----------------------
00011 // This Class' Header --
00012 //----------------------
00013 #include "CondFormats/DTObjects/interface/DTRangeT0.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 DTRangeT0::DTRangeT0():
00035   dataVersion( " " ) {
00036   dataList.reserve( 1000 );
00037   dBuf = 0;
00038 }
00039 
00040 
00041 DTRangeT0::DTRangeT0( const std::string& version ):
00042   dataVersion( version ) {
00043   dataList.reserve( 1000 );
00044   dBuf = 0;
00045 }
00046 
00047 
00048 DTRangeT0Id::DTRangeT0Id() :
00049     wheelId( 0 ),
00050   stationId( 0 ),
00051    sectorId( 0 ),
00052        slId( 0 ) {
00053 }
00054 
00055 
00056 DTRangeT0Data::DTRangeT0Data() :
00057   t0min( 0 ),
00058   t0max( 0 ) {
00059 }
00060 
00061 
00062 //--------------
00063 // Destructor --
00064 //--------------
00065 DTRangeT0::~DTRangeT0() {
00066 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00067   delete dBuf;
00068 }
00069 
00070 
00071 DTRangeT0Id::~DTRangeT0Id() {
00072 }
00073 
00074 
00075 DTRangeT0Data::~DTRangeT0Data() {
00076 }
00077 
00078 
00079 //--------------
00080 // Operations --
00081 //--------------
00082 int DTRangeT0::get( int   wheelId,
00083                      int stationId,
00084                     int  sectorId,
00085                     int      slId,
00086                     int&    t0min,
00087                     int&    t0max ) const {
00088 
00089   t0min =
00090   t0max = 0;
00091 
00092 //  std::string mName = mapName();
00093 //  DTBufferTree<int,int>* dBuf =
00094 //  DTDataBuffer<int,int>::findBuffer( mName );
00095 //  if ( dBuf == 0 ) {
00096 //    cacheMap();
00097 //    dBuf =
00098 //    DTDataBuffer<int,int>::findBuffer( mName );
00099 //  }
00100   if ( dBuf == 0 ) cacheMap();
00101 
00102   std::vector<int> chanKey;
00103   chanKey.reserve(4);
00104   chanKey.push_back(   wheelId );
00105   chanKey.push_back( stationId );
00106   chanKey.push_back(  sectorId );
00107   chanKey.push_back(      slId );
00108   int ientry;
00109   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00110   if ( !searchStatus ) {
00111     const DTRangeT0Data& data( dataList[ientry].second );
00112     t0min = data.t0min;
00113     t0max = data.t0max;
00114   }
00115 
00116   return searchStatus;
00117 
00118 }
00119 
00120 
00121 int DTRangeT0::get( const DTSuperLayerId& id,
00122                     int&    t0min,
00123                     int&    t0max ) const {
00124   return get( id.wheel(),
00125               id.station(),
00126               id.sector(),
00127               id.superLayer(),
00128               t0min, t0max );
00129 }
00130 
00131 
00132 const
00133 std::string& DTRangeT0::version() const {
00134   return dataVersion;
00135 }
00136 
00137 
00138 std::string& DTRangeT0::version() {
00139   return dataVersion;
00140 }
00141 
00142 
00143 void DTRangeT0::clear() {
00144 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00145   delete dBuf;
00146   dBuf = 0;
00147   dataList.clear();
00148   return;
00149 }
00150 
00151 
00152 int DTRangeT0::set( int   wheelId,
00153                     int stationId,
00154                     int  sectorId,
00155                     int      slId,
00156                     int     t0min,
00157                     int     t0max ) {
00158 
00159 //  std::string mName = mapName();
00160 //  DTBufferTree<int,int>* dBuf =
00161 //  DTDataBuffer<int,int>::findBuffer( mName );
00162 //  if ( dBuf == 0 ) {
00163 //    cacheMap();
00164 //    dBuf =
00165 //    DTDataBuffer<int,int>::findBuffer( mName );
00166 //  }
00167   if ( dBuf == 0 ) cacheMap();
00168   std::vector<int> chanKey;
00169   chanKey.reserve(4);
00170   chanKey.push_back(   wheelId );
00171   chanKey.push_back( stationId );
00172   chanKey.push_back(  sectorId );
00173   chanKey.push_back(      slId );
00174   int ientry;
00175   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00176 
00177   if ( !searchStatus ) {
00178     DTRangeT0Data& data( dataList[ientry].second );
00179     data.t0min = t0min;
00180     data.t0max = t0max;
00181     return -1;
00182   }
00183   else {
00184     DTRangeT0Id key;
00185     key.  wheelId =   wheelId;
00186     key.stationId = stationId;
00187     key. sectorId =  sectorId;
00188     key.     slId =      slId;
00189     DTRangeT0Data data;
00190     data.t0min = t0min;
00191     data.t0max = t0max;
00192     ientry = dataList.size();
00193     dataList.push_back( std::pair<DTRangeT0Id,DTRangeT0Data>( key, data ) );
00194     dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
00195     return 0;
00196   }
00197 
00198   return 99;
00199 
00200 }
00201 
00202 
00203 int DTRangeT0::set( const DTSuperLayerId& id,
00204                     int t0min,
00205                     int t0max ) {
00206   return set( id.wheel(),
00207               id.station(),
00208               id.sector(),
00209               id.superLayer(),
00210               t0min, t0max );
00211 }
00212 
00213 
00214 DTRangeT0::const_iterator DTRangeT0::begin() const {
00215   return dataList.begin();
00216 }
00217 
00218 
00219 DTRangeT0::const_iterator DTRangeT0::end() const {
00220   return dataList.end();
00221 }
00222 
00223 
00224 std::string DTRangeT0::mapName() const {
00225   std::stringstream name;
00226   name << dataVersion << "_map_RangeT0" << this;
00227   return name.str();
00228 }
00229 
00230 
00231 void DTRangeT0::cacheMap() const {
00232 
00233 //  std::string mName = mapName();
00234 //  DTBufferTree<int,int>* dBuf =
00235 //  DTDataBuffer<int,int>::openBuffer( mName );
00236   DTBufferTree<int,int>** pBuf;
00237   pBuf = const_cast<DTBufferTree<int,int>**>( &dBuf );
00238   *pBuf = new DTBufferTree<int,int>;
00239 
00240   int entryNum = 0;
00241   int entryMax = dataList.size();
00242   std::vector<int> chanKey;
00243   chanKey.reserve(4);
00244   while ( entryNum < entryMax ) {
00245 
00246     const DTRangeT0Id& chan = dataList[entryNum].first;
00247 
00248     chanKey.clear();
00249     chanKey.push_back( chan.  wheelId );
00250     chanKey.push_back( chan.stationId );
00251     chanKey.push_back( chan. sectorId );
00252     chanKey.push_back( chan.     slId );
00253     dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
00254 
00255   }
00256 
00257   return;
00258 
00259 }
00260