In a while loop in a thread the function : load_datamodule(…) below is called and
this while loop is an infinite while(1) loop from which the break
occurs when the stop button is pressed or time is over.
The code hangs after the message :
I am here 010
i.e. it hangs in the code c124->Update();
The code works perfectly ok if the mouse cursor is moved across the screen.
But if left idle for long the code hangs up here. Kindly help me.
parts of code is as below :
HistWin::HistWin(const TGWindow *p,UInt_t w,UInt_t h)
: TGMainFrame(p,w=1000,h=800)
{
p1 = p;
cout << "I am in HistWin constructor" << "\n" ;
cout << "before histwin1 = " << histwin1 << "\n" ;
histwin1++;
cout << "after histwin1 = " << histwin1 << "\n" ;
fHpx_waveMCA = NULL;
tracehist = NULL;
// main frame
fMainFrame2926 = new TGMainFrame(this,10,10,kMainFrame | kVerticalFrame);
fMainFrame2926->SetName("fMainFrame2926");
fMainFrame2926->SetLayoutBroken(kFALSE);
// composite frame
fMainFrame4041 = new TGCompositeFrame(fMainFrame2926,1024,705,kVerticalFrame);
fMainFrame4041->SetName("fMainFrame4041");
// vertical frame
fVerticalFrame770 = new TGVerticalFrame(fMainFrame4041,1024,703,kVerticalFrame);
fVerticalFrame770->SetName("fVerticalFrame770");
fVerticalFrame770->SetLayoutBroken(kTRUE);
// embedded canvas
fRootEmbeddedCanvas799 = new TRootEmbeddedCanvas(0,fVerticalFrame770,1016,576);
fRootEmbeddedCanvas799->SetName("fRootEmbeddedCanvas799");
Int_t wfRootEmbeddedCanvas799 = fRootEmbeddedCanvas799->GetCanvasWindowId();
c124 = new TCanvas("c124", 10, 10, wfRootEmbeddedCanvas799);
fRootEmbeddedCanvas799->AdoptCanvas(c124);
fVerticalFrame770->AddFrame(fRootEmbeddedCanvas799, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
fRootEmbeddedCanvas799->MoveResize(2,2,1016,576);
......
int HistWin::load_datamodule(unsigned short mod3333, unsigned short chan3333)
{
int retval;
unsigned int NumWords ;
NumWords = 32768;
char hname1[10] = "MCA" ;
sprintf(nam101,"%04d_mod%02d.mca",run_no,mod3333); // 0 for module no 0
strcpy(filnamused,filnam);
strcat(filnamused , nam101);
printf("In load_datamodule(..) ...Reading from Hist mode data file : %s\n",filnamused);
fNumberEntry976->SetIntNumber(channelNr);
fNumberEntry1254->SetIntNumber(moduleNr);
fTextEntry957->SetText(filnam);
fNumberEntry979->SetIntNumber(run_no); // update "Run number"
fTextEntry1814->SetText(filnamused);
if (tracehist == NULL)
tracehist = new unsigned int[NumWords];
memset(tracehist, 0, NumWords * sizeof(unsigned int));
printf("Reading Histogram from module: module no:%i , chan no.:%i \n",mod3333, chan3333);
retval = Pixie16ReadHistogramFromModule (tracehist, NumWords, mod3333, chan3333);
if(retval < 0)
{
// error handling
if (retval == -1)
{ std::cout << "retval = " << retval << " moduleNr = " << mod3333 << "\n";
std::cout << "Invalid Pixie-16 module number" << "\n";
std::cout << "Correct ModNum\n" << "\n";
}
else if (retval == -2)
{ std::cout << "retval = " << retval << " ChanNum = " << chan3333 << "\n";
std::cout << "Invalid Pixie-16 channel number" << "\n";
std::cout << "Correct Channel Number" << "\n" ;
}
else if (retval == -3)
{ std::cout << "retval = " << retval << "\n";
std::cout << "Failed to get the histogram data" << "\n";
std::cout << "Reboot the module" << "\n" ;
}
else { std::cout << "Undocumented error" << "\n"; }
return retval;
}
cout << "Success - Pixie16ReadHistogramFromModule (...)" << "\n";
char title01[20] = "data from module" ;
cout << "I am here 001" << "\n";
sprintf(histtitle,"%s,mod=%d,chan=%d", title01 ,mod3333, chan3333);
cout << "I am here 002" << "\n";
if (fHpx_waveMCA == NULL ) {
fHpx_waveMCA = new TH1I ( hname1 , histtitle , NumWords, 0, NumWords );
gStyle->SetOptStat(0);
x_waveMCA = fHpx_waveMCA->GetXaxis();
}
else {
fHpx_waveMCA->SetTitle(histtitle);
cout << "I am here 00222" << "\n";
}
cout << "I am here 003" << "\n";
fHpx_waveMCA->UseCurrentStyle();
cout << "I am here 004" << "\n";
xmaxint_waveMCA = x_waveMCA->GetLast();
xminint_waveMCA = x_waveMCA->GetFirst();
cout << "I am here 005" << "\n";
fHpx_waveMCA->Reset();
cout << "I am here 006" << "\n";
for ( int j = 0; j < NumWords ; j++)
{ fHpx_waveMCA->Fill(j, int(tracehist[j]) );
}
cout << "I am here 007" << "\n";
c124->cd();cout << "I am here 008" << "\n";
fHpx_waveMCA->DrawCopy();cout << "I am here 009" << "\n";
c124->Modified();cout << "I am here 010" << "\n";
c124->Update();cout << "I am here 011" << "\n";
gSystem->ProcessEvents();cout << "I am here 012" << "\n";
return 1;
} // int HistWin::load_datamodule(unsigned short mod3333, unsigned short chan3333)