GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MainGo4Queue.cxx
Go to the documentation of this file.
1 // $Id: MainGo4Queue.cxx 2754 2020-04-16 11:13:50Z linev $
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 fuer 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 <iostream>
15 
16 #include "TApplication.h"
17 #include "TH1.h"
18 #include "TClass.h"
19 #include "TBuffer.h"
20 
21 #include "TGo4BufferQueue.h"
22 #include "TGo4ObjectQueue.h"
23 
24 //______________________________________________________________________________
25 int main(int argc, char **argv)
26 {
27  TApplication theApp("App", &argc, argv);
28 
29  TNamed *com = new TNamed("named object", "this is a test");
30 
31  TH1F *histo = new TH1F("histogram", "this is a test histogram", 100, 0., 1.);
32  histo->Fill(0.2);
33  TH1F *histo2 = new TH1F("histogram 2", "this is a test histogram", 100, 0., 1.);
34  histo2->Fill(0.7);
35  TH1 *histo3 = 0;
36  TGo4ObjectQueue objectq("My object queue");
37  TGo4BufferQueue bufferq("My buffer queue");
38 
39  objectq.AddObject(histo, kTRUE);
40  delete histo;
41  std::cout << "deleted the first histo after cloning" << std::endl;
42  objectq.AddObject(com);
43  TObject *output = 0;
44  while (!(objectq.IsEmpty())) {
45  output = objectq.WaitObject();
46  std::cout << "object from object queue:" << std::endl;
47  std::cout << output->ClassName() << std::endl;
48  std::cout << output->GetName() << std::endl;
49  if (output->InheritsFrom(TH1::Class())) {
50  histo3 = dynamic_cast<TH1 *>(output);
51  dynamic_cast<TH1 *>(output)->Draw();
52  }
53  }
54 
55  bufferq.AddBufferFromObject(histo2);
56  bufferq.AddBufferFromObject(com);
57  bufferq.AddBufferFromObject(histo3);
58 
59  TBuffer *mess = 0;
60  while (!bufferq.IsEmpty()) {
61  mess = bufferq.WaitBuffer();
62 
63  // TMessage* mess = dynamic_cast<TMessage*> (buf);
64  // TClass* cl= buf->ReadClass();
65  std::cout << "got buffer from buffer queue:" << std::endl;
66  mess->SetReadMode();
67  mess->Reset();
68  mess->InitMap();
69  TClass *cl = mess->ReadClass();
70  std::cout << "Class: " << cl << std::endl;
71  if (cl)
72  std::cout << "Classname: " << cl->GetName() << std::endl;
73  std::cout << "Reading object from buffer..." << std::endl;
74  mess->Reset();
75  output = mess->ReadObject(cl);
76  if (output == 0) {
77  std::cout << "zero object" << std::endl;
78  exit(0);
79  }
80 
81  std::cout << output->ClassName() << std::endl;
82  std::cout << output->GetName() << std::endl;
83  if (output->InheritsFrom(TH1::Class()))
84  output->Draw();
85  objectq.AddObjectFromBuffer(mess);
86  objectq.AddObjectFromBuffer(mess);
87  objectq.AddObject(com);
88  objectq.AddObjectFromBuffer(mess);
89  }
90 
91  bufferq.AddBuffer(mess);
92  bufferq.AddBuffer(mess);
93  bufferq.AddBuffer(mess);
94 
95  while (!(objectq.IsEmpty())) {
96  output = objectq.WaitObject();
97  std::cout << "object from object queue second pass:" << std::endl;
98  std::cout << output->ClassName() << std::endl;
99  std::cout << output->GetName() << std::endl;
100  if (output->InheritsFrom(TH1::Class()))
101  output->Draw();
102  }
103 
104  while (!bufferq.IsEmpty()) {
105  mess = bufferq.WaitBuffer();
106 
107  // TMessage* mess = dynamic_cast<TMessage*> (buf);
108  // TClass* cl= buf->ReadClass();
109  std::cout << "got buffer from buffer queue second time:" << std::endl;
110  mess->SetReadMode();
111  mess->Reset();
112  mess->InitMap();
113  TClass *cl = mess->ReadClass();
114  std::cout << "Class: " << cl << std::endl;
115  if (cl)
116  std::cout << "Classname: " << cl->GetName() << std::endl;
117  std::cout << "Reading object from buffer..." << std::endl;
118  mess->Reset();
119  output = mess->ReadObject(cl);
120  if (output == 0) {
121  std::cout << "zero object" << std::endl;
122  exit(0);
123  }
124 
125  std::cout << output->ClassName() << std::endl;
126  std::cout << output->GetName() << std::endl;
127  if (output->InheritsFrom(TH1::Class()))
128  output->Draw();
129  }
130 
131  theApp.Run();
132  return 0;
133 }
void AddObject(TObject *object, Bool_t clone=kFALSE)
TBuffer * WaitBuffer()
Bool_t IsEmpty()
Definition: TGo4Queue.cxx:84
TObject * WaitObject()
void AddBuffer(TBuffer *buffer, Bool_t clone=kFALSE)
void AddObjectFromBuffer(TBuffer *buffer)
int main(int argc, char **argv)
void AddBufferFromObject(TObject *object)