StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEmcDbCrate.cxx
1 // $Id: EEmcDbCrate.cxx,v 1.1 2009/02/04 20:33:28 ogrebeny Exp $
2 
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <assert.h>
7 #include "TString.h"
8 
9 #include "EEmcDbCrate.h"
10 
11 //--------------------------------------------------
12 //--------------------------------------------------
13 EEmcDbCrate::EEmcDbCrate() {
14  clear();
15 }
16 
17 //--------------------------------------------------
18 //--------------------------------------------------
19 int EEmcDbCrate::isEmpty() const{
20  return name[0]==0;
21 }
22 
23 
24 //--------------------------------------------------
25 //--------------------------------------------------
26 void EEmcDbCrate::print() const{
27  LOG_INFO<<"EEmcDbCrate::print():"<<endm;
28 
29  if(name[0]==0) {
30  LOG_WARN<<" item not defined ???"<<endm;
31  return;
32  }
33 
34  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;
35 }
36 
37 ostream &
38 EEmcDbCrate::print( ostream &out ) const
39 {
40  out << "DbCrate: ";
41  if ( isEmpty() ) {
42  out << "crate not defined";
43  return out;
44  }
45  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);
46  return out;
47 }
48 
49 ostream &operator<<(ostream &out, const EEmcDbCrate &crate )
50 {
51  return crate.print(out);
52 }
53 //--------------------------------------------------
54 //--------------------------------------------------
55 void EEmcDbCrate::clear() {
56  name[0]=0;
57  crID=-1;
58  crIDswitch=-2;
59  fiber=-3;
60  nCh=-4;
61  nHead=-5;
62  type='X';
63  useIt=0;
64 }
65 
66 
67 //--------------------------------------------------
68 //--------------------------------------------------
69 void EEmcDbCrate::setName(char *text) {
70  strncpy(name,text,CrateNameLen-1);
71 }
72 
73 //--------------------------------------------------
74 //--------------------------------------------------
75 void EEmcDbCrate::setAll(char *buf ) {
76  //printf("buf='%s'\n",buf);
77  int ret=sscanf(buf,"%s %d %d %d %d %d %c %d",name,&crID,&crIDswitch,&fiber,&nCh,&nHead,&type,&useIt);
78  // printf("ret=%d\n",ret);
79  assert(ret==8);
80 }
81 
82 //--------------------------------------------------
83 //--------------------------------------------------
84 void EEmcDbCrate::exportAscii(FILE *fd) const{
85 
86  if(name[0]==0) return; // item not defined
87  fprintf(fd,"%s %d %d %d %d %d %c %d \n",name,crID,crIDswitch,fiber,nCh,nHead,type,useIt);}
88 
89 
90 #if 0
91 //--------------------------------------------------
92 //--------------------------------------------------
93 int EEmcDbCrate::importAscii(FILE *fd){
94  /* return:
95  <0 : error in input
96  0 : EOF
97  1 : line ignored
98  2 : valid input
99  */
100 
101  clear();
102  const int mx=1000;
103  char buf[mx];
104 
105  char * ret=fgets(buf,mx,fd);
106 
107  if(ret==0) return 0;
108 
109  if(buf[0]=='#') return 1;
110  char name0[mx];
111  int ret1=sscanf(buf,"%s",name0);
112  if(ret1==0) return -1;
113 
114  int n=0;
115  // printf("aaa name='%s' n=%d\n",name,name[0]);
116  if(name0[2]=='U' || name0[2]=='V') {
117  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);
118  }
119  else if (name0[2]=='T' || name0[2]=='P' || name0[2]=='Q' || name0[2]=='R' ) {
120  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);
121  }
122  else
123  return -3;
124 
125 
126 
127  if(n!=13) return -1000-n;
128  // print();
129  return 2;
130 }
131 #endif
132 
133 
134 
135 // $Log: EEmcDbCrate.cxx,v $
136 // Revision 1.1 2009/02/04 20:33:28 ogrebeny
137 // Moved the EEMC database functionality from StEEmcDbMaker to StEEmcUtil/database. See ticket http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1388
138 //
139 // Revision 1.7 2007/05/30 02:38:34 balewski
140 // replace printf -->LOG_XXX
141 //
142 // Revision 1.6 2007/01/26 20:45:58 balewski
143 // now we have pure new Logger, thanks Jason, Jan
144 //
145 // Revision 1.5 2004/04/04 06:10:36 balewski
146 // *** empty log message ***
147 //
148 // Revision 1.4 2004/04/03 06:32:48 balewski
149 // *** empty log message ***
150 //
151 // Revision 1.3 2004/03/30 04:44:57 balewski
152 // *** empty log message ***
153 //
154 // Revision 1.2 2004/03/28 04:09:08 balewski
155 // storage of EEMC raw data, not finished
156 //
157 // Revision 1.1 2004/03/19 21:31:52 balewski
158 // new EEMC data decoder
159 //
160 // Revision 1.8 2004/03/12 21:53:39 balewski
161 
162 
163 
int nCh
no. of valid channels for the crate
Definition: EEmcDbCrate.h:16
int nHead
no. of header words
Definition: EEmcDbCrate.h:17
int useIt
flag to ignore data from misconfig/broken crate/box
Definition: EEmcDbCrate.h:19
char name[CrateNameLen]
crT1,... for towers, 06S1,... for mapmt
Definition: EEmcDbCrate.h:12
int fiber
position of the crate in the .daq data stream, couting from 0
Definition: EEmcDbCrate.h:15
char type
is &#39;T&#39; for towers &amp; &#39;S&#39; for MAPMT
Definition: EEmcDbCrate.h:18
int crIDswitch
crate ID set by hardware switch
Definition: EEmcDbCrate.h:14
int crID
logical crate ID
Definition: EEmcDbCrate.h:13