CMS 3D CMS Logo

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