/[PAMELA software]/PamCut/Collections/SmartCollection/SmartCollection.h
ViewVC logotype

Diff of /PamCut/Collections/SmartCollection/SmartCollection.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by pam-fi, Fri May 29 10:10:31 2009 UTC revision 1.7.2.1 by pam-fi, Tue Apr 10 09:40:00 2012 UTC
# Line 15  Line 15 
15    
16  /*! @brief A collection class designed to use CollectionAction objects.  /*! @brief A collection class designed to use CollectionAction objects.
17   *   *
18   * The SmartCollection class is designed to handle CollectionAction objects. These   * The SmartCollection class is designed to handle CollectionAction objects. It
19   * defines the procedures to do when an event is selected or discarded. A SmartCollection   * holds a vector of these objects and takes care of calling Setup and Finalize for
20   * handles a vector of these objects, calling CollectionAction::OnGood() for each of them   * each of them at the beginning and at the end of the analysis, respectively.
21   * when a good event is selected and CollectionAction::OnBad() when a bad one is rejected.   * Actions can be added to the SmartCollection by means of the AddAction() method.
22   * It will also call the CollectionAction::Setup() and CollectionAction::Finalize() methods   * If a bunch of cuts have been already added to the collection, the action will
23   * at the beginning and at the end of the analysis, respectively.   * be logically placed after the cuts. The SmartCollection will call
24     * CollectionAction::OnGood() if the cuts preceding the actions are satisfied, and
25     * CollectionAction::OnBad() if at least one of them fails. An action will not be
26     * sensitive to cuts added to the collection after the action itself.
27     * The resulting structure is composed by bunches of cuts intertwined by actions,
28     * which are "executed" depending on the result of the bunch of cuts that precedes the
29     * action. Note that CollectionAction::OnBad() is called only for those actions at
30     * the end of the bunch where the first failed cut is: if after these actions there
31     * are other bunches of cuts and actions, they will be ignored.
32     * For example, in the sequence below:
33   *   *
34     * | cut1 | cut2 | action1 | action2 | cut3 | cut4 | action3 | ...
35     *
36     * action1 and action2 are executed (eg., OnGood is called for them) if cut1 and cut2
37     * are both satisfied, then cut3 and cut4 are evaluated and if both of them are satisfied
38     * then action3 is executed. If, for example, cut 1 or cut2 fail, then OnBad is called for
39     * action1 and action2; however, cut3, cut4, action3 and all that follows are ignored. The
40     * analysis goes on with the next event.
41   */   */
42  class SmartCollection: public PamCutCollection {  class SmartCollection: public PamCutCollection {
43    
# Line 30  public: Line 46  public:
46    /*! @brief Constructor.    /*! @brief Constructor.
47     *     *
48     * @param collectionName The collection's name.     * @param collectionName The collection's name.
49       * @param owns If true, the collection will own the cuts and the actions, ie., it will
50       *             destroy them in its destructor.
51     */     */
52    SmartCollection(const char* collectionName) :    SmartCollection(const char* collectionName, bool owns = true) :
53      PamCutCollection(collectionName), _actions(0) {        PamCutCollection(collectionName, owns), _actions(0) {
54    }    }
55    
56    /*! @brief Destructor. */    /*! @brief Destructor. */
57    ~SmartCollection() {    ~SmartCollection();
   }  
58    
59    /*! @brief Adds an action to the SmartCollection */    /*! @brief Adds an action to the SmartCollection */
60    virtual void AddAction(CollectionAction& action);    virtual void AddAction(CollectionAction *action);
61    
62    /*! @brief Returns the iAction-th action.    /*! @brief Returns the iAction-th action.
63     *     *
# Line 50  public: Line 67  public:
67     */     */
68    CollectionAction *GetAction(unsigned int iAction);    CollectionAction *GetAction(unsigned int iAction);
69    
70      /*! @brief Searches for an action by name.
71       *
72       * @param actionName The name of the action to search for.
73       * @return pointer to the desired action; NULL if the specified action cannot be found or if no actions are present.
74       */
75      CollectionAction *GetAction(const char *actionName);
76    
77      /*! @brief The number of actions in the collection.
78       *
79       * @return The number of actions currently in the collection.
80       */
81      unsigned int GetActionsSize() {
82        return _actions.size();
83      }
84    
85      /*! @brief The position of specified action.
86       *
87       * This method returns the position of the iAction-th action. For every action
88       * placed before the first cut this will return -1. Otherwise it will return the index
89       * of the cut preceding the action (eg., if action number 3 is after cut number 2,  GetActionPosition(3)
90       * will return 2)
91       *
92       * @param iAction The index of the action (0 = first action)
93       * @return The position of the specified action
94       */
95      int GetActionPosition(unsigned int iAction) {
96        return _actionsPositions[iAction];
97      }
98    
99    /*! @brief The pre-analysis task definition.    /*! @brief The pre-analysis task definition.
100     *     *
101     * This override of the Setup() method calls Setup() for the base class PamCutCollection, and subsequently for each     * This override of the Setup() method calls Setup() for the base class PamCutCollection, and subsequently for each
# Line 67  public: Line 113  public:
113     */     */
114    void Finalize();    void Finalize();
115    
116    /*! @brief Post-selection tasks.    /*! Applies the cuts and executes the actions.
    *  
    * This routine is automatically called after a good event has been selected by  
    * ApplyCut(). It will simply call PamCutCollection::OnGood() and then CollectionAction::OnGood() for each  
    * action in the SmartCollection.  
    * @param event The event which satisfy the cut.  
    */  
   void OnGood(PamLevel2 *event);  
   
   /*! @brief Post-selection tasks.  
117     *     *
118     * This routine is automatically called after a bad event has been rejected by     * When cuts are applied, a SmartCollection will also execute the actions at the end of the bunches of cuts.
    * ApplyCut(). It will simply call PamCutCollection::OnBad() and then CollectionAction::OnBad() for each  
    * action in the SmartCollection.  
119     *     *
120     * @see OnGood     * @param event The event to analyze.
    * @param event The event which don't satisfy the cut.  
    * @param selectionResult The return value of the Check() routine.  
121     */     */
122    void OnBad(PamLevel2 *event, int selectionResult);    int ApplyCut(PamLevel2 *event);
123    
124  private:  protected:
125    
126      /*! @brief The vector containing the actions */
127    std::vector<CollectionAction*> _actions;    std::vector<CollectionAction*> _actions;
128    
129      /*! The vector of actions' positions
130       *
131       * An action is placed after N cuts, so that the SmartCollection, after applying N cuts, has to
132       * perform the action. The numbers N for each action are stored here: the element i is N for the
133       * i-th action in #_actions.
134       */
135      std::vector<int> _actionsPositions;
136    
137  };  };
138    
139  #endif /* SMARTCOLLECTION_H_ */  #endif /* SMARTCOLLECTION_H_ */

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.7.2.1

  ViewVC Help
Powered by ViewVC 1.1.23