00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "CondFormats/DTObjects/interface/DTCCBConfig.h"
00014
00015
00016
00017
00018 #include "CondFormats/DTObjects/interface/DTDataBuffer.h"
00019
00020
00021
00022
00023 #include <iostream>
00024 #include <sstream>
00025 #include <vector>
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 DTCCBConfig::DTCCBConfig():
00036 dataVersion( " " ) {
00037 dataList.reserve( 1000 );
00038 }
00039
00040
00041 DTCCBConfig::DTCCBConfig( const std::string& version ):
00042 dataVersion( version ) {
00043 dataList.reserve( 1000 );
00044 }
00045
00046
00047 DTCCBId::DTCCBId() :
00048 wheelId( 0 ),
00049 stationId( 0 ),
00050 sectorId( 0 ) {
00051 }
00052
00053
00054
00055
00056
00057 DTCCBConfig::~DTCCBConfig() {
00058 resetMap();
00059 DTDataBuffer< int,std::vector<int>* >::dropBuffer( mapName() );
00060 }
00061
00062
00063 DTCCBId::~DTCCBId() {
00064 }
00065
00066
00067
00068
00069
00070 int DTCCBConfig::fullKey() const {
00071 return fullConfigKey;
00072 }
00073
00074
00075 int DTCCBConfig::stamp() const {
00076 return timeStamp;
00077 }
00078
00079
00080 int DTCCBConfig::configKey( int wheelId,
00081 int stationId,
00082 int sectorId,
00083 std::vector<int>& confKey ) const {
00084
00085 std::string mName = mapName();
00086 DTBufferTree< int,std::vector<int>* >* dBuf =
00087 DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00088 if ( dBuf == 0 ) {
00089 cacheMap();
00090 dBuf =
00091 DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00092 }
00093
00094 std::vector<int> chanKey;
00095 chanKey.reserve(3);
00096 chanKey.push_back( wheelId );
00097 chanKey.push_back( stationId );
00098 chanKey.push_back( sectorId );
00099 std::vector<int>* confPtr;
00100 int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), confPtr );
00101 if ( !searchStatus ) confKey = *confPtr;
00102
00103 return searchStatus;
00104
00105 }
00106
00107
00108 int DTCCBConfig::configKey( const DTChamberId& id,
00109 std::vector<int>& confKey ) const {
00110 return configKey( id.wheel(),
00111 id.station(),
00112 id.sector(),
00113 confKey );
00114 }
00115
00116
00117 DTCCBConfig::ccb_config_map
00118 DTCCBConfig::configKeyMap() const {
00119
00120 ccb_config_map keyList;
00121 std::vector< std::pair< DTCCBId,int>* > tempList;
00122 const_iterator d_iter = begin();
00123 const_iterator d_iend = end();
00124 while ( d_iter != d_iend ) tempList.push_back(
00125 new std::pair<DTCCBId,int>( *d_iter++ ) );
00126 std::vector< std::pair<DTCCBId,int>* >::iterator t_iter = tempList.begin();
00127 std::vector< std::pair<DTCCBId,int>* >::iterator t_iend = tempList.end();
00128 while ( t_iter != t_iend ) {
00129 std::pair<DTCCBId,int>* ptr = *t_iter++;
00130 if ( ptr != 0 ) {
00131 DTCCBId& ccbId = ptr->first;
00132 std::vector<int> cfgKeys;
00133 cfgKeys.push_back( ptr->second );
00134 std::vector< std::pair<DTCCBId,int>* >::iterator n_iter( t_iter );
00135 while( n_iter != t_iend ) {
00136 std::pair<DTCCBId,int>* pck = *n_iter;
00137 DTCCBId& chkId = pck->first;
00138 if ( ( chkId. wheelId == ccbId. wheelId ) &&
00139 ( chkId.stationId == ccbId.stationId ) &&
00140 ( chkId. sectorId == ccbId. sectorId ) ) {
00141 cfgKeys.push_back( pck->second );
00142 delete *n_iter;
00143 *n_iter = 0;
00144 }
00145 ++n_iter;
00146 }
00147 keyList.push_back( std::pair< DTCCBId,std::vector<int> >( ccbId,
00148 cfgKeys ) );
00149 delete ptr;
00150 }
00151 }
00152 return keyList;
00153
00154 }
00155
00156
00157 const
00158 std::string& DTCCBConfig::version() const {
00159 return dataVersion;
00160 }
00161
00162
00163 std::string& DTCCBConfig::version() {
00164 return dataVersion;
00165 }
00166
00167
00168 void DTCCBConfig::clear() {
00169 resetMap();
00170 DTDataBuffer< int,std::vector<int>* >::dropBuffer( mapName() );
00171 dataList.clear();
00172 return;
00173 }
00174
00175
00176 void DTCCBConfig::setFullKey( int key ) {
00177 fullConfigKey = key;
00178 }
00179
00180
00181 void DTCCBConfig::setStamp( int s ) {
00182 timeStamp = s;
00183 }
00184
00185
00186 int DTCCBConfig::setConfigKey( int wheelId,
00187 int stationId,
00188 int sectorId,
00189 const std::vector<int>& confKey ) {
00190
00191 std::string mName = mapName();
00192 DTBufferTree< int,std::vector<int>* >* dBuf =
00193 DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00194 if ( dBuf == 0 ) {
00195 cacheMap();
00196 dBuf =
00197 DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00198 }
00199 std::vector<int> chanKey;
00200 chanKey.reserve(3);
00201 chanKey.push_back( wheelId );
00202 chanKey.push_back( stationId );
00203 chanKey.push_back( sectorId );
00204
00205 std::vector<int>* confPtr;
00206 int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), confPtr );
00207
00208 if ( !searchStatus ) {
00209 std::vector< std::pair<DTCCBId,int> > tempList;
00210 const_iterator iter = dataList.begin();
00211 const_iterator iend = dataList.end();
00212 while ( iter != iend ) {
00213 const DTCCBId& ccbId( iter->first );
00214 if ( ( ccbId. wheelId == wheelId ) &&
00215 ( ccbId.stationId == stationId ) &&
00216 ( ccbId. sectorId == sectorId ) ) tempList.push_back( *iter );
00217 ++iter;
00218 }
00219 dataList = tempList;
00220 *confPtr = confKey;
00221 return -1;
00222 }
00223 else {
00224 dBuf->insert( chanKey.begin(),
00225 chanKey.end(), new std::vector<int>( confKey ) );
00226 DTCCBId ccbId;
00227 ccbId. wheelId = wheelId;
00228 ccbId.stationId = stationId;
00229 ccbId. sectorId = sectorId;
00230 std::vector<int>::const_iterator iter = confKey.begin();
00231 std::vector<int>::const_iterator iend = confKey.end();
00232 while ( iter != iend ) dataList.push_back( std::pair<DTCCBId,int>(
00233 ccbId, *iter++ ) );
00234 return 0;
00235 }
00236
00237 }
00238
00239
00240 int DTCCBConfig::setConfigKey( const DTChamberId& id,
00241 const std::vector<int>& confKey ) {
00242 return setConfigKey( id.wheel(),
00243 id.station(),
00244 id.sector(),
00245 confKey );
00246 }
00247
00248
00249 DTCCBConfig::const_iterator DTCCBConfig::begin() const {
00250 return dataList.begin();
00251 }
00252
00253
00254 DTCCBConfig::const_iterator DTCCBConfig::end() const {
00255 return dataList.end();
00256 }
00257
00258
00259 std::string DTCCBConfig::mapName() const {
00260 std::stringstream name;
00261 name << dataVersion << "_map_CCBConfig" << this;
00262 return name.str();
00263 }
00264
00265
00266 void DTCCBConfig::cacheMap() const {
00267
00268 std::string mName = mapName();
00269 DTBufferTree< int,std::vector<int>* >* dBuf =
00270 DTDataBuffer< int,std::vector<int>* >::openBuffer( mName );
00271 dBuf->setDefault( 0 );
00272
00273 const_iterator iter = dataList.begin();
00274 const_iterator iend = dataList.end();
00275 std::vector<int> chanKey;
00276 chanKey.reserve(3);
00277 while ( iter != iend ) {
00278
00279 const DTCCBId& chan = iter->first;
00280
00281 chanKey.clear();
00282 chanKey.push_back( chan. wheelId );
00283 chanKey.push_back( chan.stationId );
00284 chanKey.push_back( chan. sectorId );
00285 std::vector<int>* ccbConfPtr;
00286 int searchStatus = dBuf->find( chanKey.begin(),
00287 chanKey.end(), ccbConfPtr );
00288 if ( searchStatus ) dBuf->insert( chanKey.begin(),
00289 chanKey.end(),
00290 ccbConfPtr = new std::vector<int> );
00291 ccbConfPtr->push_back( iter->second );
00292
00293 iter++;
00294
00295 }
00296
00297 }
00298
00299
00300 void DTCCBConfig::resetMap() const {
00301 std::string mName = mapName();
00302 DTBufferTree< int,std::vector<int>* >* dBuf =
00303 DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00304 if ( dBuf != 0 ) {
00305 std::vector< std::vector<int>* > list( dBuf->contList() );
00306 std::vector< std::vector<int>* >::const_iterator iter = list.begin();
00307 std::vector< std::vector<int>* >::const_iterator iend = list.end();
00308 while ( iter != iend ) delete *iter++;
00309 }
00310 return;
00311 }
00312
00313