00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4AnalysisStatus.h"
00015
00016 #include "Riostream.h"
00017
00018 #include "TMutex.h"
00019 #include "TObjArray.h"
00020 #include "TROOT.h"
00021
00022 #include "TGo4LockGuard.h"
00023 #include "TGo4Log.h"
00024 #include "TGo4AnalysisStepStatus.h"
00025
00026 TGo4AnalysisStatus::TGo4AnalysisStatus() :
00027 TGo4Status("Go4 Default Analysis Status","Go4 Analysis Status Object"),
00028 fxStepArray(0),
00029 fxStepMutex(0),
00030 fxStepIterator(0),
00031 fbStepCheckingMode(1),
00032 fiFirstStepIndex(0),
00033 fiLastStepIndex(0),
00034 fiAutoSaveInterval(0),
00035 fiAutoSaveCompression(5),
00036 fbAutoSaveOverwrite(0),
00037 fbAutoSaveOn(1),
00038 fxAutoFileName(),
00039 fxConfigFileName()
00040 {
00041 GO4TRACE((15,"TGo4AnalysisStatus::TGo4AnalysisStatus()",__LINE__, __FILE__));
00042 }
00043
00044
00045 TGo4AnalysisStatus::TGo4AnalysisStatus(const char* name) :
00046 TGo4Status(name,"Go4 Analysis Status Object"),
00047 fxStepArray(0),
00048 fxStepMutex(0),
00049 fxStepIterator(0),
00050 fbStepCheckingMode(1),
00051 fiFirstStepIndex(0),
00052 fiLastStepIndex(0),
00053 fiAutoSaveInterval(0),
00054 fiAutoSaveCompression(5),
00055 fbAutoSaveOverwrite(0),
00056 fbAutoSaveOn(1),
00057 fxAutoFileName(),
00058 fxConfigFileName()
00059 {
00060 GO4TRACE((15,"TGo4AnalysisStatus::TGo4AnalysisStatus(const char*)",__LINE__, __FILE__));
00061 fxStepArray = new TObjArray;
00062 fxStepIterator = fxStepArray->MakeIterator();
00063 fxStepMutex = new TMutex;
00064 }
00065
00066 TGo4AnalysisStatus::~TGo4AnalysisStatus()
00067 {
00068 GO4TRACE((15,"TGo4AnalysisStatus::~TGo4AnalysisStatus()",__LINE__, __FILE__));
00069 delete fxStepMutex;
00070 delete fxStepIterator;
00071 fxStepArray->Delete();
00072 delete fxStepArray;
00073 }
00074
00075 Int_t TGo4AnalysisStatus::PrintStatus(Text_t* buffer, Int_t buflen)
00076 {
00077 GO4TRACE((12,"TGo4AnalysisStatus::PrintStatus()",__LINE__, __FILE__));
00078 if(buflen<=0 && buffer!=0)
00079 {
00080 std::cout << "analysis status print has invalid buflen and nonzero buffer"<< std::endl;
00081 return 0;
00082 }
00083 Int_t size=0;
00084 Int_t locallen=512000;
00085 Text_t localbuf[512000];
00086 Text_t* current=localbuf;
00087 Int_t restlen=locallen;
00088
00089 current=PrintBuffer(current,restlen, "---------------------------------------------- \n");
00090 current=PrintBuffer(current,restlen, "++++++ Status of %s ++++++\n", GetName());
00091 current=PrintBuffer(current,restlen, "First Analysis Step index: \t%d\n",GetFirstStepIndex());
00092 current=PrintBuffer(current,restlen, "Last Analysis Step index: \t%d\n",GetLastStepIndex());
00093 current=PrintBuffer(current,restlen, "Autosave Interval: \t\t%d s\n",GetAutoSaveInterval());
00094 current=PrintBuffer(current,restlen, "Autosave File: \t\t%s \n",GetAutoFileName());
00095 current=PrintBuffer(current,restlen, "Autosave File compression: \t%d \n",GetAutoSaveCompression());
00096 current=PrintBuffer(current,restlen, "Autosave overwrite mode: \t%d \n",IsAutoSaveOverwrite());
00097 current=PrintBuffer(current,restlen, "Autosave enabled: \t\t%d \n",IsAutoSaveOn());
00098 current=PrintBuffer(current,restlen, "---------------------------------------------- \n");
00099 TROOT::IncreaseDirLevel();
00100 ResetStepIterator();
00101 TGo4AnalysisStepStatus* step=0;
00102 while((step=NextStepStatus()) != 0)
00103 {
00104 Int_t delta=step->PrintStatus(current,restlen);
00105 restlen-=delta;
00106 current+= delta ;
00107 }
00108 TROOT::DecreaseDirLevel();
00109 current=PrintBuffer(current,restlen, "---------------------------------------------- \n");
00110 if(buffer==0)
00111 {
00112 std::cout << localbuf << std::endl;
00113 }
00114 else
00115 {
00116 size=locallen-restlen;
00117 if(size>buflen-1)
00118 size=buflen-1;
00119 strncpy(buffer,localbuf,size);
00120 }
00121 return size;
00122 }
00123
00124 TGo4AnalysisStepStatus * TGo4AnalysisStatus::GetStepStatus(const char* name)
00125 {
00126 GO4TRACE((11,"TGo4Analysis::GetAnalysisStep(const char*)",__LINE__, __FILE__));
00127 if(fxStepArray==0) return 0;
00128 TGo4AnalysisStepStatus* step=0;
00129 {
00130 TGo4LockGuard listguard(fxStepMutex);
00131 step = dynamic_cast<TGo4AnalysisStepStatus*>( fxStepArray->FindObject(name) );
00132 }
00133 return step;
00134 }
00135
00136 TGo4AnalysisStepStatus * TGo4AnalysisStatus::NextStepStatus()
00137 {
00138 GO4TRACE((11,"TGo4AnalysisStatus::NextStepStatus()",__LINE__, __FILE__));
00139 if(fxStepIterator==0) return 0;
00140 TGo4AnalysisStepStatus* step=0;
00141 {
00142 TGo4LockGuard listguard(fxStepMutex);
00143 step = dynamic_cast<TGo4AnalysisStepStatus*>( fxStepIterator->Next() );
00144 }
00145 return step;
00146 }
00147
00148 void TGo4AnalysisStatus::ResetStepIterator()
00149 {
00150 TGo4LockGuard listguard(fxStepMutex);
00151 delete fxStepIterator;
00152 if(fxStepArray)
00153 fxStepIterator=fxStepArray->MakeIterator();
00154 else
00155 fxStepIterator=0;
00156
00157 }
00158
00159
00160 Bool_t TGo4AnalysisStatus::AddStepStatus(TGo4AnalysisStepStatus * next)
00161 {
00162 GO4TRACE((14,"TGo4AnalysisStatus::AddAnalysisStep(TGo4AnalysisStep*)",__LINE__, __FILE__));
00163
00164 if(fxStepArray==0) return kFALSE;
00165 Bool_t rev=kFALSE;
00166 if(next)
00167 {
00168 TGo4LockGuard listguard(fxStepMutex);
00169 fxStepArray->AddLast(next);
00170 rev=kTRUE;
00171 }
00172 else
00173 {
00174 rev=kFALSE;
00175
00176 }
00177 return rev;
00178 }
00179
00180 Int_t TGo4AnalysisStatus::GetNumberOfSteps()
00181 {
00182 return fxStepArray==0 ? 0 : fxStepArray->GetLast()+1;
00183 }
00184
00185
00186 TGo4AnalysisStepStatus* TGo4AnalysisStatus::GetStepStatus(Int_t indx)
00187 {
00188 if ((indx<0) || (indx>=GetNumberOfSteps())) return 0;
00189 return dynamic_cast<TGo4AnalysisStepStatus*> (fxStepArray->At(indx));
00190 }
00191