00001
00002
00003 #include <stdio.h>
00004 #include <string.h>
00005 #include <stdlib.h>
00006 #include <assert.h>
00007 #include "TString.h"
00008
00009 #include "EEmcDbCrate.h"
00010
00011
00012
00013 EEmcDbCrate::EEmcDbCrate() {
00014 clear();
00015 }
00016
00017
00018
00019 int EEmcDbCrate::isEmpty() const{
00020 return name[0]==0;
00021 }
00022
00023
00024
00025
00026 void EEmcDbCrate::print() const{
00027 LOG_INFO<<"EEmcDbCrate::print():"<<endm;
00028
00029 if(name[0]==0) {
00030 LOG_WARN<<" item not defined ???"<<endm;
00031 return;
00032 }
00033
00034 LOG_INFO<<Form("EEmcDbCrate:: crID=%3d crIDswitch=%3d fiber=%d nCh=%d nHead=%d type=%c useIt=%d\n",name, crID, crIDswitch,fiber,nCh,nHead,type,useIt)<<endm;
00035 }
00036
00037 ostream &
00038 EEmcDbCrate::print( ostream &out ) const
00039 {
00040 out << "DbCrate: ";
00041 if ( isEmpty() ) {
00042 out << "crate not defined";
00043 return out;
00044 }
00045 out << Form("%s crID=%3d crIDswitch=%3d fiber=%d nCh=%d nHead=%d type=%c useIt=%d",name, crID, crIDswitch,fiber,nCh,nHead,type,useIt);
00046 return out;
00047 }
00048
00049 ostream &operator<<(ostream &out, const EEmcDbCrate &crate )
00050 {
00051 return crate.print(out);
00052 }
00053
00054
00055 void EEmcDbCrate::clear() {
00056 name[0]=0;
00057 crID=-1;
00058 crIDswitch=-2;
00059 fiber=-3;
00060 nCh=-4;
00061 nHead=-5;
00062 type='X';
00063 useIt=0;
00064 }
00065
00066
00067
00068
00069 void EEmcDbCrate::setName(char *text) {
00070 strncpy(name,text,CrateNameLen-1);
00071 }
00072
00073
00074
00075 void EEmcDbCrate::setAll(char *buf ) {
00076
00077 int ret=sscanf(buf,"%s %d %d %d %d %d %c %d",name,&crID,&crIDswitch,&fiber,&nCh,&nHead,&type,&useIt);
00078
00079 assert(ret==8);
00080 }
00081
00082
00083
00084 void EEmcDbCrate::exportAscii(FILE *fd) const{
00085
00086 if(name[0]==0) return;
00087 fprintf(fd,"%s %d %d %d %d %d %c %d \n",name,crID,crIDswitch,fiber,nCh,nHead,type,useIt);}
00088
00089
00090 #if 0
00091
00092
00093 int EEmcDbCrate::importAscii(FILE *fd){
00094
00095
00096
00097
00098
00099
00100
00101 clear();
00102 const int mx=1000;
00103 char buf[mx];
00104
00105 char * ret=fgets(buf,mx,fd);
00106
00107 if(ret==0) return 0;
00108
00109 if(buf[0]=='#') return 1;
00110 char name0[mx];
00111 int ret1=sscanf(buf,"%s",name0);
00112 if(ret1==0) return -1;
00113
00114 int n=0;
00115
00116 if(name0[2]=='U' || name0[2]=='V') {
00117 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);
00118 }
00119 else if (name0[2]=='T' || name0[2]=='P' || name0[2]=='Q' || name0[2]=='R' ) {
00120 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);
00121 }
00122 else
00123 return -3;
00124
00125
00126
00127 if(n!=13) return -1000-n;
00128
00129 return 2;
00130 }
00131 #endif
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163