Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4MbsHist.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "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             // two dim histo
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); // note: we ignore over + underflow bins
00064             fiBuffer=new Int_t[fiBufLen];
00065             // test: we swap x and y loops
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                } // for
00074          }
00075       else
00076           {
00077             // one dim histo and all others
00078             Int_t maxu=histo->GetNbinsX();
00079             fiBufLen=maxu; // note: we ignore over + underflow bins
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          } // if(histo->GetDimension()))
00088       }
00089 else
00090    {
00091      // case of dummy object!
00092      fiBuffer=new Int_t[fiBufLen];
00093    }    // if(histo)
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    // allocate buffer of total size
00105    //cout <<"Init buflen with "<< fiBufLen << endl;
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    //cout <<"MMMMMMMM Preparing header for histogram "<< source->GetName() << endl;
00121    s_his_head* dest=target; // use local pointer to avoid changes by snprintf
00122    dest->l_bins_1=source->GetNbinsX();
00123    dest->l_bins_2=source->GetNbinsY();
00124    //cout <<" \tMMMMMMMM Prepare header - bins1="<< dest->l_bins_1 << endl;
00125    //cout <<"\tMMMMMMMM Prepare header - bins2="<< dest->l_bins_2 << endl;
00126 // display of path enabled again to test Origin problems JA
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    //cout <<" \tMMMMMMMM Prepare header - 1low="<< dest->r_limits_low << endl;
00139    //cout <<"\tMMMMMMMM Prepare header - 1up ="<< dest->r_limits_up << endl;
00140    //cout <<" \tMMMMMMMM Prepare header - 2low="<< dest->r_limits_low_2 << endl;
00141    //cout <<"\tMMMMMMMM Prepare header - 2up ="<< dest->r_limits_up_2 << endl;
00142 
00143    if(source->InheritsFrom(TH1D::Class()) ||
00144       source->InheritsFrom(TH1F::Class()) ||
00145       source->InheritsFrom(TH2D::Class()) ||
00146       source->InheritsFrom(TH2F::Class()))
00147       {
00148          //cout <<" \tMMMMMMMM Prepare header has float histo" << endl;
00149          snprintf(dest->c_dtype,4,"r");
00150       }
00151    else
00152    {
00153       //cout <<" \tMMMMMMMM Prepare header has int histo" << endl;
00154       snprintf(dest->c_dtype,4,"i");
00155    }
00156    //snprintf(dest->c_dtype,4,"i");// we treat all histograms with integer data
00157    TTimeStamp now;
00158    snprintf(dest->c_data_time_cre,28,"%s",now.AsString("l"));    // creation time
00159    snprintf(dest->c_clear_date,28,"%s",now.AsString("l"));       // clear time, dummy here
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   // scan folder for histogram status objects
00182 // if(filter)
00183 //    cout <<"ScanGo4Folder with filter "<<filter << endl;
00184 // else
00185 //    cout <<"ScanGo4Folder with no filter "<< endl;
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 //                  num=snprintf(pathbuffer,TGo4ThreadManager::fguTEXTLENGTH,"");
00199           strcpy(pathbuffer,"");
00200        char* cursor=pathbuffer + num;
00201        Int_t edge=TGo4ThreadManager::fguTEXTLENGTH-num;
00202        if(entry->InheritsFrom(TFolder::Class()))
00203           {
00204               // found subfolder, process it recursively
00205               const char* foldname=entry->GetName();
00206               // filter out folders without histograms or graphs:
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                     //cout <<"##### parsing folder "<< foldname << endl;
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               // first check if filter is ok:
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; // no filter set, take all
00231               else if(!strcmp(filter,"*"))
00232                  ismatching=kTRUE; // take all in this folder
00233 //                      else if (strstr(filter,entryname))
00234 //                       ismatching=kTRUE; // expression just contained in name
00235               else if (entrystring.Index(reg,0)!=kNPOS)
00236                 ismatching=kTRUE; // root regular expression class
00237               else
00238                 ismatching=kFALSE;
00239 
00240               if(ismatching)
00241                  {
00242                  //cout <<"found matching:" << entryname << endl;
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                     } // if(hist==0)
00253                  PrepareHeader(hist,pathbuffer,fxCursor);
00254                  fxCursor++;
00255                  fiHisNum++;
00256                  //cout <<"MMMMMMMM found histogram "<< entry->GetName()<<" cr="<<(Int_t) fxCursor<< endl;
00257                  if( (char*) (fxCursor) > (char*)(fiBuffer)+fiBufLen*sizeof(Int_t)- sizeof(s_his_head))
00258                        {
00259                      //cout <<"MMMMMMM Realloc buffer cursor "<< (Int_t) fxCursor << endl;
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++; // set cursor in new buffer
00268 //                          cout <<"MMMMMMM Copied buffer, cursor set "<< endl;
00269 //                          cout <<" hisnum="<< (Int_t) fiHisNum<< endl;
00270 //                          cout <<" newcr="<< (Int_t) fxCursor<< endl;
00271 //                          cout <<" buffer="<< (Int_t) fiBuffer<< endl;
00272                     } else {}
00273               }//if(ismatching)
00274            }
00275     } // while
00276 }
00277 
00278 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:26 2008 for Go4-v3.04-1 by  doxygen 1.4.2