CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CondFormats/DTObjects/src/DTHVStatus.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.3 $
00006  *  \author Paolo Ronchese INFN Padova
00007  *
00008  */
00009 
00010 //----------------------
00011 // This Class' Header --
00012 //----------------------
00013 #include "CondFormats/DTObjects/interface/DTHVStatus.h"
00014 
00015 //-------------------------------
00016 // Collaborating Class Headers --
00017 //-------------------------------
00018 //#include "CondFormats/DTObjects/interface/DTDataBuffer.h"
00019 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00020 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
00021 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00022 
00023 //---------------
00024 // C++ Headers --
00025 //---------------
00026 #include <iostream>
00027 #include <sstream>
00028 
00029 //-------------------
00030 // Initializations --
00031 //-------------------
00032 
00033 
00034 //----------------
00035 // Constructors --
00036 //----------------
00037 DTHVStatus::DTHVStatus():
00038   dataVersion( " " ) {
00039   dataList.reserve( 10 );
00040   dBuf = 0;
00041 }
00042 
00043 
00044 DTHVStatus::DTHVStatus( const std::string& version ):
00045   dataVersion( version ) {
00046   dataList.reserve( 10 );
00047   dBuf = 0;
00048 }
00049 
00050 
00051 DTHVStatusId::DTHVStatusId() :
00052     wheelId( 0 ),
00053   stationId( 0 ),
00054    sectorId( 0 ),
00055        slId( 0 ),
00056     layerId( 0 ),
00057      partId( 0 ) {
00058 }
00059 
00060 
00061 DTHVStatusData::DTHVStatusData() :
00062   flagA( 0 ),
00063   flagC( 0 ),
00064   flagS( 0 ) {
00065 }
00066 
00067 
00068 //--------------
00069 // Destructor --
00070 //--------------
00071 DTHVStatus::~DTHVStatus() {
00072 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00073   delete dBuf;
00074 }
00075 
00076 
00077 DTHVStatusId::~DTHVStatusId() {
00078 }
00079 
00080 
00081 DTHVStatusData::~DTHVStatusData() {
00082 }
00083 
00084 
00085 //--------------
00086 // Operations --
00087 //--------------
00088 int DTHVStatus::get( int   wheelId,
00089                      int stationId,
00090                      int  sectorId,
00091                      int      slId,
00092                      int   layerId,
00093                      int    partId,
00094                      int&    fCell,
00095                      int&    lCell,
00096                      int&    flagA,
00097                      int&    flagC,
00098                      int&    flagS ) const {
00099   fCell =
00100   lCell =
00101   flagA =
00102   flagC = 
00103   flagS = 0;
00104 
00105 //  std::string mName = mapName();
00106 //  DTBufferTree<int,int>* dBuf =
00107 //  DTDataBuffer<int,int>::findBuffer( mName );
00108 //  if ( dBuf == 0 ) {
00109 //    cacheMap();
00110 //    dBuf =
00111 //    DTDataBuffer<int,int>::findBuffer( mName );
00112 //  }
00113   if ( dBuf == 0 ) cacheMap();
00114 
00115   std::vector<int> chanKey;
00116   chanKey.reserve(6);
00117   chanKey.push_back(   wheelId );
00118   chanKey.push_back( stationId );
00119   chanKey.push_back(  sectorId );
00120   chanKey.push_back(      slId );
00121   chanKey.push_back(   layerId );
00122   chanKey.push_back(    partId );
00123   int ientry;
00124   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00125   if ( !searchStatus ) {
00126     const DTHVStatusData& data( dataList[ientry].second );
00127     fCell = data.fCell;
00128     lCell = data.lCell;
00129     flagA = data.flagA;
00130     flagC = data.flagC;
00131     flagS = data.flagS;
00132   }
00133 
00134   return searchStatus;
00135 
00136 }
00137 
00138 
00139 int DTHVStatus::get( const DTLayerId& id,
00140                      int    partId,
00141                      int&    fCell,
00142                      int&    lCell,
00143                      int&    flagA,
00144                      int&    flagC,
00145                      int&    flagS ) const {
00146   return get( id.wheel(),
00147               id.station(),
00148               id.sector(),
00149               id.superLayer(),
00150               id.layer(),
00151               partId,
00152               fCell, lCell, flagA, flagC, flagS );
00153 }
00154 
00155 
00156 int DTHVStatus::get( const DTWireId& id,
00157                      int&         flagA,
00158                      int&         flagC,
00159                      int&         flagS ) const {
00160   flagA = flagC = flagS = 0;
00161   int iCell = id.wire();
00162   int fCell;
00163   int lCell;
00164   int
00165   fCheck = get( id.wheel(),
00166                 id.station(),
00167                 id.sector(),
00168                 id.superLayer(),
00169                 id.layer(),
00170                 0,     fCell, lCell,
00171                 flagA, flagC, flagS );
00172   if ( ( fCheck == 0 ) &&
00173        ( fCell <= iCell ) &&
00174        ( lCell >= iCell ) ) return 0;
00175   fCheck = get( id.wheel(),
00176                 id.station(),
00177                 id.sector(),
00178                 id.superLayer(),
00179                 id.layer(),
00180                 1,     fCell, lCell,
00181                 flagA, flagC, flagS );
00182   if ( ( fCheck == 0 ) &&
00183        ( fCell <= iCell ) &&
00184        ( lCell >= iCell ) ) return 0;
00185   flagA = flagC = flagS = 0;
00186   return 1;
00187 }
00188 
00189 
00190 int DTHVStatus::offChannelsNumber() const {
00191   int offNum = 0;
00192   DTHVStatus::const_iterator iter = begin();
00193   DTHVStatus::const_iterator iend = end();
00194   while ( iter != iend ) {
00195     const std::pair<DTHVStatusId,DTHVStatusData>& entry = *iter++;
00196     DTHVStatusId   hvId = entry.first;
00197     DTHVStatusData data = entry.second;
00198     int offA = data.flagA & 1;
00199     int offC = data.flagC & 1;
00200     int offS = data.flagS & 1;
00201     if ( offA || offC || offS )
00202          offNum += ( 1 + data.lCell - data.fCell );
00203   }
00204   return offNum;
00205 }
00206 
00207 
00208 int DTHVStatus::offChannelsNumber( const DTChamberId& id ) const {
00209   int offNum = 0;
00210   DTHVStatus::const_iterator iter = begin();
00211   DTHVStatus::const_iterator iend = end();
00212   while ( iter != iend ) {
00213     const std::pair<DTHVStatusId,DTHVStatusData>& entry = *iter++;
00214     DTHVStatusId   hvId = entry.first;
00215     DTHVStatusData data = entry.second;
00216     if ( hvId.  wheelId != id.  wheel() ) continue;
00217     if ( hvId.stationId != id.station() ) continue;
00218     if ( hvId. sectorId != id. sector() ) continue;
00219     int offA = data.flagA & 1;
00220     int offC = data.flagC & 1;
00221     int offS = data.flagS & 1;
00222     if ( offA || offC || offS )
00223          offNum += ( 1 + data.lCell - data.fCell );
00224   }
00225   return offNum;
00226 }
00227 
00228 
00229 int DTHVStatus::badChannelsNumber() const {
00230   int offNum = 0;
00231   DTHVStatus::const_iterator iter = begin();
00232   DTHVStatus::const_iterator iend = end();
00233   while ( iter != iend ) {
00234     const std::pair<DTHVStatusId,DTHVStatusData>& entry = *iter++;
00235     DTHVStatusId   hvId = entry.first;
00236     DTHVStatusData data = entry.second;
00237     if ( data.flagA || data.flagC || data.flagS )
00238          offNum += ( 1 + data.lCell - data.fCell );
00239   }
00240   return offNum;
00241 }
00242 
00243 
00244 int DTHVStatus::badChannelsNumber( const DTChamberId& id ) const {
00245   int offNum = 0;
00246   DTHVStatus::const_iterator iter = begin();
00247   DTHVStatus::const_iterator iend = end();
00248   while ( iter != iend ) {
00249     const std::pair<DTHVStatusId,DTHVStatusData>& entry = *iter++;
00250     DTHVStatusId   hvId = entry.first;
00251     DTHVStatusData data = entry.second;
00252     if ( hvId.  wheelId != id.  wheel() ) continue;
00253     if ( hvId.stationId != id.station() ) continue;
00254     if ( hvId. sectorId != id. sector() ) continue;
00255     if ( data.flagA || data.flagC || data.flagS )
00256          offNum += ( 1 + data.lCell - data.fCell );
00257   }
00258   return offNum;
00259 }
00260 
00261 
00262 const
00263 std::string& DTHVStatus::version() const {
00264   return dataVersion;
00265 }
00266 
00267 
00268 std::string& DTHVStatus::version() {
00269   return dataVersion;
00270 }
00271 
00272 
00273 void DTHVStatus::clear() {
00274 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00275   delete dBuf;
00276   dBuf = 0;
00277   dataList.clear();
00278   dataList.reserve( 10 );
00279   return;
00280 }
00281 
00282 
00283 int DTHVStatus::set( int   wheelId,
00284                      int stationId,
00285                      int  sectorId,
00286                      int      slId,
00287                      int   layerId,
00288                      int    partId,
00289                      int     fCell,
00290                      int     lCell,
00291                      int     flagA,
00292                      int     flagC,
00293                      int     flagS ) {
00294 
00295 //  std::string mName = mapName();
00296 //  DTBufferTree<int,int>* dBuf =
00297 //  DTDataBuffer<int,int>::findBuffer( mName );
00298 //  if ( dBuf == 0 ) {
00299 //    cacheMap();
00300 //    dBuf =
00301 //    DTDataBuffer<int,int>::findBuffer( mName );
00302 //  }
00303   if ( dBuf == 0 ) cacheMap();
00304   std::vector<int> chanKey;
00305   chanKey.reserve(6);
00306   chanKey.push_back(   wheelId );
00307   chanKey.push_back( stationId );
00308   chanKey.push_back(  sectorId );
00309   chanKey.push_back(      slId );
00310   chanKey.push_back(   layerId );
00311   chanKey.push_back(    partId );
00312   int ientry;
00313   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00314 
00315   if ( !searchStatus ) {
00316     DTHVStatusData& data( dataList[ientry].second );
00317     data.fCell = fCell;
00318     data.lCell = lCell;
00319     data.flagA = flagA;
00320     data.flagC = flagC;
00321     data.flagS = flagS;
00322     return -1;
00323   }
00324   else {
00325     DTHVStatusId key;
00326     key.  wheelId =   wheelId;
00327     key.stationId = stationId;
00328     key. sectorId =  sectorId;
00329     key.     slId =      slId;
00330     key.  layerId =   layerId;
00331     key.   partId =    partId;
00332     DTHVStatusData data;
00333     data.fCell = fCell;
00334     data.lCell = lCell;
00335     data.flagA = flagA;
00336     data.flagC = flagC;
00337     data.flagS = flagS;
00338     ientry = dataList.size();
00339     dataList.push_back( std::pair<DTHVStatusId,
00340                                   DTHVStatusData>( key, data ) );
00341     dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
00342     return 0;
00343   }
00344 
00345   return 99;
00346 
00347 }
00348 
00349 
00350 int DTHVStatus::set( const DTLayerId& id,
00351                      int    partId,
00352                      int     fCell,
00353                      int     lCell,
00354                      int     flagA,
00355                      int     flagC,
00356                      int     flagS ) {
00357   return set( id.wheel(),
00358               id.station(),
00359               id.sector(),
00360               id.superLayer(),
00361               id.layer(),
00362               partId,
00363               fCell, lCell, flagA, flagC, flagS );
00364 }
00365 
00366 
00367 int DTHVStatus::setFlagA( int   wheelId,
00368                           int stationId,
00369                           int  sectorId,
00370                           int      slId,
00371                           int   layerId,
00372                           int    partId,
00373                           int      flag ) {
00374   int fCell;
00375   int lCell;
00376   int flagA;
00377   int flagC;
00378   int flagS;
00379   get(   wheelId,
00380        stationId,
00381         sectorId,
00382             slId,
00383          layerId,
00384           partId,
00385            fCell,
00386            lCell,
00387            flagA,
00388            flagC,
00389            flagS );
00390   return set(   wheelId,
00391               stationId,
00392                sectorId,
00393                    slId,
00394                 layerId,
00395                  partId,
00396                   fCell,
00397                   lCell,
00398                    flag,
00399                   flagC,
00400                   flagS );
00401 }
00402 
00403 
00404 int DTHVStatus::setFlagA( const DTLayerId& id,
00405                           int    partId,
00406                           int      flag ) {
00407   return setFlagA( id.wheel(),
00408                    id.station(),
00409                    id.sector(),
00410                    id.superLayer(),
00411                    id.layer(),
00412                    partId,
00413                    flag );
00414 }
00415 
00416 
00417 int DTHVStatus::setFlagC( int   wheelId,
00418                           int stationId,
00419                           int  sectorId,
00420                           int      slId,
00421                           int   layerId,
00422                           int    partId,
00423                           int      flag ) {
00424   int fCell;
00425   int lCell;
00426   int flagA;
00427   int flagC;
00428   int flagS;
00429   get(   wheelId,
00430        stationId,
00431         sectorId,
00432             slId,
00433          layerId,
00434           partId,
00435            fCell,
00436            lCell,
00437            flagA,
00438            flagC,
00439            flagS );
00440   return set(   wheelId,
00441               stationId,
00442                sectorId,
00443                slId,
00444                 layerId,
00445                  partId,
00446                   fCell,
00447                   lCell,
00448                   flagA,
00449                    flag,
00450                   flagS );
00451 }
00452 
00453 
00454 int DTHVStatus::setFlagC( const DTLayerId& id,
00455                           int    partId,
00456                           int      flag ) {
00457   return setFlagC( id.wheel(),
00458                    id.station(),
00459                    id.sector(),
00460                    id.superLayer(),
00461                    id.layer(),
00462                    partId,
00463                    flag );
00464 }
00465 
00466 
00467 int DTHVStatus::setFlagS( int   wheelId,
00468                           int stationId,
00469                           int  sectorId,
00470                           int      slId,
00471                           int   layerId,
00472                           int    partId,
00473                           int      flag ) {
00474   int fCell;
00475   int lCell;
00476   int flagA;
00477   int flagC;
00478   int flagS;
00479   get(   wheelId,
00480        stationId,
00481         sectorId,
00482             slId,
00483          layerId,
00484           partId,
00485            fCell,
00486            lCell,
00487            flagA,
00488            flagC,
00489            flagS );
00490   return set(   wheelId,
00491               stationId,
00492                sectorId,
00493                    slId,
00494                 layerId,
00495                  partId,
00496                   fCell,
00497                   lCell,
00498                   flagA,
00499                   flagC,
00500                    flag );
00501 }
00502 
00503 
00504 int DTHVStatus::setFlagS( const DTLayerId& id,
00505                           int    partId,
00506                           int      flag ) {
00507   return setFlagS( id.wheel(),
00508                    id.station(),
00509                    id.sector(),
00510                    id.superLayer(),
00511                    id.layer(),
00512                    partId,
00513                    flag );
00514 }
00515 
00516 
00517 DTHVStatus::const_iterator DTHVStatus::begin() const {
00518   return dataList.begin();
00519 }
00520 
00521 
00522 DTHVStatus::const_iterator DTHVStatus::end() const {
00523   return dataList.end();
00524 }
00525 
00526 
00527 std::string DTHVStatus::mapName() const {
00528   std::stringstream name;
00529   name << dataVersion << "_map_HV" << this;
00530   return name.str();
00531 }
00532 
00533 
00534 void DTHVStatus::cacheMap() const {
00535 
00536 //  std::string mName = mapName();
00537 //  DTBufferTree<int,int>* dBuf =
00538 //  DTDataBuffer<int,int>::openBuffer( mName );
00539   DTBufferTree<int,int>** pBuf;
00540   pBuf = const_cast<DTBufferTree<int,int>**>( &dBuf );
00541   *pBuf = new DTBufferTree<int,int>;
00542 
00543   int entryNum = 0;
00544   int entryMax = dataList.size();
00545   std::vector<int> chanKey;
00546   chanKey.reserve(6);
00547   while ( entryNum < entryMax ) {
00548 
00549     const DTHVStatusId& chan = dataList[entryNum].first;
00550 
00551     chanKey.clear();
00552     chanKey.push_back( chan.  wheelId );
00553     chanKey.push_back( chan.stationId );
00554     chanKey.push_back( chan. sectorId );
00555     chanKey.push_back( chan.     slId );
00556     chanKey.push_back( chan.  layerId );
00557     chanKey.push_back( chan.   partId );
00558     dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
00559 
00560   }
00561 
00562   return;
00563 
00564 }
00565 
00566