StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_Module.cxx
1 //*-- Author : Valery Fine 24/03/98
2 // $Id: St_Module.cxx,v 1.18 2003/04/30 20:39:12 perev Exp $
3 
4 #include <assert.h>
5 #include <string.h>
6 #include "St_Module.h"
7 
8 
9 ClassImp(St_Module)
10 
11 
12 // //
14 // St_Module //
15 // //
16 // St_Module is a virtual base class to call the begin_html <A HREF="http://www.rhic.bnl.gov/STAR/html/ssd_l/staf_l/STAF-current/pams/pams.html">PAMS - Physics Analysis Modules</A> end_html
17 // modules from C++ programs and begin_html <A HREF="http://root.cern.ch">ROOT</A> end_html batch and interactive environments.
18 // //
19 // Note: This class uses the "default" parameter term. //
20 // The value of the default parameter is defined as follows: //
21 // //
22 // "it is either "zero" or //
23 // the last value of the "missed" parameters //
24 // //
25 // Calling St_Module::Call, St_Module::ExecuteModule methods with //
26 // any parameter = 0 means the wrapped STAR module will be called //
27 // with "default" parameter instead. //
28 // //
29 // //
30 // Begin_Html <P ALIGN=CENTER> <IMG SRC="gif/Module2Root.gif"> </P> End_Html
31 // //
33 
34 //______________________________________________________________________________
36 : fParams(0), fHeaders(0), fName(0), fIndex(0)
37 { // Default ctor;
38 }
39 //______________________________________________________________________________
40 St_Module::St_Module(char *, TTable *,TTable *,TTable *,TTable *
41  ,TTable *,TTable *,TTable *,TTable *
42  ,TTable *,TTable *,TTable *,TTable *
43  ,TTable *,TTable *,TTable *,TTable *
44  ,TTable *,TTable *,TTable *,TTable *
45  ,TTable *,TTable *,TTable *,TTable *
46  ,TTable *,TTable *,TTable *,TTable *
47  ,TTable *,TTable *,TTable *,TTable *
48  ,TTable *,TTable *,TTable *,TTable *
49  ,TTable *,TTable *
50  )
51 : fParams(0), fHeaders(0), fName(0), fIndex(38)
52 // : TNamed(name)
53 {}
54 //______________________________________________________________________________
55 St_Module::St_Module( TTable *f1,TTable *f2,TTable *f3,TTable *f4
56  ,TTable *f5,TTable *f6,TTable *f7,TTable *f8
57  ,TTable *f9,TTable *f10,TTable *f11,TTable *f12
58  ,TTable *f13,TTable *f14,TTable *f15,TTable *f16
59  ,TTable *f17,TTable *f18,TTable *f19,TTable *f20
60  ,TTable *f21,TTable *f22,TTable *f23,TTable *f24
61  ,TTable *f25,TTable *f26,TTable *f27,TTable *f28
62  ,TTable *f29,TTable *f30,TTable *f31,TTable *f32
63  ,TTable *f33,TTable *f34,TTable *f35,TTable *f36
64  ,TTable *f37,TTable *f38
65  )
66 : fParams(0), fHeaders(0), fName(0), fIndex(38)
67 {
68  SetAllParameters( f1, f2, f3, f4, f5, f6, f7, f8, f9,f10,f11,f12
69  ,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24
70  ,f25,f26,f27,f28,f29,f30,f31,f32,f33,f34,f35,f36
71  ,f37,f38
72  );
73 }
74 //______________________________________________________________________________
75 St_Module::~St_Module()
76 {
77  if (fHeaders) fHeaders->Delete();
78  SafeDelete(fHeaders);
79  SafeDelete(fParams);
80 }
81 //______________________________________________________________________________
82 void St_Module::ClearParams()
83 {
84  if (fHeaders) {
85  fHeaders->Delete();
86  fParams->Clear();
87  }
88 }
89 //______________________________________________________________________________
90 void St_Module::SetAllParameters(TTable *f1,TTable *f2,TTable *f3,TTable *f4
91  ,TTable *f5,TTable *f6,TTable *f7,TTable *f8
92  ,TTable *f9,TTable *f10,TTable *f11,TTable *f12
93  ,TTable *f13,TTable *f14,TTable *f15,TTable *f16
94  ,TTable *f17,TTable *f18,TTable *f19,TTable *f20
95  ,TTable *f21,TTable *f22,TTable *f23,TTable *f24
96  ,TTable *f25,TTable *f26,TTable *f27,TTable *f28
97  ,TTable *f29,TTable *f30,TTable *f31,TTable *f32
98  ,TTable *f33,TTable *f34,TTable *f35,TTable *f36
99  ,TTable *f37,TTable *f38
100  )
101 {
102  ClearParams();
103  SetParameter(f38);
104  SetParameter(f37);
105  SetParameter(f36);
106  SetParameter(f35);
107  SetParameter(f34);
108  SetParameter(f33);
109  SetParameter(f32);
110  SetParameter(f31);
111  SetParameter(f30);
112  SetParameter(f29);
113  SetParameter(f28);
114  SetParameter(f27);
115  SetParameter(f26);
116  SetParameter(f25);
117  SetParameter(f24);
118  SetParameter(f23);
119  SetParameter(f22);
120  SetParameter(f21);
121  SetParameter(f20);
122  SetParameter(f19);
123  SetParameter(f18);
124  SetParameter(f17);
125  SetParameter(f16);
126  SetParameter(f15);
127  SetParameter(f14);
128  SetParameter(f13);
129  SetParameter(f12);
130  SetParameter(f11);
131  SetParameter(f10);
132  SetParameter(f9);
133  SetParameter(f8);
134  SetParameter(f7);
135  SetParameter(f6);
136  SetParameter(f5);
137  SetParameter(f4);
138  SetParameter(f3);
139  SetParameter(f2);
140  SetParameter(f1);
141 }
142 
143 //______________________________________________________________________________
144 void St_Module::SetParameter(TTable *f)
145 {
146  if (!fIndex) return;
147  if (f) {
148  if (!fParams) {
149  fParams = new TObjArray(fIndex);
150  fHeaders = new TObjArray(fIndex);
151  }
152  fParams->AddAt(f,fIndex-1);
153  fHeaders->AddAt(new St_table_header(f),fIndex-1);
154  }
155  fIndex--;
156 }
157 //______________________________________________________________________________
158 Int_t St_Module::CheckParameters(const Char_t *names[])
159 {
161  // //
162  // CheckParameters() //
163  // //
164  // Check whether all parameters are defined to call ExecutModule //
165  // properly ? //
166  // //
167  // Return: //
168  // 0 = Ok, All parameters are "well" defined //
169  // +n = the n parameters were not defined yet. //
170  // //
171  // To print the list of parameters one may call //
172  // St_Module::Print() method //
173  // //
175  Int_t errcode = 0;
176  if (fParams) {
177  TObjArray &thisParams = *fParams;
178  Int_t thisSize = thisParams.GetSize();
179  for (Int_t i=0;i<thisSize;i++)
180  if (!thisParams[i]) {
181 // errcode = St_Module::ExecuteModule();
182  errcode++;
183  if (errcode == 1)
184  fprintf(stderr, "\n \t ***** Error calling module <%s> *****\n"
185  ,GetName());
186  const Char_t *suffix[4]={"st","nd","d","th"};
187  Int_t indx = i%10;
188  if ( (10 < i && i < 20) || indx > 3 || indx == 0) indx = 4;
189  indx--;
190  const Char_t *name = names ? names[i] : "unknown" ;
191  fprintf(stderr, "\t %i-%s table of <%s> has not been defined yet\n"
192  ,i,suffix[indx],name);
193  }
194 //===== assert (!errcode);
195  }
196  return errcode;
197 }
198 //______________________________________________________________________________
199 Int_t St_Module::CheckResults(Int_t res, const Char_t *names[])
200 {
201  Int_t errcode = 0;
202  if (fParams) {
203  Int_t thisSize = fParams->GetSize();
204  for (Int_t i=0;i<thisSize;i++) {
205  Bool_t bug = kFALSE;
206  // Get header
207  table_head_st *h = GetHeader(i);
208  TTable *table = GetTable(i);
209  if (table) {
210  assert(table->GetTableSize() == h->maxlen
211  && table->GetRowSize() == h->rbytes
212  && table == (TTable *)h->dsl_pointer);
213  table->SetNRows(h->nok);
214  if (h->nok > h->maxlen){
215  res = kFALSE;
216  errcode++;
217  bug = kTRUE;
218  }
219  table->NaN();
220  if (errcode && bug) {
221  if (errcode == 1)
222  fprintf(stderr,
223  "\n \t ***** module <%s> returned the corrupted table %s *****\n \t * The number of the used rows more (or equal) of the allocated ones *\n"
224  ,GetName(), table->GetName());
225  const Char_t *suffix[4]={"st","nd","rd","th"};
226  Int_t indx = i%10;
227  if ( (10 < i && i < 20) || indx > 3 || indx == 0) indx = 4;
228  indx--;
229  const Char_t *name = names ? names[i] : "unknown" ;
230  fprintf(stderr, "\t %i-%s <%s> %s has used %d with %d allocated\n"
231  ,i+1,suffix[indx],name, table->GetName(),(int)h->nok,(int)h->maxlen);
232  }
233  }
235  }
236 }
237  return res;
238 }
239 
240 //______________________________________________________________________________
242 {
243 
244  Int_t errcode = 0;
245  printf(" This \"%s\" module has ", GetName());
246  if (fParams)
247  {
248  Int_t thisSize = fParams->GetSize();
249  if (thisSize == 1)
250  printf("only one parameter: ");
251  else
252  printf("%i parameters: ",thisSize);
253  for (Int_t i=0;i<thisSize;i++)
254  {
255  if (fParams->At(i)) printf(" %lx ",*((ULong_t *)fParams->At(i)));
256  else {
257  errcode++;
258  //yf Char_t *suffix[4]={"st","nd","d","th"};
259  //yf Bool_t istable = i & 1;
260  printf("%i parameter has not been defined yet\n"
261  ,i+1);
262  }
263 
264  if (i < thisSize-1) printf(", ");
265  }
266  printf("; \n");
268  }
269  else
270  printf(" NO parameters \n");
271  return errcode;
272 }
273 #if 0
274 //______________________________________________________________________________
275 void St_Module::SetEntryName()
276 {
277  st_Name = new char[strlen(GetName()+10];
278  strcpy(st_Name,GetName());
279 
280  if (st_Name)
281  {
282  if (st_Type==kFortran)
283  {
284 #ifdef U_CASE
285  strupr(st_Name);
286 # ifdef CERNLIB_MSSTDCALL
287  char buftmp[10];
288  strcat(st_Name,"@");
289  atoi(buftmp,fN*4,10);
290  strcat(st_Name,buftmp);
291 # endif
292 #else //VP if defined(uscope)
293  strcat(st_Name,"_");
294 #endif
295  }
296  }
297  SetTitle(st_Name);
298 }
299 #endif
300 //______________________________________________________________________________
301 Int_t St_Module::InvokeModule(TTable *f1,TTable *f2,TTable *f3,TTable *f4,
302  TTable *f5,TTable *f6,TTable *f7,TTable *f8,
303  TTable *f9,TTable *f10,TTable *f11,TTable *f12,
304  TTable *f13,TTable *f14,TTable *f15,TTable *f16,
305  TTable *f17,TTable *f18,TTable *f19,TTable *f20
306  ,TTable *f21,TTable *f22,TTable *f23,TTable *f24,
307  TTable *f25,TTable *f26,TTable *f27,TTable *f28,
308  TTable *f29,TTable *f30,TTable *f31,TTable *f32,
309  TTable *f33,TTable *f34,TTable *f35,TTable *f36,
310  TTable *f37,TTable *f38
311  )
312 {
313  fIndex = 38;
314  SetAllParameters( f1, f2, f3, f4, f5, f6, f7, f8, f9,f10,f11,f12
315  ,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,
316  f25,f26,f27,f28,f29,f30,f31,f32,f33,f34,f35,f36,
317  f37,f38
318  );
319  return ExecuteModule();
320 }
321 void St_Module::Streamer(TBuffer &)
322 { assert(0);}
323 
324 //________________________________________________________________________
325 // $Log: St_Module.cxx,v $
326 // Revision 1.18 2003/04/30 20:39:12 perev
327 // Warnings cleanup. Modified lines marked VP
328 //
329 // Revision 1.17 2001/07/16 23:58:35 fine
330 // suppressing the compilation warning
331 //
332 // Revision 1.16 2000/09/15 15:12:37 perev
333 // NaN check added
334 //
335 // Revision 1.15 2000/07/30 01:40:12 perev
336 // StMem class added
337 //
338 // Revision 1.14 2000/03/30 05:20:51 fine
339 // bug fixed
340 //
341 // Revision 1.13 2000/03/27 02:19:26 fine
342 // warning removed
343 //
344 // Revision 1.12 2000/03/26 01:59:23 fine
345 // new version of St_Module. Works for STAF module only
346 //
347 // Revision 1.11 2000/03/24 20:35:22 fine
348 // adjusted to ROOT 2.24. Doesn't work yet. Under development
349 //
350 // Revision 1.10 1999/12/21 18:57:13 fine
351 // compilation warning plus new type for SizeAttribute
352 //
353 // Revision 1.9 1999/12/07 22:26:26 fine
354 // Clean up to remove the compilation warnings
355 //
356 // Revision 1.8 1999/06/14 09:45:41 fine
357 // assert for St_Module (thanks Fisyak)
358 //
359 // Revision 1.7 1999/03/11 00:34:44 perev
360 // St_base in new maker schema
361 //
362 // Revision 1.6 1999/02/24 17:10:57 fine
363 // St_Table New and Purge method have been introdiced, some clean up for St_module as well
364 //
365 // Revision 1.5 1998/11/25 21:58:33 fisyak
366 // Cleanup
367 //
368 // Revision 1.4 1998/08/25 23:07:24 didenko
369 // New base with Tree
370 //
371 //________________________________________________________________________
virtual Int_t ExecuteModule()
Definition: St_Module.cxx:241
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1395
virtual Int_t CheckResults(Int_t res, const Char_t *names[]=0)
Definition: St_Module.cxx:199
Int_t NaN()
Definition: TTable.cxx:1474
virtual Long_t GetTableSize() const
Returns the number of the allocated rows.
Definition: TTable.cxx:1402
Definition: TTable.h:48