10 #include "StMessMgr.h"
11 #include "StEvent/StFttRawHit.h"
12 #include "StEvent/StFttCluster.h"
13 #include "StEvent/StFttPoint.h"
16 #include "tables/St_fttHardwareMap_Table.h"
17 #include "tables/St_fttDataWindows_Table.h"
23 double
StFttDb::stripPitch = 3.2;
24 double StFttDb::rowLength = 180;
25 double StFttDb::lowerQuadOffsetX = 101.6;
26 double StFttDb::idealPlaneZLocations[] = { 280.90499, 303.70498, 326.60501, 349.40499 };
28 vector<string> StFttDb::orientationLabels = {
"Horizontal",
"Vertical",
"DiagonalH",
"DiagonalV",
"Unknown" };
31 StFttDb::StFttDb(
const char *name) :
TDataSet(name) {};
33 StFttDb::~StFttDb() {}
43 int StFttDb::InitRun(
int runNumber) {
58 size_t _uuid = (size_t)h->orientation() + (nStripOrientations) * ( h->row() + nRowsPerQuad * ( h->quadrant() + nQuadPerPlane * h->plane() ) );
61 _uuid = (size_t) h->strip() * maxStripPerRow *( h->orientation() + (nStripOrientations) * ( h->row() + nRowsPerQuad * ( h->quadrant() + nQuadPerPlane * h->plane() ) ) );
71 size_t _uuid = (size_t)c->orientation() + (nStripOrientations) * ( c->row() + nRowsPerQuad * ( c->quadrant() + nQuadPerPlane * c->plane() ) );
76 uint16_t StFttDb::packKey(
int feb,
int vmm,
int ch )
const{
80 return feb + (vmm << 3) + (ch << 6);
82 void StFttDb::unpackKey(
int key,
int &feb,
int &vmm,
int &ch )
const{
84 vmm = (key >> 3) & 0b111;
85 ch = (key >> 6) & 0b1111111;
88 uint16_t StFttDb::packVal(
int row,
int strip )
const{
91 return row + ( strip << 3 );
93 void StFttDb::unpackVal(
int val,
int &row,
int &strip )
const{
95 strip = (val >> 3) & 0b11111111;
99 void StFttDb::loadDataWindowsFromDb( St_fttDataWindows * dataset ) {
101 Int_t rows = dataset->GetNRows();
107 fttDataWindows_st *table = dataset->GetTable();
108 for (Int_t i = 0; i < rows; i++) {
109 for (
int j = 0; j < StFttDb::nVMM; j++ ) {
118 fdw.uuid = table[i].uuid[j];
119 fdw.mode = table[i].mode[j];
120 fdw.min = table[i].min[j];
121 fdw.max = table[i].max[j];
122 fdw.anchor = table[i].anchor[j];
123 dwMap[ fdw.uuid ] = fdw;
131 std::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
135 void StFttDb::loadDataWindowsFromFile( std::string fn ) {
141 void StFttDb::loadHardwareMapFromDb( St_fttHardwareMap * dataset ) {
143 Int_t rows = dataset->GetNRows();
145 std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
151 fttHardwareMap_st *table = dataset->GetTable();
152 for (Int_t i = 0; i < rows; i++) {
153 for (
int j = 0; j < 1250; j++ ) {
154 uint16_t key = packKey( table[i].feb[j], table[i].vmm[j], table[i].vmm_ch[j] );
155 uint16_t val = packVal( table[i].row[j], table[i].strip[j] );
162 std::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
167 void StFttDb::loadHardwareMapFromFile( std::string fn ){
169 inf.open( fn.c_str() );
173 LOG_WARN <<
"sTGC Hardware map file not found" << endm;
178 string hs0, hs1, hs2, hs3, hs4;
181 inf >> hs0 >> hs1 >> hs2 >> hs3 >> hs4;
184 printf(
"Map Header: %s, %s, %s, %s, %s", hs0.c_str(), hs1.c_str(), hs2.c_str(), hs3.c_str(), hs4.c_str() );
188 uint16_t row, feb, vmm, ch, strip;
189 while( inf >> row >> feb >> vmm >> ch >> strip ){
191 uint16_t key = packKey( feb, vmm, ch );
192 uint16_t val = packVal( row, strip );
196 printf(
"key=%d", key );
197 printf(
"in=(feb=%d, vmm=%d, ch=%d)\n", feb, vmm, ch );
199 unpackKey( key, ufeb, uvmm, uch );
200 printf(
"key=(feb=%d, vmm=%d, ch=%d)\n", ufeb, uvmm, uch ); puts(
"");
201 assert( feb == ufeb && vmm == uvmm && ch == uch );
203 printf(
"val=%d", val );
204 unpackVal( val, urow, ustrip );
205 assert( row == urow && strip == ustrip );
206 printf(
"(row=%d, strip=%d)\n", row, strip );
221 UChar_t StFttDb::getOrientation(
int rob,
int feb,
int vmm,
int row )
const {
223 printf(
"getOrientation( %d, %d, %d, %d )", rob, feb, vmm, row ); puts(
"");
227 if ( feb % 2 != 0 ) {
229 if ( 3 == row || 4 == row )
230 return kFttDiagonalH;
231 return kFttHorizontal;
234 if ( 3 == row || 4 == row )
235 return kFttDiagonalV;
240 if ( feb % 2 != 0 ) {
242 if ( 3 == row || 4 == row )
243 return kFttDiagonalV;
247 if ( 3 == row || 4 == row )
248 return kFttDiagonalH;
250 return kFttHorizontal;
253 return kFttUnknownOrientation;
271 bool StFttDb::hardwareMap(
int rob,
int feb,
int vmm,
int ch,
int &row,
int &strip, UChar_t &orientation )
const{
272 uint16_t key = packKey( feb, vmm, ch );
273 if ( mMap.count( key ) ){
274 uint16_t val = mMap.at( key );
275 unpackVal( val, row, strip );
276 orientation = getOrientation( rob, feb, vmm, row );
283 uint16_t key = packKey( hit->feb()+1, hit->vmm()+1, hit->channel() );
284 if ( mMap.count( key ) ){
285 uint16_t val = mMap.at( key );
286 int row=-1, strip=-1;
287 unpackVal( val, row, strip );
289 u_char iPlane = hit->sector() - 1;
290 u_char iQuad = hit->rdo() - 1;
291 int rob = iQuad + ( iPlane *nQuadPerPlane ) + 1;
293 UChar_t orientation = getOrientation( rob, hit->feb()+1, hit->vmm()+1, row );
294 hit->setMapping( iPlane, iQuad, row, strip, orientation );
302 if ( hit->plane() < nPlane )
304 return hit->sector() - 1;
308 if ( hit->quadrant() < nQuad )
309 return hit->quadrant();
310 return hit->rdo() - 1;
314 return quadrant(hit) + ( plane(hit) * nQuadPerPlane ) + 1;
318 return clu->quadrant() + ( clu->plane() * StFttDb::nQuadPerPlane );
322 return hit->feb() + ( quadrant( hit ) * nFobPerQuad ) + ( plane(hit) * nFobPerPlane ) + 1;
326 if ( hit->orientation() < kFttUnknownOrientation ){
327 return hit->orientation();
329 return kFttUnknownOrientation;
332 void StFttDb::getGloablOffset( UChar_t plane, UChar_t quad,
333 float &dx,
float &sx,
334 float &dy,
float &sy,
335 float &dz,
float &sz ){
351 dz = StFttDb::idealPlaneZLocations[plane];
356 else if ( quad == 1 )
357 dx = StFttDb::lowerQuadOffsetX;
358 else if ( quad == 2 )
359 dx = StFttDb::lowerQuadOffsetX;
360 else if ( quad == 3 )
366 else if ( quad == 2 ){
369 }
else if ( quad == 3 )
void setRun(int run)
enable(1) or disable(0) offline DB access
void setDbAccess(int v=1)
debug level
static size_t uuid(StFttRawHit *h, bool includeStrip=false)
set run#