CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CondFormats/DTObjects/src/DTPerformance.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:37:53 $
00005  *  $Revision: 1.7 $
00006  *  \author Paolo Ronchese INFN Padova
00007  *
00008  */
00009 
00010 //----------------------
00011 // This Class' Header --
00012 //----------------------
00013 #include "CondFormats/DTObjects/interface/DTPerformance.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 DTPerformance::DTPerformance():
00035   dataVersion( " " ) {
00036   dataList.reserve( 1000 );
00037   dBuf = 0;
00038 }
00039 
00040 
00041 DTPerformance::DTPerformance( const std::string& version ):
00042   dataVersion( version ) {
00043   dataList.reserve( 1000 );
00044   dBuf = 0;
00045 }
00046 
00047 
00048 DTPerformanceId::DTPerformanceId() :
00049     wheelId( 0 ),
00050   stationId( 0 ),
00051    sectorId( 0 ),
00052        slId( 0 ) {
00053 }
00054 
00055 
00056 DTPerformanceData::DTPerformanceData() :
00057   meanT0(         0.0 ),
00058   meanTtrig(      0.0 ),
00059   meanMtime(      0.0 ),
00060   meanNoise(      0.0 ),
00061   meanAfterPulse( 0.0 ),
00062   meanResolution( 0.0 ),
00063   meanEfficiency( 0.0 ) {
00064 }
00065 
00066 
00067 //--------------
00068 // Destructor --
00069 //--------------
00070 DTPerformance::~DTPerformance() {
00071 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00072   delete dBuf;
00073 }
00074 
00075 
00076 DTPerformanceData::~DTPerformanceData() {
00077 }
00078 
00079 
00080 DTPerformanceId::~DTPerformanceId() {
00081 }
00082 
00083 
00084 //--------------
00085 // Operations --
00086 //--------------
00087 int DTPerformance::get( int   wheelId,
00088                         int stationId,
00089                         int  sectorId,
00090                         int      slId,
00091                         float& meanT0,
00092                         float& meanTtrig,
00093                         float& meanMtime,
00094                         float& meanNoise,
00095                         float& meanAfterPulse,
00096                         float& meanResolution,
00097                         float& meanEfficiency,
00098                         DTTimeUnits::type unit ) const {
00099 
00100   meanT0         =
00101   meanTtrig      =
00102   meanMtime      =
00103   meanNoise      =
00104   meanAfterPulse =
00105   meanResolution =
00106   meanEfficiency = 0.0;
00107 
00108 //  std::string mName = mapName();
00109 //  DTBufferTree<int,int>* dBuf =
00110 //  DTDataBuffer<int,int>::findBuffer( mName );
00111 //  if ( dBuf == 0 ) {
00112 //    cacheMap();
00113 //    dBuf =
00114 //    DTDataBuffer<int,int>::findBuffer( mName );
00115 //  }
00116   if ( dBuf == 0 ) cacheMap();
00117 
00118   std::vector<int> chanKey;
00119   chanKey.reserve(4);
00120   chanKey.push_back(   wheelId );
00121   chanKey.push_back( stationId );
00122   chanKey.push_back(  sectorId );
00123   chanKey.push_back(      slId );
00124   int ientry;
00125   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00126   if ( !searchStatus ) {
00127     const DTPerformanceData& data( dataList[ientry].second );
00128     meanT0         = data.meanT0;
00129     meanTtrig      = data.meanTtrig;
00130     meanMtime      = data.meanMtime;
00131     meanNoise      = data.meanNoise;
00132     meanAfterPulse = data.meanAfterPulse;
00133     meanResolution = data.meanResolution;
00134     meanEfficiency = data.meanEfficiency;
00135     if ( unit == DTTimeUnits::ns ) {
00136       meanT0    *= nsPerCount;
00137       meanTtrig *= nsPerCount;
00138       meanMtime *= nsPerCount;
00139     }
00140   }
00141 
00142   return searchStatus;
00143 
00144 }
00145 
00146 
00147 int DTPerformance::get( const DTSuperLayerId& id,
00148                         float& meanT0,
00149                         float& meanTtrig,
00150                         float& meanMtime,
00151                         float& meanNoise,
00152                         float& meanAfterPulse,
00153                         float& meanResolution,
00154                         float& meanEfficiency,
00155                         DTTimeUnits::type unit ) const {
00156   return get( id.wheel(),
00157               id.station(),
00158               id.sector(),
00159               id.superLayer(),
00160               meanT0,
00161               meanTtrig,
00162               meanMtime,
00163               meanNoise,
00164               meanAfterPulse,
00165               meanResolution,
00166               meanEfficiency,
00167               unit );
00168 }
00169 
00170 
00171 float DTPerformance::unit() const {
00172   return nsPerCount;
00173 }
00174 
00175 
00176 const
00177 std::string& DTPerformance::version() const {
00178   return dataVersion;
00179 }
00180 
00181 
00182 std::string& DTPerformance::version() {
00183   return dataVersion;
00184 }
00185 
00186 
00187 void DTPerformance::clear() {
00188 //  DTDataBuffer<int,int>::dropBuffer( mapName() );
00189   delete dBuf;
00190   dBuf = 0;
00191   dataList.clear();
00192   return;
00193 }
00194 
00195 
00196 int DTPerformance::set( int   wheelId,
00197                         int stationId,
00198                         int  sectorId,
00199                         int      slId,
00200                         float meanT0,
00201                         float meanTtrig,
00202                         float meanMtime,
00203                         float meanNoise,
00204                         float meanAfterPulse,
00205                         float meanResolution,
00206                         float meanEfficiency,
00207                         DTTimeUnits::type unit ) {
00208 
00209   if ( unit == DTTimeUnits::ns ) {
00210     meanT0    /= nsPerCount;
00211     meanTtrig /= nsPerCount;
00212     meanMtime /= nsPerCount;
00213   }
00214 
00215 //  std::string mName = mapName();
00216 //  DTBufferTree<int,int>* dBuf =
00217 //  DTDataBuffer<int,int>::findBuffer( mName );
00218 //  if ( dBuf == 0 ) {
00219 //    cacheMap();
00220 //    dBuf =
00221 //    DTDataBuffer<int,int>::findBuffer( mName );
00222 //  }
00223   if ( dBuf == 0 ) cacheMap();
00224   std::vector<int> chanKey;
00225   chanKey.reserve(4);
00226   chanKey.push_back(   wheelId );
00227   chanKey.push_back( stationId );
00228   chanKey.push_back(  sectorId );
00229   chanKey.push_back(      slId );
00230   int ientry;
00231   int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00232 
00233   if ( !searchStatus ) {
00234     DTPerformanceData& data( dataList[ientry].second );
00235     data.meanT0         = meanT0;
00236     data.meanTtrig      = meanTtrig;
00237     data.meanMtime      = meanMtime;
00238     data.meanNoise      = meanNoise;
00239     data.meanAfterPulse = meanAfterPulse;
00240     data.meanResolution = meanResolution;
00241     data.meanEfficiency = meanEfficiency;
00242     return -1;
00243   }
00244   else {
00245     DTPerformanceId key;
00246     key.  wheelId =   wheelId;
00247     key.stationId = stationId;
00248     key. sectorId =  sectorId;
00249     key.     slId =      slId;
00250     DTPerformanceData data;
00251     data.meanT0         = meanT0;
00252     data.meanTtrig      = meanTtrig;
00253     data.meanMtime      = meanMtime;
00254     data.meanNoise      = meanNoise;
00255     data.meanAfterPulse = meanAfterPulse;
00256     data.meanResolution = meanResolution;
00257     data.meanEfficiency = meanEfficiency;
00258     ientry = dataList.size();
00259     dataList.push_back( std::pair<DTPerformanceId,DTPerformanceData>(
00260                         key, data ) );
00261     dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
00262     return 0;
00263   }
00264 
00265   return 99;
00266 
00267 }
00268 
00269 
00270 int DTPerformance::set( const DTSuperLayerId& id,
00271                         float meanT0,
00272                         float meanTtrig,
00273                         float meanMtime,
00274                         float meanNoise,
00275                         float meanAfterPulse,
00276                         float meanResolution,
00277                         float meanEfficiency,
00278                         DTTimeUnits::type unit ) {
00279   return set( id.wheel(),
00280               id.station(),
00281               id.sector(),
00282               id.superLayer(),
00283               meanT0,
00284               meanTtrig,
00285               meanMtime,
00286               meanNoise,
00287               meanAfterPulse,
00288               meanResolution,
00289               meanEfficiency,
00290               unit );
00291 }
00292 
00293 
00294 void DTPerformance::setUnit( float unit ) {
00295   nsPerCount = unit;
00296 }
00297 
00298 
00299 DTPerformance::const_iterator DTPerformance::begin() const {
00300   return dataList.begin();
00301 }
00302 
00303 
00304 DTPerformance::const_iterator DTPerformance::end() const {
00305   return dataList.end();
00306 }
00307 
00308 
00309 std::string DTPerformance::mapName() const {
00310   std::stringstream name;
00311   name << dataVersion << "_map_Performance" << this;
00312   return name.str();
00313 }
00314 
00315 
00316 void DTPerformance::cacheMap() const {
00317 
00318 //  std::string mName = mapName();
00319 //  DTBufferTree<int,int>* dBuf =
00320 //  DTDataBuffer<int,int>::openBuffer( mName );
00321   DTBufferTree<int,int>** pBuf;
00322   pBuf = const_cast<DTBufferTree<int,int>**>( &dBuf );
00323   *pBuf = new DTBufferTree<int,int>;
00324 
00325   int entryNum = 0;
00326   int entryMax = dataList.size();
00327   std::vector<int> chanKey;
00328   chanKey.reserve(6);
00329   while ( entryNum < entryMax ) {
00330 
00331     const DTPerformanceId& chan = dataList[entryNum].first;
00332 
00333     chanKey.clear();
00334     chanKey.push_back( chan.  wheelId );
00335     chanKey.push_back( chan.stationId );
00336     chanKey.push_back( chan. sectorId );
00337     chanKey.push_back( chan.     slId );
00338     dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
00339 
00340   }
00341 
00342   return;
00343 
00344 }
00345