StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEmcDbItem.cxx
1 // $Id: EEmcDbItem.cxx,v 1.2 2009/12/03 21:15:39 ogrebeny Exp $
2 
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <assert.h>
7 
8 #include "TString.h"
9 
10 #include "cstructs/eemcConstDB.hh"
11 
12 #include "EEmcDbItem.h"
13 
14 //--------------------------------------------------
15 //--------------------------------------------------
16 EEmcDbItem::EEmcDbItem() {
17  clear();
18 }
19 
20 //--------------------------------------------------
21 //--------------------------------------------------
22 bool EEmcDbItem::isEmpty() const{
23  return name[0]==0;
24 }
25 
26 //--------------------------------------------------
27 //--------------------------------------------------
28 bool EEmcDbItem::isTower() const{
29  if (isEmpty()) return false;
30  return (name[2]=='T');
31 }
32 
33 
34 //--------------------------------------------------
35 //--------------------------------------------------
36 void EEmcDbItem::print() const{
37  LOG_INFO<<"EEmcDbItem::print() "<<endm;
38 
39  if(name[0]==0) {
40  LOG_WARN<<" item not defined ???"<<endm;
41  return;
42  }
43  if( isSMD() ) {
44  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;
45  } else {
46  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;
47  }
48 }
49 
50 //---- ----
51 //---- ----
52 ostream &
53 EEmcDbItem::print( ostream &out ) const
54 {
55  out << "EEmcDbItem: ";
56  if ( isEmpty() ) {
57  out << "item not defined";
58  }
59  else if ( isSMD() ){
60  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);
61  }
62  else {
63  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);
64  }
65  return out;
66 }
67 
68 //---- ----
69 //---- ----
70 ostream &operator<<(ostream &out, const EEmcDbItem &item )
71 {
72  return item.print(out);
73 }
74 
75 //--------------------------------------------------
76 //--------------------------------------------------
77 void EEmcDbItem::exportAscii(FILE *fd) const{
78 
79  if(name[0]==0) return; // item not defined
80 
81  if(strchr(name,'U') || strchr(name,'V') ) {
82  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);
83  } else {
84  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);
85  }
86 }
87 
88 
89 
90 //--------------------------------------------------
91 //--------------------------------------------------
92 int EEmcDbItem::importAscii(FILE *fd){
93  /* return:
94  <0 : error in input
95  0 : EOF
96  1 : line ignored
97  2 : valid input
98  */
99 
100  clear();
101  const int mx=1000;
102  char buf[mx];
103 
104  char * ret=fgets(buf,mx,fd);
105 
106  if(ret==0) return 0;
107 
108  if(buf[0]=='#') return 1;
109 
110  char name0[mx];
111  int ret1=sscanf(buf,"%s",name0);
112 
113 
114  if(ret1==0) return -1;
115 
116  int n=0;
117  // printf("aaa name='%s' n=%d\n",name,name[0]);
118  if(name0[2]=='U' || name0[2]=='V') {
119  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);
120  }
121  else if (name0[2]=='T' || name0[2]=='P' || name0[2]=='Q' || name0[2]=='R' ) {
122  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);
123  }
124  else {
125  return -3;
126  }
127 
128 
129  if(n!=13) return -1000-n;
130  // print();
131  return 2;
132 }
133 
134 
135 //--------------------------------------------------
136 //--------------------------------------------------
137 void EEmcDbItem::clear() {
138  name[0]=0;
139  tube[0]=0;
140  crate= chan=-1;
141  gain=-2;
142  ped=-3;
143  sec=-4;
144  sub='Z';
145  eta=-5;
146  thr=-6;
147  sigPed=-7;
148  strip=-299;
149  plane='X';
150  stat=fail=0;
151  key=-999;
152 }
153 
154 
155 //________________________________________________________
156 //________________________________________________________
157 int
158 EEmcDbItem::mapmtId() const{
159  if(isTower()) return 0;
160  if(chan<0 || chan>=192) return 0; // nonsens channel value
161  int iTube=chan/16;
162  int tubeID=(iTube<=5) ? 2*iTube+1 :14- 2*(iTube-5); // tube ID counting from 1
163  // printf("chan=%d mapmtID=%d\n",chan,tubeID);
164  return tubeID;
165 }
166 
167 //--------------------------------------------------
168 //--------------------------------------------------
169 void EEmcDbItem::setDefaultTube(int cr_off) {
170  if(name[2]=='T') return; // do nothing for towers
171  // view from the front of MAPMT , the same for Left & right column
172  int ch2pix[16]={13, 14, 15, 16, 9, 10, 11, 12, 5, 6, 7, 8, 1,2,3,4};
173 
174  int iCrate=crate-cr_off;
175 
176  int tubeID=mapmtId();
177  // int cwID=tubeID+ 12*(iCrate%8); // offset for every pair of subsectors, not used
178 
179  int secID=1 + ((iCrate/4)+11)%12;
180  assert(secID==sec);
181 
182  int iBox=iCrate%4;
183  int iPix=chan%16;
184  int pixID=ch2pix[iPix];
185  char text[100], boxName[100];
186  sprintf(boxName,"S%d",iBox+1); // true for SMD
187  if (iBox==3)sprintf(boxName,"P1"); // Pre/Post box
188  sprintf(text,"%2.2d%2s-%2.2d:%2.2d%c",secID,boxName,tubeID,pixID,EEMCDbStringDelim);
189 setTube(text);
190 }
191 //--------------------------------------------------
192 //--------------------------------------------------
193 void EEmcDbItem::setTube(char *text) {
194  strncpy(tube,text,StEEmcNameLen-1);
195  // cleanup termintaing character
196  int i;
197  for(i=0;i<StEEmcNameLen;i++) {
198  if(tube[i]==EEMCDbStringDelim) {
199  tube[i]=0;
200  return;
201  }
202  }
203  LOG_WARN<<Form("Error in EEmcDbItem::setTube(%s), no terminating '%c'\n",text,EEMCDbStringDelim)<<endm;
204  assert(1==2);
205 }
206 
207 //--------------------------------------------------
208 //--------------------------------------------------
209 void EEmcDbItem::setName(char *text) {
210  strncpy(name,text,StEEmcNameLen-1);
211  sec=atoi(text);
212  if(name[2]=='U' || name[2]=='V' ) {
213  plane=name[2];
214  strip=atoi(text+3);
215  }else {
216  assert(name[2]=='T' ||name[2]=='P' ||name[2]=='Q' ||name[2]=='R' );
217  sub=text[3];
218  eta=atoi(text+4);
219  }
220  // cleanup termintaing character
221  int i;
222  for(i=0;i<StEEmcNameLen;i++) {
223  if(name[i]==EEMCDbStringDelim) {
224  name[i]=0;
225  return;
226  }
227  }
228  LOG_WARN<<Form("Error in EEmcDbItem::setName(%s), no terminating '%c'\n",text,EEMCDbStringDelim)<<endm;
229  assert(1==2);
230 }
231 
232 // $Log: EEmcDbItem.cxx,v $
233 // Revision 1.2 2009/12/03 21:15:39 ogrebeny
234 // Fixed compiler warnings
235 //
236 // Revision 1.1 2009/02/04 20:33:28 ogrebeny
237 // Moved the EEMC database functionality from StEEmcDbMaker to StEEmcUtil/database. See ticket http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1388
238 //
239 // Revision 1.16 2007/05/30 02:38:34 balewski
240 // replace printf -->LOG_XXX
241 //
242 // Revision 1.15 2007/01/26 20:45:58 balewski
243 // now we have pure new Logger, thanks Jason, Jan
244 //
245 // Revision 1.14 2005/09/19 21:43:32 balewski
246 // I was wrong, there was no bug
247 //
248 // Revision 1.13 2005/09/19 21:41:51 balewski
249 // bug : '&' was missing in importAscii()
250 //
251 // Revision 1.12 2005/02/02 01:36:50 balewski
252 // few more access methods + sigPed visible in EEmcDbItem
253 //
254 // Revision 1.11 2004/04/28 20:38:10 jwebb
255 // Added StEEmcDbMaker::setAsciiDatabase(). Currently not working, since
256 // tube name missing for some towers, triggereing a "clear" of all EEmcDbItems.
257 //
258 // Revision 1.10 2004/04/04 06:10:37 balewski
259 // *** empty log message ***
260 //
261 // Revision 1.9 2004/03/19 21:31:53 balewski
262 // new EEMC data decoder
263 //
264 // Revision 1.8 2004/03/12 21:53:39 balewski
265 // bug with not cleared 'plane'
266 //
267 // Revision 1.7 2004/03/12 02:24:10 balewski
268 // to synchronize
269 //
270 // Revision 1.6 2004/02/26 04:21:17 balewski
271 // read ASCII dump
272 //
273 // Revision 1.5 2003/12/10 04:43:10 balewski
274 // fisrt QA
275 //
276 // Revision 1.4 2003/12/04 18:27:46 balewski
277 // added MAPMT pixel names
278 //
279 // Revision 1.3 2003/12/01 05:01:40 balewski
280 // DB & SMD
281 //
282 // Revision 1.2 2003/11/22 05:35:36 balewski
283 // saves ped in DB format
284 //
285 // Revision 1.1 2003/11/20 16:01:25 balewski
286 // towards run4
287 //
288 
289 
290 
char name[StEEmcNameLen]
ASCII name of the channel, see Readme.
Definition: EEmcDbItem.h:20
char tube[StEEmcNameLen]
name of PMT or MAPMT pixel
Definition: EEmcDbItem.h:21
int chan
hardware channel
Definition: EEmcDbItem.h:28