StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
client_zs.cxx
1 /***************************************************************************
2  * $Id: client_zs.cxx,v 1.3 2003/09/02 17:55:34 perev Exp $
3  * Author: J. Schambach
4  ***************************************************************************
5  * Description: sample top-level code should be used as a tutorial
6  * for any application using the StDaqLib class library
7  *
8  *
9  ***************************************************************************
10  * $Log: client_zs.cxx,v $
11  * Revision 1.3 2003/09/02 17:55:34 perev
12  * gcc 3.2 updates + WarnOff
13  *
14  * Revision 1.2 2003/01/29 13:55:18 ward
15  * Turn off memory mapped operation in the examples, which appears to fail for 2003 daq files.
16  *
17  * Revision 1.1 2001/04/18 19:49:32 ward
18  * Added SVT example program client_zs.cxx from J. Schambach.
19  *
20  *
21  **************************************************************************/
22 
23 
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <errno.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <assert.h>
31 #include "Stiostream.h"
32 
33 #include "StDaqLib/GENERIC/EventReader.hh"
34 #include "StDaqLib/SVT/SVTV1P0_Reader.hh"
35 
36 // the following extracts the filename stripped of its directory path.
37 
38 char logfile[80];
39 
40 
41 char *convert_name_to_logfile(const char *filename)
42 {
43  static char locfile[80];
44  strcpy(locfile,filename);
45  strcat(locfile,".log");
46  char *t1;
47  char *t2 = locfile;
48  t1 = strtok(locfile,"/");
49  while (t1!=NULL) {
50  t2 = t1;
51  t1 = strtok(NULL,"/");
52  }
53  strcpy(locfile,t2);
54  return locfile;
55 }
56 
57 int main(int argc, char *argv[])
58 {
59  int fd;
60  string filename;
61  //client must provide
62  //array of pointers to padlist (one for each pad row)
63  u_char *(padlist[TPC_PADROWS]);
64  long offset = 0L;
65  int histogram[50] = {50*0};
66 
67 
68  if (argc==3) offset = atol(argv[2]);
69 
70  if(argc<2)
71  {
72  printf("Usage: %s file.daq [offset]\n",argv[0]);
73  printf("Example: %s /scratch/2sbWith2Rcv_from_Tape.dat\n",argv[0]);
74  exit(2);
75  }
76  else
77  {
78  filename = argv[1];
79  }
80 
81  strcpy(logfile,convert_name_to_logfile(filename.c_str()));
82 
83  printf(" opening log file: %s\n",logfile);
84 
85  fd = open(filename.c_str(),O_RDONLY);
86 
87  if (fd == -1)
88  {
89  perror("FormatClient");
90  }
91 
92  int eventNo;
93  //while(offset != -1)
94  for (eventNo=0; eventNo < 1; eventNo++ )
95  {
96  EventReader *er = getEventReader(fd,offset,(const char *)logfile,0); // Memory-mapped operation fails for 2003 daq files.
97  if(!er)
98  {
99  cout << "============================================" << endl;
100  cout << "Error creating ER" << endl;
101  cout << "This may be simply the end of the .daq file." << endl;
102  close(fd);
103  exit(0);
104  // assert(0); // This may be simply the end of the .daq file.
105  }
106 
107  er->printEventInfo();
108 
109 
110  // Prepare for the next event
111  if(offset != -1)
112  offset = er->NextEventOffset();
113  else
114  offset = -1;
115 
116 #define DOSVT
117 #define DO_RAW
118 
119 #ifdef DOSVT
120  DetectorReader *dr = getDetectorReader(er, "SVT");
121  if(!dr) {
122  cout << "Error creating SVT_Reader: " << er->errstr() << endl;
123  if (er->errorNo() == INFO_MISSING_BANK)
124  cout << "No SVTP bank available" << endl;
125  close(fd);
126  assert(0);
127  }
128  else printf("created SVT_Reader!!!\n");
129 
130 
131 #ifdef DO_RAW
132  SVTV1P0_Reader *sdr = (SVTV1P0_Reader *)dr;
133  int wafer = 7, barrel = 3, ladder = 1;
134  ADCRawReader *adcrr =
135  sdr->getADCRawReader(barrel, ladder, wafer);
136 
137  u_char *adcVal;
138  int nVal, hybrid=1, anode=241;
139  int ret = adcrr->getSequences(hybrid, anode, &nVal, &adcVal);
140  printf("Found %d ADC values for anode %d, hybrid %d\n",
141  nVal, anode, hybrid);
142 
143  if (nVal > 0)
144  // print the first few
145  for (int ii=0; ii<11; ii++) printf("%d ", adcVal[ii]);
146  printf("\n");
147 
148  delete adcrr;
149 #endif
150 
151 #ifdef DO_PEDR
152  SVTV1P0_Reader *sdr = (SVTV1P0_Reader *)dr;
153  int wafer = 7, barrel = 3, ladder = 1;
154  PedestalReader *pedrr =
155  sdr->getPedestalReader(barrel, ladder, wafer);
156 
157  u_char *adcVal;
158  int nVal, hybrid=1, anode=241;
159  int ret = pedrr->getSequences(hybrid, anode, &nVal, &adcVal);
160  printf("Found %d ADC values for anode %d, hybrid %d\n",
161  nVal, anode, hybrid);
162 
163  if (nVal > 0)
164  // print the first few
165  for (int ii=0; ii<11; ii++) printf("%d ", adcVal[ii]);
166  printf("\n");
167 
168  delete pedrr;
169 #endif
170 #ifdef DO_ZSR
171  for(int wafer = 104; wafer < 104+5; wafer++) {
172  ZeroSuppressedReader *zsr =
173  dr->getZeroSuppressedReader(wafer);
174  if (!zsr) {
175  printf("zsr creation for wafer %d failed\n", wafer);
176  continue;
177  }
178  else printf("Created zsr for wafer %d\n", wafer);
179  // do something with it
180  int nSeq, anode, hybrid;
181  int nAnodes, nSpt;
182  u_char *AnodeList;
183  Sequence *Seq;
184  SpacePt *Spt;
185  hybrid=1;
186 
187  nAnodes = zsr->getPadList(hybrid, &AnodeList);
188  printf("Wafer %d, hybrid %d has %d anodes with data:\n",
189  wafer, hybrid, nAnodes);
190  if (nAnodes) {
191  for (int ii=0; ii<nAnodes; ii++)
192  printf("%d ", AnodeList[ii]);
193  printf("\n");
194  int ret = zsr->getSequences(hybrid, AnodeList[0], &nSeq, &Seq);
195  printf("Found %d sequences for anode %d, hybrid %d:\n",
196  nSeq, AnodeList[0], hybrid);
197  if (nSeq) { // just print out the first sequence
198  printf("Sequence 0: startTime %d, len %d, ADC values:\n",
199  Seq[0].startTimeBin, Seq[0].Length);
200  for (int ii=0; ii<Seq[0].Length; ii++)
201  printf("%d ", Seq[0].FirstAdc[ii]);
202  printf("\n");
203  }
204  zsr->getSpacePts(hybrid, &nSpt, &Spt);
205  printf("Found %d spacepoints\n", nSpt);
206  }
207 
208  delete zsr; // remove ZeroSuppressedReader
209  }
210 #endif
211 
212  delete dr; // remove SVT reader
213 #endif
214 
215  delete er;
216  }
217  close(fd);
218 }