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