GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ADFObject.C
Go to the documentation of this file.
1 
2 
3 #include "ADFObjects.h"
4 #include "FrameFactory.h"
5 #include "PSAFrame.h"
6 #include "TrackedFrame.h"
7 
8 #include <iostream>
9 #include <sstream>
10 #include <string>
11 
12 /*
13 compilation (standalone) :
14  g++ -O -Wall -fPIC -I../ -L../ -lADF ADFObject.C -o ADFObject
15  g++ -g -pg -I../ -L../ -lADF ADFObject.C -o ADFObject
16 
17 In a root session (with include to gammaware's includes properly defined)
18  root
19  gSystem->Load("libGWCORE")
20  gSystem->Load("libGWADF")
21  .L ADFObject.C++
22 
23 --> DEBUG
24 Linux SL4
25 
26 --> VALGRIND
27 
28 Memory leak: ok
29 Profiling:
30 
31 */
32 
33 using namespace ADF;
34 using namespace std;
35 
37 
45 int test1()
46 {
47  GObject ob1;
48 
49 // add items to ob1
50  ob1.AddItem( new NamedItem<UShort_t>("Crys",0u) );
51  ob1.AddItem( new NamedItem<Float_t>("E",0.0) );
52  ob1.AddItem( new NamedItem<Int_t>("T0",0) );
53 
54  cout << "**** ob1 : definition " << endl;
55  ob1.Print();
56  cout << "**** " << endl;
57 
58 // link methods
59  cout << "**** ob1 : modification with local variable and links " << endl;
60  UShort_t Crys_link; Float_t E_link; Int_t T0_link;
61  ob1.LinkItem("Crys",&Crys_link);
62  ob1.LinkItem("E",&E_link);
63 
64  // now change the value of Crys with yyour local variable and tell ob1 to synchronize the data
65  Crys_link = 1u;
66  E_link = 1.1;
67  ob1.SetItems();
68  cout << "**** " << endl;
69 
70  ob1.Print();
71 
72 // proxy methods
73  cout << "**** ob1 : proxy, reading mode only " << endl;
74  const NamedItem<UShort_t> *Crys_prox = ob1.Get<UShort_t>("Crys");
75  const NamedItem<Float_t> *E_prox = ob1.Get<Float_t>("E");
76 
77  ob1.Print();
78  cout << " PROXY " << Crys_prox->GetName() << " " << Crys_prox->Get() << endl;
79  cout << " PROXY " << E_prox->GetName() << " " << E_prox->Get() << endl;
80  cout << "**** " << endl;
81 
82 // check clone
83 /* cout << "**** Clone method " << endl;
84  NamedItem<UShort_t> ori("Val",0);
85  ori.Set(8u);
86  NamedItem<UShort_t> *clone = dynamic_cast<NamedItem<UShort_t> *>(ori.MakeAClone());
87 
88  cout << " Clone " << clone->Get() << endl;
89  cout << " Origi " << ori.Get() << endl;
90 
91  cout << "**** " << endl;*/
92 
93  return 0;
94 }
96 
99 int test2()
100 {
101  GObject ob1, ob2, ob3;
102 
103 // add items to ob1
104  ob1.AddItem( new NamedItem<UShort_t>("Crys",0u) );
105  ob1.AddItem( new NamedItem<Float_t>("E",0.0) );
106  ob1.AddItem( new NamedItem<Int_t>("T0",0) );
107 
108  ob2.AddItem( new NamedItem<UShort_t>("Crys",0u) );
109  ob2.AddItem( new NamedItem<Float_t>("E",0.0) );
110  ob2.AddItem( new NamedItem<Double_t>("V",0) );
111 
112  // the order does not matter
113  ob3.AddItem( new NamedItem<UShort_t>("Crys",0u) );
114  ob3.AddItem( new NamedItem<Int_t>("T0",0) );
115  ob3.AddItem( new NamedItem<Double_t>("V",0) );
116 
117 // link methods
118  UShort_t Crys_link; Float_t E_link; Int_t T0_link ; Double_t V_link;
119  ob1.LinkItem("Crys",&Crys_link);
120  ob1.LinkItem("E",&E_link);
121  ob1.LinkItem("T0",&T0_link);
122  ob1.LinkItem("V",&V_link);
123 
124  // now change the value of Crys with yyour local variable and tell ob1 to synchronize the data
125  cout << "---> Set all items to 1 " << endl;
126  Crys_link = 1u;
127  E_link = 1.1;
128  T0_link = 1;
129  V_link = 1.1;
130  ob1.SetItems();
131 
132 // proxy methods
133  const NamedItem<UShort_t> *Crys_prox = ob1.Get<UShort_t>("Crys");
134  const NamedItem<Float_t> *E_prox = ob1.Get<Float_t>("E");
135 
136  cout << "**** Before calling TransferLinkAndProxy o1 -> o2 " << endl;
137  cout << "**** ob1 " << endl;
138  ob1.Print();
139  cout << "**** ob2 " << endl;
140  ob2.Print();
141 // transfer link and proxy for one to 2
142  ob1.TransferLinkAndProxy(ob2);
143  cout << "**** After calling TransferLinkAndProxy o1 -> o2 " << endl;
144  cout << "**** ob1 " << endl;
145  ob1.Print();
146  cout << "**** ob2 " << endl;
147  ob2.Print();
148  cout << "**** ob1 cannot be changed anymore " << endl;
149  cout << "---> Set Crys and E items to 2 " << endl;
150  Crys_link = 2u;
151  E_link = 2.2;
152  ob1.SetItems();
153  ob1.Print();
154  cout << "**** ob2 link and proxy works " << endl;
155  ob2.SetItems();
156  ob2.Print();
157  cout << " PROXY " << Crys_prox->GetName() << " " << Crys_prox->Get() << endl;
158  cout << " PROXY " << E_prox->GetName() << " " << E_prox->Get() << endl;
159 
160 // transfer link and proxy for 2 to 3
161  cout << "**** After calling TransferLinkAndProxy o2 -> o3 " << endl;
162  ob2.TransferLinkAndProxy(ob3);
163  cout << "---> Set Crys, T0 and E items to 3 " << endl;
164  Crys_link = 3u;
165  T0_link = 3;
166  E_link = 3.3;
167  ob3.SetItems();
168  cout << "**** ob3 " << endl;
169  ob3.Print();
170  cout << " PROXY " << Crys_prox->GetName() << " " << Crys_prox->Get() << endl;
171  cout << " PROXY " << E_prox->GetName() << " " << E_prox->Get() << endl;
172 
173  cout << "**** " << endl;
174 
175 
176  return 0;
177 }
178 
179 int test3()
180 {
181  GObject ob1;
182  Anonymous ano_link;
183 
184  // put whatever you want in the free space
185  ano_link.Set<UShort_t>(3u,0u);
186  ano_link.Set<Float_t> (0.1,2u);
187  ano_link.fRealSize = sizeof(UShort_t) + sizeof(Float_t);
188 
189  // link the anonymous with a local variable to change the content of the one in ob1
190  ob1.AddItem( new NamedItem<Anonymous>("MySpace",0) );
191  ob1.Link<Anonymous>("MySpace",&ano_link);
192  ob1.SetItems(); // copy the content of ano_link in the one in Global
193 
194  // get back using proxy
195  const NamedItem<Anonymous> *Ano_prox = ob1.Get<Anonymous>("MySpace");
196  UShort_t ano1;
197  Float_t ano2;
198 
199  ano1 = (Ano_prox->Get()).Get<UShort_t>(0u);
200  ano2 = (Ano_prox->Get()).Get<Float_t> (2u);
201 
202  cout << " PROXY " << Ano_prox->GetName() << " " << ano1 << endl;
203  cout << " PROXY " << Ano_prox->GetName() << " " << ano2 << endl;
204 
205  ob1.Print();
206 }
207 
208 int test4(UInt_t number)
209 {
210  // register factories
211  KeyFactory::Register("Agata"); FrameFactory::Register("Agata");
212 
213  // allocate the frame
214  Frame *f = FrameFactory::New(FactoryItem("Agata","data:tracked",Version(1,0)),FactoryItem("Agata","data:tracked",Version(65000,1)) );
215  // a pointer to the data interface
216  GammaTrackedInterface *data = GetDataPointer<GammaTrackedInterface>(f);
217 
218  // open the file
219  FILE *fp = fopen("FRAME.adf","rb");
220  if ( fp == 0x0 )
221  return 1;
222 
223  for (UInt_t i = 0u; i < number; i++ ) {
224  if ( ! f->Load(fp) )
225  break;
226  f->Read();
227  }
228 
229  fclose(fp);
230 }
231 
232 #if ADF_STANDALONE == 1
233 int main(int argc, char **argv)
234 {
235  const int nbtest = 1;
236  if ( argc == 1 )
237  std::cout << " Usage is : \n\t"
238  << argv[0] << " i \n i being a integer from 1 to "<< nbtest << std::endl;
239 
240  int nwhat = 0; UInt_t number = 100;
241  if ( argc > 1 ) {
242  std::istringstream what(argv[1]); what >> nwhat;
243  }
244  if ( argc > 2 ) {
245  std::istringstream what(argv[2]); what >> number;
246  }
247 
248  switch( nwhat ) {
249  case 1:
250  test1();
251  break;
252  case 2:
253  test2();
254  break;
255  case 3:
256  test3();
257  break;
258  case 4:
259  test4(number);
260  break;
261  default:
262  std::cout << " Unknown test number " << nwhat << std::endl;
263  }
264 
265  return 0;
266 }
267 #endif
268 
269 
int test1()
To show how to add named items to a GObject and how work links and proxy.
Definition: ADFObject.C:45
Base class for a Frame.
Definition: Frame.h:73
virtual UInt_t Read()
It reads the content into dedicated structures from the Frame (data part)
Definition: Frame.h:199
header file for TrackedFrame.cpp
virtual Bool_t AddItem(ANamedItem *item)
Add a named item to this. The item belongs to GObject and will be thus deleted.
Definition: GObject.cpp:69
virtual void SetItems(BufferIO &) const
write the value of all items into the buffer
Definition: GObject.cpp:367
int test4(UInt_t number)
Definition: ADFObject.C:208
int main(int argc, char **argv)
Definition: Benchmark.C:100
The tracking algorithm produces a stack of TrackedHits.
Definition: TrackedFrame.h:41
Base class for a Global Object.
Definition: GObject.h:115
int test3()
Definition: ADFObject.C:179
std::string GetName() const
change value of this nmaed item using the passed one. it checks if asked, it check first if of the sa...
Definition: DataHandling.h:219
Bool_t Link(const char *name, Data_t *external_address)
General method to Link one item with an external address.
Definition: GObject.h:212
header file for PSAFrame.cpp
void TransferLinkAndProxy(GObject &to)
transfert proxy and link for one GObject to another one
Definition: GObject.cpp:193
Base class for version numbers.
Definition: Version.h:38
virtual Data_T Get() const
Get the data.
Definition: DataHandling.h:296
Bool_t LinkItem(const Char_t *, const Char_t *, void *)
Only for basic type ... otherwise better to use the most general Link method.
Definition: GObject.cpp:120
void Set(const Data_T data, UShort_t offset=0u)
Definition: GObject.h:312
ADF::LogMessage & endl(ADF::LogMessage &log)
header file for ADFObjects.cpp
int test2()
To show how to transfer links and proxy from one Object to anoter one.
Definition: ADFObject.C:99
virtual Frame * New(const FactoryItem &key_item, const FactoryItem &frame_item)
const NamedItem< Data_t > * Get(const char *name)
to get a given item (reading mode only !!)
Definition: GObject.h:174
virtual Bool_t Load(FILE *)=0
load a Frame from a C file (for debugging)
UShort_t fRealSize
Definition: GObject.h:298
virtual void Print(std::ostream &out=std::cout) const
print some informations about this object
Definition: GObject.cpp:318
header file for FrameFactory.cpp
LogMessage & endl(LogMessage &)
Base class that described an item in a Factory.
Definition: FactoryItem.h:52