GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
m_histo_conv.c
Go to the documentation of this file.
1 // $Id: m_histo_conv.c 478 2009-10-29 12:26:09Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "typedefs.h"
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <errno.h>
18 #include <ctype.h>
19 #include <string.h>
20 #include "f_ut_wild.h"
21 #include "f_his_hist.h"
22 #include "f_radware.h"
23 /**************************************************************************/
24 main(argc,argv)
25 int argc;
26 char *argv[];
27 {
28 s_his_head *ps_his_head,*ps_his_head_dir;
29 INTS4 i_j,ii,l_status,l_port,l_int;
30 INTS4 l_size,l_histos=0;
31 INTS4 *pl_all,*pl_dir,*pl_l;
32 REAL4 *pr,*pr_l;
33 CHARS *pc;
34 CHARS c_server[32];
35 CHARS c_histo[32];
36 CHARS c_base[32];
37 CHARS c_access[32];
38 CHARS c_file[128];
39 
40 if(argc < 7)
41 {
42 printf("node port|6009 base password \"histogram\" [-print|-dir|-rad]\n");
43 exit(0);
44 }
45 l_port=atol(argv[2]);
46 strcpy(c_server,argv[1]);
47 strcpy(c_access,argv[4]);
48 strcpy(c_base,argv[3]);
49 strcpy(c_histo,argv[5]);
50 
51 pl_all=NULL;
52 /* get directory ******************************************************/
53  if(strstr(argv[6],"-d") != NULL)
54  {
55  printf("Get directory %s from server %s [%d] pass=*** base=%s\n",
56  c_histo,c_server,l_port,c_base);
57  ps_his_head_dir=NULL;
58  pl_dir=NULL;
59  l_status = f_his_getdir(c_server,l_port,c_base,c_access,c_histo,(INTS4 **)&pl_dir,(INTS4 **)&l_histos);
60  if(l_status == COMM__SUCCESS)
61  {
62  printf("Histograms: %d, slot size: %d b, Total: %d b\n",
63  l_histos,sizeof(s_his_head),l_histos*sizeof(s_his_head));
64  ps_his_head_dir = (s_his_head *)pl_dir;
65  for(i_j=0;i_j<l_histos;i_j++)
66  {
67  if(f_ut_wild(ps_his_head_dir->c_name,c_histo)==0)
68  printf("%-31s %s %8d %8d\n",
69  ps_his_head_dir->c_name,ps_his_head_dir->c_dtype,ps_his_head_dir->l_bins_1,ps_his_head_dir->l_bins_2);
70  ps_his_head_dir++;
71  }
72  } else printf("Error %d\n",l_status);
73  exit(0);
74  }
75 /* get histograms ******************************************************/
76  printf("Lookup histograms %s at server %s [%d] pass=*** base=%s\n",
77  c_histo,c_server,l_port,c_base);
78  ps_his_head_dir=NULL;
79  pl_dir=NULL;
80  l_status = f_his_getdir(c_server,l_port,c_base,c_access,c_histo,(INTS4 **)&pl_dir,(INTS4 **)&l_histos);
81  if(l_status != COMM__SUCCESS)
82  {
83  printf("Error %d getting histograms %s\n",l_status,c_histo);
84  exit(0);
85  }
86  ps_his_head_dir = (s_his_head *)pl_dir;
87  for(i_j=0;i_j<l_histos;i_j++)
88  {
89  if(f_ut_wild(ps_his_head_dir->c_name,c_histo)==0)
90  {
91  ps_his_head=NULL;
92  pl_all=NULL;
93  l_status = f_his_gethis(c_server,l_port,c_base,c_access,ps_his_head_dir->c_name,
94  (s_his_head **)&ps_his_head,(INTS4 **)&pl_all,(INTS4 **)&l_size);
95  if(l_status != COMM__SUCCESS)
96  {
97  printf("Error %d getting histogram %s\n",l_status,ps_his_head_dir->c_name);
98  exit(0);
99  }
100 
101  /* process histogram ******************************************************/
102  pl_l = pl_all;
103  pr_l =(REAL4 *)pl_all;
104  if(ps_his_head->c_dtype == 'i') l_int=1; else l_int=0;
105 
106  /* print histogram ******************************************************/
107  if(strstr(argv[6],"-p") != NULL)
108  {
109  printf("Histogram %s\n",ps_his_head_dir->c_name);
110  printf(" channels: %10d, total: %10d [b], %s %8d %8d\n",
111  ps_his_head->l_bins_1*ps_his_head->l_bins_2,l_size,
112  ps_his_head->c_dtype,ps_his_head->l_bins_1,ps_his_head->l_bins_2);
113  /* print data channels */
114  if(ps_his_head->l_bins_2 == 1)
115  {
116  for (i_j = 0; i_j < (ps_his_head->l_bins_1 - ps_his_head->l_bins_1 % 6); i_j += 6)
117  {
118  if(l_int) printf("%7d:%9d %9d %9d %9d %9d %9d\n",
119  i_j + 1,*pl_l,*(pl_l+1),*(pl_l+2),*(pl_l+3),*(pl_l+4),*(pl_l+5));
120  else printf("%7d:%11.4g %11.4g %11.4g %11.4g %11.4g %11.4g\n",
121  i_j + 1,*pr_l,*(pr_l+1),*(pr_l+2),*(pr_l+3),*(pr_l+4),*(pr_l+5));
122  pl_l+=6;
123  pr_l+=6;
124  }
125  if ((ps_his_head->l_bins_1 % 6))
126  {
127  printf("%7d:",i_j + 1);
128  for (i_j = ps_his_head->l_bins_1 - ps_his_head->l_bins_1 % 6; i_j < ps_his_head->l_bins_1; i_j++)
129  {
130  if(l_int) printf("%9d ", *pl_l);
131  else printf("%11.4g ", *pr_l);
132  pl_l++;
133  pr_l++;
134  }
135  printf("\n");
136  }}else printf("2d Histograms %s not supported\n",ps_his_head_dir->c_name);
137  }
138  /* dump radware histogram ******************************************************/
139  if(strstr(argv[6],"-r") != NULL)
140  {
141  if(argc == 8)strcpy(c_file,argv[7]);
142  else strcpy(c_file,"rad_");
143  strcat(c_file,ps_his_head_dir->c_name); // name from directory call includes path
144  pc=c_file;
145  for(ii=0;ii<strlen(c_file);ii++)
146  {
147  if(*pc == '/')*pc='-';
148  if(*pc == '(')*pc='[';
149  if(*pc == ')')*pc=']';
150  if(*pc == ' ')*pc='_';
151  pc++;
152  }
153  strcat(c_file,".spe");
154  if(ps_his_head->l_bins_2 == 1)
155  {
156  if(l_int == 0)
157  {
158  pr=(REAL4 *) malloc(ps_his_head->l_bins_1*4);
159  pr_l=pr;
160  for(ii=0;ii<ps_his_head->l_bins_1;ii++)*pr++=(REAL4)*pl_l++;
161  }
162  l_status=f_radware_out1d(c_file,ps_his_head->c_name,pr_l,ps_his_head->l_bins_1,0);
163  if(l_status == 0)printf("Radware histogram %s written to file %s.\n",ps_his_head_dir->c_name,c_file);
164  else printf("Radware histogram %s NOT written to file %s, ERROR!\n",ps_his_head_dir->c_name,c_file);
165  if(l_int == 0)free(pr_l);
166  } else printf("2d Histograms %s not supported\n",ps_his_head_dir->c_name);
167  }
168  free(pl_all);
169  }
170  ps_his_head_dir++;
171  }
172 }
173 
int f_radware_out1d(char *pc_file, char *pc_name, float *pr_data, int l_chan, int l_over)
Definition: f_radware.c:32
INTS4 f_his_getdir(const char *, int, const char *, const char *, const char *, INTS4 **, INTS4 *)
float REAL4
Definition: typedefs.h:30
#define COMM__SUCCESS
Definition: s_his_comm.h:27
main(int argc, argv)
Definition: m_histo_conv.c:24
INTS4 l_bins_2
Definition: s_his_head.h:23
int l_status
Definition: f_evcli.c:183
int INTS4
Definition: typedefs.h:28
INTS4 f_ut_wild(CHARS *pc_test, CHARS *pc_wild)
Definition: f_ut_wild.c:21
CHARS c_name[64]
Definition: s_his_head.h:41
INTS4 l_bins_1
Definition: s_his_head.h:22
INTS4 f_his_gethis(const char *, int, const char *, const char *, const char *, s_his_head **, INTS4 **, INTS4 *)
CHARS c_dtype[4]
Definition: s_his_head.h:42
char CHARS
Definition: typedefs.h:21