StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
client_svt.cxx
1 /***************************************************************************
2  * $Id: client_svt.cxx,v 1.2 2014/06/25 15:33:17 jeromel 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_svt.cxx,v $
11  * Revision 1.2 2014/06/25 15:33:17 jeromel
12  * Code not used but erradicated use of flush
13  *
14  * Revision 1.1 2007/01/04 21:27:52 jml
15  * zero suppressed reader no longer uses adcx, only seqd. Fixes bug from early 2005
16  *
17  * Revision 1.3 2003/09/02 17:55:34 perev
18  * gcc 3.2 updates + WarnOff
19  *
20  * Revision 1.2 2003/01/29 13:55:18 ward
21  * Turn off memory mapped operation in the examples, which appears to fail for 2003 daq files.
22  *
23  * Revision 1.1 2001/04/18 19:49:32 ward
24  * Added SVT example program client_zs.cxx from J. Schambach.
25  *
26  *
27  **************************************************************************/
28 
29 
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <errno.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <assert.h>
37 
38 
39 #include "StDaqLib/GENERIC/EventReader.hh"
40 #include "StDaqLib/SVT/SVTV1P0.hh"
41 #include "StDaqLib/SVT/SVTV1P0_Reader.hh"
42 
43 // the following extracts the filename stripped of its directory path.
44 
45 int main(int argc, char *argv[])
46 {
47  int fd;
48  //client must provide
49  //array of pointers to padlist (one for each pad row)
50  u_char *(padlist[TPC_PADROWS]);
51  long offset = 0L;
52  int histogram[50] = {50*0};
53 
54  if(argc<2)
55  {
56  printf("Usage: %s file.daq\n",argv[0]);
57  exit(2);
58  }
59 
60  fd = open(argv[1],O_RDONLY);
61 
62  if (fd == -1)
63  {
64  printf("Bad filename %s",argv[1]);
65  exit(2);
66  }
67 
68  int eventNo;
69  for (eventNo=0; eventNo < 1; eventNo++ )
70  {
71  EventReader *er = getEventReader(fd,offset,"log",0); // Memory-mapped operation fails for 2003 daq files.
72  if(!er)
73  {
74  printf("No event reader...\n");
75  close(fd);
76  exit(0);
77  // assert(0); // This may be simply the end of the .daq file.
78  }
79 
80  er->printEventInfo();
81 
82 
83  // Prepare for the next event
84  if(offset != -1)
85  offset = er->NextEventOffset();
86  else
87  offset = -1;
88 
89 
90  SVTV1P0_Reader *dr = (SVTV1P0_Reader *)getDetectorReader(er, "SVT");
91  if(!dr) {
92  printf("No SVT reader\n");
93  close(fd);
94  assert(0);
95  }
96  // else printf("created SVT_Reader!!!\n");
97 
98 
99 
100  for(int ii=1;ii<=3;ii++) { // barrel
101  int lads[3] = { 8,12,16 };
102 
103  for(int jj=1;jj<=lads[ii-1];jj++) { // ladders
104  int wafs[3] = { 4,6,7 };
105 
106  for(int kk=1;kk<=wafs[ii-1];kk++) { // wafers
107 
108  // printf("Getting zs read (%d %d %d)\n",ii,jj,kk);
109 
110  SVTV1P0_ZS_SR *zsr =
111  (SVTV1P0_ZS_SR *)dr->getZeroSuppressedReader(ii,jj,kk);
112 
113  // printf("Got zs read (%d,%d,%d)\n",ii,jj,kk);
114 
115  if (!zsr) {
116  //printf("zsr creation for (%d,%d,%d) failed\n", ii,jj,kk);
117  continue;
118  }
119 
120  //else printf("Created zsr for wafer (%d,%d,%d)\n",ii,jj,kk);
121  // do something with it
122  int nSeq, anode, hybrid;
123  int nAnodes, nSpt;
124  u_char *AnodeList;
125  Sequence *Seq;
126  SpacePt *Spt;
127 
128  for(int ll=1;ll<=2;ll++) { // hybrids
129 
130  //printf("getting padlist\n");
131  nAnodes = zsr->getPadList(ll, &AnodeList);
132  //printf("got padlist %d\n",nAnodes);
133 
134  for(int an = 0;an<nAnodes;an++) {
135 
136  //printf("anode[%d] = %d (0x%x)\n",an,AnodeList[an],zsr);
137  int ret = zsr->getSequences(ll, AnodeList[an], &nSeq, &Seq);
138  //printf("got seq %d\n",nSeq);
139 
140  for(int seq = 0;seq<nSeq;seq++) {
141 
142  for(int iii=0;iii<Seq[seq].Length;iii++) {
143  printf("%d %d %d %d %d %d %d\n",
144  ii,jj,kk,ll,AnodeList[an],
145  iii + Seq[seq].startTimeBin,
146  Seq[seq].FirstAdc[iii]);
147  }
148  }
149  }
150  }
151  // printf("deleting\n");
152  delete zsr; // remove ZeroSuppressedReader
153  //printf("deleted\n");
154  }
155  }
156  }
157  delete dr; // remove SVT reader
158 
159  delete er;
160  }
161  close(fd);
162 }