00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "CondFormats/DTObjects/interface/DTT0.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 DTT0::DTT0():
00035 dataVersion( " " ),
00036 nsPerCount( 25.0 / 32.0 ) {
00037 dataList.reserve( 12000 );
00038 }
00039
00040
00041 DTT0::DTT0( const std::string& version ):
00042 dataVersion( version ),
00043 nsPerCount( 25.0 / 32.0 ) {
00044 dataList.reserve( 12000 );
00045 }
00046
00047
00048 DTT0Id::DTT0Id() :
00049 wheelId( 0 ),
00050 stationId( 0 ),
00051 sectorId( 0 ),
00052 slId( 0 ),
00053 layerId( 0 ),
00054 cellId( 0 ) {
00055 }
00056
00057
00058 DTT0Data::DTT0Data() :
00059 t0mean( 0.0 ),
00060 t0rms( 0.0 ) {
00061 }
00062
00063
00064
00065
00066
00067 DTT0::~DTT0() {
00068 DTDataBuffer<int,int>::dropBuffer( mapName() );
00069 }
00070
00071
00072 DTT0Id::~DTT0Id() {
00073 }
00074
00075
00076 DTT0Data::~DTT0Data() {
00077 }
00078
00079
00080
00081
00082
00083 int DTT0::get( int wheelId,
00084 int stationId,
00085 int sectorId,
00086 int slId,
00087 int layerId,
00088 int cellId,
00089 float& t0mean,
00090 float& t0rms,
00091 DTTimeUnits::type unit ) const {
00092
00093 t0mean =
00094 t0rms = 0.0;
00095
00096 std::string mName = mapName();
00097 DTBufferTree<int,int>* dBuf =
00098 DTDataBuffer<int,int>::findBuffer( mName );
00099 if ( dBuf == 0 ) {
00100 cacheMap();
00101 dBuf =
00102 DTDataBuffer<int,int>::findBuffer( mName );
00103 }
00104
00105 std::vector<int> chanKey;
00106 chanKey.reserve(6);
00107 chanKey.push_back( wheelId );
00108 chanKey.push_back( stationId );
00109 chanKey.push_back( sectorId );
00110 chanKey.push_back( slId );
00111 chanKey.push_back( layerId );
00112 chanKey.push_back( cellId );
00113 int ientry;
00114 int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00115 if ( !searchStatus ) {
00116 const DTT0Data& data( dataList[ientry].second );
00117 t0mean = data.t0mean;
00118 t0rms = data.t0rms;
00119 if ( unit == DTTimeUnits::ns ) {
00120 t0mean *= nsPerCount;
00121 t0rms *= nsPerCount;
00122 }
00123 }
00124
00125 return searchStatus;
00126
00127 }
00128
00129
00130 int DTT0::get( const DTWireId& id,
00131 float& t0mean,
00132 float& t0rms,
00133 DTTimeUnits::type unit ) const {
00134 return get( id.wheel(),
00135 id.station(),
00136 id.sector(),
00137 id.superLayer(),
00138 id.layer(),
00139 id.wire(),
00140 t0mean, t0rms, unit );
00141 }
00142
00143
00144 float DTT0::unit() const {
00145 return nsPerCount;
00146 }
00147
00148
00149 const
00150 std::string& DTT0::version() const {
00151 return dataVersion;
00152 }
00153
00154
00155 std::string& DTT0::version() {
00156 return dataVersion;
00157 }
00158
00159
00160 void DTT0::clear() {
00161 DTDataBuffer<int,int>::dropBuffer( mapName() );
00162 dataList.clear();
00163 return;
00164 }
00165
00166
00167 int DTT0::set( int wheelId,
00168 int stationId,
00169 int sectorId,
00170 int slId,
00171 int layerId,
00172 int cellId,
00173 float t0mean,
00174 float t0rms,
00175 DTTimeUnits::type unit ) {
00176
00177 if ( unit == DTTimeUnits::ns ) {
00178 t0mean /= nsPerCount;
00179 t0rms /= nsPerCount;
00180 }
00181
00182 std::string mName = mapName();
00183 DTBufferTree<int,int>* dBuf =
00184 DTDataBuffer<int,int>::findBuffer( mName );
00185 if ( dBuf == 0 ) {
00186 cacheMap();
00187 dBuf =
00188 DTDataBuffer<int,int>::findBuffer( mName );
00189 }
00190 std::vector<int> chanKey;
00191 chanKey.reserve(6);
00192 chanKey.push_back( wheelId );
00193 chanKey.push_back( stationId );
00194 chanKey.push_back( sectorId );
00195 chanKey.push_back( slId );
00196 chanKey.push_back( layerId );
00197 chanKey.push_back( cellId );
00198 int ientry;
00199 int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
00200
00201 if ( !searchStatus ) {
00202 DTT0Data& data( dataList[ientry].second );
00203 data.t0mean = t0mean;
00204 data.t0rms = t0rms;
00205 return -1;
00206 }
00207 else {
00208 DTT0Id key;
00209 key. wheelId = wheelId;
00210 key.stationId = stationId;
00211 key. sectorId = sectorId;
00212 key. slId = slId;
00213 key. layerId = layerId;
00214 key. cellId = cellId;
00215 DTT0Data data;
00216 data.t0mean = t0mean;
00217 data.t0rms = t0rms;
00218 ientry = dataList.size();
00219 dataList.push_back( std::pair<const DTT0Id,DTT0Data>( key, data ) );
00220 dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
00221 return 0;
00222 }
00223
00224 return 99;
00225
00226 }
00227
00228
00229 int DTT0::set( const DTWireId& id,
00230 float t0mean,
00231 float t0rms,
00232 DTTimeUnits::type unit ) {
00233 return set( id.wheel(),
00234 id.station(),
00235 id.sector(),
00236 id.superLayer(),
00237 id.layer(),
00238 id.wire(),
00239 t0mean, t0rms, unit );
00240 }
00241
00242
00243 void DTT0::setUnit( float unit ) {
00244 nsPerCount = unit;
00245 }
00246
00247
00248 DTT0::const_iterator DTT0::begin() const {
00249 return dataList.begin();
00250 }
00251
00252
00253 DTT0::const_iterator DTT0::end() const {
00254 return dataList.end();
00255 }
00256
00257
00258 std::string DTT0::mapName() const {
00259 std::stringstream name;
00260 name << dataVersion << "_map_T0" << this;
00261 return name.str();
00262 }
00263
00264
00265 void DTT0::cacheMap() const {
00266
00267 std::string mName = mapName();
00268 DTBufferTree<int,int>* dBuf =
00269 DTDataBuffer<int,int>::openBuffer( mName );
00270
00271 int entryNum = 0;
00272 int entryMax = dataList.size();
00273 std::vector<int> chanKey;
00274 chanKey.reserve(6);
00275 while ( entryNum < entryMax ) {
00276
00277 const DTT0Id& chan = dataList[entryNum].first;
00278
00279 chanKey.clear();
00280 chanKey.push_back( chan. wheelId );
00281 chanKey.push_back( chan.stationId );
00282 chanKey.push_back( chan. sectorId );
00283 chanKey.push_back( chan. slId );
00284 chanKey.push_back( chan. layerId );
00285 chanKey.push_back( chan. cellId );
00286 dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
00287
00288 }
00289
00290 return;
00291
00292 }
00293