-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsh_counters.C
400 lines (287 loc) · 9.72 KB
/
sh_counters.C
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
//==================================
// part of shspe;
// OR can be loaded separately with .L ++
// #include in shspe as #include "sh____.C"
//
//==================================
#include "sh_menu.h"
//------------------- CODE everything here:
//==================================================================MPad
//==================================================================MPad
//==================================================================MPad
//==================================================================MPad
/***********************************************************************
* GetPadByName returns pointer to pad OR NULL -------general func
*
*/
//===================================TPad* GetPadByName(const char* name){
TPad* MPadGetByName(const char* name){
TPad *MyGPad=NULL;
if (gROOT->GetListOfCanvases()->GetEntries()==0){
/*
new TCanvas();
gPad->SetTitle( name );
gPad->SetName( name );
MyGPad=gPad;
printf("(GetPadByName) %s was defined %d\n" , name, MyGPad );
*/
printf("(MPadGetByName) %s NOT found \n" , name );
return NULL;
}else{
for (int i=0;i<gROOT->GetListOfCanvases()->GetEntries();i++){
TPad *cpad=(TPad*)(gROOT->GetListOfCanvases()->At(i));
// printf("canvas %d/%d\n" , i, gROOT->GetListOfCanvases()->GetEntries() );
//1st Just tpad0.....
if (strcmp(cpad->GetName(),name)==0){
MyGPad=(TPad*)cpad;
// printf("%s was found here in (ROOT): %d\n" , name, MyGPad );
}//if name is good
for (int j=0;j<cpad->GetListOfPrimitives()->GetEntries();j++){
if ( strcmp(cpad->GetListOfPrimitives()->At(j)->ClassName(),"TPad")==0){
// printf("TPad %s looked j classname %d/%d\n" , cpad->GetListOfPrimitives()->At(j)->GetName() , j, cpad->GetListOfPrimitives()->GetEntries());
if (strcmp(cpad->GetListOfPrimitives()->At(j)->GetName(),name)==0){
MyGPad=(TPad*)cpad->GetListOfPrimitives()->At(j);
// printf("%s was found here in j==%d: %d\n" , name, j, MyGPad );
}//if name is good
}// is TPad
}// for j
}//for i
}//else-there were pads....
if (MyGPad==NULL){
printf("(MPadGetByName) %s NOT found\n" , name );
return NULL;
/* new TCanvas();
gPad->SetTitle( name );
gPad->SetName( name );
MyGPad=(TPad*)gPad;
printf("%s was NOT found anywhere in pads, we define new %d\n" , name, (int)MyGPad );
*/
}//
return MyGPad;
}// GetPadName ===============================================================
/****************************************************************
* Prints a text into PAD -------general func
*
*
*/
//==========void PrintInPad(const char* label, const char* value){
void MPadPrintIn(const char* label, const char* value){
TPad *orig=NULL;
if (gROOT->GetListOfCanvases()->GetEntries()>0){orig=(TPad*)gPad;}
TPad *cpad=MPadGetByName( label );
if (cpad!=NULL){
cpad->Clear();
TText *t1=new TText(0.5 ,0.5, value ); // position 0.5,0.5; size 0.5
t1->SetTextFont(43); // 42 was helvetica prec 2, 3 is precision 3!!!!pixels!!!
int w=cpad->GetWw();
// w=cpad->GetWindowWidth();
int h=cpad->GetWh();
t1->SetTextAlign(22);// CENTER === 2*10 +2
// t1->SetY(0.1)
// EMPIRICAL FORMULA FOR HELVETICA FONT //
double size=0.4*w/h/strlen(value)*7;
// OK size=0.4*w/strlen(value)/15;// this is quite reasonable....
size=0.4*w/strlen(value)/15;// this is quite reasonable....
if (size>1.26){ size=1.26;} // from empirical test of height (350 pix)
// HACK 43 PIXELS ======================
// t1->SetTextSize( size );
if ( w/strlen(value)/1.1 < h/1.2 ){
t1->SetTextSize( w/strlen(value)/1.1 );
}else{
t1->SetTextSize( h/1.2 );
}
// printf("bounding box %d:%d :%f\n", w ,h, size);
t1->Draw();
if (orig!=NULL){orig->cd();}
}//cpad not NULL
}//DisplayInPad==================================================================
void MPadPrintIn(const char* label, int slot, const char* value){
char ch[100];
sprintf(ch, "%s_%d", label, slot);
MPadPrintIn( ch, value );
}
void MPadCreate(const char* LABEL, int columns, int rows){
/*
* HERE I (CONDITIONALY) CREATE SET OF PADS ..............................
*/
TCanvas *cc;
if (MPadGetByName( LABEL )==NULL){
cc=new TCanvas( LABEL,LABEL);
cc->Divide(columns , rows, 0.002,0.002 );
cc->GetCanvas()->SetFillColor(9);cc->GetCanvas()->SetFillStyle(1);
cc->Draw();
}else{
TPad *pp=(TPad*)MPadGetByName( LABEL );cc=pp->GetCanvas();
}
for (int j=0;j<columns;j++){
for (int i=0;i<rows;i++){
char aa[15]; sprintf(aa,"%s_%d",LABEL,i+1);
char bb[15];
sprintf(bb, "kuku %03d", i );
// sprintf(bb, "0.%d%d%d bar", i, (int)gRandom->Uniform(9),(int)gRandom->Uniform(9) );
MPadPrintIn( aa,bb );
}
}//for loop -----------------
MPadGetByName( LABEL )->Update();
}//MPadCreate(==================================================================
//=====================================================================COUNTERS OBJECTS
//=====================================================================COUNTERS OBJECTS
//=====================================================================COUNTERS OBJECTS
//-------------------------- class definition ----------------- 1
class TCounter{
public:
// protected:
// int is limited to 4e6 !
int DEBUG;
double markVO, markV; // Value (integer)
double markTO, markT; // time
double currT, currV; // currents , waiting to
TCounter();
~TCounter();
void Register(double weight=1.0);
double GetRate();
double GetTime();
void SetDebug(int deb);
};
TCounter::TCounter( )
{
printf("...creating counter%s\n","");
DEBUG=1;
double now=GetTime();
markVO=0.0;
markTO=now - 1.0;
markV=0.0;
markT=now;
currT=now;
currV=0.;
}
TCounter::~TCounter() { printf("...destroing counter%s\n","");}
// This makes it in seconds.............good for high rates
// large error at low rates
double TCounter::GetTime(){
// TString sla;
TDatime *dt=new TDatime(); // kTRUE previously...mess
// sla.Append( dt->AsString() );//append date
// sla.Append( " : " );//append fname
// sla.Append( s_p.Data() );//append fname
// sla.Append( " : END" );//append openfile
// printf("%s\n", sla.Data() );
return 1.0* dt->Get();
}// GetTime
double TCounter::GetRate(){
return (markV-markVO)/(markT-markTO);
}
void TCounter::Register(double weight){
double now=GetTime();
currV=currV+weight;
currT=now;
if (currT - markT >= 1.0 ){
markVO=markV;
markTO=markT;
markV=currV;
markT=currT;
}//if 1 sec
if (DEBUG>0){ printf( "%09.3f ... %f/%f\n", GetRate() , currT, currV );}
return;
}
void TCounter::SetDebug(int deb){
DEBUG=deb;
}
void test(){
int i,imax=2;
TCounter *c[2];
for (i=0;i<imax;i++){
c[i]=new TCounter;
}
for (i=0;i<imax;i++){
delete c[i];
}
}
//-------------------------- class definition ----------------- 2
class TCounterMulti{
public:
// protected:
// int is limited to 4e6 !
double markTO, markT; // time
double currT, currV; // currents , waiting to
static const int max=10;
int N;
TCounter *mcounter[max];
int i;
TCounterMulti( int counters );
~TCounterMulti();
void Register(int counter, double weight=1.0);
void GetRate();
double GetTime(); // same
void Display();
};
double TCounterMulti::GetTime(){
TDatime *dt=new TDatime(); // kTRUE previously...mess
return 1.0* dt->Get();
}// GetTime
TCounterMulti::TCounterMulti( int counters ){
markT=GetTime();
markTO=markT-1;
currT=markT;
N=max;
if (N>counters){ N=counters;}
printf("...creating multicounter, # of counters is %d\n", N);
for (i=0;i<N;i++){
printf(" %d)", i );
mcounter[i]=new TCounter();
// mcounter[i]->SetDebug(0);
}
MPadCreate("COUNTERS",1,N);
}//------------------constructor
TCounterMulti::~TCounterMulti() {
printf("...destroing multicounter%s\n","");
for (i=0;i<N;i++){
delete mcounter[i];
}
}//-------------------------destructor
void TCounterMulti::GetRate(){
for (i=0;i<N;i++){
// printf("%d/%d - \n", i , N );
// if ((i>=0)&&(i<N) ) {
printf("%9.2f ",mcounter[i]->GetRate( ) );
// }
}
printf("%s","\n");
}//---------------------------
void TCounterMulti::Register(int counter, double weight){
if ((counter>=0)&&(counter<N) ) {
mcounter[counter]->Register( weight );
}else{
printf(" counter not in the predefined range (0-%d)\n", N );
}
currT=GetTime();
if (currT>=markT+1){ markT=currT; Display(); }// once per second autodisplay (max.)
return;
}//----------------------------
void TCounterMulti::Display(){
char c[40];
//---taken from MySql multipads2-----------
TCanvas *cc;
if (MPadGetByName( "COUNTERS" )==NULL){
cc=new TCanvas( "COUNTERS","COUNTERS" );
cc->Divide(1 ,N, 0.002,0.002 );
cc->GetCanvas()->SetFillColor(9);cc->GetCanvas()->SetFillStyle(1);
cc->Draw();
}else{
TPad *pp=(TPad*)MPadGetByName( "COUNTERS" );cc=pp->GetCanvas();
}
//---------------------------------------------
// === IT CAN SEEM STOPPED === NO WAY TO SEE THE notcomming COUNTS ?????==
// GetRate();
for (i=0;i<N;i++){
// printf("%d/%d - \n", i , N );
// if ((i>=0)&&(i<N) ) {
sprintf(c, "%09.1f",mcounter[i]->GetRate( ) );
MPadPrintIn("COUNTERS", i+1, c );
// }
}
printf("%s","\n");
}//---------------------------
//=====================================================================COUNTERS OBJECTS
//=====================================================================COUNTERS OBJECTS
//=====================================================================COUNTERS OBJECTS