-
Notifications
You must be signed in to change notification settings - Fork 62
/
StMaker.cxx
executable file
·2580 lines (2437 loc) · 80.9 KB
/
StMaker.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// $Id: StMaker.cxx,v 1.269 2020/02/20 22:26:33 genevb Exp $
//
//
/*!
* Base class for user maker class. Provide common functionality for all
* makers(modules). Allows to arrange modules in a tree, consisting of modules
* and produced datasets.
*
* User must provide at least its own methods
* - Init() mandatory
* - Make() mandatory
* - InitRun(newRunNumber) if needed
* - FinishRun(oldRunNumber) if needed
* - Clear() if standard StMaker::Clear() is not appropriate
* - Finish() if standard StMaker::Finish() is not appropriate
*
* The method will be described.
*
*/
#define STAR_LOGGER 1
#include "StMaker.h"
#include "Stiostream.h"
#include <stdio.h>
#include <stdlib.h>
#include "TClass.h"
#include "TROOT.h"
#include "TError.h"
#if 0
#include "THtml.h"
#endif
#include "TH1.h"
#include "TChain.h"
#include "TTree.h"
#include "TList.h"
#include "TClonesArray.h"
#include "TBrowser.h"
#include "StChainOpt.h"
#include "TObjectSet.h"
#include "StChain.h"
#include "TTable.h"
#include "StMemStat.h"
#include "TAttr.h"
#include "StMkDeb.h"
#include "StMessMgr.h"
StMaker *StMaker::fgTopChain = 0;
StMaker *StMaker::fgStChain = 0;
StMaker *StMaker::fgFailedMaker = 0;
StTestMaker *StMaker::fgTestMaker = 0;
Int_t StMaker::fgTallyMaker[kStFatal+1] = {0,0,0,0,0};
Int_t MaxWarnings = 26;
class MyObjectSet : public TObjectSet
{
typedef void (*MyDelete_t)(void *p);
public:
MyObjectSet(const char *name,void *p,void *d):TObjectSet(name,(TObject*)p,0)
{fD=(MyDelete_t)d;}
~MyObjectSet(){ (*fD)(GetObject());}
private:
MyDelete_t fD;
};
/* geometry version from Maxim 09/29/2005
year2000 VMC
year_2a
year_2b
year2001 VMC
year2002 VMC
year2003 VMC
y2003a VMC
y2003b VMC
y2003x VMC
y2004 VMC
y2004a VMC
y2004b VMC
y2004c VMC
y2004x VMC
y2004y VMC
y2005 VMC
y2005b VMC
y2005c VMC
y2005x VMC
dev2005 - non-production
complete - non-production
ist1 - non-production VMC
pix1 - non-production
----------------
old version of db tags
{"sd97", 19970101, 0},
{"sd98", 19980101, 0},
{"year_1a", 19990101, 0},
{"year_1b", 19990501, 0},
{"es99", 19990615, 0},
{"er99", 19990616,120000},
{"year_1c", 19991001, 0},
{"year_1d", 19991101, 0},
{"year_1e", 19991201, 0},
{"dc99", 19991206, 80000},
{"y2000", 20000614,175430},
{"year_2b", 20010501, 0},
{"year_2a", 20010610, 0},
{"year2001", 20010615, 0},
{"year2003", 20021115, 0},
{"y2003b", 20021115, 0},
{"y2003a", 20021115, 0},
{"y2003x", 20021115, 0},
{"y2004b", 20031120, 0},
{"y2004a", 20031120, 0},
{"y2004x", 20031120, 0},
{"y2004", 20031120, 0},
{"y2004c", 20031125, 0},
{"y2005x", 20041030, 0},
{"y2005", 20041030, 0},
{"y2005b", 20041101, 0},
{"y2005c", 20041201, 0},
Production
=============
MC:
2000: y1a,y1b,y1h,y2000,year_1a,year_1b
2001: y2001,y2001n
2002: y2a,y2b,y2x,y2y,year_2a
2003: y2003,y2003x
2004: y2004a, y2004c,y2004,y2004y
2005: y2005,y2005x
2006: y2006c,y2006
2007: y2007g,y2007
upgr: upgr01, upgr05, upgr06, upgr07, upgr08, upgr09, upgr10, upgr11, upgr13
=============
rawData:
2000: y1h, y2000a (?), y2000
y2001
y2003
y2004
y2005b,y2005f
y2006g,y2006
y2007g,y2007
y2008
04/29/09 Lidia
Geometry versions used for raw data productions
ry2008, ry2007g, ry2007, ry2006, ry2006g, ry2005f, ry2005b, ry2004, ry2003,
ry2001, ry2000, ry2000a, ry1h
Geometry versions used for MC data productions
y2008, y2007, y2007g, y2007h, y2006, y2006c, y2005, y2005b, y2005h, y2005x,
y2004, y2004a, y2004c, y2004y, y2003, y2003x, y2001, y2001n, y2000, y1h
Raw Data: MC:
ry1h, y1h,
ry2000, y2000,
ry2000a, <====== does not exists
ry2001, y2001,
y2001n,<====== the same as y2001
ry2003, y2003,
y2003x,
ry2004, y2004,
y2004a,
y2004c,
y2004y,
y2005,
ry2005b, y2005b,
ry2005f,
y2005h,
y2005x,
ry2006, y2006,
ry2006g,
y2006c,
ry2007, y2007,
ry2007g, y2007g,
y2007h,
ry2008, y2008,
*/
#include "GeometryDbAliases.h"
// Turn the logger of the current maker
#define TURN_LOGGER(maker) \
if (!fLogger) fLogger = StMessMgr::Instance(ClassName()); \
StTurnLogger SaveRestoreLogger(maker->GetLogger());
ClassImp(StMaker)
//_____________________________________________________________________________
StMaker::StMaker(const Char_t *name,const Char_t *):TDataSet(name,".maker"),
m_Number(0), m_LastRun(-3),
m_DebugLevel(0),m_MakeReturn(0),fStatus(0),
fLogger(0),fLoggerHold(0),m_Mode(0)
{
m_Attr=0;
m_Inputs = 0;
if (!fgStChain) { // it is first maker, it is chain
fgTopChain = fgStChain = this;
gROOT->GetListOfBrowsables()->Add(this,GetName());
AddData(0,".make");
} else { // add this maker to chain
fgStChain->AddData(this,".make");
}
m_DataSet = new TObjectSet(".data") ;Add(m_DataSet);
m_ConstSet = new TObjectSet(".const");Add(m_ConstSet);
m_GarbSet = new TObjectSet(".garb" );Add(m_GarbSet);
m_Inputs = new TObjectSet(".aliases" );Add(m_Inputs);
m_Runco = new TObjectSet(".runco" );Add(m_Runco);
AddHist(0); m_Histograms = GetHistList();
StMemStat::doPs(GetName(), "Construct");
m_Timer.Stop();
fMemStatMake = 0;
fMemStatClear = 0;
memset(fTallyMaker,0,(kStFatal+1)*sizeof(Int_t));
SetActive();
StMkDeb::Register(this);
}
//_____________________________________________________________________________
void StMaker::AddMaker(StMaker *mk)
{
TDataSet *dotmk = Find(".make");
if (!dotmk) dotmk = new TDataSet(".make",this);
mk->Shunt(dotmk);
}
//_____________________________________________________________________________
StMaker::~StMaker()
{
if (fgTopChain == this) fgTopChain = 0;
if (fgStChain == this) fgStChain = 0;
delete fMemStatMake; fMemStatMake = 0;
delete fMemStatClear; fMemStatClear = 0;
TDataSet *ds = this;
Cleanup(ds);
StMkDeb::Cancel(this);
// delete fLogger; fLogger = 0;
}
//_____________________________________________________________________________
const Char_t *StMaker::GetName() const
{
static Int_t occ = 0;
const Char_t *name = TNamed::GetName();
if (name && *name ) return name;
TString ts(ClassName());
ts+="#"; ts+=(occ++);
((TNamed*)this)->SetName(ts.Data());
return GetName();
}
//______________________________________________________________________________
void StMaker::SetNumber(Int_t number)
{
StMaker *par = GetParentMaker();
if (par) par->SetNumber(number);
m_Number = number;
SetIventNumber(number);
}
//______________________________________________________________________________
Int_t StMaker::GetNumber() const
{
StMaker *par = GetParentMaker();
if (par) return par->GetNumber();
return m_Number;
}
//______________________________________________________________________________
StMaker *StMaker::GetParentMaker() const
{
TDataSet *par = GetParent(); if (!par) return 0;
return (StMaker*)par->GetParent();
}
//______________________________________________________________________________
StMaker *StMaker::GetMaker(const Char_t *mkname)
{
TString path(".make/"); path+=mkname;
return (StMaker*)GetDataSet((const char*)path);
}
//______________________________________________________________________________
TObject *StMaker::GetDirObj(const Char_t *dir) const
{
TObjectSet *h = (TObjectSet*)Find(dir);
if (!h) return 0;
return h->GetObject();
}
//______________________________________________________________________________
void StMaker::SetDirObj(TObject *obj,const Char_t *dir)
{
TObjectSet *set = (TObjectSet *)Find(dir);
if (!set) { // No dir, make it
set = new TObjectSet(dir); Add(set);}
set->SetObject(obj);
}
//______________________________________________________________________________
TDataSet *StMaker::AddObj(TObject *obj,const Char_t *dir,int owner)
{
assert (dir[0]=='.');
if (strcmp(".hist",dir)==0) { //Histogram directory
AddHist((TH1*)obj); return 0;
} else if (strcmp(".data",dir)==0) { //.data
return ToWhiteBoard(obj->GetName(),obj,owner);
} else if (strcmp(".const",dir)==0) { //.const
return ToWhiteConst(obj->GetName(),obj);
} else { assert(0 && "No .data || .const ||.hist");}
}
//______________________________________________________________________________
void StMaker::AddHist(TH1 *h,const Char_t *)
{
TObjectSet *set = (TObjectSet*)Find(".hist");
if (!set) { // No dir, make it
set = new TObjectSet(".hist"); Add(set);}
TList *list = (TList *)set->GetObject();
if (!list) {// No list, make it
list = new TList(); set->SetObject(list);}
if (!h) return ;
if(!list->FindObject(h)) list->Add(h);
if (h->InheritsFrom(TH1::Class())) h->SetDirectory(0);
}
//______________________________________________________________________________
void StMaker::AddRunco (Double_t par,const Char_t *name,const Char_t *comment)
{
assert (name && name && comment[0]);
TDataSet *dp = new TDataSet(name,m_Runco);
TString ts(" // "); ts += comment;
Char_t buf[40];
sprintf(buf,"%f",par);
ts.Replace(0,0,buf);
dp->SetTitle((const char*)ts);
}
//______________________________________________________________________________
void StMaker::AddData(TDataSet *ds, const Char_t *dir)
{
assert (dir); assert(dir[0]=='.');
TDataSet *set = Find(dir);
if (!set) { // No dir, make it
set = new TObjectSet(dir); Add(set);}
if (!ds) return;
Int_t dotMake = (strcmp(dir,".make")==0);
Int_t inhMake = ds->InheritsFrom(StMaker::Class());
if (dotMake!=inhMake) {
Error("AddData","Add to %s is NOT allowed: %s.%s\n"
,dir,ds->ClassName(),ds->GetName());
return;}
TList *tl = set->GetList();
if (!tl || !tl->FindObject(ds->GetName())) {
set->Add(ds);
} else {
Error("AddData","Data %s/%s is not added. ***Name clash***",dir,ds->GetName());
return;
}
return;
}
//______________________________________________________________________________
TDataSet *StMaker::GetData(const Char_t *name, const Char_t *dir) const
{
TDataSet *set = Find(dir);
if (!set) return 0;
if (!name || !name[0]) return set;
return set->Find(name);
}
//______________________________________________________________________________
TDataSet *StMaker::ToWhiteBoard(const Char_t *name, void *dat)
{
TObjectSet *envelop = new TObjectSet(name,(TObject*)dat,0);
envelop->SetTitle(".envelop");
AddData(envelop,".data");
return envelop;
}
//______________________________________________________________________________
TDataSet *StMaker::ToWhiteBoard(const Char_t *name, void *dat, void *owner)
{
MyObjectSet *envelop = new MyObjectSet(name,dat,owner);
envelop->SetTitle(".envelop");
AddData(envelop,".data");
return envelop;
}
//______________________________________________________________________________
TDataSet *StMaker::ToWhiteBoard(const Char_t *name, TObject *dat, Int_t owner)
{
TObjectSet *envelop = new TObjectSet(name,dat,owner);
envelop->SetTitle(".envelop");
AddData(envelop,".data");
return envelop;
}
//______________________________________________________________________________
TDataSet *StMaker::ToWhiteConst(const Char_t *name, void *dat)
{
TObjectSet *envelop = new TObjectSet(name,(TObject*)dat,0);
envelop->SetTitle(".envelop");
AddData(envelop,".const");
return envelop;
}
//______________________________________________________________________________
TDataSet *StMaker::ToWhiteConst(const Char_t *name, TObject *dat)
{
TObjectSet *envelop = new TObjectSet(name,dat,0);
envelop->SetTitle(".envelop");
AddData(envelop,".const");
return envelop;
}
//______________________________________________________________________________
TDataSet *StMaker::WhiteBoard(const Char_t *name, void *v) const
{
void **dat = (void **)v;
*dat = 0;
TDataSet *ds = GetDataSet(name);
if (!ds) return 0;
if (strcmp(".envelop",ds->GetTitle())==0) {*dat = ds->GetObject();}
else {*dat = ds ;}
return ds;
}
//______________________________________________________________________________
void StMaker::AddAlias(const Char_t *log, const Char_t *act,const Char_t *dir)
{
TDataSet *ali = new TDataSet(log);
ali->SetTitle(act);
AddData(ali,dir);
}
//______________________________________________________________________________
void StMaker::SetNotify(const Char_t *about, StMaker *mk)
{
TDataSet *ali = new TObjectSet(about,mk,0);
AddData(ali,".notify");
}
//______________________________________________________________________________
void StMaker::NotifyEm(const Char_t *about, const void *ptr)
{
// Turn the logger of the current maker
TURN_LOGGER(this);
TDataSet *set = Find(".notify");
if (!set) return;
TDataSetIter iter(set);
TObjectSet *os=0;
while((os=(TObjectSet*)iter())) {
if (strcmp(about,os->GetName())) continue;
StMaker *mk=(StMaker*)os->GetObject();
if (!mk) continue;
TURN_LOGGER(mk);
mk->NotifyMe(about,ptr);
}
}
//______________________________________________________________________________
void StMaker::SetAlias(const Char_t *log, const Char_t *act,const Char_t *dir)
{
TDataSet *ali = GetData(log,dir);
if (ali) {
if (!strcmp(act,ali->GetTitle())) return;
} else {
ali = new TDataSet(log); AddData(ali,dir);
}
ali->SetTitle(act);
if (GetDebug()) {
#ifdef STAR_LOGGER
LOG_DEBUG << "<" << ClassName() << "(" << GetName() << "::SetAlias> "
<< log << " = " << act << endm;
#else
printf("<%s(%s)::SetAlias> %s = %s\n",ClassName(),GetName(),log,act);
#endif
}
}
//______________________________________________________________________________
void StMaker::SetOutput(const Char_t *log,TDataSet *ds)
{
Int_t idx;
const Char_t *logname = log;
if (!logname || !logname[0]) logname = ds->GetName();
TString act = ds->Path();
while ((idx=act.Index(".make/"))>=0) act.Replace(0,idx+6,"");
SetOutput(logname,act);
}
//______________________________________________________________________________
void StMaker::SetOutputAll(TDataSet *ds, Int_t level)
{
TDataSet *set;
TDataSetIter next(ds,level);
while ((set = next())) SetOutput(set);
}
//______________________________________________________________________________
TList *StMaker::GetMakeList() const
{ TDataSet *ds = Find(".make");
if (!ds) return 0;
return ds->GetList();
}
//______________________________________________________________________________
TString StMaker::GetAlias(const Char_t *log,const Char_t *dir) const
{
Int_t nspn = strcspn(log," /");
TString act(log,nspn);
TDataSet *in = GetData(act,dir);
act ="";
if (in) {act = in->GetTitle(); act += log+nspn;}
return act;
}
//______________________________________________________________________________
TDataSet *StMaker::FindDataSet(const Char_t *logInput,
const StMaker *uppMk,
const StMaker *dowMk) const
{
TURN_LOGGER(this);
TDataSetIter nextMk(0);
TString actInput,findString,tmp;
TDataSet *dataset=0,*dir;
StMaker *parent,*mk;
Int_t icol,islas;
for (int itry=0;itry<2;itry++) {
actInput = (!itry)? GetInput(logInput).Data():logInput;
dataset = 0;
if (actInput.IsNull()) continue;
// Direct try
//if (actInput.Contains(".")) dataset = Find(actInput);
// GVB: The use of TString::Contains() [above] is time-expensive for
// finding a single character. Using strchr() [below] is much faster.
if (strchr(actInput.Data(),'.')) dataset = Find(actInput);
if (dataset) goto FOUND;
if (actInput==GetName()) dataset = m_DataSet;
if (dataset) goto FOUND;
// Not so evident, do some editing
icol = actInput.Index(":");
if (icol>=0) {//there is maker name is hidden
tmp = actInput;
tmp.Replace(0,0,".make/"); icol +=6;
tmp.Replace(icol,1,"/.data/");
dataset = Find((const char*)tmp); // .make/MAKER/.data/...
if (dataset) goto FOUND;
dataset = Find((const char*)tmp+6); // MAKER/.data/...
if (dataset) goto FOUND;
tmp.Replace(icol,7,"/.const/");
dataset = Find((const char*)tmp); // .make/MAKER/.const/...
if (dataset) goto FOUND;
dataset = Find((const char*)tmp+6); // MAKER/.const/...
if (dataset) goto FOUND;
goto DOWN;
}
if (m_DataSet) {
islas = actInput.Index("/");
if (islas>0) {
tmp.Replace(0,999,actInput,islas);
if (tmp == GetName()) { //
tmp = actInput;
tmp.Replace(0,islas+1,"");
dataset = m_DataSet->Find(tmp);
if (dataset) goto FOUND;
dataset = m_ConstSet->Find(tmp);
if (dataset) goto FOUND;
}
}
dataset = m_DataSet->Find(actInput);
if (dataset) goto FOUND;
dataset = m_ConstSet->Find(actInput);
if (dataset) goto FOUND;
}
// Try to search DOWN
DOWN: if (!(dir = Find(".make"))) goto UP;
nextMk.Reset(dir);
while ((mk = (StMaker* )nextMk()))
{
if (mk==dowMk) continue;
dataset = mk->FindDataSet(actInput,this,0);
if (dataset) goto FOUND;
}
// Try to search UP
UP: if (uppMk) return 0;
parent = GetMaker(this); if (!parent) goto NOTFOUND;
dataset = parent->FindDataSet(actInput,0,this);
if (dataset) goto FOUND;
// Not FOUND
NOTFOUND:
if (!dowMk && GetDebug()>1) //PrintWarning message
if ((MaxWarnings--) > 0) Warning("GetDataSet"," \"%s\" Not Found ***\n",(const char*)actInput);
dataset = 0; continue;
// DataSet FOUND
FOUND: if (uppMk || dowMk) return dataset;
if (GetDebug()<2) return dataset;
#ifdef STAR_LOGGER
LOG_DEBUG << Form("<%s::%s> DataSet %s FOUND in %s\n"
,ClassName(),"GetDataSet",logInput,(const char*)dataset->Path()) << endm;
#else
printf("Remark: <%s::%s> DataSet %s FOUND in %s\n"
,ClassName(),"GetDataSet",logInput,(const char*)dataset->Path());
#endif
break;
}
return dataset;
}
//______________________________________________________________________________
TDataSet *StMaker::GetDataBase(const Char_t *logInput,const TDatime *td)
{
TURN_LOGGER(this);
TDataSet *ds = 0;
StMaker *mk = GetMakerInheritsFrom("St_db_Maker");
if (mk) ds = mk->GetDataBase(logInput,td);
return ds;
}
//______________________________________________________________________________
StMaker *StMaker::GetMakerInheritsFrom (const Char_t *mktype) const
{
TURN_LOGGER(this);
StMaker *mk = 0;
StMakerIter mkiter(this);
while ((mk = mkiter.NextMaker())) {//loop over makers
if (mk->InheritsFrom(mktype)) break;
}
return mk;
}
//______________________________________________________________________________
void StMaker::SetFlavor(const Char_t *flav,const Char_t *tabname)
{
StMaker *mk = GetMakerInheritsFrom("St_db_Maker");
if (mk) mk->SetFlavor(flav,tabname);
}
//_____________________________________________________________________________
void StMaker::Clear(Option_t *option)
{
TURN_LOGGER(this);
m_MakeReturn = 0;
if(option){};
if (m_DataSet) m_DataSet->Delete();
// Reset lists of event objects
TIter next(GetMakeList(),kIterBackward);
StMaker *maker;
Int_t curr = StMkDeb::GetCurrent();
while ((maker = (StMaker* )next())) {
assert(maker->TestBIT(kCleaBeg)==0);
StMkDeb::SetCurrent(maker,3);
maker->SetBIT(kCleaBeg);
maker->StartTimer();
if (maker->fMemStatClear && GetNumber()>20) maker->fMemStatClear->Start();
TURN_LOGGER(maker);
maker->Clear(option);
if (maker->fMemStatClear && GetNumber()>20) maker->fMemStatClear->Stop();
maker->StopTimer();
maker->ResetBIT(kCleaBeg);
StMkDeb::SetCurrent(curr);
}
TCollection::EmptyGarbageCollection();
StMemStat::doPs(GetName(), "Clear");
// Maker=StChain or whatever is called "Eread" would
// reach this with a NULL pointer when executed from a macro
// such as doEvent(). Same reason for the patch below ...
//else printf("StMaker::Clear :: cannot call method doPs on NULL pointer [%s]\n",GetName()) ;
return;
}
//_____________________________________________________________________________
Int_t StMaker::Init()
{
TURN_LOGGER(this);
TObject *objLast,*objHist;
TList *tl = GetMakeList();
if (!tl) return kStOK;
TIter nextMaker(tl);
StMaker *maker;
Int_t curr = StMkDeb::GetCurrent();
while ((maker = (StMaker* )nextMaker())) {
TURN_LOGGER(maker);
// save last created histogram in current Root directory
gROOT->cd();
objLast = gDirectory->GetList()->Last();
// Initialise maker
assert( !( maker->TestBIT(kInitBeg) || maker->TestBIT(kInitEnd) ));
StMkDeb::SetCurrent(maker,1);
maker->SetBIT(kInitBeg);
maker->StartTimer();
if (GetDebug()) {
LOG_DEBUG << "*** Call << " << maker->ClassName() << ":Init() ***" << endm;
}
TString ts1(maker->ClassName()); ts1+="("; ts1+=maker->GetName(); ts1+=")::";
TString ts2 = ts1; ts2+="Make ";
maker->fMemStatMake = new StMemStat(ts2);
ts2 = ts1; ts2+="Clear";
maker->fMemStatClear = new StMemStat(ts2);
if ( maker->Init()) {
LOG_ERROR << " Maker "<< maker->GetName() << " failed in Init" << endm;
return kStErr;
}
maker->StopTimer();
// Add the Maker histograms in the Maker histograms list
// and remove it from the ROOT system directory
gROOT->cd();
TIter nextHist(gDirectory->GetList());
Int_t ready = !objLast;
while((objHist=nextHist())) {// loop over gDirectory
if (!ready && objHist!=objLast) continue;
ready = 1999;
if (objHist==objLast) continue;
if (!objHist->InheritsFrom("TH1")) continue;
// Move the histogram from the ROOT list into the "maker's" list
((TH1*)objHist)->SetDirectory(0);
maker->AddHist((TH1*)objHist);
}
StMemStat::doPs(maker->GetName(), "Init");
maker->ResetBIT(kInitBeg);
maker->SetBIT (kInitEnd);
StMkDeb::SetCurrent(curr);
}
return kStOK;
}
//_____________________________________________________________________________
void StMaker::StartMaker()
{
// Save the previous logger status
if (!fLoggerHold) fLoggerHold = new StTurnLogger(GetLogger());
if (!m_DataSet) {//Keep legacy code
m_DataSet = Find(".data");
if (!m_DataSet) {m_DataSet = new TObjectSet(".data"); Add(m_DataSet);}
}
/*if (GetNumber()>3)*/
if (fMemStatMake && GetNumber()>20) fMemStatMake->Start();
StartTimer();
}
//_____________________________________________________________________________
void StMaker::EndMaker(Int_t ierr)
{
SetMakeReturn(ierr);
// check dimension in case of logic problem
int idx = ierr%10;
if ( idx <= kStFatal ){
fgTallyMaker[idx]++;
fTallyMaker [idx]++;
}
if (m_DataSet) m_DataSet->Pass(ClearDS,0);
if (m_GarbSet) m_GarbSet->Delete();
StMemStat::doPs(GetName(), "EndMaker");
/* if (GetNumber()>3)*/
if (fMemStatMake && GetNumber()>20) fMemStatMake->Stop();
StopTimer();
// Restore the previous logger status
if (fLoggerHold) { delete fLoggerHold; fLoggerHold = 0;}
}
//_____________________________________________________________________________
/*!
Terminate a run.
Place to make operations on histograms, normalization,etc.
*/
Int_t StMaker::Finish()
{
if (TestBIT(kFiniEnd)) return 1;
TURN_LOGGER(this);
Int_t nerr = 0;
Int_t run = GetRunNumber();
if (run>-1) FinishRun(run);
TIter next(GetMakeList(),kIterBackward);
StMaker *maker;
Double_t totalCpuTime = 0;
Double_t totalRealTime = 0;
while ((maker = (StMaker* )next()))
{
totalCpuTime += maker->CpuTime();
totalRealTime += maker->RealTime();
}
// Printrelative time
if (!totalRealTime) totalRealTime = 1;
if (!totalCpuTime ) totalCpuTime = 1;
next.Reset();
Int_t fst=1;
while ((maker = (StMaker*)next())) {
#ifdef STAR_LOGGER
TURN_LOGGER(maker);
if (fst) {
fst=0;
LOG_QA <<
Form("=================================================================================") << endm;
LOG_QA <<
Form("QAInfo:Chain %20s::%-20s Ast =%6.2f Cpu =%6.2f "
,ClassName(),GetName(),totalRealTime,totalCpuTime) << endm;
}
LOG_QA <<
Form("QAInfo:Maker %20s::%-20s Ast =%6.2f(%4.1f%%) Cpu =%6.2f(%4.1f%%) "
,maker->ClassName(),maker->GetName()
,maker->RealTime()
,100*maker->RealTime()/totalRealTime
,maker->CpuTime()
,100*maker->CpuTime()/totalCpuTime) << endm;
static const Char_t *ee[]={"nStOK","nStWarn","nStEOF","nStErr","nStFatal"};
TString tail("");
for (Int_t j=0;j<=kStFatal;j++) {
if (fTallyMaker[j]) tail += Form(" %s=%d",ee[j],fTallyMaker[j]);}
if (tail != "") LOG_QA << (const Char_t *) tail << endm;
#else
if (fst) {
fst=0;
Printf("=================================================================================\n");
Printf("QAInfo: Chain %20s::%-20s Ast =%6.2f Cpu =%6.2f "
,ClassName(),GetName(),totalRealTime,totalCpuTime);
}
printf("QAInfo: Maker %20s::%-20s Ast =%6.2f(%4.1f%%) Cpu =%6.2f(%4.1f%%) "
,maker->ClassName(),maker->GetName()
,maker->RealTime()
,100*maker->RealTime()/totalRealTime
,maker->CpuTime()
,100*maker->CpuTime()/totalCpuTime);
static const Char_t *ee[]={"nStOK","nStWarn","nStEOF","nStErr","nStFatal"};
for (Int_t j=0;j<=kStFatal;j++) {
if (fTallyMaker[j]) printf(" %s=%d",ee[j],fTallyMaker[j]);}
printf("\n");
#endif
}
next.Reset();
Int_t curr = StMkDeb::GetCurrent();
while ((maker = (StMaker* )next()))
{
TURN_LOGGER(maker);
if (maker->TestBIT(kFiniEnd)) {
maker->Warning("Finish","maker %s.%s Finished twice"
,maker->GetName(),maker->ClassName());
continue;}
StMkDeb::SetCurrent(maker,4);
maker->SetBIT(kFiniBeg);
if ( maker->Finish() ) nerr++;
maker->ResetBIT(kFiniBeg);
maker->SetBIT (kFiniEnd);
StMkDeb::SetCurrent(curr);
}
if (!GetParent()) {// Only for top maker
#ifdef STAR_LOGGER
LOG_INFO << "--------------Error Codes-------------------------" << endm;
LOG_INFO << " nStOK nStWarn nStEOF nStErr nStFatal" << endm;
TString tail("");
for( Int_t i=0; i<=kStFatal; i++) tail += Form("%10d",fgTallyMaker[i]);
if (tail != "")
LOG_INFO << (const Char_t *)tail << endm;
LOG_INFO << "--------------------------------------------------" << endm;
#else
printf("\n--------------Error Codes-------------------------\n");
printf(" nStOK nStWarn nStEOF nStErr nStFatal \n");
for( Int_t i=0; i<=kStFatal; i++) printf("%10d",fgTallyMaker[i]);
printf("\n--------------------------------------------------\n");
#endif
}
//VP Printf("=================================================================================\n");
if (GetParent()==0) StMemStat::Summary();
// delete fLogger; fLogger=0;
return nerr;
}
//_____________________________________________________________________________
/*!
The Make() method is the one responsible for calling the
maker's InitRun(). Note that that InitRun() is called for
real data and if both of the following are true
- a header exists
- the run number changes
This is the ONLY place calling the InitRun() routine.
*/
Int_t StMaker::Make()
{
TURN_LOGGER(this);
// Loop on all makers
Int_t ret,run=-1,oldrun;
TList *tl = GetMakeList();
if (!tl) return kStOK;
StEvtHddr *hd = GetEvtHddr();
TIter nextMaker(tl);
StMaker *maker;
fgFailedMaker = 0;
Int_t curr = StMkDeb::GetCurrent();
while ((maker = (StMaker* )nextMaker())) {
if (!maker->IsActive()) continue;
TURN_LOGGER(maker);
assert(!maker->TestBIT(kMakeBeg));
maker->SetBIT(kMakeBeg);
StMkDeb::SetCurrent(maker,2);
oldrun = maker->m_LastRun;
if (hd && hd->GetRunNumber()!=oldrun) {
if (oldrun>-1) maker->FinishRun(oldrun);
run = hd->GetRunNumber();
if (Debug() && this == fgStChain && m_LastRun!=run){
m_LastRun = run;
#ifdef STAR_LOGGER
LOG_INFO << " +++ New RunNumber found=" << run << " (previous = " << oldrun << ")" << endm;
#else
printf(" +++ New RunNumber found=%d (previous = %d)\n",run,oldrun);
#endif
hd->Print();
}
maker->InitRun(run);
maker->m_LastRun=run;
}
// Call Maker
if (fgTestMaker) { fgTestMaker->SetNext(maker); fgTestMaker->Make();}
maker->StartMaker();
ret = maker->Make();
assert((ret%10)>=0 && (ret%10)<=kStFatal);
maker->EndMaker(ret);
if (Debug() || ret) {
#ifdef STAR_LOGGER
LOG_INFO << "*** " << maker->ClassName() << "::Make() == "
<< RetCodeAsString(ret) << "(" << ret << ") ***"
<< endm;
#else
printf("*** %s::Make() == %s(%d) ***\n"
,maker->ClassName(),RetCodeAsString(ret),ret);
#endif
}
maker->ResetBIT(kMakeBeg);
StMkDeb::SetCurrent(curr);
if ((ret%10)>kStWarn) { //something unusual
if ((ret%10) != kStERR) return ret;
/// check privilege to skip event
fgFailedMaker = maker;
if (maker->IAttr(".Privilege")) return ret;
continue;
}
}
return kStOK;
}
//_____________________________________________________________________________
void StMaker::FatalErr(Int_t Ierr, const Char_t *com)
{
#ifdef STAR_LOGGER
LOG_QA << Form("QAInfo:%s::Fatal: Error %d %s",GetName(),Ierr,com) << endm;
LOG_FATAL << Form("QAInfo:%s::Fatal: Error %d %s",GetName(),Ierr,com) << endm;
#else
printf("QAInfo:%s::Fatal: Error %d %s\n",GetName(),Ierr,com);
#endif
StMaker *parent = (StMaker *)GetParent();
if (parent) ((StMaker*)parent)->FatalErr(Ierr,com);
#ifndef STAR_LOGGER
fflush(stdout);
#endif
}
//_____________________________________________________________________________
StMaker *StMaker::GetMaker(const TDataSet *ds)
{
const TDataSet *par = ds;
while (par && (par = par->GetParent()) && strncmp(".maker",par->GetTitle(),6)) {}
return ( StMaker*) par;
}
//_____________________________________________________________________________
/*!
Reduce the size of the table to the used rows + 1
and filll the last empty row awith a special pattern
Check the table for NaN floating cells if any
*/
EDataSetPass StMaker::ClearDS (TDataSet* ds,void * )
{
if (ds->InheritsFrom(TTable::Class())){
TTable *table = (TTable *)ds;
Int_t setSize = table->GetTableSize();
table->ReAllocate();
memset((void *)table->At(table->GetNRows()),127,table->GetRowSize());
//if (setSize && (setSize - table->GetTableSize() > 100)) {