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