Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4HistogramServer/TGo4MbsHist.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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             // two dim histo
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); // note: we ignore over + underflow bins
00053             fiBuffer=new Int_t[fiBufLen];
00054             // test: we swap x and y loops
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                } // for
00063          }
00064       else
00065           {
00066             // one dim histo and all others
00067             Int_t maxu=histo->GetNbinsX();
00068             fiBufLen=maxu; // note: we ignore over + underflow bins
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          } // if(histo->GetDimension()))
00077       }
00078 else
00079    {
00080      // case of dummy object!
00081      fiBuffer=new Int_t[fiBufLen];
00082    }    // if(histo)
00083 
00084 }
00085 
00086 TGo4MbsHist::TGo4MbsHist(TFolder* folder, const Text_t* filter)
00087 : fiBufLen(fgiLISTLEN), fxCursor(0), fiHisNum(0)
00088 {
00089    // allocate buffer of total size
00090    //cout <<"Init buflen with "<< fiBufLen << endl;
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    //cout <<"MMMMMMMM Preparing header for histogram "<< source->GetName() << endl;
00109    s_his_head* dest=target; // use local pointer to avoid changes by snprintf
00110    dest->l_bins_1=source->GetNbinsX();
00111    dest->l_bins_2=source->GetNbinsY();
00112    //cout <<" \tMMMMMMMM Prepare header - bins1="<< dest->l_bins_1 << endl;
00113    //cout <<"\tMMMMMMMM Prepare header - bins2="<< dest->l_bins_2 << endl;
00114 // display of path enabled again to test Origin problems JA
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    //cout <<" \tMMMMMMMM Prepare header - 1low="<< dest->r_limits_low << endl;
00127    //cout <<"\tMMMMMMMM Prepare header - 1up ="<< dest->r_limits_up << endl;
00128    //cout <<" \tMMMMMMMM Prepare header - 2low="<< dest->r_limits_low_2 << endl;
00129    //cout <<"\tMMMMMMMM Prepare header - 2up ="<< dest->r_limits_up_2 << endl;
00130 
00131    if(source->InheritsFrom("TH1D") ||
00132       source->InheritsFrom("TH1F") ||
00133       source->InheritsFrom("TH2D") ||
00134       source->InheritsFrom("TH2F"))
00135       {
00136          //cout <<" \tMMMMMMMM Prepare header has float histo" << endl;
00137          snprintf(dest->c_dtype,4,"r");
00138       }
00139    else
00140    {
00141       //cout <<" \tMMMMMMMM Prepare header has int histo" << endl;
00142       snprintf(dest->c_dtype,4,"i");
00143    }
00144    //snprintf(dest->c_dtype,4,"i");// we treat all histograms with integer data
00145    TTimeStamp now;
00146    snprintf(dest->c_data_time_cre,28,"%s",now.AsString("l"));    // creation time
00147    snprintf(dest->c_clear_date,28,"%s",now.AsString("l"));       // clear time, dummy here
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   // scan folder for histogram status objects
00170 // if(filter)
00171 //    cout <<"ScanGo4Folder with filter "<<filter << endl;
00172 // else
00173 //    cout <<"ScanGo4Folder with no filter "<< endl;
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 //                  num=snprintf(pathbuffer,TGo4ThreadManager::fguTEXTLENGTH,"");
00189                   strcpy(pathbuffer,"");
00190                Text_t* cursor=pathbuffer + num;
00191                Int_t edge=TGo4ThreadManager::fguTEXTLENGTH-num;
00192                if(entry->InheritsFrom("TFolder"))
00193                   {
00194                       // found subfolder, process it recursively
00195                       const Text_t* foldname=entry->GetName();
00196                       // filter out folders without histograms or graphs:
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                             //cout <<"##### parsing folder "<< foldname << endl;
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                       // first check if filter is ok:
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; // no filter set, take all
00221                       else if(!strcmp(filter,"*"))
00222                          ismatching=kTRUE; // take all in this folder
00223 //                      else if (strstr(filter,entryname))
00224 //                       ismatching=kTRUE; // expression just contained in name
00225                       else if (entrystring.Index(reg,0)!=kNPOS)
00226                         ismatching=kTRUE; // root regular expression class
00227                       else
00228                         ismatching=kFALSE;
00229 
00230                       if(ismatching)
00231                          {
00232                          //cout <<"found matching:" << entryname << endl;
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                             } // if(hist==0)
00243                          PrepareHeader(hist,pathbuffer,fxCursor);
00244                          fxCursor++;
00245                          fiHisNum++;
00246                          //cout <<"MMMMMMMM found histogram "<< entry->GetName()<<" cr="<<(Int_t) fxCursor<< endl;
00247                          if( (char*) (fxCursor) > (char*)(fiBuffer)+fiBufLen*sizeof(Int_t)- sizeof(s_his_head))
00248                                {
00249                              //cout <<"MMMMMMM Realloc buffer cursor "<< (Int_t) fxCursor << endl;
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++; // set cursor in new buffer
00258    //                          cout <<"MMMMMMM Copied buffer, cursor set "<< endl;
00259    //                          cout <<" hisnum="<< (Int_t) fiHisNum<< endl;
00260    //                          cout <<" newcr="<< (Int_t) fxCursor<< endl;
00261    //                          cout <<" buffer="<< (Int_t) fiBuffer<< endl;
00262                             } else {}
00263                       }//if(ismatching)
00264                    }
00265                else
00266                   {
00267                      // ignore everything except histograms and subfolder
00268                   } // if (entry->InheritsFrom("..."))
00269             } // while
00270          delete listiter;
00271          }   else {   } // if(folder)
00272 }
00273 
00274 
00275 ClassImp(TGo4MbsHist)
00276 
00277 
00278 
00279 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:03 2005 for Go4-v2.10-5 by doxygen1.2.15