Hello everyone,
I'm still observing some strange behaviour after executing two or three
times in quick succession the program which uses my classes. I've checked on
the net and noone seems to have reported this type of behaviour before.
Infact after a certain number of executions the computer shuts down when an
object of one of the classes tries to recreate it's member root file.
It's not very wise to attach files to mails so I'm going to copy the files of
my programs and classes into this mail. I hope it's not too long and that
someome will find some time to take a look at them. There is one source file
for the program and there are two classes(TRun and TObjNA50). I will only
send information on the class which is giving trouble(TRun) in order to
reduce the size of the email. Parts of these files have been left out to make
them clearer.
Thank you very much,
Primrose.
//-------------------------------------The files-----------------------------
//-----------------------------The program------------------------------
#include "TRun.h"
#include "TF1.h"
#include "TSystem.h"
#include "TClassTable.h"
#include "TRint.h"
int main(int argc,char ** argv)
{
TRint theApp("App",&argc,argv);
cout<<"Treating run123"<<endl;
TRun * run = new TRun(123,808,1332); //after succesive executions program
stops here when trying to recreate the member file
cout <<"initialising chambers"<<endl;
run->Addobj(224,'c','1');
run->Addobj(256,'c','2');
run->Addobj(288,'c','3');
run->Addobj(320,'c','4');
run->Addobj(512,'c','5');
run->Addobj(544,'c','6');
run->Addobj(576,'c','7');
run->Addobj(608,'c','8');
cout<<"initialising hodos"<<endl;
run->Addobj(32,'h','1');
run->Addobj(32,'h','2');
run->Addobj(32,'h','3');
run->Addobj(32,'h','4');
run->Addobj(32,'h','5');
cout<<"initialising hodos p"<<endl;
run->Addobj(48,'p','1');
run->AddtoMemory();
Int_t num_run = run->Getfrun_numb();
Char_t name[20];
Int_t i,j;
TF1 f1("fonction1","x*(x-500)+62500",0,500);
int nbfils;
char nomhisto[80];
sprintf (name,"run%d",num_run);
for (j=0; j<13;j++)
{
nbfils = (run->Getobj(j))->Getnb_fils_lattes();
for (i=0;i<6;i++)
{ //naming histos
sprintf(nomhisto,"dp%d",i+1);
strcat(nomhisto,name);
strcat(nomhisto,(run->Getobj(j))->GetnomObjNA50());
//filling histos
(run->Getobj(j))->Addhist(nomhisto,nomhisto,nbfils,0,nbfils);
((run->Getobj(j))->Gethist(i))->FillRandom("fonction1",1000);
run->Writehisto((run->Getobj(j))->Gethist(i));
}
}
run->UpdateMemory();
run->CloseFile();
run->CloseSharedMemory();
return (0);
}
//----------------------------------------The Classes------------------------
//------------------------------------The class TRun-----------------------
//---------------------------File: TRun.h-------------------------------------
#ifndef _TRun_
#define _TRun_
#include "TObjNA50.h" //the second class
#include "TFile.h"
#include "TMapFile.h"
class TRun : public TObject
{
public:
// constants
enum {maxobj = 14}; //size maximal of the ftab_obj array
enum {maxhisto = 6}; //size maximal of the ftab_histo array
//the constructeur
TRun(Int_t run_numb = -1,Int_t date = 0, Int_t time = 0);
//the destructor
~TRun();
//the other methods
Int_t Getfrun_numb() const;
Int_t Getfdate() const;
Int_t Getftime() const;
const Char_t * Getfbeam() const;
const Char_t * Getftrigger() const;
TObjNA50* Getobj(Int_t i) ;
TH1F * Gethisto(Int_t i) ;
void Addobj(Int_t nbfils,Char_t opt,Char_t num_obj);
void Addhisto(const Char_t* nom, const Char_t* titre, Int_t nbbins,
Int_t low, Int_t high);
void Writehisto(TH1F *h) const;
void CloseFile();
TMapFile *GetSharedMemory();
void CloseSharedMemory();
void AddtoMemory(TH1F * h);
void AddtoMemory();
void UpdateMemory();
static Int_t GetnbObjRun(); //get number of objects which belong to class TRun
private:
TObjArray ftab_obj; //will contain the 8 chambers and the 4
hodoscopes
TObjArray ftab_histo; //will contain 6 other histogrammes
TFile *ffile; //root file for saving histograms
Int_t findexobj; //current index in the ftab_obj array
Int_t findexhisto; //current index in the ftab_histo array
Int_t frun_numb; //run number
Int_t fdate; //date of run
Int_t ftime; //time of run
Char_t fbeam[10]; //beam used
Char_t ftrigger[10]; //trigger used
TMapFile *fsharedmemory; //! memeory shared between the creator
of histograms and their display
static Int_t fgnbObjRun ; //number of objects in the class<=>
number of runs effected
ClassDef(TRun,1)
};
#endif
//----------------------------------------File: TRun.cxx---------------------
#include "TRun.h"
ClassImp(TRun)
//initialisation of the number of objects in the class
Int_t TRun::fgnbObjRun = 0;
//constructor
TRun::TRun(Int_t run_numb = -1,Int_t date = 0, Int_t time = 0):
ftab_obj(maxobj),
ftab_histo(maxhisto),
findexobj(0),
findexhisto(0),
frun_numb(run_numb),
fdate(date),
ftime(time)
{
if (run_numb == -1)
{
ffile=NULL;
fsharedmemory = NULL;
}
else
{
fsharedmemory =
TMapFile::Create("runcour.map","RECREATE",500000,"temp_mem");
fsharedmemory->RemoveAll();
Char_t name[20];
sprintf(name,"run%d.root",frun_numb);
ffile = new TFile(name,"RECREATE"); //program stops at this point.
}
for (int i=0;i<maxobj;i++)
{
ftab_obj[i]=NULL;
}
for (int i=0;i<maxhisto;i++)
{
ftab_histo[i]=NULL;
}
//beam and trigger have no exact structure for now
strcpy(fbeam,"beam");
strcpy(ftrigger,"trigger");
fgnbObjRun++;
}
//destructor
TRun::~TRun()
{
this->CloseFile();
this->CloseSharedMemory();
for (int i=0;i<maxobj;i++)
{
if(ftab_obj[i] != NULL)
{
delete ftab_obj[i];
}
}
for (int i=0;i<maxhisto;i++)
{
if(ftab_histo[i] != NULL)
{
delete ftab_histo[i];
}
}
fgnbObjRun--;
}
//the other methods
/*-----------------------------------------------------
*- adds an objNA50 to the array of objects NA50
*-----------------------------------------------------*/
void TRun::Addobj(Int_t nbfils,Char_t opt,Char_t num_obj)
{
if (findexobj<maxobj)
{
ftab_obj.AddAt(new TObjNA50(nbfils,opt,num_obj),findexobj++);
}
else
{
cout<<"there is no more space for new NA50 objects"<<endl;
}
}
/*-------------------------------------------------------------
*-Adds new histograms to the array for histograms
*-------------------------------------------------------------*/
void TRun::Addhisto(const Char_t * nom,const Char_t * titre,Int_t
nbbins,Int_t low,Int_t high)
{
if (findexhisto<maxhisto)
{
ftab_histo.AddAt(new TH1F(nom,titre,nbbins,low,high),findexhisto++);
}
else
{
cout<<"there is no more space for new histograms"<<endl;
}
}
/*---------------------------------------------------------
*-saves a histogram to the file: ffile
*---------------------------------------------------------*/
void TRun::Writehisto(TH1F * h) const
{
if (ffile==NULL)
{
cout<<"no file to write to"<<endl;
}
else
{
h->Write();
}
}
/*----------------------------------------------------------
*-Closes the file:ffile
*----------------------------------------------------------*/
void TRun::CloseFile()
{
if (ffile == NULL) return;
ffile->Close();
delete ffile;
ffile = NULL;
}
/*-----------------------------------------------------------
*-Adds a histogram to shared memory
*-----------------------------------------------------------*/
void TRun::AddtoMemory(TH1F * h)
{
if (fsharedmemory == NULL)
{
cout<<"no shared memory created"<<endl;
}
else
{
fsharedmemory->Add(h);
}
}
/*-----------------------------------------------------------
*-Adds the present run to shared memory
*-----------------------------------------------------------*/
void TRun::AddtoMemory()
{
if (fsharedmemory == NULL)
{
cout<<"no shared memory created"<<endl;
}
else
{
fsharedmemory->Add(this,"runcour");
}
}/*------------------------------------------------------------
*-updates everything in shared memory
*-----------------------------------------------------------*/
void TRun::UpdateMemory()
{
if (fsharedmemory == NULL)
{
cout<<"no shared memory created"<<endl;
}
else
{
fsharedmemory->Update();
}
}
/*--------------------------------------------------------------
*-Closes the shared memory
*--------------------------------------------------------------*/
void TRun::CloseSharedMemory()
{
if (fsharedmemory == NULL) return;
fsharedmemory->Close();
fsharedmemory=NULL;
}
/*--------------------------------------------------------------
*-the following methodes give access to the members of the class
*--------------------------------------------------------------*/
//run number
Int_t TRun::Getfrun_numb() const
{
return frun_numb;
}
//date of run
Int_t TRun::Getfdate() const
{
return fdate;
}
//time
Int_t TRun::Getftime() const
{
return ftime;
}
//beam
const Char_t * TRun::Getfbeam() const
{
return fbeam;
}
//trigger
const Char_t * TRun::Getftrigger() const
{
return ftrigger;
}
//to the object at ftab_obj[i]
TObjNA50* TRun::Getobj(Int_t i)
{
return ((TObjNA50 *)ftab_obj[i]);
}
//to the object at ftab_histo[i]
TH1F* TRun::Gethisto(Int_t i)
{
return ((TH1F *)ftab_histo[i]);
}
//to shared memory
TMapFile * TRun::GetSharedMemory()
{
return fsharedmemory;
}
//the number of existing objects
Int_t TRun::GetnbObjRun()
{
return fgnbObjRun;
}
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:59 MET