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