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 = 200;
int upd = 50;
hpx =
new TH1F(
"hpx",
"This is the px distribution", 100, -4, 4);
hpx->SetFillColor(48);
for (
Int_t i = 0; i < nfills; i++) {
pz = px*px + py*py;
hpx->Fill(px);
if (i && (i%upd) == 0) {
if (i == upd) {
hpx->Draw();
}
void *arr[4];
arr[3] = (void*)"\"hpxanim.gif+50\"";
(*gThreadXAR)("METH", 4, arr, NULL);
}
}
void *arr[4];
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);
total->SetMarkerStyle(21);
total->SetMarkerSize(0.7);
for (
Int_t i = 0; i < nfills; i++) {
if (i && (i%upd) == 0) {
if (i == upd) {
}
void *arr[4];
arr[3] = (void*)"\"hsumanim.gif+50\"";
(*gThreadXAR)("METH", 4, arr, NULL);
}
}
void *arr[4];
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;
else if (
id == 2) ((
TRootCanvas *)
c2->GetCanvasImp())->CloseWindow();
}
void threadsh2()
{
return;
}
c1 =
new TCanvas(
"c1",
"Dynamic Filling Example", 100, 30, 400, 300);
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderSize(6);
c1->GetFrame()->SetBorderMode(-1);
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;
}
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
float Float_t
Float 4 bytes (float).
static unsigned int total
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
void DontCallClose()
Typically call this method in the slot connected to the CloseWindow() signal to prevent the calling o...
1-D histogram with a float per channel (see TH1 documentation)
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void Draw(Option_t *option="") override
Draw this histogram with options.
Method or function calling interface.
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
This class creates a main window with menubar, scrollbars and a drawing area.
<div class="legacybox"><h2>Legacy Code</h2> TThread is a legacy interface: there will be no bug fixes...
static void Ps()
Static method listing the existing threads.
static Int_t UnLock()
Static method to unlock the main thread mutex.
Long_t Join(void **ret=nullptr)
Join this thread.
Int_t Run(void *arg=nullptr, const int affinity=-1)
Start the thread.
static Int_t Lock()
Static method to lock the main thread mutex.