00001
00002
00003 #include <stdio.h>
00004 #include <string.h>
00005 #include <stdlib.h>
00006 #include <assert.h>
00007
00008 #include "TString.h"
00009
00010 #include "cstructs/eemcConstDB.hh"
00011
00012 #include "EEmcDbItem.h"
00013
00014
00015
00016 EEmcDbItem::EEmcDbItem() {
00017 clear();
00018 }
00019
00020
00021
00022 bool EEmcDbItem::isEmpty() const{
00023 return name[0]==0;
00024 }
00025
00026
00027
00028 bool EEmcDbItem::isTower() const{
00029 if (isEmpty()) return false;
00030 return (name[2]=='T');
00031 }
00032
00033
00034
00035
00036 void EEmcDbItem::print() const{
00037 LOG_INFO<<"EEmcDbItem::print() "<<endm;
00038
00039 if(name[0]==0) {
00040 LOG_WARN<<" item not defined ???"<<endm;
00041 return;
00042 }
00043 if( isSMD() ) {
00044 LOG_INFO<<Form("EEmcDbItem::SMD %s crate=%d chan=%3d sec=%2d plane=%c strip=%3d gain=%.3f ped=%.2f sPed=%.2f ADC_thr=%.2f stat=0x%4.4x fail=0x%4.4x pix=%s key=%d\n",name,crate,chan,sec,plane,strip,gain,ped,sigPed,thr,stat,fail,tube,key)<<endm;
00045 } else {
00046 LOG_INFO<<Form("EEmcDbItem::Tail %s crate=%d chan=%3d sec=%2d sub=%c eta=%2d gain=%.3f ped=%.2f sPed=%.2f ADC_thr=%.2f stat=0x%4.4x fail=0x%4.4x tube=%s key=%d\n",name,crate,chan,sec,sub,eta,gain,ped,sigPed,thr,stat,fail,tube,key)<<endm;
00047 }
00048 }
00049
00050
00051
00052 ostream &
00053 EEmcDbItem::print( ostream &out ) const
00054 {
00055 out << "EEmcDbItem: ";
00056 if ( isEmpty() ) {
00057 out << "item not defined";
00058 }
00059 else if ( isSMD() ){
00060 out << Form("%s crate=%d chan=%3d sec=%2d plane=%c strip=%3d gain=%.3f ped=%.2f sPed=%.2f ADC_thr=%.2f stat=0x%4.4x fail=0x%4.4x pix=%s key=%d\n",name,crate,chan,sec,plane,strip,gain,ped,sigPed,thr,stat,fail,tube,key);
00061 }
00062 else {
00063 out << Form(" %s crate=%d chan=%3d sec=%2d sub=%c eta=%2d gain=%.3f ped=%.2f sPed=%.2f ADC_thr=%.2f stat=0x%4.4x fail=0x%4.4x tube=%s key=%d\n",name,crate,chan,sec,sub,eta,gain,ped,sigPed,thr,stat,fail,tube,key);
00064 }
00065 return out;
00066 }
00067
00068
00069
00070 ostream &operator<<(ostream &out, const EEmcDbItem &item )
00071 {
00072 return item.print(out);
00073 }
00074
00075
00076
00077 void EEmcDbItem::exportAscii(FILE *fd) const{
00078
00079 if(name[0]==0) return;
00080
00081 if(strchr(name,'U') || strchr(name,'V') ) {
00082 fprintf(fd,"%s %3d %3d %2d %c %4d %.3f %.2f %.2f 0x%4.4x 0x%4.4x %s %d\n",name,crate,chan,sec,plane,strip,gain,ped,thr,stat,fail,tube,key);
00083 } else {
00084 fprintf(fd,"%s %d %3d %2d %c %2d %.3f %.2f %.2f 0x%4.4x 0x%4.4x %s %d\n",name,crate,chan,sec,sub,eta,gain,ped,thr,stat,fail,tube,key);
00085 }
00086 }
00087
00088
00089
00090
00091
00092 int EEmcDbItem::importAscii(FILE *fd){
00093
00094
00095
00096
00097
00098
00099
00100 clear();
00101 const int mx=1000;
00102 char buf[mx];
00103
00104 char * ret=fgets(buf,mx,fd);
00105
00106 if(ret==0) return 0;
00107
00108 if(buf[0]=='#') return 1;
00109
00110 char name0[mx];
00111 int ret1=sscanf(buf,"%s",name0);
00112
00113
00114 if(ret1==0) return -1;
00115
00116 int n=0;
00117
00118 if(name0[2]=='U' || name0[2]=='V') {
00119 n=sscanf(buf,"%s %d %d %d %c %d %f %f %f %x %x %s %d",name,&crate,&chan,&sec,&plane,&strip,&gain,&ped,&thr,&stat,&fail,tube,&key);
00120 }
00121 else if (name0[2]=='T' || name0[2]=='P' || name0[2]=='Q' || name0[2]=='R' ) {
00122 n=sscanf(buf,"%s %d %d %d %c %d %f %f %f %x %x %s %d",name,&crate,&chan,&sec,&sub,&eta,&gain,&ped,&thr,&stat,&fail,tube,&key);
00123 }
00124 else {
00125 return -3;
00126 }
00127
00128
00129 if(n!=13) return -1000-n;
00130
00131 return 2;
00132 }
00133
00134
00135
00136
00137 void EEmcDbItem::clear() {
00138 name[0]=0;
00139 tube[0]=0;
00140 crate= chan=-1;
00141 gain=-2;
00142 ped=-3;
00143 sec=-4;
00144 sub='Z';
00145 eta=-5;
00146 thr=-6;
00147 sigPed=-7;
00148 strip=-299;
00149 plane='X';
00150 stat=fail=0;
00151 key=-999;
00152 }
00153
00154
00155
00156
00157 int
00158 EEmcDbItem::mapmtId() const{
00159 if(isTower()) return 0;
00160 if(chan<0 || chan>=192) return 0;
00161 int iTube=chan/16;
00162 int tubeID=(iTube<=5) ? 2*iTube+1 :14- 2*(iTube-5);
00163
00164 return tubeID;
00165 }
00166
00167
00168
00169 void EEmcDbItem::setDefaultTube(int cr_off) {
00170 if(name[2]=='T') return;
00171
00172 int ch2pix[16]={13, 14, 15, 16, 9, 10, 11, 12, 5, 6, 7, 8, 1,2,3,4};
00173
00174 int iCrate=crate-cr_off;
00175
00176 int tubeID=mapmtId();
00177
00178
00179 int secID=1 + ((iCrate/4)+11)%12;
00180 assert(secID==sec);
00181
00182 int iBox=iCrate%4;
00183 int iPix=chan%16;
00184 int pixID=ch2pix[iPix];
00185 char text[100], boxName[100];
00186 sprintf(boxName,"S%d",iBox+1);
00187 if (iBox==3)sprintf(boxName,"P1");
00188 sprintf(text,"%2.2d%2s-%2.2d:%2.2d%c",secID,boxName,tubeID,pixID,EEMCDbStringDelim);
00189 setTube(text);
00190 }
00191
00192
00193 void EEmcDbItem::setTube(char *text) {
00194 strncpy(tube,text,StEEmcNameLen-1);
00195
00196 int i;
00197 for(i=0;i<StEEmcNameLen;i++) {
00198 if(tube[i]==EEMCDbStringDelim) {
00199 tube[i]=0;
00200 return;
00201 }
00202 }
00203 LOG_WARN<<Form("Error in EEmcDbItem::setTube(%s), no terminating '%c'\n",text,EEMCDbStringDelim)<<endm;
00204 assert(1==2);
00205 }
00206
00207
00208
00209 void EEmcDbItem::setName(char *text) {
00210 strncpy(name,text,StEEmcNameLen-1);
00211 sec=atoi(text);
00212 if(name[2]=='U' || name[2]=='V' ) {
00213 plane=name[2];
00214 strip=atoi(text+3);
00215 }else {
00216 assert(name[2]=='T' ||name[2]=='P' ||name[2]=='Q' ||name[2]=='R' );
00217 sub=text[3];
00218 eta=atoi(text+4);
00219 }
00220
00221 int i;
00222 for(i=0;i<StEEmcNameLen;i++) {
00223 if(name[i]==EEMCDbStringDelim) {
00224 name[i]=0;
00225 return;
00226 }
00227 }
00228 LOG_WARN<<Form("Error in EEmcDbItem::setName(%s), no terminating '%c'\n",text,EEMCDbStringDelim)<<endm;
00229 assert(1==2);
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290