00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "Riostream.h"
00015 #include <stdlib.h>
00016
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 cout << "deleted the first histo after cloning" << endl;
00045 objectq.AddObject(com);
00046 TObject* output=0;
00047 while(! (objectq.IsEmpty()) )
00048 {
00049 output= objectq.WaitObject();
00050 cout << "object from object queue:"<< endl;
00051 cout << output->ClassName() << endl;
00052 cout << output->GetName() << endl;
00053 if (output->InheritsFrom(TH1::Class()))
00054 {
00055 histo3= dynamic_cast<TH1*>(output);
00056 dynamic_cast<TH1*>(output)->Draw();
00057 }
00058 }
00059
00060
00061 bufferq.AddBufferFromObject(histo2);
00062 bufferq.AddBufferFromObject(com);
00063 bufferq.AddBufferFromObject(histo3);
00064
00065
00066 TBuffer* mess=0;
00067 while(!bufferq.IsEmpty())
00068 {
00069 mess= bufferq.WaitBuffer();
00070
00071
00072
00073 cout << "got buffer from buffer queue:"<< endl;
00074 mess->SetReadMode();
00075 mess->Reset();
00076 mess->InitMap();
00077 TClass* cl = mess->ReadClass();
00078 cout << "Class: " << cl << endl;
00079 if(cl)
00080 cout << "Classname: " << cl->GetName() << endl;
00081 cout << "Reading object from buffer..."<< endl;
00082 mess->Reset();
00083 output=mess->ReadObject(cl);
00084 if(output==0)
00085 {
00086 cout << "zero object" <<endl;
00087 exit(0);
00088 }
00089
00090 cout << output->ClassName() << endl;
00091 cout << output->GetName() << endl;
00092 if (output->InheritsFrom(TH1::Class()))
00093 output->Draw();
00094 objectq.AddObjectFromBuffer(mess);
00095 objectq.AddObjectFromBuffer(mess);
00096 objectq.AddObject(com);
00097 objectq.AddObjectFromBuffer(mess);
00098 }
00099
00100 bufferq.AddBuffer(mess);
00101 bufferq.AddBuffer(mess);
00102 bufferq.AddBuffer(mess);
00103
00104 while(! (objectq.IsEmpty()) )
00105 {
00106 output= objectq.WaitObject();
00107 cout << "object from object queue second pass:"<< endl;
00108 cout << output->ClassName() << endl;
00109 cout << output->GetName() << endl;
00110 if (output->InheritsFrom(TH1::Class()))
00111 output->Draw();
00112 }
00113
00114
00115 while(!bufferq.IsEmpty())
00116 {
00117 mess= bufferq.WaitBuffer();
00118
00119
00120
00121 cout << "got buffer from buffer queue second time:"<< endl;
00122 mess->SetReadMode();
00123 mess->Reset();
00124 mess->InitMap();
00125 TClass* cl = mess->ReadClass();
00126 cout << "Class: " << cl << endl;
00127 if(cl)
00128 cout << "Classname: " << cl->GetName() << endl;
00129 cout << "Reading object from buffer..."<< endl;
00130 mess->Reset();
00131 output=mess->ReadObject(cl);
00132 if(output==0)
00133 {
00134 cout << "zero object" <<endl;
00135 exit(0);
00136 }
00137
00138 cout << output->ClassName() << endl;
00139 cout << output->GetName() << endl;
00140 if (output->InheritsFrom(TH1::Class()))
00141 output->Draw();
00142 }
00143
00144
00145 theApp.Run();
00146 return 0;
00147 }
00148
00149 void usage(char **args)
00150 {
00151 cout << "Usage: " << args[0] << " \n";
00152 exit(1);
00153 }