StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
client.cxx
1 /***************************************************************************
2  * $Id: client.cxx,v 1.13 2003/09/02 17:55:34 perev Exp $
3  * Author: M.J. LeVine
4  ***************************************************************************
5  * Description: sample top-level code sould be used as a tutorial
6  * for any application using the StDaqLib class library
7  *
8  *
9  * change log
10  * 02-Jul-99 MJL remove #include "StDaqLib/TPC/MemMan.hh"
11  * 09-Jul-99 MJL add calls to various non_TPC detector readers
12  * 12-Jul-99 MJL add calls to getSpacePts()
13  * 20-Jul-99 MJL use new EventReader constructor with log file name
14  *
15  ***************************************************************************
16  * $Log: client.cxx,v $
17  * Revision 1.13 2003/09/02 17:55:34 perev
18  * gcc 3.2 updates + WarnOff
19  *
20  * Revision 1.12 2003/01/29 20:08:09 geurts
21  * disabled usage of TRG_Reader::PrintAllTheData() and ::PrintDataCompact().
22  * Both methods are unavailabe in TRG_Reader.
23  *
24  * Revision 1.11 2003/01/29 13:55:18 ward
25  * Turn off memory mapped operation in the examples, which appears to fail for 2003 daq files.
26  *
27  * Revision 1.10 2000/07/03 16:03:17 ward
28  * Minor improvements to client.cxx, eg a usage message.
29  *
30  * Revision 1.9 2000/06/08 12:45:10 jml
31  * Added <assert.h> to fix compile error in offline
32  *
33  * Revision 1.8 2000/06/07 15:06:26 jml
34  * Changed exit() calls to assert(0) to aid in debugging
35  *
36  * Revision 1.7 2000/01/14 17:54:26 levine
37  * example use of TRG_Reader
38  *
39  * Revision 1.6 2000/01/04 20:55:05 levine
40  * Implemented memory-mapped file access in EventReader.cxx. Old method
41  * (via seeks) is still possible by setting mmapp=0 in
42  *
43  * getEventReader(fd,offset,(const char *)logfile,mmapp);
44  *
45  *
46  * but memory-mapped access is much more effective.
47  *
48  * Revision 1.4 1999/07/21 21:33:10 levine
49  *
50  *
51  * changes to include error logging to file.
52  *
53  * There are now 2 constructors for EventReader:
54  *
55  * EventReader();
56  * EventReader(const char *logfilename);
57  *
58  * Constructed with no argument, there is no error logging. Supplying a file name
59  * sends all diagnostic output to the named file (N.B. opens in append mode)
60  *
61  * See example in client.cxx for constructing a log file name based on the
62  * datafile name.
63  *
64  * It is strongly advised to use the log file capability. You can grep it for
65  * instances of "ERROR:" to trap anything noteworthy (i.e., corrupted data files).
66  *
67  * Revision 1.3 1999/07/10 21:31:33 levine
68  * Detectors RICH, EMC, TRG now have their own (defined by each detector) interfaces.
69  * Existing user code will not have to change any calls to TPC-like detector
70  * readers.
71  *
72  * Revision 1.2 1999/07/07 19:24:37 levine
73  * Added comments on using 8-bit to 10-bit translation table by popular request
74  * (well, at least one person requested this change)
75  *
76  * Revision 1.1 1999/07/02 20:40:57 levine
77  * Moved to examples directory from top-level
78  *
79  *
80  **************************************************************************/
81 
82 
83 #include <stdio.h>
84 #include <unistd.h>
85 #include <errno.h>
86 #include <sys/types.h>
87 #include <sys/stat.h>
88 #include <fcntl.h>
89 #include <assert.h>
90 #include "Stiostream.h"
91 
92 #include "StDaqLib/GENERIC/EventReader.hh"
93 #include "StDaqLib/EMC/EMC_Reader.hh"
94 #include "StDaqLib/RICH/RICH_Reader.hh"
95 #include "StDaqLib/TRG/TRG_Reader.hh"
96 
97 #include "StDaqLib/TPC/trans_table.hh"
98 // this contains the 8-bit to 10-bit translation table
99 // for PHYSICS running
100 
101  // the following extracts the filename stripped of its directory path.
102 
103 char logfile[80];
104 
105 
106 char *convert_name_to_logfile(const char *filename)
107 {
108  static char locfile[80];
109  strcpy(locfile,filename);
110  strcat(locfile,".log");
111  char *t1;
112  char *t2 = locfile;
113  t1 = strtok(locfile,"/");
114  while (t1!=NULL) {
115  t2 = t1;
116  t1 = strtok(NULL,"/");
117  }
118  strcpy(locfile,t2);
119  return locfile;
120 }
121 
122 int main(int argc, char *argv[])
123 {
124  int fd;
125  string filename;
126  //client must provide
127  //array of pointers to padlist (one for each pad row)
128  u_char *(padlist[TPC_PADROWS]);
129  long offset = 0L;
130  int histogram[50] = {50*0};
131 
132 
133  if (argc==3) offset = atol(argv[2]);
134 
135  if(argc<2)
136  {
137  printf("Usage: %s file.daq [offset]\n",argv[0]);
138  printf("Example: %s /scratch/2sbWith2Rcv_from_Tape.dat\n",argv[0]);
139  exit(2);
140  }
141  else
142  {
143  filename = argv[1];
144  }
145 
146  strcpy(logfile,convert_name_to_logfile(filename.c_str()));
147 
148  printf(" opening log file: %s\n",logfile);
149 
150  fd = open(filename.c_str(),O_RDONLY);
151 
152  if (fd == -1)
153  {
154  perror("FormatClient");
155  }
156 
157  while(offset != -1)
158  {
159  EventReader *er = getEventReader(fd,offset,(const char *)logfile,0); // Mamory map appears not to work with 2003 daq files.
160  if(!er)
161  {
162  cout << "============================================" << endl;
163  cout << "Error creating ER" << endl;
164  cout << "This may be simply the end of the .daq file." << endl;
165  close(fd);
166  assert(0); // This may be simply the end of the .daq file.
167  }
168 
169  er->printEventInfo();
170 
171 
172  // Prepare for the next event
173  if(offset != -1)
174  offset = er->NextEventOffset();
175  else
176  offset = -1;
177 
178  TRG_Reader *tr = getTRGReader(er);
179  if(!tr) {
180  cout << "Error creating TRG_Reader: " << er->errstr() << endl;
181  close(fd);
182  assert(0);
183  }
184  else printf("created TRG_Reader!!!\n");
185  //fprintf(er->logfd,"\n\n================\n\nHerb's formatted TRGD dump:\n\n\n");
186  //tr->pBankTRGD->PrintAllTheData(er->logfd);
187  //fprintf(er->logfd,"\n\n================\n\nMike's formatted TRGD dump:\n\n\n");
188  //tr->pBankTRGD->PrintDataCompact(er->logfd);
189 
190 #ifdef DOTPC
191 
192  DetectorReader *dr = getDetectorReader(er, "TPCV2P0");
193  if(!dr) {
194  cout << "Error creating TPC_Reader: " << er->errstr() << endl;
195  close(fd);
196  assert(0);
197  }
198  else printf("created TPC_Reader!!!\n");
199 #ifdef DO_SECTORS
200  for(int sector=1;sector <= 24;sector++)
201  {
202 
203  int nSeq[TPC_MAXPADS];
204  Sequence *Seq[TPC_MAXPADS];
205 
206 
207  PedestalReader *pedr = dr->getPedestalReader(sector);
208  if(!pedr)
209  {
210  cout << "Error creating pedestal reader: " << dr->errstr() << endl;
211  close(fd);
212  assert(0);
213  }
214 
215  PedestalRMSReader *rmsr = dr->getPedestalRMSReader(sector);
216  if(!rmsr)
217  {
218  cout << "Error creating pedestal RMS reader: " << dr->errstr() << endl;
219  close(fd);
220  assert(0);
221  }
222 
223  // test for existence of PEDR banks this sector
224  if (pedr->getNumberOfEvents()==0) continue; // no PEDR banks this sector
225 #ifdef PEDS
226  for(int row=1;row <= TPC_PADROWS; row++)
227  {
228  int count = pedr->getPadList(row, &padlist[row-1]);
229  if (count){
230  printf("%2d -- pad list\n",row);
231  for(int i=0;i<count;i++)
232  {
233  printf("%4d",padlist[row-1][i]);
234  }
235  printf("\n");
236  }
237  }
238 
239  for(int row=1;row <= TPC_PADROWS; row++)
240  {
241  int count = pedr->getPadList(row, &padlist[row-1]);
242 
243  for(int i=0;i<count;i++)
244  {
245  int length;
246  u_char *Array[TPC_MAXPADS];
247  u_char thispad = padlist[row-1][i];
248  int nseq = pedr->getSequences(row, thispad, &length, &Array[thispad-1]);
249  // print non-zero ADC values for this pad (all 512)
250  if (!nseq) continue; // pad not implemented
251  printf("pedestal values for row %d, pad %d:\n",row,thispad);
252  for(int j=0; j<length; j++)
253  {
254  printf("%d ", Array[thispad-1][j]);
255  if (j%16==0) printf("\n");
256  }
257  printf("\n");
258  }
259  }
260 #endif
261  for(int row=1;row <= TPC_PADROWS; row++)
262  {
263  int count = rmsr->getPadList(row, &padlist[row-1]);
264 
265  for(int i=0;i<count;i++)
266  {
267  int length;
268  u_char *Array[TPC_MAXPADS];
269  u_char thispad = padlist[row-1][i];
270  int nseq = rmsr->getSequences(row, thispad, &length, &Array[thispad-1]);
271  // print non-zero ADC values for this pad (all 512)
272  if (!nseq) continue; // pad not implemented
273  printf("pedestal RMS values for row %d, pad %d:\n",row,thispad);
274  for(int j=0; j<length; j++)
275  {
276  printf("%4.1f ", (float)Array[thispad-1][j]/16.0);
277  if (j%16==0) printf("\n");
278  }
279  printf("\n");
280  }
281  }
282 
283  delete pedr;
284  delete rmsr;
285  }
286 #endif
287  delete dr; // remove TPC reader
288 #endif
289  delete tr; // remove TRG reader
290  delete er;
291  }
292  close(fd);
293 }
294