GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Trigger.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #include "FactoryItem.h"
24 
25 #ifndef ADF_Trigger
26 #include "Trigger.h"
27 #endif
28 #ifndef ADF_Key
29 #include "Key.h"
30 #endif
31 #ifndef ADF_FrameFactory
32 #include "FrameFactory.h"
33 #endif
34 #ifndef ADF_ConfigurationFrame
35 #include "ConfigurationFrame.h"
36 #endif
37 #ifndef ADF_GObject
38 #include "GObject.h"
39 #endif
40 #ifndef ADF_GenericFrame
41 #include "GenericFrame.h"
42 #endif
43 #ifndef ADF_DFAgent
44 #include "DFAgent.h"
45 #endif
46 
47 using namespace ADF;
48 
49 UInt_t Trigger::gUniqueID = 0u;
50 
51 FrameTrigger::FrameTrigger(const Char_t *trig_name) :
52  DFTrigger(trig_name),
53  fInputFrames(0u),
54  fInputKeyConst(0u),
55  fIsConsumable(),
56  fFiredOn(),
57  fIndividualFired(),
58  fScanPattern(),
59  fUtilities(),
60  fInputConfFrames(0u),
61  fMap(),
62  fActiveInputConfFrames(),
63  fIsOwnerOfOutput(true),
64  fOutputFrame(0x0),
65  fEmbeddedOutputFrame(0x0)
66 {
67  fLog.GetProcessName() = "FrameTrigger"; fLog.GetProcessMethod() = "FrameTrigger()";
68 
69  // frames which are owned by the trigger
70  fInputConfFrames.SetOwner(true); fInputFrames.SetOwner(true); /* fInputKeyConst.SetOwner(true); */ fUtilities.SetOwner(true);
71 }
72 
74 {
75  if ( fOutputFrame ) {
76  if ( !fIsOwnerOfOutput )
77  fOutputFrame->SetFrame(0x0); // to avoid deleting the non owned frame
78  delete fOutputFrame;
79  }
80  // delete constant keys used to check the data flow
81  for (UInt_t i = 0u; i < fInputKeyConst.size(); i++) {
82  if ( fInputKeyConst[i] ) {
83  delete fInputKeyConst[i]; fInputKeyConst[i] = 0x0;
84  }
85  }
86 
87  fInputConfFrames.Delete(); fInputFrames.Delete(); // fInputKeyConst.Delete();
88 }
89 
91 {
92  // for all kind of frames
93  to->SetCheckLevel(from->GetCheckLevel());
94 
95  DataInterface *dfrom = GetDataPointer<DataInterface>(from);
96  DataInterface *dto = GetDataPointer<DataInterface>(to);
97 
98  // for data frames to be sured the link are kept
99  if ( dfrom && dto ) {
100  dfrom->Global()->TransferLinkAndProxy ( (*dto->Global()) ) ;
101  }
102 }
103 
105 {
106  // cannot reconfigure a zombie
107  FactoryItem kitem, fitem, newkeyitem, newframeitem;
108  if ( IsZombie() )
109  return false;
110 
111  // a universal trigger works whatever the data flow, so no need to reconfigure
112  // the trigger to be suitable for a new definition
113  if ( IsUniversal() )
114  { Active(true); return true; }
115 
116  fLog.SetProcessMethod("Reconfigure( ConfAgent * )");
117 
118  // from the confagent, get the DF Agent
119  DFAgent *agent = confagent->GetDFAgent();
120 
121  // check all input to know which frame is suitable to be modified
122  // or is already exactly defined as it is on the dataflow
123  std::vector< UShort_t > ok, exact; UShort_t nb_ok, change_input_ok = 0u, change_output_ok = 0u, change_utility_ok = 0u ;
124  Bool_t okframe /*, okconfframe = false */; ;
125 
126  nb_ok = 0u;
127  ok.clear();
128  exact.clear();
129  for(UInt_t which = 0u; which < GetNbInputFrame(); which++ ){
130 
131  SharedFP *sfp = fInputFrames.At(which); Frame *fp = sfp->GetFrame();
132  kitem =
133  fp->GetKey()->GetSignature();
134  fitem =
135  fp->GetSignature();
136 
137  exact.push_back(
138  agent->IsAKnownFrame(kitem,fitem,NoChange,NoChange) );
139 
140  ok.push_back(
141  agent->IsAKnownFrame(kitem,fitem,sfp->GetKeyChangeFunction(),sfp->GetFrameChangeFunction()));
142 
143  // to remove ambigous cases, keep only those with one possible change
144  if ( ok.back() == 1u ) {
145  nb_ok++;
146  }
147  else {
148  fLog << info << kitem << " " << fitem << " cannot be used for this dataflow " << nline;
149  }
150  }
151  // all the frames could be modified or are already well defined
152  okframe = (nb_ok == GetNbInputFrame());
153  if ( okframe ) {
154 
155  Bool_t changeok = true;
156  for(UInt_t which = 0u; which < GetNbInputFrame(); which++ ){
157 
158  // no need to change this one, key and frame are already ok
159  if ( exact[which] == 1u )
160  continue;
161 
162  SharedFP *sfp = fInputFrames.At(which); Frame *fp = sfp->GetFrame();
163  kitem =
164  fp->GetKey()->GetSignature();
165  fitem =
166  fp->GetSignature();
167 
168  newkeyitem =
169  agent->WhichKnownKey(kitem,fitem,
171  newframeitem =
172  agent->WhichKnownFrame(kitem,fitem,
174 
175  // try and allocate a new frame
176  Frame *newframe = MainFrameFactory::theMainFactory().New(newkeyitem,newframeitem);
177  if ( newframe ) {
178  Frame *oldframe = sfp->SetFrame(newframe);
179  if ( oldframe ) {
180  FrameTransfert(oldframe,newframe);
181  delete oldframe;
182  oldframe = 0x0;
183  }
184  // modify also embedded frame
185  if ( which == 0u ) {
186  if ( fEmbeddedOutputFrame ) { // means the trigger is on a composite frame, no need to check it again
187  //
188  delete fEmbeddedOutputFrame;
189  //
190  fEmbeddedOutputFrame = MainFrameFactory::theMainFactory().Clone(fInputFrames.At(0u)->GetFrame());
191  if ( fEmbeddedOutputFrame == 0x0 ) {
192  changeok = false;
193  fLog << error << "Input Frame " << kitem << " " << fitem << " cannot be cloned ! " << nline;
194  break;
195  }
196  else
197  fEmbeddedOutputFrame->Reset();
198  }
199  }
200  fLog << "Input Frame " << kitem << " " << fitem << " has been changed successfully into " << newkeyitem << " " << newframeitem << nline;
201  }
202  else {
203  changeok = false;
204  fLog << error << "Fail in changing the Frame " << kitem << " " << fitem << " into " << newkeyitem << " " << newframeitem << nline;
205  }
206  if ( changeok == false ) {
207  break;
208  }
209  }
210 
211  // now apply changes to the autoconf frames
212  if ( changeok ) {
213 
214  // now apply possible key changes for configuration frames
215  // since configuration frames allows version changements
216  fActiveInputConfFrames.clear();
217 
218  for (UInt_t i = 0u; i < fInputConfFrames.GetSize(); i++ ) {
219 
220  SharedFP *sfp = fInputConfFrames.At(i); Frame *confframe = sfp->GetFrame();
221  kitem =
222  confframe->GetKey()->GetSignature();
223  fitem =
224  confframe->GetSignature();
225 
226  // unknown by the new agent or ambigous
227  if ( agent->IsAKnownFrame(kitem,fitem, sfp->GetKeyChangeFunction(), sfp->GetFrameChangeFunction()) != 1u ) {
228  change_input_ok = 2u;
229  fLog << error << "changing Configuration Frame " << kitem << " " << fitem << " since not known precisely " << nline;
230  break;
231  }
232  // changes possible ==> do it
233  newkeyitem =
234  agent->WhichKnownKey(kitem,fitem,sfp->GetKeyChangeFunction(),sfp->GetFrameChangeFunction());
235  newframeitem =
236  agent->WhichKnownFrame(kitem,fitem,sfp->GetKeyChangeFunction(),sfp->GetFrameChangeFunction());
237 
238  Frame *newframe = MainFrameFactory::theMainFactory().New(newkeyitem,newframeitem);
239  if ( newframe ) {
240  ConfigurationFrame *newconfframe = dynamic_cast<ConfigurationFrame *> (newframe);
241  if ( newconfframe ) {
242 
243  Frame *oldframe = sfp->SetFrame(newconfframe);
244  if ( oldframe ) {
245  FrameTransfert(oldframe,newconfframe);
246 
247  // add this to the list of active configuration frames on the data flow
248  std::pair<ConfigurationFrame *, UShort_t> newactiveconf;
249  newactiveconf.first = newconfframe;
250  newactiveconf.second = fMap[i];
251  fActiveInputConfFrames.push_back(newactiveconf);
252 
253  delete oldframe;
254  oldframe = 0x0;
255  }
256  fLog << "Configuration Frame " << kitem << " " << fitem << " has been changed successfully into " << newkeyitem << " " << newframeitem << nline;
257  }
258  else {
259  change_input_ok = 2u;
260  fLog << warning << "Fail casting Configuration Frame " << kitem << " " << fitem << " into " << newkeyitem << " " << newframeitem << nline;
261  break;
262  }
263  }
264  else {
265  change_input_ok = 2u;
266  fLog << error << "Fail allocating new Configuration Frame " << newkeyitem << " " << newframeitem << nline;
267  break;
268  }
269  }
270  }
271  else {
272  change_input_ok = 2u;
273  fLog << error << "Fail during reconfiguration of input frames of trigger " << GetName() << nline;
274  }
275  }
276  else {
277  change_input_ok = 1u;
278  fLog << info << "Inputs of trigger " << GetName() << " not suitable for the current dataflow " << nline;
279  }
280 
281 // now check output frame ... if not know in the agent, add the definition !
282  if ( fOutputFrame ) {
283  if ( fOutputFrame->GetFrame() ) {
284 
285  // current output frame
286  SharedFP *sfp = fOutputFrame; Frame *fp = sfp->GetFrame();
287  kitem =
288  fp->GetKey()->GetSignature();
289  fitem =
290  fp->GetSignature();
291 
292  UShort_t wcase = 10u;
293  if ( agent->IsAKnownFrame(kitem,fitem,NoChange,NoChange) == 1u )
294  wcase = 0u; // already ok without any changes
295  else {
296  if ( agent->IsAKnownFrame(kitem,fitem,sfp->GetKeyChangeFunction(),sfp->GetFrameChangeFunction()) == 0u )
297  wcase = 1u; // unknown by the agent, add the definition
298  if ( agent->IsAKnownFrame(kitem,fitem,sfp->GetKeyChangeFunction(),sfp->GetFrameChangeFunction()) == 1u )
299  wcase = 2u; // unambiguous changes possible ==> try it
300  }
301  switch (wcase) {
302  case 0u:
303  fLog << info << "Output of trigger " << GetName() << " already suitable for the data flow " << nline;
304  break;
305  case 1u:
306  fLog << info << "Frame " << kitem << " " << fitem << " has been added to the current agent " << nline;
307  agent->AddKnownFrame(fp);
308  break;
309  case 2u:
310  {
311  Bool_t changeok = true;
312 
313  // new definition
314  newkeyitem =
315  agent->WhichKnownKey(kitem,fitem, sfp->GetKeyChangeFunction(),sfp->GetFrameChangeFunction());
316  newframeitem =
317  agent->WhichKnownFrame(kitem,fitem, sfp->GetKeyChangeFunction(),sfp->GetFrameChangeFunction());
318 
319  Frame *newframe = MainFrameFactory::theMainFactory().New(newkeyitem,newframeitem);
320  if ( newframe ) {
321  Frame *oldframe = sfp->SetFrame(newframe);
322  if ( oldframe ) {
323  FrameTransfert(oldframe,newframe);
324  delete oldframe;
325  oldframe = 0x0;
326  }
327  fLog << "Output Frame " << kitem << " " << fitem << " has been changed successfully into " << newkeyitem << " " << newframeitem << nline;
328 
329  }
330  else changeok = false;
331 
332  if ( changeok ) {
333  fLog << info << "Trigger " << GetName() << " modification output frame done " << nline;
334  }
335  else {
336  change_output_ok = 2u;
337  fLog << error << "Trigger " << GetName() << " modification output failed " << nline;
338  }
339  }
340  break;
341  default:
342  change_output_ok = 2u;
343  fLog << error << "Trigger " << GetName() << " modification output failed " << nline;
344  break;
345  }
346  }
347  }
348 // apply modifications to utilities.
349  nb_ok = 0u;
350  ok.clear();
351  exact.clear();
352  for(UInt_t which = 0u; which < fUtilities.GetSize(); which++ ){
353 
354  SharedFP *sfp = fUtilities.At(which); Frame *fp = sfp->GetFrame();
355  kitem =
356  fp->GetKey()->GetSignature();
357  fitem =
358  fp->GetSignature();
359 
360  exact.push_back(
361  agent->IsAKnownFrame(kitem,fitem,NoChange,NoChange) );
362 
363  ok.push_back(
364  agent->IsAKnownFrame(kitem,fitem,sfp->GetKeyChangeFunction(),sfp->GetFrameChangeFunction()));
365 
366  // to remove ambigous cases, keep only those with one possible change
367  if ( ok.back() == 1u )
368  nb_ok++;
369  else {
370  fLog << info << kitem << " " << fitem << " cannot be used for this dataflow " << nline;
371  }
372  }
373  // all the frames could be modified or are already well defined
374  okframe = (nb_ok == fUtilities.GetSize());
375  if ( okframe ) {
376 
377  Bool_t changeok = true;
378  for(UInt_t which = 0u; which < fUtilities.GetSize(); which++ ){
379 
380  // no need to change this one, key and frame are already ok
381  if ( exact[which] == 1u )
382  continue;
383 
384  SharedFP *sfp = fUtilities.At(which); Frame *fp = sfp->GetFrame();
385  kitem =
386  fp->GetKey()->GetSignature();
387  fitem =
388  fp->GetSignature();
389 
390  newkeyitem =
391  agent->WhichKnownKey(kitem,fitem,
393  newframeitem =
394  agent->WhichKnownFrame(kitem,fitem,
396 
397  // try and allocate a new frame
398  Frame *newframe = MainFrameFactory::theMainFactory().New(newkeyitem,newframeitem);
399  if ( newframe ) {
400  Frame *oldframe = sfp->SetFrame(newframe);
401  if ( oldframe ) {
402  FrameTransfert(oldframe,newframe);
403  delete oldframe;
404  oldframe = 0x0;
405  }
406  fLog << "Utility Frame " << kitem << " " << fitem << " has been changed successfully into " << newkeyitem << " " << newframeitem << nline;
407 
408  }
409  else {
410  changeok = false;
411  fLog << error << "Fail in changing the Frame " << kitem << " " << fitem << " into " << newkeyitem << " " << newframeitem << nline;
412  }
413 
414  if ( changeok == false )
415  break;
416  }
417  if ( !changeok ) {
418  change_utility_ok = 2u;
419  fLog << error << "Fail during reconfiguration of utilities Frame of trigger " << GetName() << nline;
420  }
421  }
422  else {
423  change_utility_ok = 1u;
424  fLog << info << "Utilities of trigger " << GetName() << " not suitable for the current dataflow " << nline;
425  }
426 
427  // global decision
428  if ( change_input_ok == 0u && change_output_ok == 0u && change_utility_ok == 0u ) {
429  fLog << info << "Trigger " << GetName() << " set to Active " << nline;
430  Active(true);
431  }
432  else {
433  Active(false);
434  if ( change_input_ok < 2u && change_output_ok < 2u && change_utility_ok < 2u ) {
435  fLog << warning << "Trigger " << GetName() << " not suitable for the data flow, set inactive " << nline;
436  }
437  else {
438  Zombie(true);
439  fLog << error << "Trigger " << GetName() << " has become a zombie ! " << nline;
440  }
441  }
442  // flush log system
443  fLog << dolog;
444  //
445  return IsActive();
446 }
447 
449 {
450  if ( frame == 0x0 )
451  return 0x0; // cannot set this as output frame
452 
453  if ( fOutputFrame == 0x0 )
454  fOutputFrame = new SharedFP();
455 
456  // returns the pointer embedded in SharedFP and replace by frame
457  Frame *f =
458  fOutputFrame->SetFrame(frame);
459 
460  // last term reauired in case of passing twice the same frame
461  if ( fIsOwnerOfOutput && f && f != frame )
462  delete f;
463 
464  fIsOwnerOfOutput = false; // using this method means the user has allocated this so this is not the owner
465 
466  return fOutputFrame;
467 }
468 
469 SharedFP *FrameTrigger::SetOutputFrame(const FactoryItem &key_item, const FactoryItem &frame_item)
470 {
471  SharedFP *sfp = MainFrameFactory::theMainFactory().NewSharedFrame(key_item,frame_item);
472  if ( sfp == 0x0 )
473  return sfp;
474 
475  if ( fOutputFrame ) {
476  if ( ! fIsOwnerOfOutput )
477  fOutputFrame->SetFrame(0x0); // to avoid deleting the embedded frame
478 
479  delete fOutputFrame ;
480  }
481  fOutputFrame = sfp; fIsOwnerOfOutput = true;
482 
483  return sfp;
484 }
485 
487 {
488  // to treat specific cases i.e. write only trigger
489  if ( GetNbInputFrame() == 0u ) {
490  if ( fOutputFrame && fOutputFrame->IsValid() )
491  return fOutputFrame->GetFrame();
492  else
493  return 0x0;
494  }
495 
496  Frame *main_frame, *single_output = 0x0; Bool_t invalid_out = true, ok = true; UInt_t sizemax;
497  //
498  main_frame =
499  fInputFrames.At(0u)->GetFrame();
500  if ( fOutputFrame && fOutputFrame->IsValid() ) {
501  invalid_out = false;
502  single_output = fOutputFrame->GetFrame(); // out can be valid or not
503  }
504 
505  // if the input frame is not an composite frame, it checks if the ouput is composite
506  // if it is, it tries and add the input frame depending on the model !
507  if ( !main_frame->IsComposite() ) {
508  if ( invalid_out )
509  return 0x0;
510  if ( single_output->IsComposite() && single_output->IsASubFrame((*main_frame)) ) {
511  switch( model ){
512  case ConfAgent::kStrict:
513  case ConfAgent::kSafe:
514  if ( ! IsConsumable(0u) && fInputFrames.At(0u)->IsValid() )
515  single_output->AddSubFrame((*main_frame));
516  break;
517  case ConfAgent::kGrowing:
518  single_output->AddSubFrame((*main_frame)); // no check on vadity, growing mode is extremely conservative
519  break;
520  }
521  }
522  return single_output;
523  }
524  else {
525 /* if ( invalid_out )
526  return 0x0; */
527  // input is composite but not of the right type to embedded the output frame
528  if ( single_output && !main_frame->IsASubFrame((*single_output)) )
529  return single_output;
530  }
531 
532  // the input Frame is consumed completely even if it is a composite frame
533  if ( IsConsumable(0u) || !fInputFrames.At(0u)->IsValid() )
534  return single_output;
535 
536  // reset the embedded frame, copy the content of the input main frame
537  // (should be the same type of key ... so no problems)
538  // and set the data length to 0 to start adding subframes
539  fEmbeddedOutputFrame->FastReset();
540  fEmbeddedOutputFrame->GetKey()->Copy( main_frame->GetKey() );
541  fEmbeddedOutputFrame->GetKey()->SetDataLength(0u);
542 
543  // add first the output frame
544  if ( !invalid_out )
545  ok = ok && fEmbeddedOutputFrame->AddSubFrame((*single_output));
546  switch( model ){
547  // add output frame and input frames if set as non-consumable by the user
548  case ConfAgent::kStrict:
549  // add input frames if not consumed, unknown are consumed
550  sizemax = (UInt_t)fScanPattern.size();
551  for (UInt_t i = 0u; i < sizemax; i++) {
552  if ( fScanPattern[i] > 0u ) { // known by the trigger ==> apply user's wishes
553  if( ! fIsConsumable[fScanPattern[i]] && fInputFrames.At(fScanPattern[i])->IsValid() )
554  ok =
555  ok && fEmbeddedOutputFrame->TransfertSubFrame((*main_frame),i);
556  }
557  }
558  break;
559  case ConfAgent::kSafe:
560  sizemax = (UInt_t)fScanPattern.size();
561  for (UInt_t i = 0u; i < sizemax; i++) {
562  if ( fScanPattern[i] > 0u ) { // known by the trigger ==> apply user's wishes
563  if( ! fIsConsumable[fScanPattern[i]] && fInputFrames.At(fScanPattern[i])->IsValid() )
564  ok =
565  ok && fEmbeddedOutputFrame->TransfertSubFrame((*main_frame),i);
566  }
567  else { // unknown by the trigger ==> keep it
568  ok =
569  ok && fEmbeddedOutputFrame->TransfertSubFrame((*main_frame),i);
570  }
571  }
572  break;
573  case ConfAgent::kGrowing:
574  sizemax = (UInt_t)fScanPattern.size();
575  for (UInt_t i = 0u; i < sizemax; i++) { // keep all input frames
576  ok =
577  ok && fEmbeddedOutputFrame->TransfertSubFrame((*main_frame),i);
578 
579  }
580  break;
581  } // model
582 
583  if ( ok )
584  return fEmbeddedOutputFrame;
585  else
586  return 0x0;
587 }
588 
589 Bool_t FrameTrigger::IsConsumable(UInt_t which) const
590 {
591  if ( which < fIsConsumable.size() )
592  return fIsConsumable[which];
593  return false;
594 }
595 
596 SharedFP *FrameTrigger::Add(const FactoryItem &key_item, const FactoryItem &frame_item, bool iscons, const Char_t *option)
597 {
598  // option
599  // ! : anti-coincidences
600  // | : with or without
601  std::string opt = option;
602 
603  // cannot add a frame to a zombie
604  if ( fIsZombie )
605  return 0x0;
606 
607  // try and allocate key and frame to see if they exists for the current system
608  SharedFP *sfp =
609  MainFrameFactory::theMainFactory().NewSharedFrame(key_item,frame_item);
610  const Key *cstkey =
611  MainKeyFactory::theMainFactory().New(key_item);
612 
613  if ( sfp && cstkey ) {
614  // add a frame with the key used to check if an input frame fired or not
615  fInputFrames.Add(sfp); fInputKeyConst.push_back(cstkey);
616  // fine tuning to determine if the input frame is consumed or not
617  fIsConsumable.push_back(iscons);
618  // not fired yet
619  fIndividualFired.push_back(false);
620  // if option contains !, set anti-coincidence
621  if ( opt.find("!") != std::string::npos )
622  fFiredOn.push_back(0);
623  else {
624  if ( opt.find("|") != std::string::npos )
625  fFiredOn.push_back(-1);
626  else
627  fFiredOn.push_back(1);
628  }
629 
630  // the embedded output does not exist yet, creates it using the main input frame
631  if ( fEmbeddedOutputFrame == 0x0 &&
632  /*fInputFrames.GetSize() == 2u && */fInputFrames.At(0u)->GetFrame()->IsComposite() ) {
633  fEmbeddedOutputFrame =
634  MainFrameFactory::theMainFactory().Clone(fInputFrames.At(0u)->GetFrame());
635  if ( fEmbeddedOutputFrame == 0x0 )
636  fIsZombie = true;
637  else fEmbeddedOutputFrame->Reset();
638  }
639  }
640  else {
641  if ( cstkey )
642  delete cstkey;
643  if ( sfp )
644  delete sfp;
645 
646  sfp = 0x0;
647  fIsZombie = true;
648  }
649  return sfp;
650 }
651 
652 SharedFP *FrameTrigger::AddUtility(const FactoryItem &key_item, const FactoryItem &frame_item)
653 {
654  // try and allocate key and frame to see if they exists for the current system
655  SharedFP *sfp =
656  MainFrameFactory::theMainFactory().NewSharedFrame(key_item,frame_item);
657 
658  if ( sfp ) {
659  // version allowed by default only for the frame part. The key part is the charge of the user.
661  fUtilities.Add(sfp);
662  }
663 
664  return sfp;
665 }
666 
667 Frame *FrameTrigger::GetSubFrameFrom(UInt_t which_input, UInt_t which_sub, SharedFP *utility, Bool_t do_scan)
668 {
669  // check event frame : exist, fired in the current trigger, is composite and has the expected sub
670  if ( which_input < GetNbInputFrame() ) {
671  if ( fIndividualFired[which_input] == false )
672  return 0x0;
673  Frame *composite = fInputFrames.At(which_input)->GetFrame();
674  if ( !composite->IsComposite() )
675  return 0x0;
676  if ( do_scan )
677  composite->Scan();
678  if ( which_sub < composite->GetNbSubFrame() ) {
679  composite->LinkSubFrame(which_sub,utility->GetFrame());
680  utility->GetFrame()->Read();
681  }
682  else return 0x0;
683  }
684  else return 0x0;
685 
686  return utility->GetFrame();
687 }
688 
689 
690 SharedFP *FrameTrigger::AddAutoConf(const FactoryItem &key_item, const FactoryItem &frame_item, UInt_t which)
691 {
692  // the frame pointer to be returned
693  SharedFP *sfp = 0x0, *sfpc = 0x0; ConfigurationFrame *confframe = 0x0;
694 
695  // cannot add an embedded frame to a zombie
696  if ( fIsZombie )
697  return sfpc;
698 
699  // the Frame to be reconfigured should be defined before
700  sfp = fInputFrames.At(which);
701  if ( sfp == 0x0 )
702  return sfpc;
703 
704  if ( sfp->GetFrame() ) {
705  sfpc = MainFrameFactory::theMainFactory().NewSharedFrame(key_item,frame_item);
706  if ( sfpc ) {
707  confframe = dynamic_cast<ConfigurationFrame *>(sfpc->GetFrame());
708  if ( confframe ) {
709  // the frame is adopted by a frame pointer
710  fInputConfFrames.Add(sfpc); fMap.push_back(which);
711  }
712  else { delete sfpc; sfpc = 0x0; }
713  }
714  }
715  return sfpc;
716 }
717 
719 {
720  if ( GetNbInputFrame() == 0u )
721  return false;
722 
723  Bool_t ok = false; Frame *f_to_chek = fInputFrames.At(0u)->GetFrame();
724 
725  for (UInt_t i = 0u; i < fActiveInputConfFrames.size() ; i++) {
726 
727  ConfigurationFrame *confframe = fActiveInputConfFrames[i].first;
728 
729  // just to be sure it as not been linked before
730  // WARNING should never be copied otherwise associated keyConst should be
731  // declered like for InputFrames
732  confframe->Unlink();
733 
734  if ( confframe->GetKey()->IsAKey(f_to_chek->GetKey()) ) {
735  confframe->Link(
736  f_to_chek->GetKey()->GetRealBuffer()->GetAddress(),
737  f_to_chek->GetKey()->GetKeyLength(),'k');
738  confframe->Link(
739  f_to_chek->GetRealBuffer()->GetAddress(),
740  f_to_chek->GetKey()->GetDataLength(),'f');
741 
742  ok = fInputFrames.At(fMap[i])->GetFrame()->Configure(confframe,"in");
743  }
744  }
745  return ok;
746 }
747 
749 {
750  fIsFired = fIndividualFired[0] = false;
751 
752  // nothing to be checked
753  if ( fInputFrames.GetSize() == 0u )
754  return fIsFired;
755 
756  // it is a configuration frame for one frame of that trigger
757  // ==> do the Frame::Configure action and return false since
758  // the input frame is known as a configuration frame
759  if ( CheckConf() )
760  return fIsFired;
761 
762  // the main frame is always at slot 0
763  Frame *mainframe = fInputFrames.At(0)->GetFrame();
764  // check whether or not this is a frame of the expected kind
765  Bool_t is_a_frame =
766  fInputKeyConst[0u]->IsAKey(mainframe->GetKey());
767 
768  // if the main frame does not fulfill the condition
769  if ( !is_a_frame )
770  return fIsFired;
771 
772  // expected kind
773  fIsFired = fIndividualFired[0] = true;
774  if ( fInputFrames.GetSize() == 1u ) { // non-embedded frame, no need to go further
775  fInputFrames.At(0)->SetValid(true);
776  return fIsFired;
777  }
778  // only if this is a composite frame with subframes in it
779  if ( mainframe->IsComposite() && mainframe->Scan() != 0u ) {
780 
781  // clear the scan pattern, set all frames to not fired.
782  fScanPattern.clear();
783  for (UInt_t sec = 0u ; sec < mainframe->GetNbSubFrame() ; sec++ )
784  fScanPattern.push_back(0u);
785 
786  // check the conditions for the sub-frames since if we are here
787  for (UInt_t sec = 1u ; sec < fInputFrames.GetSize() ; sec++ ) {
788 
789  fIndividualFired[sec] = false; fInputFrames.At(sec)->SetValid(false);
790 
791  // Unlink to be sure the comparison is not done with a previous linked key
792  Frame *subframe = fInputFrames.At(sec)->GetFrame();
793  subframe->Unlink();
794 
795  Bool_t is_ok = false;
796  for (UInt_t sub = 0u ; sub < mainframe->GetNbSubFrame(); sub++ ) {
797 
798  // get the key of the sub frame
799  const Key *subkey = mainframe->GetSubKey(sub);
800 
801  // subkey->Print();
802  // subframe->GetKey()->Print();
803  // check if it is a key for the current trigger
804  if ( subframe->GetKey()->IsAKey(subkey) ) {
805  if ( mainframe->LinkSubFrame(sub,subframe) ) {
806  is_ok = true;
807  fScanPattern[sub] = sec;
808  fInputFrames.At(sec)->SetValid(true);
809  fIndividualFired[sec] = true;
810  break;
811  }
812  }
813  }
814  // check the global condition
815  switch ( fFiredOn[sec] ) {
816  // whether it is there or not doest not influence the global trigger
817  case -1:
818  is_ok = true;
819  break;
820  // anti-coincidence
821  case 0:
822  is_ok = !is_ok ;
823  break;
824  // it has to be there
825  default:
826  break;
827  }
828  if ( !is_ok ) {
829  fIsFired = false;
830  break; // at least one condition is not fulfill !
831  }
832  }
833  }
834 
835  //
836  return fIsFired;
837 }
838 
839 AgataFrameTrigger *AgataFrameTrigger::Build(const Char_t *name, const Char_t *in, const Char_t *out, ConfAgent *agent)
840 {
841  std::string sin = in, sout = out, tmp, opt; ConfAgent *lagent;
842 
843  // otherwise input and output string not read correctly by istringstream
844  sin += " ";
845  sout += " ";
846 
847  // if no agent, take the global one
848  if ( agent == 0x0 )
849  lagent = ConfAgent::theGlobalAgent();
850  else
851  lagent = agent;
852 
853  // allocate a new Trigger
854  AgataFrameTrigger *trig = new AgataFrameTrigger(name);
855  // decode input string
856  {
857  std::istringstream decode(sin);
858  // just to be sure ...
859  decode.clear();
860  while ( 1 ) {
861  decode >> tmp ;
862  if ( !decode.good() )
863  { /* std::cout << " IT BREAKS " << tmp.data() << std::endl; */ break;}
864  opt = "";
865  if ( tmp.find("!") == 0 ) { // anti coincidence
866  opt = "!";
867  tmp.erase(0,1);
868  }
869  else {
870  if ( tmp.find("|") == 0 ) { // start with | means frmae is there or not
871  opt = "|";
872  tmp.erase(0,1);
873  }
874  }
875  trig->Add("Agata",tmp.data(),lagent,false,opt.c_str());
876  }
877  }
878  {
879  std::istringstream decode(sout);
880  // just to be sure ...
881  decode.clear();
882  while ( 1 ) {
883  decode >> tmp ;
884  if ( !decode.good() )
885  break;
886  trig->SetOutputFrame("Agata", tmp.data(), lagent);
887  break;
888  }
889  }
890 
891  return trig;
892 }
893 
894 SharedFP *AgataFrameTrigger::Add(const char *type, const Version &v_key, const Version &v_frame,
895  bool iscons, const Char_t *option)
896 {
897  FactoryItem kitem("Agata",type,v_key), fitem("Agata",type,v_frame);
898 
899  return FrameTrigger::Add(kitem,fitem,iscons,option);
900 }
901 
902 SharedFP *AgataFrameTrigger::Add(const char *factory_name, const char *frame_type, const ConfAgent *confagent,
903  bool iscons, const Char_t *option)
904 {
905  const DFAgent *lagent;
906 
907  // from the confagent, get the DF Agent or from the global agent
908  if ( confagent )
909  lagent = confagent->GetConstDFAgent();
910  else
912 
913  // set properly the item to be compatible with the curremt agent
914  FactoryItem k_asked(factory_name,frame_type,Version()), f_asked(factory_name,frame_type,Version()), k_defined, f_defined;
915 
916  // check if a key/frame whatever the version # exist for that definition
917  lagent->SetAsCompatibleItems(k_asked,f_asked);
918  //
919  if ( lagent->IsAKnownFrame(k_asked,f_asked) != 1u )
920  return 0x0;
921 
922  // now get the true definition and asked for the creation
923  k_defined = lagent->WhichKnownKey (k_asked, f_asked);
924  f_defined = lagent->WhichKnownFrame(k_asked, f_asked);
925  //
926  return FrameTrigger::Add(k_defined, f_defined, iscons, option);
927 }
928 
929 SharedFP *AgataFrameTrigger::AddUtility(const char *type, const ConfAgent *confagent)
930 {
931  FactoryItem kitem("Agata",type,Version(0,0)), fitem("Agata",type,Version(0,0));
932 
933  return AgataFrameTrigger::AddUtility(kitem,fitem,confagent);
934 }
935 
936 SharedFP *AgataFrameTrigger::AddUtility(const FactoryItem &key_item, const FactoryItem &frame_item, const ConfAgent *confagent)
937 {
938  const DFAgent *lagent;
939 
940  // from the confagent, get the DF Agent or from the global agent
941  if ( confagent )
942  lagent = confagent->GetConstDFAgent();
943  else
945 
946  // set properly the item to be compatible with the curremt agent
947  FactoryItem k_asked(key_item), f_asked(frame_item), k_defined, f_defined;
948 
949  // check if a key/frame whatever the version # exist for that definition
950  lagent->SetAsCompatibleItems(k_asked,f_asked);
951  //
952  if ( lagent->IsAKnownFrame(k_asked,f_asked) != 1u )
953  return 0x0;
954 
955  // now get the true definition and asked for the creation
956  k_defined = lagent->WhichKnownKey (k_asked, f_asked);
957  f_defined = lagent->WhichKnownFrame(k_asked, f_asked);
958 
959  return FrameTrigger::AddUtility(k_defined, f_defined);
960 }
961 
962 SharedFP *AgataFrameTrigger::SetOutputFrame(const char *type, const Version &v_key, const Version &v_frame)
963 {
964  FactoryItem kitem("Agata",type,v_key), fitem("Agata",type,v_frame);
965 
966  return FrameTrigger::SetOutputFrame(kitem,fitem);
967 }
968 
969 SharedFP *AgataFrameTrigger::SetOutputFrame(const char *factory_name, const char *type, const ConfAgent *confagent)
970 {
971  const DFAgent *lagent;
972 
973  // from the confagent, get the DF Agent or from the global agent
974  if ( confagent )
975  lagent = confagent->GetConstDFAgent();
976  else
978 
979  // set properly the item to be compatible with the curremt agent
980  FactoryItem k_asked(factory_name,type,Version()), f_asked(factory_name,type,Version()), k_defined, f_defined;
981 
982  // check if a key/frame whatever the version # exist for that definition
983  lagent->SetAsCompatibleItems(k_asked,f_asked);
984  //
985  if ( lagent->IsAKnownFrame(k_asked,f_asked) != 1u )
986  return 0x0;
987 
988  // now get the true definition and asked for the creation
989  k_defined = lagent->WhichKnownKey (k_asked, f_asked);
990  f_defined = lagent->WhichKnownFrame(k_asked, f_asked);
991  //
992  return FrameTrigger::SetOutputFrame(k_defined,f_defined);
993 }
994 
995 
996 
FrameTrigger(const Char_t *trig_name)
Definition: Trigger.cpp:51
virtual const Key * GetSubKey(UInt_t) const =0
Returns one of the sub-key in case this is a composite frame.
virtual const BufferIO * GetRealBuffer() const
Definition: Key.h:118
virtual SharedFP * SetOutputFrame(Frame *frame)
Once a trigger has fired, the result of the algorithm is set through this.
Definition: Trigger.cpp:448
virtual Bool_t IsValid() const
true if it is a valid pointer
Definition: Frame.h:616
virtual ~FrameTrigger()
Definition: Trigger.cpp:73
Bool_t fIsZombie
true if this is a zombie (EX: objects not properly allocated)
Definition: Trigger.h:69
virtual Key * GetKey()=0
To get the Key associated to this frame.
virtual Frame * GetFrame() const
Definition: Frame.h:625
Base class for a Key.
Definition: Key.h:56
virtual Bool_t TransfertSubFrame(const Frame &, UInt_t)
copy the sub-frame #i to the Frame given in the second argument
Definition: Frame.h:268
Bool_t IsUniversal() const
Check if this trigger is in fired state.
Definition: Trigger.h:134
static MainFrameFactory & theMainFactory()
the main (global) keyfactory
header file for FactoryItem.cpp
Base class for a Frame.
Definition: Frame.h:73
virtual Frame * New(const FactoryItem &key_item, const FactoryItem &frame_item)
just a frame
virtual void Unlink()
Copy a buffer to this Frame.
Definition: Frame.h:433
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
virtual UInt_t Read()
It reads the content into dedicated structures from the Frame (data part)
Definition: Frame.h:199
virtual void FastReset()=0
FastReset the current frame, means the data part keep the previous values.
const FactoryItem & GetSignature() const
Definition: Key.h:115
virtual SharedFP * Add(const FactoryItem &key_item, const FactoryItem &frame_item, bool iscons=true, const Char_t *option="")
Add a frame to the list of required frames.
Definition: Trigger.h:492
A configuration frame is just an encapsulation of a string.
virtual Bool_t Copy(const Char_t *, UInt_t)
Copy an external buffer to this key.
Definition: Key.cpp:90
virtual const BufferIO * GetRealBuffer() const =0
give access to the underlying buffer of the data part
LogMessage & error(LogMessage &)
Bool_t IsActive() const
Check if this trigger is in fired state.
Definition: Trigger.h:126
virtual Key * GetKey()
To get the Key associated to this frame.
Definition: Frame.h:344
virtual DFAgent * GetDFAgent()=0
to get the Data Flow Agent in charge of knowing the structure of the DF
virtual UInt_t GetDataLength() const
Definition: Key.h:134
virtual Bool_t Link(const Char_t *buf, UInt_t size, const char opt= 'b')
Link a buffer to this Frame.
Definition: Frame.h:374
header file for Key.cpp
static ConfAgent * theGlobalAgent(std::string="Agata")
to get the global agent
Definition: ConfAgent.cpp:402
virtual Bool_t IsConsumable(UInt_t which=0u) const
to know if the frame is consumable or not
Definition: Trigger.cpp:589
virtual std::string & GetProcessMethod()
To get the current method.
Bool_t NoChange(const FactoryItem &item_from, const FactoryItem &item_to)
No changes allowed.
Definition: FactoryItem.h:136
const PF_FactoryItemChange & GetKeyChangeFunction() const
Definition: Frame.h:637
LogMessage fLog
to send messages to the log server
Definition: Trigger.h:62
static AgataFrameTrigger * Build(const Char_t *name, const Char_t *in, const Char_t *out="", ConfAgent *agent=0x0)
Build a new AgataFrame Trigger.
Definition: Trigger.cpp:839
UShort_t IsAKnownFrame(const FactoryItem &kit, const FactoryItem &fit, PF_FactoryItemChange kch=ChangeOfVersion, PF_FactoryItemChange fch=ChangeOfVersion) const
To know if a Frame is known by the Agent under the conditions given.
Definition: DFAgent.cpp:334
header file for Trigger.cpp
virtual Bool_t IsComposite() const
tells if this frame is a composite frame i.e. if it is composed of sub-frames
Definition: Frame.h:212
friend LogMessage & clear(LogMessage &)
others
void AddKnownFrame(const FactoryItem &item_key, const FactoryItem &item_frame, const Char_t opt= '+')
internal use to avoid adding a definition of a Frame that cannot be allocated
Definition: DFAgent.cpp:266
virtual Frame * GetSubFrameFrom(UInt_t which_input, UInt_t which_sub, SharedFP *utility, Bool_t do_scan=false)
to extract a sub frame from one event frame of the current trigger
Definition: Trigger.cpp:667
virtual void FrameTransfert(Frame *from, Frame *to)
Definition: Trigger.cpp:90
virtual UInt_t GetKeyLength() const
Unique number corresponding to a type of Key.
Definition: Key.h:210
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 SharedFP * AddUtility(const FactoryItem &key_item, const FactoryItem &frame_item)
Add utilities, used to decode/encode composite frames.
Definition: Trigger.cpp:652
ConfAgent.
Definition: ConfAgent.h:63
virtual SharedFP * SetOutputFrame(Frame *frame)
Once a trigger has fired, the result of the algorithm is set through this.
Definition: Trigger.h:512
const Char_t * GetAddress() const
Pointer to the current underlying array of bytes.
Definition: BufferIO.h:216
virtual void SetProcessMethod(const char *)
To set the current method.
virtual void Unlink()=0
UnLink a buffer to this Frame.
void Active(Bool_t b=true)
Active this trigger.
Definition: Trigger.h:122
LogMessage & nline(LogMessage &)
virtual Bool_t Reconfigure(ConfAgent *)
Modify the Frame definitions respecting the new data flow definition and the acceptable Frame changes...
Definition: Trigger.cpp:104
virtual const DFAgent * GetConstDFAgent() const =0
virtual Bool_t Check()
Check the content of the frame if the primary frame is a composite one.
Definition: Trigger.cpp:748
virtual SharedFP * Add(const FactoryItem &key_item, const FactoryItem &frame_item, bool iscons=true, const Char_t *option="")
Add a frame to the list of required frames.
Definition: Trigger.cpp:596
virtual SharedFP * NewSharedFrame(const FactoryItem &, const FactoryItem &)
Ask the main for a new Frame.
Bool_t SetAsCompatibleItems(FactoryItem &factory_key_item, FactoryItem &factory_frame_item) const
change both item as the same time
Definition: DFAgent.h:146
const std::string & GetName() const
Definition: Trigger.h:102
To be used for Agata Data Flow.
Definition: Trigger.h:462
Bool_t fIsFired
true if this has just been fired
Definition: Trigger.h:67
FactoryItem WhichKnownKey(const FactoryItem &kit, const FactoryItem &fit, PF_FactoryItemChange kch=ChangeOfVersion, PF_FactoryItemChange fch=ChangeOfVersion) const
Definition: DFAgent.cpp:353
header file for DFAgent.cpp
A DFAgent contains all the information concerning the structure of the data flow. ...
Definition: DFAgent.h:71
A Shared Frame Pointer.
Definition: Frame.h:597
EModel
Model for FrameIO.
Definition: ConfAgent.h:69
virtual Short_t GetCheckLevel() const
Definition: Frame.h:123
virtual void Reset()=0
Reset the current frame.
virtual Bool_t LinkSubFrame(UInt_t, Frame *)
Attach the sub-frame corresponding to the given subkey # to the Frame given in the second argument...
Definition: Frame.h:251
Bool_t IsZombie() const
Check if this trigger is in fired state.
Definition: Trigger.h:114
void Zombie(Bool_t b=true)
this trigger
Definition: Trigger.h:118
virtual Frame * SetFrame(Frame *)
change the frame, returns the current one
Definition: Frame.cpp:275
Base class for a trigger on a data flow.
Definition: Trigger.h:155
AgataFrameTrigger(const Char_t *trig_name)
Definition: Trigger.h:465
virtual void SetCheckLevel(Short_t checklevel)
The number of tests (and the speed !) once writing/reading in Frame increase with this level...
Definition: Frame.h:120
virtual void SetKeyChangeFunction(PF_FactoryItemChange pf)
Definition: Frame.h:634
virtual UInt_t GetNbInputFrame() const
number of input frames that define this trigger
Definition: Trigger.h:331
virtual SharedFP * AddAutoConf(const FactoryItem &key_item, const FactoryItem &frame_item, UInt_t which)
Add a configuration frame to the input frame #which.
Definition: Trigger.cpp:690
LogMessage & dolog(LogMessage &)
virtual Bool_t IsASubFrame(const Frame &)
to check if a subframe could be added to the composite frame
Definition: Frame.h:235
virtual Frame * GetEmbeddedOutputFrame(ConfAgent::EModel model=ConfAgent::kStrict)
In case the output frame should be embedded.
Definition: Trigger.cpp:486
virtual SharedFP * AddUtility(const FactoryItem &key_item, const FactoryItem &frame_item, const ConfAgent *agent)
Add utilities, used to decode/encode composite frames.
Definition: Trigger.cpp:936
virtual UInt_t Scan()
Scan this Frame. If it is a composite frame, it looks for the keys of sub-frames. ...
Definition: Frame.h:219
virtual Bool_t AddSubFrame(const Frame &)
Add a subframe to that frame (only if composite)
Definition: Frame.h:242
virtual std::string & GetProcessName()
To get the Process name.
Base class for a DataInterface.
Definition: GObject.h:340
static MainKeyFactory & theMainFactory()
the main (global) keyfactory
Definition: KeyFactory.cpp:150
header file for FrameFactory.cpp
virtual UInt_t GetNbSubFrame() const
Returns the number of sub-frames composing this frame. Scan have to be called first.
Definition: Frame.h:228
virtual Bool_t CheckConf()
Check if the currently read key fired this trigger. If yes, IsFired is true.
Definition: Trigger.cpp:718
virtual Key * New(const FactoryItem &)
build a key using item.
Definition: KeyFactory.cpp:155
FactoryItem WhichKnownFrame(const FactoryItem &kit, const FactoryItem &fit, PF_FactoryItemChange kch=ChangeOfVersion, PF_FactoryItemChange fch=ChangeOfVersion) const
To get the exact definition of a key and a Frame.
Definition: DFAgent.cpp:370
virtual Bool_t IsAKey(const Key *akey) const
Compares two keys.
Definition: Key.h:217
const PF_FactoryItemChange & GetFrameChangeFunction() const
Definition: Frame.h:649
Base class that described an item in a Factory.
Definition: FactoryItem.h:52
LogMessage & warning(LogMessage &)
const FactoryItem & GetSignature() const
Signature of that frame.
Definition: Frame.h:127
virtual GObject * Global()
Definition: GObject.h:353