CMS 3D CMS Logo

DTRangeT0.cc

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

Generated on Tue Jun 9 17:26:26 2009 for CMSSW by  doxygen 1.5.4