10 #include "St_db_Maker/St_db_Maker.h"
12 #include "StSpinDbMaker.h"
14 #include "tables/St_spinDbV124_Table.h"
15 #include "tables/St_spinDbStar_Table.h"
16 #include "tables/St_spinDbBXmask_Table.h"
18 #include <StMessMgr.h>
25 gMessMgr->Message(
"",
"D") <<GetName()<<endm;
26 setDBname(
"Calibrations/rhic");
34 StSpinDbMaker::~StSpinDbMaker(){
43 StSpinDbMaker::Init(){
44 return StMaker::Init();
51 StSpinDbMaker::clearTables(){
58 for(i=0;i<SPINDbMaxBXings;i++) {
63 for(i=0;i<SPINDbMaxRing;i++) mNfilledBunches[i]=-2;
64 mCADpolPattern=
"noLabel";
72 LOG_INFO <<
GetName()<<
"::InitRun= " <<runNumber <<endm;
81 LOG_DEBUG <<
GetName()<<
"::InitRun() nFound "<< mNFound<<
" SPIN related tables "<<endm;
83 return StMaker::InitRun(runNumber);
90 void StSpinDbMaker::requestDataBase(){
92 LOG_DEBUG <<Form (
"%s::reloadDb using TimeStamp from 'StarDb'=%p or 'db'=%p ",
GetName(),(
void*)GetMaker(
"StarDb"),(
void*)GetMaker(
"db"))<<endm;
98 mDbDate = stdb->GetDateTime().GetDate();
102 LOG_INFO <<
GetName()<<
"::RequestDataBase(),\n event time stamp="<< (int)fEvtHddr->GetUTime()<<
" , yyyy/mm/dd="<< fEvtHddr->GetDate()<<
" hh/mm/ss="<<fEvtHddr->GetTime()<<endm;
104 LOG_DEBUG <<
GetName()<<
"::RequestDataBase(), access DB='"<<mDbName<<
"' use timeStamp="<< stdb->GetDateTime().AsString()<<endm;
106 TDataSet *spindb=GetDataBase(mDbName );
108 LOG_ERROR <<
GetName()<<
"::RequestDataBase() Could not find dbName ="<<mDbName <<endm;
113 getTable<St_spinDbV124,spinDbV124_st>(spindb,
"spinV124",&mTabSpinV124);
114 getTable<St_spinDbStar,spinDbStar_st>(spindb,
"spinStar",&mTabSpinStar);
115 getTable<St_spinDbBXmask,spinDbBXmask_st>(spindb,
"spinBXmask",&mTabSpinBXmask);
126 void StSpinDbMaker::optimizeTables (){
137 const int nibZ=9, nibP=3, nibN=5, nibE=0;
141 int nP2=0,nP1=0,nP0=0,nPer=0;
142 for(bx=0;bx<SPINDbMaxBXings;bx++){
145 int bBucket=(bx*3+mTabSpinV124->bucketOffset[blueRing])%SPINDbMaxBuckets;
146 if(bBucket<0) bBucket+=SPINDbMaxBuckets;
148 int yBucket=(bx*3+mTabSpinV124->bucketOffset[yellRing])%SPINDbMaxBuckets;
151 int yNib=mTabSpinV124->v124bits[yBucket]&0x0f;
152 int bNib=mTabSpinV124->v124bits[bBucket]>>4;
154 int spin8=(bNib<<4) + yNib;
158 if( (yNib==nibZ && bNib==nibZ) || (yNib==nibE && bNib==nibE) )
160 else if ( yNib==nibE && bNib==nibP ) spin4=4;
161 else if ( yNib==nibE && bNib==nibN ) spin4=8;
162 else if ( yNib==nibP && bNib==nibE ) spin4=1;
163 else if ( yNib==nibP && bNib==nibP ) spin4=5;
164 else if ( yNib==nibN && bNib==nibP ) spin4=6;
165 else if ( yNib==nibN && bNib==nibE ) spin4=2;
166 else if ( yNib==nibP && bNib==nibN ) spin4=9;
167 else if ( yNib==nibN && bNib==nibN ) spin4=10;
172 case 0: nP0++;
break;
190 string polDir=
"scrambled";
194 LOG_INFO<<
GetName()<<
"::InitRun mOptimized() "<<
195 " nFillBunch blue="<<numberOfFilledBunchesBlue()<<
" yellow="<<numberOfFilledBunchesYellow()<<
", CAD pol pattern="<<mCADpolPattern<<
196 "\n polDir="<<polDir<<
197 " bXing w/ pol2="<<nP2<<
" pol1="<<nP1<<
" unPol="<<nP0<<
" errPol="<<nPer<<endm;
218 template <
class St_T,
class T_st>
void
219 StSpinDbMaker::getTable(
TDataSet *mydb, TString tabName, T_st** outTab ){
225 sprintf(name,
"%s",tabName.Data());
227 gMessMgr->Message(
"",
"D") <<
GetName()<<
"::InitRun request="<< name <<endm;
229 St_T *ds= (St_T *)mydb->
Find(name);
231 gMessMgr->Message(
"",
"W") <<
GetName()<<
"::InitRun table='"<< name <<
"' not Found in DB, continue "<<endm;
235 if(ds->GetNRows()!=1) {
236 gMessMgr->Message(
"",
"W") <<
GetName()<<
"::InitRun table='"<< name <<
"' no records, continue "<<endm;
240 *outTab=(T_st *) ds->GetArray();
243 LOG_WARN<<
" GetArray() failed"<<endm;
248 gMessMgr->Message(
"",
"I") <<
GetName()<<
"::table '"<< name <<
"': "<<(*outTab)->comment<<endm;
258 StSpinDbMaker::isPolDir(spinDbEnum polDir){
259 if(!mTabSpinV124)
return false;
263 for(i=0;i<SPINDbMaxRing;i++)
264 if(mTabSpinV124->rotatorState[i]!=polDir)
return false;
273 if(bx48<0 || bx48>=SPINDbMaxBXings)
return -1;
274 int bx=(bx48+mTabSpinStar->bXoff48)%SPINDbMaxBXings;
284 if(bx7<0 || bx7>=SPINDbMaxBXings)
return -1;
285 int bx=(bx7+mTabSpinStar->bXoff7)%SPINDbMaxBXings;
294 if(bx48<0 || bx48>=SPINDbMaxBXings)
return -1;
295 int bx=(bx48+mTabSpinStar->bXoff48)%SPINDbMaxBXings;
302 StSpinDbMaker:: spin8usingBX7(
int bx7){
304 if(bx7<0 || bx7>=SPINDbMaxBXings)
return -1;
305 int bx=(bx7+mTabSpinStar->bXoff7)%SPINDbMaxBXings;
314 return mTabSpinStar->bXoff48;
322 if(bx48<0 || bx48>=SPINDbMaxBXings)
return false;
323 int bx=(bx48+mTabSpinStar->bXoff48)%SPINDbMaxBXings;
333 if(bx<0 || bx>=SPINDbMaxBXings)
return false;
343 if(bx48<0 || bx48>=SPINDbMaxBXings)
return -1;
344 return (bx48+mTabSpinStar->bXoff48)%SPINDbMaxBXings;
350 StSpinDbMaker::BXstarUsingBX48(
int bx48){
352 if(bx48<0 || bx48>=SPINDbMaxBXings)
return -1;
353 return (bx48+mTabSpinStar->bXoff48)%SPINDbMaxBXings;
360 StSpinDbMaker:: isMaskedUsingBX48(
int bx48){
362 if(bx48<0 || bx48>=SPINDbMaxBXings)
return true;
363 int bxStar= BXstarUsingBX48(bx48);
364 return mTabSpinBXmask->bXmask[bxStar];
371 StSpinDbMaker::offsetBX48minusBX7(
int bx48,
int bx7){
373 int bxa=BXstarUsingBX48(bx48);
375 if(bxa<0 || bxb<0)
return -1;
377 if(diff<0) diff+=SPINDbMaxBXings;
386 if(bxStar<0 || bxStar>=SPINDbMaxBXings)
return false;
387 return ((
spin8bits[bxStar] & 0x11)==0x11);
394 StSpinDbMaker::isBXmaskedUsingBXyellow(
int bxStar){
396 if(bxStar<0 || bxStar>=SPINDbMaxBXings)
return true;
397 return mTabSpinBXmask->bXmask[bxStar];
409 const unsigned char *
411 return mTabSpinV124->v124bits;
418 return mTabSpinV124->bucketOffset;
434 return mTabSpinStar->bXoff7;
443 if(bx7<0 || bx7>=SPINDbMaxBXings)
return -1;
444 return (bx7+mTabSpinStar->bXoff7)%SPINDbMaxBXings;
452 if(bx7<0 || bx7>=SPINDbMaxBXings)
return -1;
453 return (bx7+mTabSpinStar->bXoff7)%SPINDbMaxBXings;
459 const char* StSpinDbMaker::getV124comment(){
460 return mTabSpinV124->comment;}
466 printf(
"SpinDb::print(level=%d) ...isValid=%d \n",level,
isValid());
468 printf(
" SpinDb not loaded or some tables not found, nFound=%d \n spinDB will not work if InitRun() was executed !!!\n\n",mNFound);
475 printf(
" spinDB: bXing offset: off7=%d off48=%d\n",mTabSpinStar->bXoff7,mTabSpinStar->bXoff48);
477 printf(
"DB records labels:\n V124: %s \n BXoffset: %s\n BXmask: %s\n\n",mTabSpinV124->comment,mTabSpinStar->comment,mTabSpinBXmask->comment);
478 printf(
"dump of spin bits @ STAR IP, for 120 bXings, range [0,119]\n");
481 printf(
"bXstar spin8 spin4(dec) filled? masked? bx48 blueBx yellBx\n");
484 int bx48=bx%SPINDbMaxBXings;
485 int bXstar=BXstarUsingBX48(bx48);
490 const char *ftt=
"empty ";
492 const char *mtt=
"use ";
493 if(isMaskedUsingBX48(bx48))mtt=
"*mask*";
494 printf(
" %3d 0x%02x %2d %6s %6s %3d %3d %3d\n",bXstar,spin8,spin4,ftt,mtt,bx48,blueBx,yellBx);
501 printf(
"dump raw V124 spin bits:\n time bucket, spin8(hex)\n");
502 for(j=0;j<SPINDbMaxBuckets;j++)
505 printf(
"dump raw bXing mask \n STAR bXing mask (0=use, none-0=drop)\n");
506 for(j=0;j<SPINDbMaxBXings;j++)
507 printf(
"%3d %d\n",j,mTabSpinBXmask->bXmask[j]);
513 StSpinDbMaker::numberOfFilledBunches(
enum spinDbEnum iby) {
515 return mNfilledBunches[iby];
521 StSpinDbMaker::auxilairyVariables(){
522 int sumF[SPINDbMaxRing]={0,0};
523 TString patt[SPINDbMaxRing];
527 for (i=0;i<SPINDbMaxBXings;i++ ) {
529 for(iby=0;iby<SPINDbMaxRing;iby++) {
531 case blueRing: nib=mTabSpinV124->v124bits[i*3]>>4;
break;
532 case yellRing: nib=mTabSpinV124->v124bits[i*3]&0x0f;
break;
533 default: assert(1==2);
535 if (! nib&0x01)
continue;
540 case 0x01: patt[iby]+=
"+";
break;
541 case 0x02: patt[iby]+=
"-";
break;
542 case 0x04: patt[iby]+=
"0";
break;
543 default: patt[iby]+=
"?";
550 for(i=0;i<SPINDbMaxRing;i++) mNfilledBunches[i]=sumF[i];
553 int year=mDbDate/10000;
554 mCADpolPattern=
""; mCADpolPattern+=year; mCADpolPattern+=
"_";
558 if(patt[blueRing].BeginsWith(
"+-+-") && patt[yellRing].BeginsWith(
"++--"))
559 { mCADpolPattern+=
"p1";
break; }
560 if(patt[blueRing].BeginsWith(
"-+-+") && patt[yellRing].BeginsWith(
"++--"))
561 { mCADpolPattern+=
"p2";
break; }
562 if(patt[blueRing].BeginsWith(
"+-+-") && patt[yellRing].BeginsWith(
"--++"))
563 { mCADpolPattern+=
"p3";
break; }
564 if(patt[blueRing].BeginsWith(
"-+-+") && patt[yellRing].BeginsWith(
"--++"))
565 { mCADpolPattern+=
"p4";
break; }
567 mCADpolPattern+=
"noLabel";
570 LOG_DEBUG <<
GetName()<<
"::auxilairyVariables()" <<
571 Form(
" dbDate=%d, CADpattern=%s\n Blue=%s\n Yell=%s, \n", mDbDate,mCADpolPattern.Data(), patt[blueRing].Data(), patt[yellRing].Data())<<endm;
bool isBXfilledUsingInternalBX(int bx)
defined only for 2005 run by CAD , based on first 4 filled bunches in both rings. Note...
bool isPolDirTrans()
true if all needed DB tables were found
bool isValid()
dump spinDb content for current time stamp
int spin4bits[SPINDbMaxBXings]
vs. STAR==yellow bXing
int spin8usingBX48(int bx48)
Returns true if beams are longitudinally polarized, false otherwise.
bool isBXfilledUsingBX48(int bx48)
STAR==yellow bXing=(bx48+48off)%120.
bool isBXfilledUsingBXyellow(int bxStar)
should be zero for every run
virtual Int_t InitRun(int runumber)
to access STAR-DB
int spin4usingBX48(int bx48)
8bit spin information
int spin4usingBX7(int bx7)
8bit spin information
int BXyellowUsingBX7(int bx7)
4bit spin information
int BX7offset()
bXing at STAR IP, [0,119]
void print(int level=0)
vs. STAR==yellow bXing
int BXyellowUsingBX48(int bx48)
4bit spin information
const unsigned char * getRawV124bits()
bXing at STAR IP, [0,119]
virtual const char * GetName() const
special overload
int BX48offset()
bXing at STAR IP, [0,119]
int BXstarUsingBX7(int bx7)
bXing at STAR IP, [0,119]
int spin8bits[SPINDbMaxBXings]
defined at cstructs/spinConstDB.hh
const int * getSpin8bits()
experts only
const int * getBucketOffsets()
experts only
virtual TDataSet * Find(const char *path) const
bool isPolDirLong()
Returns true if beams are transversely polarized, false otherwise.