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