GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestFIO.C
Go to the documentation of this file.
1 
2 
3 #include "ADFLogCollector.h"
4 
5 #ifndef _BasicAFP
6 #include "BasicAFP.h"
7 #endif
8 #ifndef _BasicAFC
9 #include "BasicAFC.h"
10 #endif
11 
12 #ifndef _TestFIO
13 #include "TestFIO.h"
14 #endif
15 
16 #include <sys/times.h>
17 
18 #include <iostream>
19 #include <sstream>
20 #include <string>
21 
22 /*
23 compilation (standalone) :
24  g++ -O -Wall -fPIC -I../ -L../ -lADF TestFIO.C -o TestFIO
25  g++ -g -pg -I../ -L../ -lADF TestFIO.C -o TestFIO
26 
27 In a root session (with include to gammaware's includes properly defined)
28  root
29  gSystem->Load("libGWCORE")
30  gSystem->Load("libGWADF")
31  .L Producer.C++
32 
33 --> DEBUG
34 Linux SL4
35 
36 --> VALGRIND
37 
38 Memory leak
39 Profiling
40 
41 */
42 
43 using namespace ADF;
44 
46 {
47  const char *MainPATH = "./";
48  std::string tmp_path;
49 
50  // to-pre initiate the ADF system (not mandatory)
51  UInt_t error_adf = 0u;
52  NarvalInterface::process_config(MainPATH,&error_adf);
53  if ( error_adf > 0u )
54  { printf("Error in NarvalInterface::process_config %d \n ",error_adf); return 1; }
55 
56  // A log collector is created to collector logs in a file
57  // it becomes automatically the current collector
58  // WARNING !! should be pointer since all collectors are collected
59  // and destroyed at the end by the global collector
60 // OStreamCollector *test_collector = new OStreamCollector("TEST.log");
61 
62  // block going from producer to filter and from filter to consumer
63  const UInt_t size_buf_in = 400*aKByte;
64  const UInt_t size_buf_out = aMByte;
65  Char_t *buf1 = NULL;
66  Char_t *buf2 = NULL;
67  buf1 = BaseBuffer::New(buf1,size_buf_in);
68  buf2 = BaseBuffer::New(buf2,size_buf_out);
69 
70  // it creates and inits the different actors
71  // producer
72  UInt_t error_pro = 0u;
73  tmp_path = MainPATH;
74  BasicAFP::process_config(tmp_path.data(),&error_pro);
75  if ( error_pro > 0u )
76  printf("Error in BasicAFP::process_config %d \n ",error_pro);
77  BasicAFP *pro = new BasicAFP();
78  pro->process_initialise(&error_pro);
79  if ( error_pro > 0u )
80  printf("Error in BasicAFP::process_config %d \n ",error_pro);
81 
82  // filter
83  UInt_t error_filter = 0u;
84  tmp_path = MainPATH;
85  TestFIO::process_config(tmp_path.data(),&error_filter);
86  if ( error_filter > 0u )
87  printf("Error in TestFIO::process_config %d \n ",error_filter);
88  TestFIO *filter = new TestFIO() ;
89  filter->process_initialise(&error_filter);
90  if ( error_filter > 0u )
91  printf("Error in TestFIO::process_config %d \n ",error_filter);
92 
93  // consumer
94  UInt_t error_cons = 0u;
95  tmp_path = MainPATH;
96  BasicAFC::process_config(tmp_path.data(),&error_cons);
97  if ( error_cons > 0u )
98  printf("Error in BasicAFC::process_config %d \n ",error_cons);
99  BasicAFC *cons = new BasicAFC();
100  cons->process_initialise(&error_cons);
101  if ( error_cons > 0u )
102  printf("Error in BasicAFC::process_config %d \n ",error_cons);
103 
104  // loop on events
105  UInt_t realsize1 = 0u, realsize2= 0u, nb_loop = 0u, error = 0u;
106  struct tms t0, t; times(&t0);
107  while ( error == 0u ) {
108  // printf("nb_loop_in %d \n",nb_loop);
109  // to get an input block
110  pro->process_block(buf1,size_buf_in,&realsize1,&error); if ( realsize1 == 0u ) break;
111  std::cout << "realsize1 " << realsize1 << std::endl;
112  //
113  filter->process_block(buf1,realsize1,buf2,size_buf_out,&realsize2,&error);
114  //
115  std::cout << "realsize2 " << realsize2 << std::endl;
116  cons->process_block(buf1,realsize1,&error); nb_loop++;
117 // cons->process_block(buf2,realsize2,&error); nb_loop++;
118  }
119  //
120  printf("\n");
121  printf("[[ test0.1 ]] : BENCHMARKS \n[...\n");
122  printf("nb_loop %d %d\n",nb_loop,error);
123  times(&t);
124  std::cout << "User " << Float_t(t.tms_utime-t0.tms_utime)/sysconf(_SC_CLK_TCK)
125  << " second, System " << Float_t(t.tms_stime-t0.tms_stime)/sysconf(_SC_CLK_TCK)
126  << " seconds" << std::endl;
127  printf("...]\n\n");
128 
129  if ( pro )
130  delete pro;
131  if ( filter )
132  delete filter;
133  if ( cons )
134  delete cons;
136 
137  return 0;
138 }
139 
141 {
142  const char *MainPATH = "./";
143  std::string tmp_path;
144 
145  // to-pre initiate the ADF system (not mandatory)
146  UInt_t error_adf = 0u;
147  NarvalInterface::process_config(MainPATH,&error_adf);
148  if ( error_adf > 0u )
149  { printf("Error in NarvalInterface::process_config %d \n ",error_adf); return 1; }
150 
151  // A log collector is created to collector logs in a file
152  // it becomes automatically the current collector
153  // WARNING !! should be pointer since all collectors are collected
154  // and destroyed at the end by the global collector
155 // OStreamCollector *test_collector = new OStreamCollector("TEST.log");
156 
157  // block going from producer to filter and from filter to consumer
158  OneBlock FB0_1(aMByte);
159  OneBlock FB1_2(aMByte);
160 
161  // it creates and inits the different actors
162  // producer
163  UInt_t error_pro = 0u;
164  tmp_path = MainPATH;
165  BasicAFP::process_config(tmp_path.data(),&error_pro);
166  if ( error_pro > 0u )
167  printf("Error in BasicAFP::process_config %d \n ",error_pro);
168  BasicAFP *pro = new BasicAFP();
169  pro->process_initialise(&error_pro);
170  if ( error_pro > 0u )
171  printf("Error in BasicAFP::process_config %d \n ",error_pro);
172 
173  // filter
174  UInt_t error_filter = 0u;
175  tmp_path = MainPATH;
176  TestFIO::process_config(tmp_path.data(),&error_filter);
177  if ( error_filter > 0u )
178  printf("Error in TestFIO::process_config %d \n ",error_filter);
179  TestFIO *filter = new TestFIO() ;
180  filter->process_initialise(&error_filter);
181  if ( error_filter > 0u )
182  printf("Error in TestFIO::process_config %d \n ",error_filter);
183 
184  // consumer
185  UInt_t error_cons = 0u;
186  tmp_path = MainPATH;
187  BasicAFC::process_config(tmp_path.data(),&error_cons);
188  if ( error_cons > 0u )
189  printf("Error in BasicAFC::process_config %d \n ",error_cons);
190  BasicAFC *cons = new BasicAFC();
191  cons->process_initialise(&error_cons);
192  if ( error_cons > 0u )
193  printf("Error in BasicAFC::process_config %d \n ",error_cons);
194 
195  // loop on events
196  UInt_t nb_loop = 0u, error = 0u; struct tms t0, t; times(&t0);
197  while ( error == 0u ) {
198  // to get an input block
199  printf("Call producer \n");
200  if ( pro->ProcessBlock(FB0_1) != 0u )
201  break;
202  if ( FB0_1.GetSize() == 0u )
203  break;
204  else
205  printf("Produced block with size %d \n",FB0_1.GetSize());
206  // to apply the algorithm
207  printf("Call filter \n");
208  if ( filter->ProcessBlock(FB0_1,FB1_2) != 0u )
209  break;
210  if ( FB1_2.GetSize() == 0u )
211  break;
212  else
213  printf("Output filter size %d \n",FB1_2.GetSize());
214  // to save the outpout of the algorithm
215  printf("Call consumer \n");
216 
217  if ( cons->ProcessBlock(FB1_2) != 0u )
218  break;
219  nb_loop++;
220 // if ( nb_loop == 1u )
221 // break;
222  }
223  //
224  printf("\n");
225  printf("[[ test0.2 ]] : BENCHMARKS \n[...\n");
226  printf("nb_loop %d %d\n",nb_loop,error);
227  times(&t);
228  std::cout << "User " << Float_t(t.tms_utime-t0.tms_utime)/sysconf(_SC_CLK_TCK)
229  << " second, System " << Float_t(t.tms_stime-t0.tms_stime)/sysconf(_SC_CLK_TCK)
230  << " seconds" << std::endl;
231  printf("...]\n\n");
232 
233  if ( pro )
234  delete pro;
235  if ( filter )
236  delete filter;
237  if ( cons )
238  delete cons;
239 
240  return 0;
241 }
242 
244 {
245  const char *MainPATH = "./";
246  std::string tmp_path;
247 
248  // to-pre initiate the ADF system (not mandatory)
249  UInt_t error_adf = 0u;
250  NarvalInterface::process_config(MainPATH,&error_adf);
251  if ( error_adf > 0u )
252  { printf("Error in NarvalInterface::process_config %d \n ",error_adf); return 1; }
253 
254  // A log collector is created to collector logs in a file
255  // it becomes automatically the current collector
256  // WARNING !! should be pointer since all collectors are collected
257  // and destroyed at the end by the global collector
258 // OStreamCollector *test_collector = new OStreamCollector("TEST.log");
259 
260  // block going from producer to filter and from filter to consumer
261  OneBlock FB0_1(aMByte);
262  OneBlock FB1_2(aMByte);
263 
264  // it creates and inits the different actors
265  // producer
266  UInt_t error_pro = 0u;
267  tmp_path = MainPATH;
268  BasicAFP::process_config(tmp_path.data(),&error_pro);
269  if ( error_pro > 0u )
270  printf("Error in BasicAFP::process_config %d \n ",error_pro);
271  BasicAFP *pro = new BasicAFP();
272  pro->process_initialise(&error_pro);
273  if ( error_pro > 0u )
274  printf("Error in BasicAFP::process_config %d \n ",error_pro);
275 
276  // filter
277  UInt_t error_filter = 0u;
278  tmp_path = MainPATH;
279  TestFIO::process_config(tmp_path.data(),&error_filter);
280  if ( error_filter > 0u )
281  printf("Error in TestFIO::process_config %d \n ",error_filter);
282  TestFIO *filter = new TestFIO() ;
283  filter->process_initialise(&error_filter);
284  if ( error_filter > 0u )
285  printf("Error in TestFIO::process_config %d \n ",error_filter);
286 
287  // loop on events
288  UInt_t nb_loop = 0u, error = 0u; struct tms t0, t; times(&t0);
289  while ( error == 0u ) {
290  // to get an input block
291 // printf("Call producer \n");
292  if ( pro->ProcessBlock(FB0_1) != 0u )
293  break;
294  if ( FB0_1.GetSize() == 0u )
295  break;
296 // else
297 // printf("Produced block with size %d \n",FB0_1.GetSize());
298  // to apply the algorithm
299 // printf("Call filter \n");
300  if ( filter->ProcessBlock(FB0_1,FB1_2) != 0u )
301  break;
302 
303  nb_loop++;
304 // if ( nb_loop == 1u )
305 // break;
306  }
307  //
308  printf("\n");
309  printf("[[ test1.2 ]] : BENCHMARKS \n[...\n");
310  printf("nb_loop %d %d\n",nb_loop,error);
311  times(&t);
312  std::cout << "User " << Float_t(t.tms_utime-t0.tms_utime)/sysconf(_SC_CLK_TCK)
313  << " second, System " << Float_t(t.tms_stime-t0.tms_stime)/sysconf(_SC_CLK_TCK)
314  << " seconds" << std::endl;
315  printf("...]\n\n");
316 
317  if ( pro )
318  delete pro;
319  if ( filter )
320  delete filter;
321 
322  return 0;
323 }
324 
325 
326 #if ADF_STANDALONE == 1
327 int main(int argc, char **argv)
328 {
329  const int nbtest = 2;
330  if ( argc == 1 )
331  std::cout << " Usage is : \n\t"
332  << argv[0] << " i \n i being a integer from 1 to "<< nbtest << std::endl;
333 
334  int nwhat; UInt_t number = 100;
335  if ( argc > 1 ) {
336  std::istringstream what(argv[1]); what >> nwhat;
337  }
338  if ( argc > 2 ) {
339  std::istringstream what(argv[2]); what >> number;
340  }
341  switch( nwhat ) {
342  case 1:
343  TestFIO_0_1();
344  break;
345  case 2:
346  TestFIO_0_2();
347  break;
348  case 3:
349  TestFIO_1_2();
350  break;
351  default:
352  std::cout << " Unknown test number " << nwhat << std::endl;
353  }
354 
355  return 0;
356 }
357 #endif
358 
359 
360 
header file for BasicAFC.cpp
printf("******************************************************************** \n")
static void process_config(const Char_t *, UInt_t *, Short_t do_adf_conf=0)
Have to be overwritten and called in your implementation.
TestFIO algorithm embedded in Narval.
Definition: TestFIO.h:38
BasicAFP.
Definition: BasicAFP.h:41
int main(int argc, char **argv)
Definition: Benchmark.C:100
static void process_config(const Char_t *, UInt_t *)
to init globals (static) from a directory
Definition: BasicAFP.cpp:104
static void Delete(Char_t *p)
Definition: BaseBuffer.h:151
LogMessage & error(LogMessage &)
int TestFIO_0_1()
Definition: TestFIO.C:45
virtual void process_block(void *input_buffer, UInt_t size_of_input_buffer, UInt_t *error_code)
Narval interface, Ask the algorithm to process the input data block.
virtual void process_block(void *input_buffer, UInt_t size_of_input_buffer, void *output_buffer, UInt_t size_of_output_buffer, UInt_t *used_size_of_output_buffer, UInt_t *error_code)
Ask the algorithm to process the data block.
const UInt_t aKByte
Definition: BaseBuffer.h:35
const UInt_t aMByte
Definition: BaseBuffer.h:36
header file for BasicAFP.cpp
virtual void process_initialise(UInt_t *error_code)
Constructor implementation.
Definition: BasicAFC.cpp:164
virtual UInt_t ProcessBlock(ADF::FrameBlock &)
Produce one block of data.
Definition: BasicAFP.cpp:114
static void process_config(const Char_t *, UInt_t *)
to init globals (static) from a directory
Definition: BasicAFC.cpp:67
int TestFIO_1_2()
Definition: TestFIO.C:243
virtual void process_initialise(UInt_t *error_code)
Constructor implementation.
Definition: TestFIO.cpp:170
virtual Long64_t GetSize(UInt_t=0u) const
size of the current block
Definition: FrameBlock.h:234
static Char_t * New(Char_t *p, Int_t nb=32 *aKByte)
Definition: BaseBuffer.h:209
virtual UInt_t ProcessBlock(ADF::FrameBlock &)
virtual method to be implemented
Definition: BasicAFC.cpp:128
ADF::LogMessage & endl(ADF::LogMessage &log)
virtual UInt_t ProcessBlock(ADF::FrameBlock &, ADF::FrameBlock &)
To process just a block of data.
Definition: TestFIO.cpp:135
header file for TestFIO.cpp
int TestFIO_0_2()
Definition: TestFIO.C:140
static void process_config(const Char_t *, UInt_t *)
to init globals (static) from a directory
Definition: TestFIO.cpp:65
virtual void process_initialise(UInt_t *error_code)
Constructor implementation.
Definition: BasicAFP.cpp:174
It implements an in-memory block of Frames.
Definition: FrameBlock.h:206
virtual void process_block(void *output_buffer, UInt_t size_of_output_buffer, UInt_t *used_size_of_output_buffer, UInt_t *error_code)
Ask the algorithm to process the data block.
basic consumer, it counts and dumps Frame in files
Definition: BasicAFC.h:38