GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
agapro/ApplyTracking/Emulator.h
Go to the documentation of this file.
1 
2 
3 #ifndef _Emulator
4 #define _Emulator
5 
6 #ifndef _LogMessage
7 #include "LogMessage.h"
8 #endif
9 #ifndef ADF_FrameBlock
10 #include "FrameBlock.h"
11 #endif
12 
13 #include "EmulatorControl.h"
14 
15 #include "TROOT.h"
16 
17 #include <string>
18 
19 using namespace ADF;
20 
21 
22 template <typename Prod_actor, typename Filt_actor, typename Cons_actor>
23 class EmulatorPFC : public BaseEmulatorChain
24 {
25 private:
26  Prod_actor *fProducer;
27  Filt_actor *fFilter;
28  Cons_actor *fConsumer;
29 
30 private:
31  OneBlock fBProd;
32  ExpandableBlock fBFilt;
33 
34 private:
35  std::string fPathProd;
36  std::string fPathFilt;
37  std::string fPathCons;
38 
39 public:
40  EmulatorPFC(const char *path, UInt_t bsize = aMByte);
41 /* EmulatorPFC(const char *path_prod, const char *path_filt, const char * path_cons,
42  UInt_t bsize_prod = aMByte, UInt_t bsize_filter = aMByte, UInt_t bsize_cons = aMByte) ; */
43  ~EmulatorPFC();
44 
46  { return fProducer; }
47 
49  { return fConsumer; }
50 
51  Cons_actor *GetConsumer()
52  { return fConsumer; }
53 
55  virtual Bool_t Init(const Char_t *rootafp)
56  {
57  return BaseEmulatorChain::Init(rootafp);
58  }
59  virtual Bool_t Init(Int_t which_run, const char *experiment, const char *which_adf_data, const char *run_pat, Option_t *opt_adf_pattern)
60  {
61  return BaseEmulatorChain::Init(which_run,experiment,which_adf_data,run_pat, opt_adf_pattern);
62  }
63 
64  virtual Bool_t Init();
65  virtual Bool_t Run(UInt_t max_loop = kMaxUInt_t);
66 };
67 
68 template <typename Prod_actor, typename Filt_actor, typename Cons_actor>
71  fProducer(0x0),
72  fFilter(0x0),
73  fConsumer(0x0),
74  fBProd(bsize),
75  fBFilt(bsize),
76  fPathProd(path),
77  fPathFilt(path),
78  fPathCons(path)
79 {
80 
81 }
82 template <typename Prod_actor, typename Filt_actor, typename Cons_actor>
84 {
85  if ( fProducer )
86  delete fProducer;
87  if ( fFilter )
88  delete fFilter;
89  if ( fConsumer )
90  delete fConsumer;
91 }
92 
93 template <typename Prod_actor, typename Filt_actor, typename Cons_actor>
95 {
96  UInt_t err = 0u;
97 
98  // just in case a actor forget to call it and it is required.
99  NarvalInterface::process_config(fPathProd.data(),&err);
100  if ( err > 0u ) {
101  }
102 
103  err = 0u;
104  // it creates and inits the different actors
105  // producer
106  Prod_actor::process_config(fPathProd.data(),&err);
107  if ( err > 0u ) {
108  return false;
109  }
110  fProducer = new Prod_actor();
111  fProducer->process_initialise(&err);
112  if ( err > 0u ) {
113  return false;
114  }
115 
116  // filter
117  Filt_actor::process_config(fPathFilt.data(),&err);
118  if ( err > 0u ) {
119  return false;
120  }
121  fFilter = new Filt_actor() ;
122  fFilter->process_initialise(&err);
123  if ( err > 0u ) {
124  return false;
125  }
126 
127  // consumer
128  Cons_actor::process_config(fPathCons.data(),&err);
129  if ( err > 0u ) {
130  return false;
131  }
132  fConsumer = new Cons_actor();
133  fConsumer->process_initialise(&err);
134  if ( err > 0u ) {
135  return false;
136  }
137 
138  return true;
139 }
140 
141 
142 template <typename Prod_actor, typename Filt_actor, typename Cons_actor>
144 {
145  printf("************** EMULATOR MAIN LOOP ************** \n");
146 
147  // loop on events
148  UInt_t nb_loop = 0u, err = 0u, nb_try = 0;
149  while ( err == 0u ) {
150  // to get an input block
151  //printf("Call producer \n");
152 
153  int Prodstatus = fProducer->ProcessBlock(fBProd);
154  int ProdSize = fBProd.GetSize();
155 
156 // cout<<"Loop Nbr "<<nb_loop<<endl;
157 // cout<<"Producer status = "<<Prodstatus<<endl;
158 // cout<<"Producer size = "<<ProdSize<<endl;
159 
160  if ( ProdSize == 0u ) {
161  if ( nb_try > 1 ) { // up to XX tries of consecutive empty output before stooping
162  break;
163  }
164  else {
165  nb_try++;
166  continue;
167  }
168  }
169  else nb_try = 0u;
170 
171  int Filterstatus = fFilter->ProcessBlock(fBProd,fBFilt);
172  int FilterSize = fBFilt.GetSize();
173 
174 // cout<<"Filter status = "<<Filterstatus<<endl;
175 // cout<<"Filter size = "<<FilterSize<<endl;
176 
177  if ( FilterSize == 0u ) break;
178 
179  int ConsStatus = fConsumer->ProcessBlock(fBFilt);
180 
181 // cout<<"Consumer status = "<<ConsStatus<<endl;
182 
183  if(Prodstatus != 0 || Filterstatus !=0 || ConsStatus != 0u) break;
184 
185  nb_loop++;
186  if ( nb_loop == max_loop )
187  break;
188  }
189  printf("nb_loop %d error %d\n",nb_loop,err);
190  printf("************** EMULATOR MAIN LOOP ************** \n");
191 
192  return true;
193 }
194 
195 template <typename Prod_actor, typename Cons_actor>
196 class EmulatorPC : public BaseEmulatorChain
197 {
198 private:
199  Prod_actor *fProducer;
200  Cons_actor *fConsumer;
201 
202 private:
203  OneBlock fBProd;
204 
205 private:
206  std::string fPathProd;
207  std::string fPathCons;
208 
209 public:
210  EmulatorPC(const char *path, UInt_t bsize = aMByte);
211  /* EmulatorPC(const char *path_prod,const char * path_cons, UInt_t bsize_prod = aMByte, UInt_t bsize_cons = aMByte) ; */
212  ~EmulatorPC();
213 
215  { return fProducer; }
216 
218  { return fConsumer; }
219 
220  Cons_actor *GetConsumer()
221  { return fConsumer; }
222 
223  Prod_actor *GetProducer()
224  { return fProducer; }
225 
227  virtual Bool_t Init(const Char_t *rootafp)
228  {
229  return BaseEmulatorChain::Init(rootafp);
230  }
231  virtual Bool_t Init(Int_t which_run, const char *experiment, const char *which_adf_data, const char *run_name_pattern, Option_t *opt_adf_pattern)
232  {
233  return BaseEmulatorChain::Init(which_run,experiment,which_adf_data,run_name_pattern,opt_adf_pattern);
234  }
235  virtual Bool_t Init();
236  virtual Bool_t Run(UInt_t max_loop = kMaxUInt_t);
237 };
238 
239 template <typename Prod_actor, typename Cons_actor>
240 EmulatorPC<Prod_actor,Cons_actor>::EmulatorPC(const char *path, UInt_t bsize):
242  fProducer(0x0),
243  fConsumer(0x0),
244  fBProd(bsize),
245  fPathProd(path),
246  fPathCons(path)
247 {
248 
249 }
250 
251 template <typename Prod_actor, typename Cons_actor>
253 {
254  if ( fProducer )
255  delete fProducer;
256  if ( fConsumer )
257  delete fConsumer;
258 }
259 
260 template <typename Prod_actor, typename Cons_actor>
262 {
263  UInt_t err = 0u;
264 
265  // just in case a actor forget to call it and it is required.
266  NarvalInterface::process_config(fPathProd.data(),&err);
267  if ( err > 0u ) {
268  }
269 
270  err = 0u;
271  // it creates and inits the different actors
272  // producer
273  Prod_actor::process_config(fPathProd.data(),&err);
274  if ( err > 0u ) {
275  return false;
276  }
277  fProducer = new Prod_actor();
278  fProducer->process_initialise(&err);
279  if ( err > 0u ) {
280  return false;
281  }
282 
283  // consumer
284  Cons_actor::process_config(fPathCons.data(),&err);
285  if ( err > 0u ) {
286  return false;
287  }
288  fConsumer = new Cons_actor();
289  fConsumer->process_initialise(&err);
290  if ( err > 0u ) {
291  return false;
292  }
293 
294  return true;
295 }
296 
297 template <typename Prod_actor, typename Cons_actor>
298 Bool_t EmulatorPC<Prod_actor,Cons_actor>::Run(UInt_t max_loop)
299 {
300  printf("\n*********** EMULATOR MAIN LOOP : START ... \n\n");
301  // loop on events
302  UInt_t nb_loop = 0u, err = 0u, nb_try = 0;
303  while ( err == 0u ) {
304  // to get an input block
305  //printf("Call producer \n");
306  if ( fProducer->ProcessBlock(fBProd) != 0u )
307  {
308  fConsumer->ProcessBlock(fBProd);
309  break;
310  }
311  if ( fBProd.GetSize() == 0u ) {
312  if ( nb_try > 1 ) { // up to XX tries of consecutive empty output before stooping
313  break;
314  }
315  else {
316  nb_try++;
317  continue;
318  }
319  }
320  else nb_try = 0u;
321 
322  /* else
323  printf("Produced block with size %d \n",FB0_1.GetSize());*/
324  //printf("Call consumer \n");
325  if ( fConsumer->ProcessBlock(fBProd) != 0u )
326  break;
327 
328  nb_loop++;
329  if ( nb_loop == max_loop )
330  break;
331  }
332  printf("\n*********** EMULATOR MAIN LOOP : ... STOP after %d loops (error %d)\n\n",nb_loop,err);
333 
334  return true;
335 }
336 
337 #endif
338 
339 
NarvalProducer * GetBaseProducer()
virtual Bool_t Run(UInt_t max_loop=kMaxUInt_t)
loop
printf("******************************************************************** \n")
header file for FrameBlock.cpp
It defines the interface needed to be a narval actor (producer).
It implements an expandable block of Frame.
Definition: FrameBlock.h:351
EmulatorPC(const char *path, UInt_t bsize=aMByte)
virtual Bool_t Run(UInt_t max_loop=kMaxUInt_t)
loop
const UInt_t kMaxUInt_t
Definition: ADFConfig.h:100
virtual Bool_t Init()
It should be overwritten !
virtual Bool_t Init(Int_t which_run, const char *experiment, const char *which_adf_data, const char *run_name_pattern, Option_t *opt_adf_pattern)
NarvalProducer * GetBaseProducer()
const UInt_t aMByte
Definition: BaseBuffer.h:36
global header
EmulatorPFC(const char *path, UInt_t bsize=aMByte)
virtual Bool_t Init()
It should be overwritten !
virtual Bool_t Init(const Char_t *rootafp)
Init the emulator using a different root afp file for the producer.
NarvalConsumer * GetBaseConsumer()
It defines the interface needed to be a consumer.
to have a common base class to be able to control the emulator through a TTask
virtual Bool_t Init(Int_t which_run, const char *experiment, const char *which_adf_data, const char *run_pat, Option_t *opt_adf_pattern)
NarvalConsumer * GetBaseConsumer()
virtual Bool_t Init(const Char_t *rootafp)
Init the emulator using a different root afp file for the producer.
virtual Bool_t Init()
It should be overwritten !
It implements an in-memory block of Frames.
Definition: FrameBlock.h:206