CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/CondFormats/DTObjects/src/DTCCBConfig.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.9 $
00006  *  \author Paolo Ronchese INFN Padova
00007  *
00008  */
00009 
00010 //-----------------------
00011 // This Class' Header --
00012 //-----------------------
00013 #include "CondFormats/DTObjects/interface/DTCCBConfig.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 #include <vector>
00026 
00027 //-------------------
00028 // Initializations --
00029 //-------------------
00030 
00031 
00032 //----------------
00033 // Constructors --
00034 //----------------
00035 DTCCBConfig::DTCCBConfig():
00036   dataVersion( " " ) {
00037   dataList.reserve( 1000 );
00038   dBuf = 0;
00039 }
00040 
00041 
00042 DTCCBConfig::DTCCBConfig( const std::string& version ):
00043   dataVersion( version ) {
00044   dataList.reserve( 1000 );
00045   dBuf = 0;
00046 }
00047 
00048 
00049 DTCCBId::DTCCBId() :
00050     wheelId( 0 ),
00051   stationId( 0 ),
00052    sectorId( 0 ) {
00053 }
00054 
00055 
00056 DTConfigKey::DTConfigKey() :
00057   confType( 0 ),
00058   confKey ( 0 ) {
00059 }
00060 
00061 
00062 //--------------
00063 // Destructor --
00064 //--------------
00065 DTCCBConfig::~DTCCBConfig() {
00066   resetMap();
00067 //  DTDataBuffer< int,std::vector<int>* >::dropBuffer( mapName() );
00068   delete dBuf;
00069 }
00070 
00071 
00072 DTCCBId::~DTCCBId() {
00073 }
00074 
00075 
00076 DTConfigKey::~DTConfigKey() {
00077 }
00078 
00079 
00080 //--------------
00081 // Operations --
00082 //--------------
00083 std::vector<DTConfigKey> DTCCBConfig::fullKey() const {
00084   return fullConfigKey;
00085 }
00086 
00087 
00088 int DTCCBConfig::stamp() const {
00089   return timeStamp;
00090 }
00091 
00092 
00093 int DTCCBConfig::configKey( int   wheelId,
00094                             int stationId,
00095                             int  sectorId,
00096                             std::vector<int>& confKey ) const {
00097 
00098   confKey.clear();
00099 //  std::string mName = mapName();
00100 //  DTBufferTree< int,std::vector<int>* >* dBuf =
00101 //  DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00102 //  if ( dBuf == 0 ) {
00103 //    cacheMap();
00104 //    dBuf =
00105 //    DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00106 //  }
00107   if ( dBuf == 0 ) cacheMap();
00108 
00109   std::vector<int> chanKey;
00110   chanKey.reserve(3);
00111   chanKey.push_back(   wheelId );
00112   chanKey.push_back( stationId );
00113   chanKey.push_back(  sectorId );
00114   std::vector<int>* confPtr;
00115   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), confPtr );
00116   if ( !searchStatus ) confKey = *confPtr;
00117 
00118   return searchStatus;
00119 
00120 }
00121 
00122 
00123 int DTCCBConfig::configKey( const DTChamberId& id,
00124                             std::vector<int>& confKey ) const {
00125   return configKey( id.wheel(),
00126                     id.station(),
00127                     id.sector(),
00128                     confKey );
00129 }
00130 
00131 
00132 DTCCBConfig::ccb_config_map
00133 DTCCBConfig::configKeyMap() const {
00134 
00135   ccb_config_map keyList;
00136   std::vector< std::pair<DTCCBId,int>* > tempList;
00137   const_iterator d_iter = begin();
00138   const_iterator d_iend = end();
00139   while ( d_iter != d_iend ) tempList.push_back(
00140                              new std::pair<DTCCBId,int>( *d_iter++ ) );
00141   std::vector< std::pair<DTCCBId,int>* >::iterator t_iter = tempList.begin();
00142   std::vector< std::pair<DTCCBId,int>* >::iterator t_iend = tempList.end();
00143   while ( t_iter != t_iend ) {
00144     std::pair<DTCCBId,int>* ptr = *t_iter++;
00145     if ( ptr == 0 ) continue;
00146     DTCCBId& ccbId = ptr->first;
00147     std::vector<int> cfgKeys;
00148     cfgKeys.push_back( ptr->second );
00149     std::vector< std::pair<DTCCBId,int>* >::iterator n_iter( t_iter );
00150     while( n_iter != t_iend ) {
00151       std::pair<DTCCBId,int>*& pck = *n_iter++;
00152       if ( pck == 0 ) continue; 
00153       DTCCBId& chkId = pck->first;
00154       if ( ( chkId.  wheelId == ccbId.  wheelId ) && 
00155            ( chkId.stationId == ccbId.stationId ) && 
00156            ( chkId. sectorId == ccbId. sectorId ) ) {
00157         cfgKeys.push_back( pck->second );
00158         delete pck;
00159         pck = 0;
00160       }
00161     }
00162     keyList.push_back( std::pair< DTCCBId,std::vector<int> >( ccbId,
00163                                                               cfgKeys ) );
00164     delete ptr;
00165   }
00166   return keyList;
00167 
00168 }
00169 
00170 
00171 const
00172 std::string& DTCCBConfig::version() const {
00173   return dataVersion;
00174 }
00175 
00176 
00177 std::string& DTCCBConfig::version() {
00178   return dataVersion;
00179 }
00180 
00181 
00182 void DTCCBConfig::clear() {
00183   resetMap();
00184 //  DTDataBuffer< int,std::vector<int>* >::dropBuffer( mapName() );
00185   delete dBuf;
00186   dBuf = 0;
00187   dataList.clear();
00188   return;
00189 }
00190 
00191 
00192 void DTCCBConfig::setFullKey( std::vector<DTConfigKey> key ) {
00193   fullConfigKey = key;
00194 }
00195 
00196 
00197 void DTCCBConfig::setStamp( int s ) {
00198   timeStamp = s;
00199 }
00200 
00201 
00202 int DTCCBConfig::setConfigKey( int   wheelId,
00203                                int stationId,
00204                                int  sectorId,
00205                                const std::vector<int>& confKey ) {
00206 
00207 //  std::string mName = mapName();
00208 //  DTBufferTree< int,std::vector<int>* >* dBuf =
00209 //  DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00210 //  if ( dBuf == 0 ) {
00211 //    cacheMap();
00212 //    dBuf =
00213 //    DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00214 //  }
00215   if ( dBuf == 0 ) cacheMap();
00216 
00217   std::vector<int> chanKey;
00218   chanKey.reserve(3);
00219   chanKey.push_back(   wheelId );
00220   chanKey.push_back( stationId );
00221   chanKey.push_back(  sectorId );
00222 
00223   std::vector<int>* confPtr;
00224   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), confPtr );
00225 
00226   if ( !searchStatus ) {
00227     std::vector< std::pair<DTCCBId,int> > tempList;
00228     const_iterator iter = dataList.begin();
00229     const_iterator iend = dataList.end();
00230     while ( iter != iend ) {
00231       const DTCCBId& ccbId( iter->first );
00232 //      if ( ( ccbId.  wheelId ==   wheelId ) &&
00233 //           ( ccbId.stationId == stationId ) &&
00234 //           ( ccbId. sectorId ==  sectorId ) ) tempList.push_back( *iter );
00235       if ( ( ccbId.  wheelId !=   wheelId ) ||
00236            ( ccbId.stationId != stationId ) ||
00237            ( ccbId. sectorId !=  sectorId ) ) tempList.push_back( *iter );
00238       ++iter;
00239     }
00240     dataList = tempList;
00241     DTCCBId ccbId;
00242     ccbId.  wheelId =   wheelId;
00243     ccbId.stationId = stationId;
00244     ccbId. sectorId =  sectorId;
00245     std::vector<int>::const_iterator cfgIter = confKey.begin();
00246     std::vector<int>::const_iterator cfgIend = confKey.end();
00247     while ( cfgIter != cfgIend ) dataList.push_back( std::pair<DTCCBId,int>(
00248                                                      ccbId, *cfgIter++ ) );
00249     *confPtr = confKey;
00250     return -1;
00251   }
00252   else {
00253     dBuf->insert( chanKey.begin(),
00254                   chanKey.end(), new std::vector<int>( confKey ) );
00255     DTCCBId ccbId;
00256     ccbId.  wheelId =   wheelId;
00257     ccbId.stationId = stationId;
00258     ccbId. sectorId =  sectorId;
00259     std::vector<int>::const_iterator cfgIter = confKey.begin();
00260     std::vector<int>::const_iterator cfgIend = confKey.end();
00261     while ( cfgIter != cfgIend ) dataList.push_back( std::pair<DTCCBId,int>(
00262                                                      ccbId, *cfgIter++ ) );
00263     return 0;
00264   }
00265 
00266 }
00267 
00268 
00269 int DTCCBConfig::setConfigKey( const DTChamberId& id,
00270                                const std::vector<int>& confKey ) {
00271   return setConfigKey( id.wheel(),
00272                        id.station(),
00273                        id.sector(),
00274                        confKey );
00275 }
00276 
00277 
00278 int DTCCBConfig::appendConfigKey( int   wheelId,
00279                                   int stationId,
00280                                   int  sectorId,
00281                                   const std::vector<int>& confKey ) {
00282 
00283 //  std::string mName = mapName();
00284 //  DTBufferTree< int,std::vector<int>* >* dBuf =
00285 //  DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00286 //  if ( dBuf == 0 ) {
00287 //    cacheMap();
00288 //    dBuf =
00289 //    DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00290 //  }
00291   if ( dBuf == 0 ) cacheMap();
00292 
00293   std::vector<int> chanKey;
00294   chanKey.reserve(3);
00295   chanKey.push_back(   wheelId );
00296   chanKey.push_back( stationId );
00297   chanKey.push_back(  sectorId );
00298 
00299   DTCCBId ccbId;
00300   ccbId.  wheelId =   wheelId;
00301   ccbId.stationId = stationId;
00302   ccbId. sectorId =  sectorId;
00303   std::vector<int>::const_iterator iter = confKey.begin();
00304   std::vector<int>::const_iterator iend = confKey.end();
00305   int key;
00306 
00307   std::vector<int>* confPtr;
00308   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), confPtr );
00309 
00310   if ( searchStatus ) {
00311     dBuf->insert( chanKey.begin(),
00312                   chanKey.end(), confPtr = new std::vector<int>( confKey ) );
00313   }
00314 
00315   while ( iter != iend ) {
00316     key = *iter++;
00317     dataList.push_back( std::pair<DTCCBId,int>( ccbId, key ) );
00318     confPtr->push_back( key );
00319   }
00320 
00321   if ( !searchStatus ) {
00322     return -1;
00323   }
00324   else {
00325     return 0;
00326   }
00327 
00328 }
00329 
00330 
00331 int DTCCBConfig::appendConfigKey( const DTChamberId& id,
00332                                   const std::vector<int>& confKey ) {
00333   return appendConfigKey( id.wheel(),
00334                           id.station(),
00335                           id.sector(),
00336                           confKey );
00337 }
00338 
00339 
00340 DTCCBConfig::const_iterator DTCCBConfig::begin() const {
00341   return dataList.begin();
00342 }
00343 
00344 
00345 DTCCBConfig::const_iterator DTCCBConfig::end() const {
00346   return dataList.end();
00347 }
00348 
00349 
00350 /*
00351 std::string DTCCBConfig::mapName() const {
00352   std::stringstream name;
00353   name << dataVersion << "_map_CCBConfig" << this;
00354   return name.str();
00355 }
00356 */
00357 
00358 
00359 void DTCCBConfig::cacheMap() const {
00360 
00361 //  std::string mName = mapName();
00362 //  DTBufferTree< int,std::vector<int>* >* dBuf =
00363 //  DTDataBuffer< int,std::vector<int>* >::openBuffer( mName );
00364   DTBufferTree< int,std::vector<int>* >** pBuf;
00365   pBuf = const_cast<DTBufferTree< int,std::vector<int>* >**>( &dBuf );
00366   *pBuf = new DTBufferTree< int,std::vector<int>* >;
00367   dBuf->setDefault( 0 );
00368 
00369   const_iterator iter = dataList.begin();
00370   const_iterator iend = dataList.end();
00371   std::vector<int> chanKey;
00372   chanKey.reserve(3);
00373   while ( iter != iend ) {
00374 
00375     const DTCCBId& chan = iter->first;
00376 
00377     chanKey.clear();
00378     chanKey.push_back( chan.  wheelId );
00379     chanKey.push_back( chan.stationId );
00380     chanKey.push_back( chan. sectorId );
00381     std::vector<int>* ccbConfPtr;
00382     int searchStatus = dBuf->find( chanKey.begin(),
00383                                    chanKey.end(), ccbConfPtr );
00384     if ( searchStatus ) dBuf->insert( chanKey.begin(),
00385                                       chanKey.end(),
00386                                       ccbConfPtr = new std::vector<int> );
00387     ccbConfPtr->push_back( iter->second );
00388 
00389     iter++;
00390 
00391   }
00392 
00393 }
00394 
00395 
00396 void DTCCBConfig::resetMap() const {
00397 //  std::string mName = mapName();
00398 //  DTBufferTree< int,std::vector<int>* >* dBuf =
00399 //  DTDataBuffer< int,std::vector<int>* >::findBuffer( mName );
00400   if ( dBuf != 0 ) {
00401     std::vector< std::vector<int>* > list( dBuf->contList() );
00402     std::vector< std::vector<int>* >::const_iterator iter = list.begin();
00403     std::vector< std::vector<int>* >::const_iterator iend = list.end();
00404     while ( iter != iend ) delete *iter++;
00405   }
00406   return;
00407 }
00408 
00409