00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4MbsHist.h"
00015
00016 #include <string.h>
00017
00018 #include "TGraph.h"
00019 #include "TH1.h"
00020 #include "TH2.h"
00021 #include "TList.h"
00022 #include "TFolder.h"
00023 #include "TTimeStamp.h"
00024 #include "TRegexp.h"
00025 #include "snprintf.h"
00026
00027 #include "TGo4ThreadManager.h"
00028 #include "TGo4AnalysisObjectManager.h"
00029
00030 const Int_t TGo4MbsHist::fgiLISTLEN=512;
00031
00032 TGo4MbsHist::TGo4MbsHist() :
00033 TObject(),
00034 fiBufLen(128),
00035 fiBuffer(0),
00036 fxCursor(0),
00037 fiHisNum(0)
00038 {
00039 fiBuffer=new Int_t[fiBufLen];
00040 }
00041
00042 TGo4MbsHist::TGo4MbsHist(TH1* histo) :
00043 TObject(),
00044 fiBufLen(1),
00045 fiBuffer(0),
00046 fxCursor(0),
00047 fiHisNum(1)
00048 {
00049 if(histo)
00050 {
00051 PrepareHeader(histo,0,&fxHistoHead);
00052 if(histo->GetDimension()==2)
00053 {
00054
00055 Int_t i=0;
00056 Stat_t value=0;
00057
00058 Int_t maxu=histo->GetNbinsX();
00059 Int_t maxv=histo->GetNbinsY();
00060 fiBufLen=(maxu)*(maxv);
00061 fiBuffer=new Int_t[fiBufLen];
00062
00063 for (Int_t v = 0;v<maxv; v++)
00064 {
00065 for (Int_t u = 0; u<maxu; u++)
00066 {
00067 value=histo->GetBinContent(u,v);
00068 SetValue((char*) &fiBuffer[i++], value);
00069 }
00070 }
00071 }
00072 else
00073 {
00074
00075 Int_t maxu=histo->GetNbinsX();
00076 fiBufLen=maxu;
00077 fiBuffer=new Int_t[fiBufLen];
00078 Stat_t value=0;
00079 for (Int_t u = 0; u<maxu;u++)
00080 {
00081 value=histo->GetBinContent(u);
00082 SetValue((char*) &fiBuffer[u], value);
00083 }
00084 }
00085 }
00086 else
00087 {
00088
00089 fiBuffer=new Int_t[fiBufLen];
00090 }
00091
00092 }
00093
00094 TGo4MbsHist::TGo4MbsHist(TFolder* folder, const char* filter) :
00095 TObject(),
00096 fiBufLen(fgiLISTLEN),
00097 fiBuffer(0),
00098 fxCursor(0),
00099 fiHisNum(0)
00100 {
00101
00102
00103 fiBuffer=new Int_t[fiBufLen];
00104 fxCursor= (s_his_head*) fiBuffer;
00105 ScanGo4Folder(folder,0,filter);
00106 }
00107
00108
00109 TGo4MbsHist::~TGo4MbsHist()
00110 {
00111 delete [] fiBuffer;
00112 }
00113
00114 void TGo4MbsHist::PrepareHeader(TH1* source, const char* path, s_his_head* target)
00115 {
00116 if(source==0 || target==0) return;
00117
00118 s_his_head* dest=target;
00119 dest->l_bins_1=source->GetNbinsX();
00120 dest->l_bins_2=source->GetNbinsY();
00121
00122
00123
00124 if(path)
00125 snprintf(dest->c_name,64,"%s%s",path,source->GetName());
00126 else
00127 snprintf(dest->c_name,64,"%s",source->GetName());
00128 snprintf(dest->c_lettering_1,64,"%s",source->GetXaxis()->GetTitle());
00129 snprintf(dest->c_lettering_2,64,"%s",source->GetYaxis()->GetTitle());
00130 snprintf(dest->c_lettering_res,64,"%s",source->GetYaxis()->GetTitle());
00131 dest->r_limits_low=source->GetXaxis()->GetXmin();
00132 dest->r_limits_up=source->GetXaxis()->GetXmax();
00133 dest->r_limits_low_2=source->GetYaxis()->GetXmin();
00134 dest->r_limits_up_2=source->GetYaxis()->GetXmax();
00135
00136
00137
00138
00139
00140 if(source->InheritsFrom(TH1D::Class()) ||
00141 source->InheritsFrom(TH1F::Class()) ||
00142 source->InheritsFrom(TH2D::Class()) ||
00143 source->InheritsFrom(TH2F::Class())) {
00144
00145 strcpy(dest->c_dtype,"r");
00146 }
00147 else
00148 {
00149
00150 strcpy(dest->c_dtype,"i");
00151 }
00152 TTimeStamp now;
00153 snprintf(dest->c_data_time_cre,28,"%s",now.AsString("l"));
00154 snprintf(dest->c_clear_date,28,"%s",now.AsString("l"));
00155
00156 }
00157
00158
00159 void TGo4MbsHist::SetValue(char* address, Stat_t value)
00160 {
00161 if(!strcmp(fxHistoHead.c_dtype,"r"))
00162 {
00163 Float_t* faddress=(Float_t*) address;
00164 *faddress= (Float_t) value;
00165 }
00166 else
00167 {
00168 Int_t* iaddress=(Int_t*) address;
00169 *iaddress= (Int_t) value;
00170 }
00171 }
00172
00173
00174 void TGo4MbsHist::ScanGo4Folder(TFolder* folder, const char* superfolders, const char* filter)
00175 {
00176
00177
00178
00179
00180
00181
00182
00183 if(folder==0) return;
00184
00185 TIter iter(folder->GetListOfFolders());
00186 TObject* entry = 0;
00187 while((entry = iter()) !=0) {
00188 char pathbuffer[TGo4ThreadManager::fguTEXTLENGTH];
00189 Int_t num=0;
00190 if(superfolders)
00191 num=snprintf(pathbuffer,TGo4ThreadManager::fguTEXTLENGTH,"%s/",superfolders);
00192 else
00193
00194 strcpy(pathbuffer,"");
00195 char* cursor=pathbuffer + num;
00196 Int_t edge=TGo4ThreadManager::fguTEXTLENGTH-num;
00197 if(entry->InheritsFrom(TFolder::Class()))
00198 {
00199
00200 const char* foldname=entry->GetName();
00201
00202 if(!strcmp(foldname,TGo4AnalysisObjectManager::fgcDYNFOLDER)){;}
00203 else if(!strcmp(foldname,TGo4AnalysisObjectManager::fgcCONDFOLDER)){;}
00204 else if(!strcmp(foldname,TGo4AnalysisObjectManager::fgcPARAFOLDER)){;}
00205 else if(!strcmp(foldname,TGo4AnalysisObjectManager::fgcTREEFOLDER)){;}
00206 else if(!strcmp(foldname,TGo4AnalysisObjectManager::fgcPICTFOLDER)){;}
00207 else if(!strcmp(foldname,TGo4AnalysisObjectManager::fgcCANVFOLDER)){;}
00208 else if(!strcmp(foldname,TGo4AnalysisObjectManager::fgcANALYSISFOLDER)){;}
00209 else
00210 {
00211
00212 snprintf(cursor,edge,"%s",foldname);
00213 TFolder* subobj= dynamic_cast<TFolder*> (entry);
00214 ScanGo4Folder(subobj,pathbuffer, filter);
00215 }
00216 }
00217 else if (entry->InheritsFrom(TH1::Class()) || entry->InheritsFrom(TGraph::Class()))
00218 {
00219
00220 Bool_t ismatching=kFALSE;
00221 const char* entryname=entry->GetName();
00222 TString entrystring=entryname;
00223 TRegexp reg(filter,kTRUE);
00224 if(filter==0)
00225 ismatching=kTRUE;
00226 else if(!strcmp(filter,"*"))
00227 ismatching=kTRUE;
00228
00229
00230 else if (entrystring.Index(reg,0)!=kNPOS)
00231 ismatching=kTRUE;
00232 else
00233 ismatching=kFALSE;
00234
00235 if(ismatching)
00236 {
00237
00238 TH1* hist= dynamic_cast<TH1*> (entry);
00239 if(hist==0)
00240 {
00241 TGraph* graf=dynamic_cast<TGraph*> (entry);
00242 if(graf && graf->GetN()>0)
00243 {
00244 hist=graf->GetHistogram();
00245 }
00246 if(hist==0) continue;
00247 }
00248 PrepareHeader(hist,pathbuffer,fxCursor);
00249 fxCursor++;
00250 fiHisNum++;
00251
00252 if( (char*) (fxCursor) > (char*)(fiBuffer)+fiBufLen*sizeof(Int_t)- sizeof(s_his_head))
00253 {
00254
00255 Int_t oldbuflen=fiBufLen;
00256 fiBufLen+=fgiLISTLEN;
00257 Int_t* otherbuf= new Int_t[fiBufLen];
00258 memcpy(otherbuf, fiBuffer,oldbuflen*sizeof(Int_t) );
00259 delete[] fiBuffer;
00260 fiBuffer=otherbuf;
00261 fxCursor= (s_his_head*) fiBuffer;
00262 for(Int_t n=0; n< fiHisNum; ++n) fxCursor++;
00263
00264
00265
00266
00267 } else {}
00268 }
00269 }
00270 }
00271 }