(file) Return to thGroup.c CVS log (file) (dir) Up to [HallC] / Analyzer / CTP

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

Analyzer/Replay: Mark Jones, Documents: Stephen Wood
Powered by
ViewCVS 0.9.2-cvsgraph-1.4.0