1 saw 1.1 /*-----------------------------------------------------------------------------
2 * Copyright (c) 1995,1996 Southeastern Universities Research Association,
3 * Continuous Electron Beam Accelerator Facility
4 *
5 * This software was developed under a United States Government license
6 * described in the NOTICE file included as part of this distribution.
7 *
8 * Stephen A. Wood, 12000 Jefferson Ave., Newport News, VA 23606
9 * Email: saw@cebaf.gov Tel: (804) 249-7367 Fax: (804) 249-5800
10 *-----------------------------------------------------------------------------
11 *
12 * Description:
13 * Code for dealing with blocks in groups.
14 *
15 * Author: Stephen Wood, CEBAF Hall C
16 *
17 * Revision History:
18 * $Log: thGroup.c,v $
|
19 jones 1.6 * Revision 1.5.8.1 2007/09/10 21:32:47 pcarter
20 * Implemented changes to allow compilation on RHEL 3,4,5 and MacOSX
21 *
22 * Revision 1.5 2004/07/08 20:05:37 saw
23 * Use dummy fortran ctp tree routines when ROOTSYS not defined.
24 *
|
25 saw 1.5 * Revision 1.4 2004/07/07 18:15:27 saw
26 * Consistenly use thtreeexeg
27 *
|
28 saw 1.4 * Revision 1.3 2004/07/02 20:11:07 saw
29 * Make fortran tree group function names sane
30 *
|
31 saw 1.3 * Revision 1.2 1999/11/04 20:34:05 saw
32 * Alpha compatibility.
33 * New RPC call needed for root event display.
34 * Start of code to write ROOT trees (ntuples) from new "tree" block
35 *
|
36 saw 1.2 * Revision 1.1 1998/12/07 22:11:12 saw
37 * Initial setup
38 *
|
39 saw 1.1 * Revision 1.2 1996/07/31 20:31:52 saw
40 * Book blocks in the order they appear in the input files.
41 *
42 * Revision 1.1 1996/01/30 15:35:16 saw
43 * Initial revision
44 *
45 */
46 #include <stdio.h>
47 #include "daVar.h"
48 #include "th.h"
49 #include "thInternal.h"
50 #include "thUtils.h"
51 #include "cfortran.h"
52 #include "thGroup.h"
53
54 thStatus thBookGroup(char *name);
55 /* Fortran Interface */
|
56 saw 1.2 FCALLSCFUN0(INT,thBook,THBOOK,thbook)
57 FCALLSCFUN1(INT,thBookGroup,THGBOOK,thgbook,STRING)
58 FCALLSCFUN1(INT,thExecuteGroup,THGEXE,thgexe,STRING)
59 FCALLSCFUN1(INT,thClearGroup,THGCLR,thgclr,STRING)
60 FCALLSCFUN1(INT,thClearScalersGroup,THGCLS,thgcls,STRING)
61 FCALLSCFUN1(INT,thIncrementScalersGroup,THGINS,thgins,STRING)
|
62 saw 1.1
63 struct thHook {
64 char *type;
65 thStatus (*book)(); /* Hooks to the appropriate routines */
66 thStatus (*execute)();
67 thStatus (*clear)();
68 thStatus (*clearScalers)();
69 thStatus (*incrementScalers)();
|
70 saw 1.2 thStatus (*ctpwrite)();
71 thStatus (*ctpclose)();
|
72 saw 1.1 };
73 typedef struct thHook thHook;
74 /* V indicates these calls take a variable pointer, not a name */
75 /* Eventually calls without V may go away, and these will all be renamed */
76 /* How many of these c routines are "advertised */
77 thHook thHooks[] = {
|
78 saw 1.2 {PARMSTR ,thLoadParameters,0,0,0,0,0,0},
79 {GETHITSTR ,thBookGethits,thExecuteaGethitBlock,0,0,0,0,0},
|
80 saw 1.1 {TESTSTR ,thBookTests,thExecuteTestsV,thClearTestFlagsV,thClearTestScalersV
|
81 saw 1.2 ,thIncTestScalersV,0,0},
82 {HISTSTR,thBookHists,thExecuteHistsV,thClearHistsV,0,0,0,0},
83 {UHISTSTR,thBookHists,0,0,0,0,0,0},
84 {TREESTR,thBookTree,thFillTreeV,thClearTreeV,0,0,thWriteTreeV,thCloseTreeV},
85 {REPORTSTR,thBookReports,0,0,0,0,0,0},
86 {0,0,0,0,0,0,0,0}};
|
87 saw 1.1
88 int thGroupClassesSet=0;
89
90 thStatus thSetGroupClasses();
91
92 void thInitGroupOpaque(char *name, thGroupOpaque *opqptr)
93 {
94 daVarStatus status;
95 daVarStruct *varclass;
96 thGroupOpaque *classopqptr;
97
98 if(!thGroupClassesSet) {
99 status = thSetGroupClasses();
100 thGroupClassesSet = 1;
101 }
102 status = daVarClassFind(name,&varclass);
103 classopqptr = varclass->opaque;
104 opqptr->blocklist = 0;
105 opqptr->type = classopqptr->type;
106 opqptr->book = classopqptr->book;
107 opqptr->execute = classopqptr->execute;
108 saw 1.1 opqptr->clear = classopqptr->clear;
109 opqptr->clearScalers = classopqptr->clearScalers;
110 opqptr->incrementScalers = classopqptr->incrementScalers;
|
111 saw 1.2 opqptr->ctpwrite = classopqptr->ctpwrite;
112 opqptr->ctpclose = classopqptr->ctpclose;
|
113 saw 1.1 /* Find out what group type we are copy the information out of it's
114 opaque block */
115 }
116 thStatus thSetGroupClasses()
117 {
118 /* thBookList *booklist;
119 thBookList **booknext;*/
120 thGroupOpaque *opqptr;
121 char *classname;
122 daVarStruct var;
123 int i;
124
125 for(i=0;thHooks[i].type;i++){
126 /* Need to decide later to do automatic booking by groups
127 What do I mean by that ^^^ ?*/
128 classname = (char *) malloc(strlen(GROUPSTR)+strlen(thHooks[i].type)+2);
129 strcpy(classname,GROUPSTR);
130 strcat(classname,".");
131 strcat(classname,thHooks[i].type);
132
133 var.name = classname;
134 saw 1.1 var.title = 0;/*""*/
135 var.type = DAVARINT;
136 var.varptr = (DAINT *) malloc(sizeof(DAINT));
137 *((DAINT *) var.varptr) = i; /* Booking order */
138 var.size = 1;
139 var.whook = 0; /* Need handlers? */
140 var.rhook = 0;
141 var.flag = DAVAR_READWRITE | DAVAR_REPOINTOK;
|
142 jones 1.6 // var.opaque = (void *)opqptr = (thGroupOpaque *) malloc(sizeof(thGroupOpaque));/*phil*/
143 var.opaque = (void *) (opqptr = (thGroupOpaque *) (void *)
144 ((thGroupOpaque *) malloc(sizeof(thGroupOpaque))));
|
145 saw 1.1 opqptr->blocklist = 0;
146 opqptr->type = (char *) malloc(strlen(thHooks[i].type) + 1);
147 strcpy(opqptr->type,thHooks[i].type);
148 opqptr->book = thHooks[i].book;
149 opqptr->execute = thHooks[i].execute;
150 opqptr->clear = thHooks[i].clear;
151 opqptr->clearScalers = thHooks[i].clearScalers;
152 opqptr->incrementScalers = thHooks[i].incrementScalers;
|
153 saw 1.2 opqptr->ctpwrite = thHooks[i].ctpwrite;
154 opqptr->ctpclose = thHooks[i].ctpclose;
|
155 saw 1.1 if(daVarRegister((int) 0, &var) == S_FAILURE){
156 fprintf(STDERR,"Failed to register %s\n",var.name);
157 return(S_FAILURE);
158 }
159 /* printf("Registered %s\n",var.name);*/
160 }
161 return(S_SUCCESS);
162 }
163 thStatus thBookGroup(char *group)
164 {
165 daVarStruct *varp, *bvar;
166 daVarStructList *blocklist;
167 thStatus stat;
168 thStatus (*hook)();
169
170 if(daVarLookupP(group, &varp) != S_SUCCESS){
171 /* fprintf(STDERR,"Failed to find %s\n",group);*/
172 return(S_FAILURE);
173 }
174 hook = ((thGroupOpaque *)varp->opaque)->book;
175 blocklist = ((thGroupOpaque *)varp->opaque)->blocklist;
176 saw 1.1 while(blocklist) {
177 bvar = blocklist->varp;
178 if(!bvar->varptr) { /* Only book those not already booked */
179 bvar->varptr = (DAINT *) malloc(sizeof(DAINT));
180 *((DAINT *) bvar->varptr) = 0; /* Initializec execution counter */
181 if(hook) {
182 /* printf("Booking %s\n",bvar->name);*/
183 stat = (hook)(bvar);
184 } else {
185 /* printf("No booking required for %s\n",bvar->name);*/
186 }
187 }
188 blocklist = blocklist->next;
189 }
190 return(S_SUCCESS);
191 }
192
193 #define MAKEGSUB(SUBNAME,QSUBNAME,ELEMENT) \
194 thStatus SUBNAME(char *group)\
195 {\
196 daVarStruct *varp, *bvar;\
197 saw 1.1 daVarStructList *blocklist;\
198 thStatus stat;\
199 thStatus (*hook)();\
200 \
201 if(daVarLookupP(group, &varp) != S_SUCCESS){\
202 /* fprintf(STDERR,"(%s) Failed to find %s\n",QSUBNAME,group);*/\
203 return(S_SUCCESS);\
204 }\
205 hook = ((thGroupOpaque *)varp->opaque)->ELEMENT;\
206 blocklist = ((thGroupOpaque *)varp->opaque)->blocklist;\
207 if(hook) {\
208 while(blocklist) {\
209 bvar = blocklist->varp;\
210 stat = (hook)(bvar);\
211 blocklist = blocklist->next;\
212 }\
213 }\
214 return(S_SUCCESS);\
215 }
216 MAKEGSUB(thExecuteGroup,"thExecuteGroup",execute)
217 MAKEGSUB(thClearGroup,"thClearGroup",clear)
218 saw 1.1 MAKEGSUB(thClearScalersGroup,"thClearScalersGroup",clearScalers)
219 MAKEGSUB(thIncrementScalersGroup,"thIncrementScalersGroup",incrementScalers)
|
220 saw 1.2 MAKEGSUB(thWriteGroup,"thWriteGroup",ctpwrite)
221 MAKEGSUB(thCloseGroup,"thCloseGroup",ctpclose)
|
222 saw 1.1
223 thStatus thBook()
224 /* Book all the parameter, tests and histograms and anything else that is
225 in the booking order list. Books groups in alphabetical order. Within
226 groups booking is done in the order that the blocks appear in the CTP
227 files.
228
229 1/30/96 New behaviour. Just book the "all" group for each class. That way
230 booking order will be precisely as appears in the CTP files.
231 */
232 {
233 int i;
234 thStatus status;
235
236 status = S_FAILURE; /* Return failure if everything fails to book */
237
238 for(i=0;thHooks[i].type;i++){
239 char *prefix; char **glist0; char **glist; int count;
240
241 #if 0
242 prefix = (char *) malloc(strlen(GROUPSTR) + strlen(thHooks[i].type) + 3);
243 saw 1.1 #else
244 prefix = (char *) malloc(strlen(GROUPSTR) + strlen(thHooks[i].type)
245 + strlen(ALLGRPSTR) + 3);
246 #endif
247 strcpy(prefix,GROUPSTR);
248 strcat(prefix,".");
249 strcat(prefix,thHooks[i].type);
250 strcat(prefix,".");
251
252 #if 0
253 /* Make a list of all groups in this class */
254
255 daVarList(prefix,&glist0,&count);
256 glist = glist0;
257 while(count-- > 0){
258 /* printf("Booking group %s\n",*glist);*/
259 if(thBookGroup(*glist) == S_SUCCESS){
260 status = S_SUCCESS;
261 } else {
262 fprintf(STDERR,"Failed to book %s\n",*glist);
263 }
264 saw 1.1 glist++;
265 }
266 #else
267 strcat(prefix,ALLGRPSTR);
268 /* printf("Booking %s\n",prefix);*/
269 if(thBookGroup(prefix) == S_SUCCESS){
270 status = S_SUCCESS;
271 } else {
272 /* fprintf(STDERR,"Failed to book %s\n",prefix);*/
273 }
274 #endif
275 free(prefix);
276 }
277 return(status);
278 }
279
280 #define MAKEFSUB(SUBNAME,TYPESTR,CSUBNAME) \
|
281 saw 1.2 int SUBNAME(char *A1,unsigned C1)\
|
282 saw 1.1 {\
|
283 saw 1.2 int A0;\
|
284 saw 1.1 char *B1=0;\
285 int newsize;\
286 static char *full_name=0;\
287 static int full_name_size;\
288 \
289 newsize = strlen(GROUPSTR) + strlen(TYPESTR) + C1 + 3;\
290 if(!full_name) {\
291 full_name_size = newsize;\
292 full_name = (char *) malloc(full_name_size);\
293 } else {\
294 if(newsize > full_name_size) {\
295 full_name = realloc(full_name,newsize);\
296 }\
297 }\
298 strcpy(full_name,GROUPSTR);\
299 strcat(full_name,".");\
300 strcat(full_name,TYPESTR);\
301 strcat(full_name,".");\
302 strcat(full_name,(!*(int *)A1)?0:memchr(A1,'\0',C1)?A1:\
303 (memcpy(B1=malloc(C1+1),A1,C1),B1[C1]='\0'\
304 ,kill_trailing(B1,' ')));\
305 saw 1.1 A0 = CSUBNAME(full_name);\
306 if(B1) free(B1);\
307 return(A0);\
308 }
309
310 #ifdef AbsoftUNIXFortran
311 MAKEFSUB(thtstexeg,TESTSTR,thExecuteGroup)
312 MAKEFSUB(thtstclrg,TESTSTR,thClearGroup)
313 MAKEFSUB(thtstclsg,TESTSTR,thClearScalersGroup)
314 MAKEFSUB(thtstinsg,TESTSTR,thIncrementScalersGroup)
315 MAKEFSUB(thhstexeg,HISTSTR,thExecuteGroup)
316 MAKEFSUB(thgethitg,GETHITSTR,thExecuteGroup)
|
317 saw 1.3 MAKEFSUB(thtreeexeg,TREESTR,thExecuteGroup)
318 MAKEFSUB(thtreecloseg,TREESTR,thCloseGroup)
319 MAKEFSUB(thtreewriteg,TREESTR,thWriteGroup)
|
320 saw 1.1 #else
321 MAKEFSUB(thtstexeg_,TESTSTR,thExecuteGroup)
322 MAKEFSUB(thtstclrg_,TESTSTR,thClearGroup)
323 MAKEFSUB(thtstclsg_,TESTSTR,thClearScalersGroup)
324 MAKEFSUB(thtstinsg_,TESTSTR,thIncrementScalersGroup)
325 MAKEFSUB(thhstexeg_,HISTSTR,thExecuteGroup)
326 MAKEFSUB(thgethitg_,GETHITSTR,thExecuteGroup)
|
327 saw 1.4 MAKEFSUB(thtreeexeg_,TREESTR,thExecuteGroup)
|
328 saw 1.2 MAKEFSUB(thtreecloseg_,TREESTR,thCloseGroup)
329 MAKEFSUB(thtreewriteg_,TREESTR,thWriteGroup)
|
330 saw 1.1 #endif
331
332 /*
333 #define MAKEFCALL(SUBNAME,CLASS) \
334
335 MAKEFCALL(thhstexeg,hist)
336 */
|