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

TGo4TreeHistogramEntry.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 "TGo4TreeHistogramEntry.h"
00017 
00018 #include "Riostream.h"
00019 
00020 #include "TTree.h"
00021 #include "snprintf.h"
00022 #include "TROOT.h"
00023 
00024 #include "TGo4Log.h"
00025 #include "TGo4Status.h"
00026 #include "TGo4DynamicListException.h"
00027 
00028 const char* TGo4TreeHistogramEntry::fgcENTRYSUF="-DL";
00029 
00030 TGo4TreeHistogramEntry::TGo4TreeHistogramEntry() :
00031    TGo4DynamicEntry(),
00032    fxHistogramName(),
00033    fxVarExp(),
00034    fxCutExp(),
00035    fiDynListInterval(1000),
00036    fbNewHistogram(kTRUE),
00037    fiLastEvent(0)
00038 {
00039    TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry()",__LINE__, __FILE__));
00040    fxTreeName="Go4Tree";
00041    EnableProcessing(kTRUE);
00042 }
00043 
00044 TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const char* histogramname,
00045                                                const char* treename,
00046                                                const char* varexp,
00047                                                const char* cutexp) :
00048    TGo4DynamicEntry(histogramname),
00049    fxHistogramName(histogramname),
00050    fxTreeName(treename),
00051    fxVarExp(varexp),
00052    fxCutExp(cutexp),
00053    fiDynListInterval(1000),
00054    fbNewHistogram(kTRUE),
00055    fiLastEvent(0)
00056 {
00057    TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const Text_t*, const Text_t*, const Text_t*, TCut)",__LINE__, __FILE__));
00058    char buffer[2048];
00059    snprintf(buffer,2047,"%s%s",histogramname,fgcENTRYSUF);
00060    SetName(buffer); // histogram name is different from entryname!
00061    EnableProcessing(kTRUE);
00062 
00063    Reset();
00064 }
00065 
00066 TGo4TreeHistogramEntry::~TGo4TreeHistogramEntry()
00067 {
00068    TRACE((15,"TGo4TreeHistogramEntry::~TGo4TreeHistogramEntry()",__LINE__, __FILE__));
00069 }
00070 
00071 void TGo4TreeHistogramEntry::Reset()
00072 {
00073    TRACE((12,"TGo4TreeHistogramEntry::Reset()",__LINE__, __FILE__));
00074    TGo4DynamicEntry::Reset();
00075    fiLastEvent=0;
00076    fbNewHistogram=kTRUE;
00077 }
00078 
00079 void TGo4TreeHistogramEntry::ProcessTreeNew(TTree* tree, Int_t times)
00080 {
00081    if(times<=0) times=1;
00082 
00083    Int_t lastentrynumber = static_cast<Int_t> (tree->GetEntries());
00084    if(tree->TestBit(TGo4Status::kGo4BackStoreReset))
00085       fiLastEvent=0; // start again with first entry of backstore tree
00086 
00087    if(fiLastEvent==lastentrynumber)
00088       throw TGo4DynamicListException(this,
00089                      "Tree Histogram Entry: %s Reached end of tree %s. Draw() is stopped. ",
00090                      GetName(), tree->GetName());
00091    Int_t startindex= lastentrynumber -times;
00092    //cout << "\t -- init startindex: "<< startindex<< endl;
00093    if(startindex<fiLastEvent)
00094       {
00095          // we have to check if some of the events were not filled in the tree,
00096          // in this case we take all from the last processed event to the current:
00097          if(startindex>0)
00098             {
00099                // normal case in continuous processed tree
00100                startindex=fiLastEvent;
00101             }
00102             else
00103             {
00104                // this can happen when tree was Reset() in the meantime
00105                // e.g. tree of TGo4BackStore, then fiLastEvent is wrong
00106                startindex=0;
00107             }
00108          times=lastentrynumber-startindex;
00109       }
00110    else
00111       {
00112          // this happens when dynamic list entry started after the tree filling has begun
00113          // switch this on for cint tree processing:
00114          startindex=fiLastEvent;
00115          //times=lastentrynumber-startindex;
00116          // <- this would cause to process all events in tree since the last time this
00117          // dynamic entry was active. might be dangerous though, not useful...
00118       }
00119 
00120    fiLastEvent=startindex+times; // for cint mode
00121 
00122    if(fiLastEvent>lastentrynumber) {
00123       cout <<"Passing over end of tree - NEVER COME HERE!!!" << endl;
00124       fiLastEvent=lastentrynumber;
00125       times=fiLastEvent-startindex;
00126       cout << "\t -- startindex: "<< startindex<< endl;
00127       cout << "\t -- times: "<< times<< endl;
00128       cout << "\t -- treeentries: "<< lastentrynumber<< endl;
00129    }
00130 
00131    TString drawexp = GetVarExp();
00132    drawexp += ">>+";
00133    drawexp += GetHistogramName();
00134 
00135    TDirectory* savdir = gDirectory;
00136    gROOT->cd(); // be sure to be in the top directory when processing
00137    tree->Draw(drawexp.Data(), fxCutExp.Data(), "goff", times, startindex);
00138    savdir->cd();
00139 }
00140 
00141 
00142 void TGo4TreeHistogramEntry::Print(Option_t* dummy) const
00143 {
00144    // this trick is needed since root defines Print as const function...
00145    TROOT::IndentLevel();
00146    cout <<"-Dynamic TreeDraw Entry " << GetName() << " :" << endl;
00147    TROOT::IncreaseDirLevel();
00148    if(IsEnabledProcessing()) cout <<"\t-- Enabled --" << endl;
00149                         else cout <<"\t-- Disabled --" << endl;
00150 
00151    TROOT::IndentLevel();
00152    cout <<"\tHistogram:\t"<< GetHistogramName()<<endl;
00153    TROOT::IndentLevel();
00154    cout <<"\tTree:\t"<< GetTreeName()<<endl;
00155    TROOT::IndentLevel();
00156    cout <<"\tDraw Expression:\t" << GetVarExp() <<endl;
00157    TROOT::IndentLevel();
00158    cout <<"\tCut Expression:\t" << GetCutExp() << endl;
00159    TROOT::DecreaseDirLevel();
00160    TROOT::IndentLevel();
00161    cout <<"-End "<<GetName()<<"-----------" << endl;
00162 }
00163 
00164 //----------------------------END OF GO4 SOURCE FILE ---------------------

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