GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MainGo4Queue.cxx
Go to the documentation of this file.
1 // $Id: MainGo4Queue.cxx 1844 2016-02-12 12:42:48Z adamczew $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include <stdlib.h>
15 
16 #include "Riostream.h"
17 #include "TApplication.h"
18 #include "TH1.h"
19 #include "TClass.h"
20 #include "TBuffer.h"
21 
22 #include "TGo4BufferQueue.h"
23 #include "TGo4ObjectQueue.h"
24 
25 
26 void usage(char **args);
27 
28 //______________________________________________________________________________
29 int main(int argc, char **argv)
30 {
31  TApplication theApp("App", &argc, argv);
32 
33  TNamed *com = new TNamed("named object", "this is a test");
34 
35  TH1F *histo = new TH1F("histogram", "this is a test histogram", 100, 0., 1.);
36  histo->Fill(0.2);
37  TH1F *histo2 = new TH1F("histogram 2", "this is a test histogram", 100, 0., 1.);
38  histo2->Fill(0.7);
39  TH1* histo3=0;
40  TGo4ObjectQueue objectq("My object queue");
41  TGo4BufferQueue bufferq("My buffer queue");
42 
43  objectq.AddObject(histo,kTRUE);
44  delete histo;
45  std::cout << "deleted the first histo after cloning" << std::endl;
46  objectq.AddObject(com);
47  TObject* output = 0;
48  while(! (objectq.IsEmpty()) )
49  {
50  output = objectq.WaitObject();
51  std::cout << "object from object queue:"<< std::endl;
52  std::cout << output->ClassName() << std::endl;
53  std::cout << output->GetName() << std::endl;
54  if (output->InheritsFrom(TH1::Class())) {
55  histo3 = dynamic_cast<TH1*>(output);
56  dynamic_cast<TH1*>(output)->Draw();
57  }
58  }
59 
60 
61  bufferq.AddBufferFromObject(histo2);
62  bufferq.AddBufferFromObject(com);
63  bufferq.AddBufferFromObject(histo3);
64 
65 
66  TBuffer* mess=0;
67  while(!bufferq.IsEmpty())
68  {
69  mess= bufferq.WaitBuffer();
70 
71  //TMessage* mess = dynamic_cast<TMessage*> (buf);
72  //TClass* cl= buf->ReadClass();
73  std::cout << "got buffer from buffer queue:"<< std::endl;
74  mess->SetReadMode();
75  mess->Reset();
76  mess->InitMap();
77  TClass* cl = mess->ReadClass();
78  std::cout << "Class: " << cl << std::endl;
79  if(cl)
80  std::cout << "Classname: " << cl->GetName() << std::endl;
81  std::cout << "Reading object from buffer..."<< std::endl;
82  mess->Reset();
83  output=mess->ReadObject(cl);
84  if(output==0)
85  {
86  std::cout << "zero object" <<std::endl;
87  exit(0);
88  }
89 
90  std::cout << output->ClassName() << std::endl;
91  std::cout << output->GetName() << std::endl;
92  if (output->InheritsFrom(TH1::Class()))
93  output->Draw();
94  objectq.AddObjectFromBuffer(mess);
95  objectq.AddObjectFromBuffer(mess);
96  objectq.AddObject(com);
97  objectq.AddObjectFromBuffer(mess);
98  }
99 
100  bufferq.AddBuffer(mess);
101  bufferq.AddBuffer(mess);
102  bufferq.AddBuffer(mess);
103 
104  while(! (objectq.IsEmpty()) )
105  {
106  output= objectq.WaitObject();
107  std::cout << "object from object queue second pass:"<< std::endl;
108  std::cout << output->ClassName() << std::endl;
109  std::cout << output->GetName() << std::endl;
110  if (output->InheritsFrom(TH1::Class()))
111  output->Draw();
112  }
113 
114 
115  while(!bufferq.IsEmpty())
116  {
117  mess= bufferq.WaitBuffer();
118 
119  //TMessage* mess = dynamic_cast<TMessage*> (buf);
120  //TClass* cl= buf->ReadClass();
121  std::cout << "got buffer from buffer queue second time:"<< std::endl;
122  mess->SetReadMode();
123  mess->Reset();
124  mess->InitMap();
125  TClass* cl = mess->ReadClass();
126  std::cout << "Class: " << cl << std::endl;
127  if(cl)
128  std::cout << "Classname: " << cl->GetName() << std::endl;
129  std::cout << "Reading object from buffer..."<< std::endl;
130  mess->Reset();
131  output=mess->ReadObject(cl);
132  if(output==0)
133  {
134  std::cout << "zero object" <<std::endl;
135  exit(0);
136  }
137 
138  std::cout << output->ClassName() << std::endl;
139  std::cout << output->GetName() << std::endl;
140  if (output->InheritsFrom(TH1::Class()))
141  output->Draw();
142  }
143 
144 
145  theApp.Run();
146  return 0;
147 }
148 
149 void usage(char **args)
150 {
151  std::cout << "Usage: " << args[0] << " \n";
152  exit(1);
153 }
void AddObject(TObject *object, Bool_t clone=kFALSE)
TBuffer * WaitBuffer()
Bool_t IsEmpty()
Definition: TGo4Queue.cxx:88
TObject * WaitObject()
void AddBuffer(TBuffer *buffer, Bool_t clone=kFALSE)
void AddObjectFromBuffer(TBuffer *buffer)
void usage(char **args)
int main(int argc, char **argv)
void AddBufferFromObject(TObject *object)