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