StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMkDeb.cxx
1 #include <stdio.h>
2 #include <assert.h>
3 #include "TObject.h"
4 #include "TNamed.h"
5 #include "TObjArray.h"
6 #include "TString.h"
7 #include "StMkDeb.h"
8 
9 int StMkDeb::fgCurr = -2003;
10 int StMkDeb::fgStage = 0;
11 TObjArray *StMkDeb::fgArr=0;
12 
13 //_____________________________________________________________________________
14 int StMkDeb::Register (const TObject *mk)
15 {
16  if (!fgArr) fgArr = new TObjArray(100);
17  fgArr->Add((TObject*)mk);
18  return fgArr->GetLast();
19 }
20 
21 //_____________________________________________________________________________
22 int StMkDeb::Register (StMaker *mk)
23 {
24  int id = Register ((TObject*)mk);
25  ((TObject*)mk)->TObject::SetUniqueID(id+1);
26  return id;
27 }
28 
29 //_____________________________________________________________________________
30 void StMkDeb::Cancel(const TObject *mk)
31 {
32  if (!fgArr) return;
33  if (!mk ) return;
34  int i = fgArr->IndexOf(mk);
35  fgArr->AddAt(0,i);
36 }
37 //_____________________________________________________________________________
38 void StMkDeb::Cancel(StMaker *mk)
39 {
40  if (!fgArr) return;
41  if (!mk ) return;
42  int id = int(((TObject*)mk)->TObject::GetUniqueID())-1;
43  if (id<0) return;
44  ((TObject*)mk)->TObject::SetUniqueID(0);
45  TObject *to = fgArr->At(id);
46  TObject *tmk= (TObject *) mk;
47  if (to != tmk) delete to;
48  fgArr->AddAt(0,id);
49 }
50 //_____________________________________________________________________________
51 int StMkDeb::SetCurrent(const TObject *mk, int kind)
52 {
53  if (fgCurr<-1) Ready();
54  fgCurr = kind+100*(fgArr->IndexOf(mk));
55  return fgCurr;
56 }
57 
58 //_____________________________________________________________________________
59 int StMkDeb::SetCurrent(const StMaker *mk, int kind)
60 {
61  if (fgCurr<-1) Ready();
62  fgCurr = int(((TObject*)mk)->TObject::GetUniqueID())-1;
63  assert(fgCurr>=0);
64  fgCurr = fgCurr*100+kind;
65  return fgCurr;
66 }
67 
68 //_____________________________________________________________________________
69 int StMkDeb::SetCurrent(int curr)
70 {
71  if (fgCurr<-1) Ready();
72  if (curr>=0) fgCurr = curr;
73  return fgCurr;
74 }
75 //_____________________________________________________________________________
76 void StMkDeb::SetStage(int stage)
77 {
78  fgStage = stage;
79 }
80 //_____________________________________________________________________________
81 void StMkDeb::Ready()
82 {
83  if (fgCurr>-2003) return;
84  if (!fgArr) return;
85  fgCurr=0;
86  int lst = fgArr->GetLast();
87  for (int i=0;i<=lst; i++) {
88  TObject *to = fgArr->At(i);
89  if (!to) continue;
90  if (!to->TObject::TestBit(TObject::kNotDeleted)) {fgArr->AddAt(0,i); continue;}
91  if (to->IsA() == TNamed::Class()) continue;
92  TString ts(to->ClassName());
93  ts += "::";
94  ts += to->GetName();
95  ts += "#";
96  ts += i;
97  TNamed *tn = new TNamed(ts.Data(),"");
98  fgArr->AddAt(tn,i);
99  }
100 }
101 //_____________________________________________________________________________
102 const char *StMkDeb::GetName(int id)
103 {
104  if (!fgArr) return 0;
105  static TString ts;
106  int lst = fgArr->GetLast();
107  if (id < 0 ) return "";
108  int stage = id%100; id/=100;
109  int kind = id%100; id/=100;
110  if (id > lst) return "";
111  ts = fgArr->At(id)->GetName();
112  ts += " kind=" ;ts += kind ;
113  ts += " stage=";ts += stage;
114  return ts.Data();
115 }
116 //_____________________________________________________________________________
117 int StMkDeb::SetUser(TObject *us)
118 {
119  if (!fgArr) return 0;
120  us->TObject::SetUniqueID(fgCurr*100+fgStage+1);
121  return fgCurr;
122 }
123 //_____________________________________________________________________________
124 const char *StMkDeb::GetUser(const TObject *us)
125 {
126  return GetName(us->TObject::GetUniqueID()-1);
127 }
128 //_____________________________________________________________________________
129 void StMkDeb::Pause(const char *tit)
130 {
131  if (tit && *tit) printf("Pause %s\n",tit);
132 }
133 //_____________________________________________________________________________
134 int StMkDeb::GetCurrent(){return fgCurr;}
135 
136 
137 
138