/*:>-------------------------------------------------------------------- **: FILE: mMvdDbase.c **: HISTORY: **: 00jan93-v000a-hpl- Created by stic Version **: Id: idl-yacc.c,v 1.1.1.1 1997/09/26 20:43:47 dave Exp **:<------------------------------------------------------------------*/ #include "mMvdDbase.h" #include extern int bDbase_Table( DMVDGEO_ST *Geo, DMVBPAR_ST *bPar, DMVCPAR_ST *cPar, short shell, short row, short panel, short strip ); extern int cDbase_Table( DMVDGEO_ST *Geo, DMVBPAR_ST *bPar, DMVCPAR_ST *cPar, short end, short wedge, short row, short column); void Bread_noise_cross_talk(DMVDGEO_ST *Geo ,DMVBPAR_ST *bPar ,DMVCPAR_ST *cPar , DMVBDBASE_ST *bDbase, DMVDDBASESTATUS_ST *Status, FILE *in1,char *s1, short MVD_KEY,short BTYPE, int total,short run); void Eread_noise_cross_talk(DMVDGEO_ST *Geo , DMVBPAR_ST *bPar ,DMVCPAR_ST *cPar , DMVCDBASE_ST *cDbase, DMVDDBASESTATUS_ST *Status, FILE *in1,char *s1, short MVD_KEY,short CTYPE, int total,short run); void Bread_calib_const( DMVDGEO_ST *Geo , DMVBPAR_ST *bPar , DMVCPAR_ST *cPar , DMVBDBASE_ST *bDbase, DMVDDBASESTATUS_ST *Status, DMVDDNDETAPAR_ST *dNdEtaPar, FILE *in3,char *s1, short MVD_KEY,short BTYPE, int total,short run); void MvdMess_(char *name_of_function, short ierror, short level, char *message, ...); #define NO_ERROR 0 /* used for message output with no error */ #define RANGE_ERROR0 1 /* subscript out of range error */ #define RANGE_ERROR1 2 /* subscript out of range error */ #define RANGE_ERROR2 3 /* subscript out of range error */ #define RANGE_ERROR3 4 /* subscript out of range error */ #define WRONG_FORMAT_ERROR1 5 /* wrong database format */ #define WRONG_FORMAT_ERROR2 6 /* wrong database format */ #define WRONG_FORMAT_ERROR3 7 /* wrong database format */ #define FILE_MISSING_ERR1 8 /* missing "database" file */ #define FILE_MISSING_ERR2 9 /* missing "database" file */ #define FILE_MISSING_ERR3 10 /* missing "database" file */ #define FILE_MISSING_ERR4 11 /* missing "database" file */ #define FILE_MISSING_ERR5 12 /* missing "database" file */ #define VERY_LOUD 3 /* for error messages */ #define LOUD 2 /* messages which are usually output */ #define QUIET 1 /* used for messages which are output at default setting */ #define SILENT 0 /* for messages which are usually not output */ long mMvdDbase_( TABLE_HEAD_ST *Geo_h, DMVDGEO_ST *Geo , TABLE_HEAD_ST *bPar_h, DMVBPAR_ST *bPar , TABLE_HEAD_ST *cPar_h, DMVCPAR_ST *cPar , TABLE_HEAD_ST *Par_h, DMVDPAR_ST *Par , TABLE_HEAD_ST *DPar_h, DMVDDBASEPAR_ST *DPar , TABLE_HEAD_ST *bDbase_h, DMVBDBASE_ST *bDbase , TABLE_HEAD_ST *cDbase_h, DMVCDBASE_ST *cDbase , TABLE_HEAD_ST *Status_h,DMVDDBASESTATUS_ST *Status , TABLE_HEAD_ST *dNdEtaPar_h, DMVDDNDETAPAR_ST *dNdEtaPar ) { /*:>-------------------------------------------------------------------- **: ROUTINE: mMvdDbase_ **: DESCRIPTION: Establish links between table and MVD database. **: and read noise , cross talk ,dead channel data from database **: and fill MVD database table **: **: AUTHOR : J.H.Park(Yonsei Univ.) , J.P.Sullivan(LANL) **: ARGUMENTS: **: IN: **: Geo - Geant MVD geometry **: Geo_h - header Structure for Geo **: bPar - barrel detector geometry parameters **: bPar_h - header Structure for bPar **: cPar - endcap detector geometry parameters **: cPar_h - header Structure for cPar **: Par - mvd uncalibration parameters **: Par_h - header Structure for Par **: DPar - mvd database parameters **: DPar_h - header Structure for DPar **: INOUT: **: OUT: **: bDbase - mvd barrel database table **: bDbase_h - header Structure for bDbase **: cDbase - mvd endcap database table **: cDbase_h - header Structure for cDbase **: Status - status for mvd database **: Status_h - header Structure for Status **: RETURNS: STAF Condition Value **: Revision History **: Name Date Comment **: J.H.PARK Feb.12,1998 initialize Database Status table **: in case that there is no database **: files. **: J.P.Sullivan Apr.14,1998 replace printf calls with MvdMess_ **: J.P.Sullivan Jul.21,1998 changed return code STAFCV_BAD to **: STAFCV_OK because **: 1) it is really OK **: 2) it crashes on linux **: J.P.Sullivan Dec. 1,1998 added MVD_ to beginning of all **: input files names. **: S.S.Ryu 06-JUL-1999 replaces declarations like **: "struct dMvdGeo_st *geo" **: with STAF standard "DMVDGEO_ST *geo" **:>------------------------------------------------------------------*/ short MVD_KEY=0; /* temperal key for MVD database */ /* for Barrels */ short STRIP=(short)Geo->nstrip; short PANEL=(short)bPar->NCHDIM; short ROW =(short)bPar->NPHDIM; short SHELL=(short)bPar->NSHELL; short HOLE =(short)Geo->nwhole; short SEGMENT=(short)bPar->NSEGMENT; short BTYPE=DPar->barrel_type; /* for Endcaps */ short CROW =(short)cPar->NVPAD_RBINS; short WEDGE =(short)cPar->NVPAD_SEGS; short COLUMN=(short)cPar->NVPAD_SEGS2; short END =(short)cPar->NEND; short CTYPE=DPar->endcap_type; int total=0; /* total # of table */ static short run=0; static short icall=0; short number=0; int mvd_key,type; int s_e,r_w,p_r,s_c; /* shell or end ,row or wedge,panel or row , strip or column */ int index; int i,j,k,l; FILE *in1,*in2,*in3; char filename[7][30]={"MVD_noise_barrel.dat","MVD_cross_talk_barrel.dat",\ "MVD_noise_pad.dat" ,"MVD_cross_talk_pad.dat",\ "MVD_dead_channel.dat","MVD_bcal.dat","MVD_ccal.dat" }; if ( icall != 0 ) { return STAFCV_OK; } icall++; MvdMess_("mMvdDbase",NO_ERROR,LOUD,"mMvdDbase{\n"); run++; /* # of run of event */ /* for Barrels */ total=SHELL*ROW*PANEL*STRIP-HOLE*SEGMENT*STRIP; /* # of table of dMvbDbase */ ds2ReallocTable(&bDbase_h,&bDbase,total); /* initialize barrel tables */ for(i=0;ifull_scale/Par->smax_mip-1.0; bDbase[i].calib_const[1]=0.0; bDbase[i].calib_const[2]=0.0; bDbase[i].calib_const[3]=0.0; bDbase[i].calib_const[4]=0.0; bDbase[i].reserved[0]=0; bDbase[i].reserved[1]=0; } for (i=0;i<10;++i) Status->reserved[i]=1000; Status->noise_barrel=total; Status->ct_barrel=total; in1=fopen(filename[0],"r"); if (!in1) { MvdMess_("mMvdDbase",FILE_MISSING_ERR1,VERY_LOUD, "\nWarning: Place \"%s\" in WRK directory !!\n\ loading default value....",filename[0]); for (i=0;i1 && k <10 ) ; else { index=bDbase_Table(Geo,bPar,cPar,i,j,k,l); bDbase[index].run=run; bDbase[index].shell=(short)i; bDbase[index].row=(short)j; bDbase[index].panel=(short)k; bDbase[index].strip=(short)l; bDbase[index].noise=Par->skev_noise; bDbase[index].flag_dead_channel=1; /* not dead channel */ bDbase[index].reserved[0]=1000; } } } else Bread_noise_cross_talk(Geo,bPar,cPar,bDbase,Status,in1,filename[0],\ MVD_KEY,BTYPE,total,run); in2=fopen(filename[1],"r"); if (!in2) { MvdMess_("mMvdDbase",FILE_MISSING_ERR2,VERY_LOUD, "\nWarning: Place \"%s\" in WRK directory !!\n\ loading default value....",filename[1]); for (i=0;i1 && k <10 ) ; else { index=bDbase_Table(Geo,bPar,cPar,i,j,k,l); bDbase[index].run=run; bDbase[index].shell=(short)i; bDbase[index].row=(short)j; bDbase[index].panel=(short)k; bDbase[index].strip=(short)l; bDbase[index].cross_talk=Par->cross_talk; bDbase[index].flag_dead_channel=1; /* not dead channel */ bDbase[index].reserved[1]=1000; } } } else Bread_noise_cross_talk(Geo,bPar,cPar,bDbase,Status,in2,filename[1],\ MVD_KEY,BTYPE,total,run); /* while (!feof(in1)) { fscanf(in1,"%d\t%d\t%d\t\%d\t%d\t%d\t%f\t%d\n",mvd_key,btype,\ shell,row,panel,strip,noise,reserved); total++; } */ /**********************************************/ /* calibration constant for barrel detectors */ /**********************************************/ in3=fopen(filename[5],"r"); if (!in3) { MvdMess_("mMvdDbase",FILE_MISSING_ERR2,VERY_LOUD, "\nWarning: Place \"%s\" in WRK directory !!\n\ Default values already loaded....",filename[5]); } else Bread_calib_const( Geo,bPar,cPar,bDbase,Status,dNdEtaPar,in3,filename[5],\ MVD_KEY,BTYPE,total,run); bDbase_h->nok=total; /* for Endcaps */ total=END*WEDGE*CROW*COLUMN; /* # of table of dMvcDbase */ Status->noise_pad=total; Status->ct_pad=total; ds2ReallocTable(&cDbase_h,&cDbase,total); /* initialize endcap tables */ for (i=0;i < total;++i) { cDbase[i].end=-1; cDbase[i].wedge=-1; cDbase[i].row=-1; cDbase[i].column=-1; cDbase[i].noise=0; cDbase[i].cross_talk=0; cDbase[i].flag_dead_channel=0; cDbase[i].run=0; cDbase[i].reserved[0]=0; cDbase[i].reserved[1]=0; } in1=fopen(filename[2],"r"); if (!in1) { MvdMess_("mMvdDbase",FILE_MISSING_ERR3,VERY_LOUD, "\nWarning: Place \"%s\" in WRK directory !!\n\ loading default value....",filename[2]); for (i=0;i < END;++i) for (j=0;j skev_noise; cDbase[index].flag_dead_channel=1; /* not dead channel */ cDbase[index].reserved[0]=1000; } } else Eread_noise_cross_talk(Geo,bPar,cPar,cDbase,Status,in1,filename[2], MVD_KEY,CTYPE,total,run); in2=fopen(filename[3],"r"); if (!in2) { MvdMess_("mMvdDbase",FILE_MISSING_ERR4,VERY_LOUD, "\nWarning: Place \"%s\" in WRK directory !!\n\ loading default value....",filename[3]); for (i=0;i < END;++i) for (j=0;j cross_talk; cDbase[index].flag_dead_channel=1; /* not dead channel */ cDbase[index].reserved[1]=1000; } } else Eread_noise_cross_talk(Geo,bPar,cPar,cDbase,Status,in2,filename[3],\ MVD_KEY,CTYPE,total,run); cDbase_h->nok=total; /* finding dead channel data and record their data in table */ in1=fopen(filename[4],"r"); if (!in1) { MvdMess_("mMvdDbase",FILE_MISSING_ERR5,VERY_LOUD,"\n== No dead channels ==\n\ Warning: Place \"%s\" in WRK directory !!",filename[4]); for (i=0; i <30;++i) Status->calib_id[i]='\0'; strcpy(&Status->calib_id[0],"Hubert van Hecke"); Status_h->nok=1; MvdMess_("mMvdDbase",NO_ERROR,LOUD,"}"); /* return STAFCV_BAD; */ /* should work but does not */ return STAFCV_OK; /* added because STAFCV_BAD causes */ /* segmentation fault on linux */ } else MvdMess_("mMvdDbase",NO_ERROR,QUIET, "\n\"%s\" is found and opened !!\nProcessing dead channel data !!", filename[4]); while (!feof(in1)) { fscanf(in1,"%d\t%d\t%d\t%d\t%d\t%d\n",&mvd_key,&type,&s_e,&r_w,&p_r,&s_c); MvdMess_("mMvdDbase",NO_ERROR,QUIET, "dead_channel:%d\t%d\t%d\t%d\t%d\t%d",mvd_key,type,s_e,r_w,p_r,s_c); /* check MVD Database format */ if ((mvd_key==MVD_KEY) && (type==BTYPE)) { index=bDbase_Table(Geo,bPar,cPar,s_e,r_w,p_r,s_c); total=SHELL*ROW*PANEL*STRIP-HOLE*SEGMENT*STRIP; /* # of table of dMvbDbase */ /* check subscript range of index */ if ( index >=0 && index < total ) { bDbase[index].flag_dead_channel=0; /* 0 for dead channel */ bDbase[index].cross_talk=0; /* supress cross talk effect */ number++; } else MvdMess_("mMvdDbase",RANGE_ERROR0,VERY_LOUD, " SubscriptRange Error !!"); } else if ((mvd_key==MVD_KEY) && (type==CTYPE)) { index=cDbase_Table(Geo,bPar,cPar,s_e,r_w,p_r,s_c); total=END*WEDGE*CROW*COLUMN; /* # of table of dMvcDbase */ /* check subscript range of index */ if ( index >=0 && index < total ) { cDbase[index].flag_dead_channel=0; /* 0 for dead channel */ cDbase[index].cross_talk=0; /* supress cross talk effect */ number++; } else MvdMess_("mMvdDbase",RANGE_ERROR1,VERY_LOUD, " SubscriptRange Error !!"); } else { MvdMess_("mMvdDbase",WRONG_FORMAT_ERROR1,VERY_LOUD, "\n Wrong Database Format !! \n Ignoring this table..."); } } Status->dead_channel=number; for (i=0; i <30;++i) Status->calib_id[i]='\0'; strcpy(&Status->calib_id[0],"Hubert van Hecke"); fclose(in1); Status_h->nok=1; MvdMess_("mMvdDbase",NO_ERROR,LOUD,"}"); return STAFCV_OK; } void Bread_noise_cross_talk(DMVDGEO_ST *Geo ,DMVBPAR_ST *bPar ,DMVCPAR_ST *cPar ,\ DMVBDBASE_ST *bDbase,\ DMVDDBASESTATUS_ST *Status,\ FILE *in1,char *s1,\ short MVD_KEY,short BTYPE,\ int total,short run) { int mvd_key; int btype; int shell; int row; int panel; int strip; int reserved; int index=0; /* index of table */ float noise_cross_talk; long number=0; /* # of table */ static int flag=0; MvdMess_("mMvdDbase",NO_ERROR,QUIET, "\n\"%s\" is opened !!\nReading from \"%s\" ", s1,s1); lseek(in1,0,SEEK_SET); /* moving read pointer to the beginning of file */ while (!feof(in1)) { fscanf(in1,"%d\t%d\t%d\t%d\t%d\t%d\t%f\t%d\n",&mvd_key,&btype,\ &shell,&row,&panel,&strip,&noise_cross_talk,&reserved); /* Type checking for dMvbDbase table */ if ((mvd_key==MVD_KEY) && (btype==BTYPE)) { index=bDbase_Table(Geo,bPar,cPar,shell,row,panel,strip); /* MvdMess_("mMvdDbase",NO_ERROR,SILENT, "%d\t%d\t%d\t\%d\t",shell,row,panel,strip); MvdMess_("mMvdDbase",NO_ERROR,SILENT,"index-->%d",index); */ /* automatically, sorting tables from Database file */ /* and check subscript range of index */ if ( index >=0 && index < total ) { bDbase[index].shell=(short)shell; bDbase[index].row=(short)row; bDbase[index].panel=(short)panel; bDbase[index].strip=(short)strip; bDbase[index].flag_dead_channel=1; /* not dead channel */ bDbase[index].run =run; if ( flag ==0){ bDbase[index].noise=noise_cross_talk; bDbase[index].reserved[0]=(short)reserved; /* reserved element from Hubert */ } if ( flag ==1) { bDbase[index].cross_talk=noise_cross_talk; bDbase[index].reserved[1]=(short)reserved; /* reserved element from Hubert */ } number++; } else { MvdMess_("mMvdDbase",RANGE_ERROR2,VERY_LOUD, " SubscriptRange Error !! \n\ Index of noise data : %d",index); } } else { MvdMess_("mMvdDbase",WRONG_FORMAT_ERROR2,VERY_LOUD, "\n Wrong Database Format !! \n Ignoring this table..."); } } fclose(in1); if (flag==1){ Status->ct_barrel=number; flag=0; return; } if (flag==0) { Status->noise_barrel=number; flag=1; return; } } void Bread_calib_const( DMVDGEO_ST *Geo , DMVBPAR_ST *bPar , DMVCPAR_ST *cPar , DMVBDBASE_ST *bDbase, DMVDDBASESTATUS_ST *Status, DMVDDNDETAPAR_ST *dNdEtaPar, FILE *in3,char *s1, short MVD_KEY,short BTYPE, int total,short run){ short i; int mvd_key; int btype; int shell; int row; int panel; int strip; int amuadc; int first_in_amuadc; float calib_const[5]; float a,b,c,d,f; int reserved; int index=0; /* index of table */ MvdMess_("mMvdDbase",NO_ERROR,QUIET, "\n\"%s\" is opened !!\nReading from \"%s\" ", s1,s1); lseek(in3,0,SEEK_SET); /* moving read pointer to the beginning of file */ while (!feof(in3)){ fscanf(in3,"%d %d %d %d\n%f %f %f %f %f\n", &shell,&row,&panel,&amuadc, &a,&b,&c,&d,&f); /* Type checking for dMvbDbase table */ /* if ((mvd_key==MVD_KEY) && (btype==BTYPE)) { */ if ( !(shell==1 && row<4 && panel>1 && panel<10 )){ first_in_amuadc=amuadc*dNdEtaPar->nBunch; for(strip=first_in_amuadc;stripnBunch;strip++){ index=bDbase_Table(Geo,bPar,cPar,shell,row,panel,strip); /* MvdMess_("mMvdDbase",NO_ERROR,SILENT, "%d\t%d\t%d\t\%d\t",shell,row,panel,strip); MvdMess_("mMvdDbase",NO_ERROR,SILENT,"index-->%d",index); */ /* automatically, sorting tables from Database file */ /* and check subscript range of index */ if ( index >=0 && index < total ) { /* bDbase[index].shell=(short)shell; bDbase[index].row=(short)row; bDbase[index].panel=(short)panel; bDbase[index].strip=(short)istrip; */ bDbase[index].calib_const[0]=a; bDbase[index].calib_const[1]=b; bDbase[index].calib_const[2]=c; bDbase[index].calib_const[3]=d; bDbase[index].calib_const[4]=f; /* bDbase[index].run =run; */ } else MvdMess_("mMvdDbase",RANGE_ERROR2,VERY_LOUD, " SubscriptRange Error !! \n\ Index of strip calibration data : %d",index); } } else MvdMess_("mMvdDbase",WRONG_FORMAT_ERROR2,VERY_LOUD, "\n Wrong Database Format !! \n Ignoring this table..."); } /* while */ fclose(in3); return; } void Eread_noise_cross_talk(DMVDGEO_ST *Geo , DMVBPAR_ST *bPar ,DMVCPAR_ST *cPar , DMVCDBASE_ST *cDbase, DMVDDBASESTATUS_ST *Status, FILE *in1,char *s1, short MVD_KEY,short CTYPE, int total,short run) { int mvd_key; int ctype; int end; int wedge; int row; int column; int reserved; int index=0; /* index of table */ float noise_cross_talk; short number=0; static int flag=0; MvdMess_("mMvdDbase",NO_ERROR,SILENT, "\n\"%s\" is opened !!\nReading from \"%s\" ",s1,s1); lseek(in1,0,SEEK_SET); /* moving read pointer to the beginning of file */ while (!feof(in1)) { fscanf(in1,"%d\t%d\t%d\t%d\t%d\t%d\t%f\t%d\n",&mvd_key,&ctype,\ &end,&wedge,&row,&column,&noise_cross_talk,&reserved); /* Type checking for dMvcDbase table */ if ((mvd_key==MVD_KEY) && (ctype==CTYPE)) { index=cDbase_Table(Geo,bPar,cPar,end,wedge,row,column); /* automatically, sorting tables from Database file */ /* and check subscript range of index */ if ( index >=0 && index < total ) { cDbase[index].end=(short)end; cDbase[index].wedge=(short)wedge; cDbase[index].row=(short)row; cDbase[index].column=(short)column; cDbase[index].flag_dead_channel=1; /* not dead channel */ cDbase[index].run=run; if ( flag ==0 ) { cDbase[index].noise=noise_cross_talk; cDbase[index].reserved[0]=(short)reserved; /* reserved element from Hubert */ } if ( flag ==1) { cDbase[index].cross_talk=noise_cross_talk; cDbase[index].reserved[1]=(short)reserved; /* reserved element from Hubert */ } number++; } else { MvdMess_("mMvdDbase",RANGE_ERROR3,VERY_LOUD, " SubscriptRange Error !! \n\ Index of noise data : %d",index); } } else { MvdMess_("mMvdDbase",WRONG_FORMAT_ERROR3,VERY_LOUD, "\n Wrong Database Format !! \n Ignoring this table..."); } } fclose(in1); if (flag ==1){ Status->ct_pad=number; flag=0; return; } if (flag ==0){ Status->noise_pad=number; flag=1; return; } }