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

/Go4EventServer/TGo4TreeStore.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 "TGo4TreeStore.h"
00017 
00018 #include "Go4Log/TGo4Log.h"
00019 #include "Go4Event/TGo4EventElement.h"
00020 #include "Go4Event/TGo4EventCalibration.h"
00021 #include "Go4StatusBase/TGo4Parameter.h"
00022 
00023 const Text_t TGo4TreeStore::fgcFILESUF[] = ".root";
00024 
00025 TGo4TreeStore::TGo4TreeStore(const char* name,
00026                              TGo4EventElement* event,
00027                              Int_t splitlevel,
00028                              Int_t bufsize,
00029                              Text_t* filename,
00030                              Int_t compression)
00031 : TGo4EventStore(name),
00032    fxBranch(0), fxEvent(event), fiSplit(splitlevel), fiBufsize(bufsize)
00033 {
00034    TRACE((15,"TGo4TreeStore::TGo4TreeStore(Text_t*,...)", __LINE__, __FILE__));
00035 
00036    Text_t buffer [TGo4EventStore::fguTXTLEN];
00037    snprintf(buffer, TGo4EventStore::fguTXTLEN-5, name);
00038    strcat(buffer,"."); // for branches containing the same event structure
00039    fxSingletonTree=TGo4MainTree::Instance();
00040    if(fxEvent)
00041       {
00042          strncpy(fcEventClass, fxEvent->ClassName(), TGo4EventStore::fguTXTLEN-1);
00043          fxTree=fxSingletonTree->GetTree();
00044          fxBranch= fxTree->GetBranch(buffer);
00045          if(fxBranch)
00046             {
00047                // tree already had branch of our name, check it
00048                TGo4Log::Debug(" TreeStore: Found existing branch %s , reset it ", name);
00049                fxBranch->Reset();
00050             }
00051          else
00052             {
00053                // no such branch existing, create a new one
00054                fxBranch=fxTree->Branch(buffer, fcEventClass, &fxEvent, fiBufsize, fiSplit);
00055                TGo4Log::Debug(" TreeStore: Created new branch %s ", name);
00056             } // if(fxBranch)
00057          if(filename)
00058             {
00059                snprintf(buffer, TGo4EventStore::fguTXTLEN -10, filename);
00060                strcat(buffer,fgcFILESUF);
00061                fxFile = new TFile(buffer, "UPDATE");
00062                fxFile->SetCompressionLevel(compression);
00063                fxBranch->SetFile(fxFile);
00064                TGo4Log::Debug(" TreeStore: Set branch to file %s ", filename);
00065             }
00066          else
00067             {
00068                fxFile=0;
00069             } //  if(filename)
00070 
00071       }
00072    else
00073       {
00074          TGo4Log::Debug(" !!! TreeStore creation ERROR: no event structure !!! ");
00075       } // if(fxEvent)
00076 
00077 
00078 }
00079 
00080 TGo4TreeStore::TGo4TreeStore(TGo4TreeStoreParameter* par, TGo4EventElement* event)
00081 : TGo4EventStore("dummy"),
00082    fxBranch(0), fxEvent(event), fiSplit(par->fiSplit), fiBufsize(par->fiBufsize)
00083 {
00084    TRACE((15,"TGo4TreeStore::TGo4TreeStore(Text_t*,...)", __LINE__, __FILE__));
00085 
00086    Text_t buffer [TGo4EventStore::fguTXTLEN];
00087    snprintf(buffer, TGo4EventStore::fguTXTLEN -5,  par->GetName());
00088    SetName(buffer);
00089    strcat(buffer,"."); // for branches containing the same event structure
00090    fxSingletonTree=TGo4MainTree::Instance();
00091    if(fxEvent)
00092       {
00093          strncpy(fcEventClass, fxEvent->ClassName(),TGo4EventStore::fguTXTLEN-1);
00094          fxTree=fxSingletonTree->GetTree();
00095          fxBranch= fxTree->GetBranch(buffer);
00096          if(fxBranch)
00097             {
00098                // tree already had branch of our name, check it
00099                TGo4Log::Debug(" TreeStore: Found existing branch %s , reset it ", buffer);
00100                fxBranch->Reset();
00101             }
00102          else
00103             {
00104                // no such branch existing, create a new one
00105                fxBranch=fxTree->Branch(buffer, fcEventClass, &fxEvent, fiBufsize, fiSplit);
00106                TGo4Log::Debug(" TreeStore: Created new branch %s ", buffer);
00107             } // if(fxBranch)
00108          if(!par->fxBranchFile.IsNull())
00109             {
00110                snprintf(buffer, TGo4EventStore::fguTXTLEN -10, par->fxBranchFile.Data());
00111                strcat(buffer,fgcFILESUF);
00112                fxFile = new TFile(buffer, "UPDATE");
00113                fxFile->SetCompressionLevel(par->fiCompression);
00114                fxBranch->SetFile(fxFile);
00115                TGo4Log::Debug(" TreeStore: Set branch to file %s ", buffer);
00116             }
00117          else
00118             {
00119                fxFile=0;
00120             } //  if(filename)
00121 
00122       }
00123    else
00124       {
00125          TGo4Log::Debug(" !!! TreeStore creation ERROR: no event structure !!! ");
00126       } // if(fxEvent)
00127 }
00128 
00129 TGo4TreeStore::TGo4TreeStore()
00130 :TGo4EventStore("Go4 Default Tree Store"),
00131    fxBranch(0), fxEvent(0), fiSplit(0), fiBufsize(0)
00132 {
00133    TRACE((15,"TGo4TreeStore::TGo4TreeStore()", __LINE__, __FILE__));
00134    // public default ctor for streamer
00135 }
00136 
00137 
00138 TGo4TreeStore::~TGo4TreeStore()
00139 {
00140    TRACE((15,"TGo4TreeStore::~TGo4TreeStore()", __LINE__, __FILE__));
00141    //delete fxFile; // closes File <- done by maintree dtor
00142 }
00143 
00144 
00145 
00146 Int_t TGo4TreeStore::Store(TGo4EventElement* event)
00147 {
00148    TRACE((12,"TGo4TreeStore::Store(TGo4EventElement*)", __LINE__, __FILE__));
00149 
00150    Int_t rev=-1;
00151      // check if new event is of the right class
00152    if(!strcmp( event->ClassName(), fcEventClass) )
00153       {
00154          // event class is matching, we fill it into our tree
00155          fxEvent=event;
00156          fxBranch->SetAddress(&fxEvent);
00157          fxBranch->Fill();
00158          rev=0;
00159       }
00160    else
00161       {
00162          // new event does not match the old ones, we ignore it
00163          TGo4Log::Debug(" !!! TreeStore::Store ERROR: this event does not match !!! ");
00164          fxEvent->Clear();
00165          fxEvent->SetValid(kFALSE);
00166          fxBranch->SetAddress(&fxEvent);
00167          fxBranch->Fill(); // we fill dummy event for consistency
00168          rev=1;
00169       }
00170    //fxBranch->Write();
00171    return rev;
00172 }
00173 
00174 
00175 Int_t TGo4TreeStore::Store(TGo4Parameter* cali)
00176 {
00177    TRACE((12,"TGo4TreeStore::Store(TGo4EventCalibration*)", __LINE__, __FILE__));
00178    if(cali)
00179       {
00180          Text_t buf[256];
00181          Text_t oldname[256];
00182          strncpy(oldname,cali->GetName(),255);
00183          snprintf(buf,255,"%s_%d" , oldname, fxSingletonTree->GetCurrentIndex());
00184          cali->SetName(buf);
00185          fxSingletonTree->fxFile->cd(); // we are main tree's friend
00186          cali->Write(0, TObject::kOverwrite);
00187          cali->SetName(oldname);
00188       }
00189    else
00190       {
00191          // do nothing
00192       }
00193 
00194    return 0;
00195 }
00196 
00197 void TGo4TreeStore::SetCompression(Int_t comp)
00198 {
00199    TRACE((12,"TGo4TreeStore::SetCompression(Int_t)", __LINE__, __FILE__));
00200    fxFile->SetCompressionLevel(comp);
00201 }
00202 
00203 ClassImp(TGo4TreeStore)
00204 
00205 //----------------------------END OF GO4 SOURCE FILE ---------------------

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