Example of a simple script creating 2 threads each with one canvas.
This script can only be executed via ACliC .x threadsh2.C++. The canvases are saved in a animated gif file.
TThread *thread1, *thread2, *threadj;
void *handle1(void *)
{
int nfills = 10000;
int upd = 500;
hpx =
new TH1F(
"hpx",
"This is the px distribution", 100, -4, 4);
gRandom->SetSeed();
for (
Int_t i = 0; i < nfills; i++) {
gRandom->Rannor(px, py);
pz = px*px + py*py;
if (i && (i%upd) == 0) {
if (i == upd) {
}
void *arr[4];
arr[2] = (void *)c1;
arr[3] = (void*)"\"hpxanim.gif+50\"";
(*gThreadXAR)("METH", 4, arr, NULL);
}
}
void *arr[4];
arr[2] = (void *)c1;
arr[3] = (void*)"\"hpxanim.gif++\"";
(*gThreadXAR)("METH", 4, arr, NULL);
return 0;
}
void *handle2(void *)
{
int nfills = 10000;
int upd = 500;
total =
new TH1F(
"total",
"This is the total distribution",100,-4,4);
hmain =
new TH1F(
"hmain",
"Main contributor",100,-4,4);
s1 =
new TH1F(
"s1",
"This is the first signal",100,-4,4);
s2 =
new TH1F(
"s2",
"This is the second signal",100,-4,4);
gRandom->SetSeed();
for (
Int_t i = 0; i < nfills; i++) {
xmain = gRandom->Gaus(-1,1.5);
xs1 = gRandom->Gaus(-0.5,0.5);
xs2 = gRandom->Landau(1,0.15);
if (i && (i%upd) == 0) {
if (i == upd) {
}
void *arr[4];
arr[2] = (void *)c2;
arr[3] = (void*)"\"hsumanim.gif+50\"";
(*gThreadXAR)("METH", 4, arr, NULL);
}
}
void *arr[4];
arr[2] = (void *)c2;
arr[3] = (void*)"\"hsumanim.gif++\"";
(*gThreadXAR)("METH", 4, arr, NULL);
return 0;
}
void *joiner(void *)
{
return 0;
}
void tryclosing(
Int_t id)
{
if (!finished) return;
}
void threadsh2()
{
return;
}
c1 =
new TCanvas(
"c1",
"Dynamic Filling Example", 100, 30, 400, 300);
if (!rc) return;
"tryclosing(Int_t=1)");
c2 =
new TCanvas(
"c2",
"Dynamic Filling Example", 515, 30, 400, 300);
if (!rc) return;
"tryclosing(Int_t=2)");
printf("Starting Thread 0\n");
thread1 =
new TThread(
"t0", handle1, (
void*) 0);
printf("Starting Thread 1\n");
thread2 =
new TThread(
"t1", handle2, (
void*) 1);
printf("Starting Joiner Thread \n");
threadj =
new TThread(
"t4", joiner, (
void*) 3);
while (!finished) {
}
delete thread1;
delete thread2;
delete threadj;
}
- Author
- Victor Perevovchikov
Definition in file threadsh2.C.