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

MainGo4Queue.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 "Riostream.h"
00017 #include <stdlib.h>
00018 
00019 #include "TApplication.h"
00020 #include "TH1.h"
00021 #include "TClass.h"
00022 
00023 #include "TGo4BufferQueue.h"
00024 #include "TGo4ObjectQueue.h"
00025 
00026 
00027 void usage(char **args);
00028 
00029 //______________________________________________________________________________
00030 int main(int argc, char **argv)
00031 {
00032    TApplication theApp("App", &argc, argv);
00033 
00034    TNamed *com = new TNamed("named object", "this is a test");
00035 
00036    TH1F *histo = new TH1F("histogram", "this is a test histogram", 100, 0., 1.);
00037    histo->Fill(0.2);
00038    TH1F *histo2 = new TH1F("histogram 2", "this is a test histogram", 100, 0., 1.);
00039    histo2->Fill(0.7);
00040    TH1* histo3=0;
00041    TGo4ObjectQueue objectq("My object queue");
00042    TGo4BufferQueue bufferq("My buffer queue");
00043 
00044    objectq.AddObject(histo,kTRUE);
00045    delete histo;
00046    cout << "deleted the first histo after cloning" << endl;
00047    objectq.AddObject(com);
00048    TObject* output=0;
00049    while(! (objectq.IsEmpty()) )
00050        {
00051            output= objectq.WaitObject();
00052            cout << "object from object queue:"<< endl;
00053            cout << output->ClassName() << endl;
00054            cout << output->GetName() << endl;
00055            if (output->InheritsFrom(TH1::Class()))
00056                {
00057                     histo3= dynamic_cast<TH1*>(output);
00058                     dynamic_cast<TH1*>(output)->Draw();
00059                }
00060        }
00061 
00062 
00063     bufferq.AddBufferFromObject(histo2);
00064     bufferq.AddBufferFromObject(com);
00065     bufferq.AddBufferFromObject(histo3);
00066 
00067 
00068    TBuffer* mess=0;
00069    while(!bufferq.IsEmpty())
00070        {
00071            mess= bufferq.WaitBuffer();
00072 
00073            //TMessage* mess = dynamic_cast<TMessage*> (buf);
00074            //TClass* cl= buf->ReadClass();
00075            cout << "got buffer from buffer queue:"<< endl;
00076            mess->SetReadMode();
00077            mess->Reset();
00078            mess->InitMap();
00079            TClass* cl = mess->ReadClass();
00080            cout << "Class: " << cl << endl;
00081            if(cl)
00082               cout << "Classname: " << cl->GetName() << endl;
00083            cout << "Reading object from buffer..."<< endl;
00084            mess->Reset();
00085            output=mess->ReadObject(cl);
00086            if(output==0)
00087               {
00088                   cout << "zero object" <<endl;
00089                  exit(0);
00090               }
00091 
00092            cout << output->ClassName() << endl;
00093            cout << output->GetName() << endl;
00094            if (output->InheritsFrom(TH1::Class()))
00095               output->Draw();
00096          objectq.AddObjectFromBuffer(mess);
00097          objectq.AddObjectFromBuffer(mess);
00098          objectq.AddObject(com);
00099          objectq.AddObjectFromBuffer(mess);
00100       }
00101 
00102        bufferq.AddBuffer(mess);
00103        bufferq.AddBuffer(mess);
00104        bufferq.AddBuffer(mess);
00105 
00106     while(! (objectq.IsEmpty()) )
00107        {
00108            output= objectq.WaitObject();
00109            cout << "object from object queue second pass:"<< endl;
00110            cout << output->ClassName() << endl;
00111            cout << output->GetName() << endl;
00112            if (output->InheritsFrom(TH1::Class()))
00113               output->Draw();
00114        }
00115 
00116 
00117     while(!bufferq.IsEmpty())
00118        {
00119            mess= bufferq.WaitBuffer();
00120 
00121            //TMessage* mess = dynamic_cast<TMessage*> (buf);
00122            //TClass* cl= buf->ReadClass();
00123            cout << "got buffer from buffer queue second time:"<< endl;
00124            mess->SetReadMode();
00125            mess->Reset();
00126            mess->InitMap();
00127            TClass* cl = mess->ReadClass();
00128            cout << "Class: " << cl << endl;
00129            if(cl)
00130               cout << "Classname: " << cl->GetName() << endl;
00131            cout << "Reading object from buffer..."<< endl;
00132            mess->Reset();
00133            output=mess->ReadObject(cl);
00134            if(output==0)
00135               {
00136                   cout << "zero object" <<endl;
00137                  exit(0);
00138               }
00139 
00140            cout << output->ClassName() << endl;
00141            cout << output->GetName() << endl;
00142            if (output->InheritsFrom(TH1::Class()))
00143               output->Draw();
00144       }
00145 
00146 
00147    theApp.Run();
00148    return 0;
00149 }
00150 
00151 void usage(char **args)
00152 {
00153   cout << "Usage: " << args[0] << " \n";
00154   exit(1);
00155 }
00156 
00157 //----------------------------END OF GO4 SOURCE FILE ---------------------

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