00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "CondFormats/DTObjects/interface/DTReadOutMapping.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 DTReadOutMapping::DTReadOutMapping():
00035 cellMapVersion( " " ),
00036 robMapVersion( " " ) {
00037 readOutChannelDriftTubeMap.reserve( 12000 );
00038 }
00039
00040
00041 DTReadOutMapping::DTReadOutMapping( const std::string& cell_map_version,
00042 const std::string& rob_map_version ):
00043 cellMapVersion( cell_map_version ),
00044 robMapVersion( rob_map_version ) {
00045 readOutChannelDriftTubeMap.reserve( 12000 );
00046 }
00047
00048
00049 DTReadOutGeometryLink::DTReadOutGeometryLink():
00050 dduId( 0 ),
00051 rosId( 0 ),
00052 robId( 0 ),
00053 tdcId( 0 ),
00054 channelId( 0 ),
00055 wheelId( 0 ),
00056 stationId( 0 ),
00057 sectorId( 0 ),
00058 slId( 0 ),
00059 layerId( 0 ),
00060 cellId( 0 ) {
00061 }
00062
00063
00064
00065
00066 DTReadOutMapping::~DTReadOutMapping() {
00067 DTDataBuffer<int,int>::dropBuffer( mapNameRG() );
00068 DTDataBuffer<int,int>::dropBuffer( mapNameGR() );
00069 }
00070
00071 DTReadOutGeometryLink::~DTReadOutGeometryLink() {
00072 }
00073
00074
00075
00076
00077 int DTReadOutMapping::readOutToGeometry( int dduId,
00078 int rosId,
00079 int robId,
00080 int tdcId,
00081 int channelId,
00082 DTWireId& wireId ) const {
00083
00084 int wheelId;
00085 int stationId;
00086 int sectorId;
00087 int slId;
00088 int layerId;
00089 int cellId;
00090
00091 int status = readOutToGeometry( dduId,
00092 rosId,
00093 robId,
00094 tdcId,
00095 channelId,
00096 wheelId,
00097 stationId,
00098 sectorId,
00099 slId,
00100 layerId,
00101 cellId );
00102
00103 wireId = DTWireId( wheelId, stationId, sectorId, slId, layerId, cellId );
00104 return status;
00105
00106 }
00107
00108 int DTReadOutMapping::readOutToGeometry( int dduId,
00109 int rosId,
00110 int robId,
00111 int tdcId,
00112 int channelId,
00113 int& wheelId,
00114 int& stationId,
00115 int& sectorId,
00116 int& slId,
00117 int& layerId,
00118 int& cellId ) const {
00119
00120 wheelId =
00121 stationId =
00122 sectorId =
00123 slId =
00124 layerId =
00125 cellId = 0;
00126
00127 std::string mNameRG = mapNameRG();
00128 DTBufferTree<int,int>* rgBuf =
00129 DTDataBuffer<int,int>::findBuffer( mNameRG );
00130 if ( rgBuf == 0 ) {
00131 cacheMap();
00132 rgBuf =
00133 DTDataBuffer<int,int>::findBuffer( mNameRG );
00134 }
00135
00136 std::vector<int> chanKey;
00137 chanKey.reserve(5);
00138 chanKey.push_back( dduId );
00139 chanKey.push_back( rosId );
00140 chanKey.push_back( robId );
00141 chanKey.push_back( tdcId );
00142 chanKey.push_back( channelId );
00143 int ientry;
00144 int searchStatus = rgBuf->find( chanKey.begin(), chanKey.end(), ientry );
00145 if ( !searchStatus ) {
00146 const DTReadOutGeometryLink& link( readOutChannelDriftTubeMap[ientry] );
00147 wheelId = link. wheelId;
00148 stationId = link.stationId;
00149 sectorId = link. sectorId;
00150 slId = link. slId;
00151 layerId = link. layerId;
00152 cellId = link. cellId;
00153 }
00154
00155 return searchStatus;
00156
00157 }
00158
00159
00160 int DTReadOutMapping::geometryToReadOut( const DTWireId& wireId,
00161 int& dduId,
00162 int& rosId,
00163 int& robId,
00164 int& tdcId,
00165 int& channelId ) const {
00166 return geometryToReadOut( wireId.wheel(),
00167 wireId.station(),
00168 wireId.sector(),
00169 wireId.superLayer(),
00170 wireId.layer(),
00171 wireId.wire(),
00172 dduId,
00173 rosId,
00174 robId,
00175 tdcId,
00176 channelId);
00177 }
00178
00179
00180 int DTReadOutMapping::geometryToReadOut( int wheelId,
00181 int stationId,
00182 int sectorId,
00183 int slId,
00184 int layerId,
00185 int cellId,
00186 int& dduId,
00187 int& rosId,
00188 int& robId,
00189 int& tdcId,
00190 int& channelId ) const {
00191
00192 dduId =
00193 rosId =
00194 robId =
00195 tdcId =
00196 channelId = 0;
00197
00198 std::string mNameGR = mapNameGR();
00199 DTBufferTree<int,int>* grBuf =
00200 DTDataBuffer<int,int>::findBuffer( mNameGR );
00201 if ( grBuf == 0 ) {
00202 cacheMap();
00203 grBuf =
00204 DTDataBuffer<int,int>::findBuffer( mNameGR );
00205 }
00206
00207 std::vector<int> cellKey;
00208 cellKey.reserve(6);
00209 cellKey.push_back( wheelId );
00210 cellKey.push_back( stationId );
00211 cellKey.push_back( sectorId );
00212 cellKey.push_back( slId );
00213 cellKey.push_back( layerId );
00214 cellKey.push_back( cellId );
00215 int ientry;
00216 int searchStatus = grBuf->find( cellKey.begin(), cellKey.end(), ientry );
00217 if ( !searchStatus ) {
00218 const DTReadOutGeometryLink& link( readOutChannelDriftTubeMap[ientry] );
00219 dduId = link. dduId;
00220 rosId = link. rosId;
00221 robId = link. robId;
00222 tdcId = link. tdcId;
00223 channelId = link.channelId;
00224 }
00225
00226 return searchStatus;
00227
00228 }
00229
00230
00231
00232 const
00233 std::string& DTReadOutMapping::mapCellTdc() const {
00234 return cellMapVersion;
00235 }
00236
00237
00238 std::string& DTReadOutMapping::mapCellTdc() {
00239 return cellMapVersion;
00240 }
00241
00242
00243 const
00244 std::string& DTReadOutMapping::mapRobRos() const {
00245 return robMapVersion;
00246 }
00247
00248
00249 std::string& DTReadOutMapping::mapRobRos() {
00250 return robMapVersion;
00251 }
00252
00253
00254 void DTReadOutMapping::clear() {
00255 DTDataBuffer<int,int>::dropBuffer( mapNameRG() );
00256 DTDataBuffer<int,int>::dropBuffer( mapNameGR() );
00257 readOutChannelDriftTubeMap.clear();
00258 return;
00259 }
00260
00261
00262 int DTReadOutMapping::insertReadOutGeometryLink( int dduId,
00263 int rosId,
00264 int robId,
00265 int tdcId,
00266 int channelId,
00267 int wheelId,
00268 int stationId,
00269 int sectorId,
00270 int slId,
00271 int layerId,
00272 int cellId ) {
00273 DTReadOutGeometryLink link;
00274 link. dduId = dduId;
00275 link. rosId = rosId;
00276 link. robId = robId;
00277 link. tdcId = tdcId;
00278 link.channelId = channelId;
00279 link. wheelId = wheelId;
00280 link.stationId = stationId;
00281 link. sectorId = sectorId;
00282 link. slId = slId;
00283 link. layerId = layerId;
00284 link. cellId = cellId;
00285
00286 int ientry = readOutChannelDriftTubeMap.size();
00287 readOutChannelDriftTubeMap.push_back( link );
00288
00289 std::string mNameRG = mapNameRG();
00290 std::string mNameGR = mapNameGR();
00291
00292 DTBufferTree<int,int>* rgBuf =
00293 DTDataBuffer<int,int>::openBuffer( mNameRG );
00294 DTBufferTree<int,int>* grBuf =
00295 DTDataBuffer<int,int>::openBuffer( mNameGR );
00296
00297 std::vector<int> cellKey;
00298 cellKey.reserve(6);
00299 cellKey.push_back( wheelId );
00300 cellKey.push_back( stationId );
00301 cellKey.push_back( sectorId );
00302 cellKey.push_back( slId );
00303 cellKey.push_back( layerId );
00304 cellKey.push_back( cellId );
00305 int grStatus =
00306 grBuf->insert( cellKey.begin(), cellKey.end(), ientry );
00307 std::vector<int> chanKey;
00308 chanKey.reserve(5);
00309 chanKey.push_back( dduId );
00310 chanKey.push_back( rosId );
00311 chanKey.push_back( robId );
00312 chanKey.push_back( tdcId );
00313 chanKey.push_back( channelId );
00314 int rgStatus =
00315 rgBuf->insert( chanKey.begin(), chanKey.end(), ientry );
00316
00317 if ( grStatus || rgStatus ) return 1;
00318 else return 0;
00319
00320 }
00321
00322
00323 DTReadOutMapping::const_iterator DTReadOutMapping::begin() const {
00324 return readOutChannelDriftTubeMap.begin();
00325 }
00326
00327
00328 DTReadOutMapping::const_iterator DTReadOutMapping::end() const {
00329 return readOutChannelDriftTubeMap.end();
00330 }
00331
00332
00333 std::string DTReadOutMapping::mapNameGR() const {
00334 std::stringstream name;
00335 name << cellMapVersion << "_" << robMapVersion << "_map_GR" << this;
00336 return name.str();
00337 }
00338
00339
00340 std::string DTReadOutMapping::mapNameRG() const {
00341 std::stringstream name;
00342 name << cellMapVersion << "_" << robMapVersion << "_map_RG" << this;
00343 return name.str();
00344 }
00345
00346
00347 void DTReadOutMapping::cacheMap() const {
00348
00349 std::string mNameRG = mapNameRG();
00350 std::string mNameGR = mapNameGR();
00351
00352 DTBufferTree<int,int>* rgBuf =
00353 DTDataBuffer<int,int>::openBuffer( mNameRG );
00354 DTBufferTree<int,int>* grBuf =
00355 DTDataBuffer<int,int>::openBuffer( mNameGR );
00356
00357 int entryNum = 0;
00358 int entryMax = readOutChannelDriftTubeMap.size();
00359 std::vector<int> cellKey;
00360 cellKey.reserve(6);
00361 std::vector<int> chanKey;
00362 chanKey.reserve(5);
00363 while ( entryNum < entryMax ) {
00364
00365 const DTReadOutGeometryLink& link( readOutChannelDriftTubeMap[entryNum] );
00366
00367 cellKey.clear();
00368 cellKey.push_back( link. wheelId );
00369 cellKey.push_back( link.stationId );
00370 cellKey.push_back( link. sectorId );
00371 cellKey.push_back( link. slId );
00372 cellKey.push_back( link. layerId );
00373 cellKey.push_back( link. cellId );
00374
00375 grBuf->insert( cellKey.begin(), cellKey.end(), entryNum );
00376
00377 chanKey.clear();
00378 chanKey.push_back( link. dduId );
00379 chanKey.push_back( link. rosId );
00380 chanKey.push_back( link. robId );
00381 chanKey.push_back( link. tdcId );
00382 chanKey.push_back( link.channelId );
00383
00384 rgBuf->insert( chanKey.begin(), chanKey.end(), entryNum );
00385
00386 entryNum++;
00387
00388 }
00389
00390 return;
00391
00392 }
00393