34 #include "StETofHardwareMap.h"
35 #include "StMessMgr.h"
37 #include "tables/St_etofElectronicsMap_Table.h"
40 StETofHardwareMap::StETofHardwareMap( St_etofElectronicsMap* etofElectronicsMap,
unsigned int year )
44 mOrderedPlanes.push_back( 2 );
45 mOrderedPlanes.push_back( 1 );
46 mOrderedPlanes.push_back( 3 );
48 init( etofElectronicsMap );
51 StETofHardwareMap::StETofHardwareMap( std::string fileName,
unsigned int year )
55 mOrderedPlanes.push_back( 2 );
56 mOrderedPlanes.push_back( 1 );
57 mOrderedPlanes.push_back( 3 );
63 StETofHardwareMap::~StETofHardwareMap()
69 StETofHardwareMap::init( St_etofElectronicsMap* etofElectronicsMap )
71 LOG_INFO <<
"StETofHardwareMap -- initializing eTOF electronics to hardware mapping via database" << endm;
74 if( !etofElectronicsMap ) {
75 LOG_ERROR <<
"StETofHardwareMap -- unable to get the electronics map from the database" << endm;
79 etofElectronicsMap_st* table = etofElectronicsMap->GetTable();
82 LOG_DEBUG <<
"nAfcks: " << ( int ) table->nAfcks << endm;
83 LOG_DEBUG <<
"nChannels: " << table->nChannels << endm;
85 for(
size_t i=0; i<12; i++ ) {
86 LOG_DEBUG <<
"AFCK address: 0x" << std::hex << table->afckAddress[ i ] << std::dec <<
" --> sector: " << ( int ) table->sector[ i ] << endm;
89 for(
size_t i=0; i<576; i++ ) {
90 LOG_DEBUG <<
"channelNumber: " << table->channelNumber[ i ] <<
" --> geometryId: " << table->geometryId[ i ] << endm;
95 for(
size_t i=0; i<12; i++ ) {
96 if( table->sector[ i ] != 0 ) {
97 mAfckToSector.push_back( table->sector[ i ] );
98 mAfckAddressMap[ table->afckAddress[ i ] ] = i;
102 for(
size_t i=0; i<576; i++ ) {
103 mChannelNumberMap[ table->channelNumber[ i ] ] = table->geometryId[ i ];
106 LOG_INFO <<
"StETofHardwareMap -- initialization finished" << endm;
111 StETofHardwareMap::init( std::string fileName )
113 LOG_INFO <<
"StETofHardwareMap -- initializing eTOF electronics to hardware mapping via local parameter file" << endm;
116 std::ifstream paramFile;
118 if( fileName.empty() ) {
119 LOG_ERROR <<
"StETofHardwareMap -- local file name is empty" << endm;
122 LOG_INFO <<
"StETofHardwareMap -- local file for electronics to hardware mapping: " << fileName << endm;
124 paramFile.open( fileName.c_str() );
126 if( !paramFile.is_open() ) {
127 LOG_ERROR <<
"StETofHardwareMap -- unable to get the parameters from local file --> file does not exist" << endm;
131 unsigned int nAfcks = 0;
132 unsigned int nChannels = 0;
133 std::vector< unsigned int > afckAddress;
134 std::vector< unsigned int > sector;
135 std::vector< unsigned int > channelNumber;
136 std::vector< unsigned int > geometryId;
140 if( !paramFile.eof() ) {
143 if( !paramFile.eof() ) {
144 paramFile >> nChannels;
149 for(
int i=0; i<12; i++ ) {
150 if( !paramFile.eof() ) {
151 paramFile >> std::hex >> temp;
152 afckAddress.push_back( temp );
156 for(
int i=0; i<12; i++ ) {
157 if( !paramFile.eof() ) {
158 paramFile >> std::dec >> temp;
159 sector.push_back( temp );
162 for(
int i=0; i<576; i++ ) {
163 if( !paramFile.eof() ) {
164 paramFile >> std::dec >> temp;
165 channelNumber.push_back( temp );
169 for(
int i=0; i<576; i++ ) {
170 if( !paramFile.eof() ) {
171 paramFile >> std::dec >> temp;
172 geometryId.push_back( temp );
178 if( !paramFile.eof() || nAfcks == 0 || nChannels == 0 ||
179 afckAddress.size() != 12 || sector.size() != 12 ||
180 channelNumber.size() != 576 || geometryId.size() != 576 )
182 LOG_ERROR <<
"StETofHardwareMap -- parameter file has not the right amount of entries !!!!" << endm;
188 LOG_DEBUG <<
"nAfcks: " << nAfcks << endm;
189 LOG_DEBUG <<
"nChannels: " << nChannels << endm;
191 for(
size_t i=0; i<12; i++ ) {
192 LOG_DEBUG <<
"AFCK address: 0x" << std::hex << afckAddress[ i ] << std::dec <<
" --> sector: " << sector.at( i ) << endm;
195 for(
size_t i=0; i<576; i++ ) {
196 LOG_DEBUG <<
"channelNumber: " << channelNumber.at( i ) <<
" --> geometryId: " << geometryId.at( i ) << endm;
201 for(
size_t i=0; i<12; i++ ) {
202 if( sector.at( i ) != 0 ) {
203 mAfckToSector.push_back( sector.at( i ) );
205 mAfckAddressMap[ afckAddress.at( i ) ] = i;
209 for(
size_t i=0; i<576; i++ ) {
210 mChannelNumberMap[ channelNumber.at( i ) ] = geometryId.at( i );
213 LOG_INFO <<
"StETofHardwareMap -- initialization finished" << endm;
218 StETofHardwareMap::mapToGeom(
unsigned int rocId,
unsigned int chipId,
unsigned int chanId, std::vector< unsigned int >& geomVec )
223 if( mAfckAddressMap.count( rocId ) == 0 ) {
224 LOG_INFO <<
"StETofHardwareMap::Map - rocId is out of range: 0x" << std::hex << rocId << std::dec << endm;
228 unsigned int rocIndex = mAfckAddressMap.at( rocId );
229 unsigned int channel = chipId * 10 + chanId;
231 if( mYear == 2018 ) {
232 channel += rocIndex * 1000;
236 if( mChannelNumberMap.count( channel ) == 0 ) {
237 LOG_INFO <<
"StETofHardwareMap::Map - channel is out of range: chipId " << chipId <<
" chanId " << chanId << endm;
242 unsigned int sector = mAfckToSector.at( rocIndex );
243 unsigned int geometryId = mChannelNumberMap.at( channel );
245 if( geometryId == 0 ) {
246 LOG_INFO <<
"chipId: " << chipId <<
" chanId: " << chanId <<
" -> channel: " << channel <<
" --> geometryId: " << geometryId << endm;
250 geomVec.push_back( sector );
251 geomVec.push_back( geometryId / 10000 );
252 geomVec.push_back( ( geometryId % 10000 ) / 1000 );
253 geomVec.push_back( ( geometryId % 1000 ) / 10 );
254 geomVec.push_back( geometryId % 10 );
260 StETofHardwareMap::mapToSector(
unsigned int rocId,
unsigned int& sector )
264 if( mAfckAddressMap.count( rocId ) == 0 ) {
265 LOG_INFO <<
"StETofHardwareMap::Map - rocId is out of range: 0x" << std::hex << rocId << std::dec << endm;
269 unsigned int rocIndex = mAfckAddressMap.at( rocId );
271 sector = mAfckToSector.at( rocIndex );
278 StETofHardwareMap::module(
unsigned int sector,
unsigned int plane )
280 return ( sector - 13 ) * 3 + mOrderedPlanes[ plane - 1 ];