1 |
pam-fi |
1.1 |
/* |
2 |
|
|
* CollectionAction.h |
3 |
|
|
* |
4 |
|
|
* Created on: 13-mag-2009 |
5 |
|
|
* Author: Nicola Mori |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
/*! @file CollectionAction.h The CollectionAction class definition file */ |
9 |
|
|
|
10 |
|
|
#ifndef COLLECTIONACTION_H_ |
11 |
|
|
#define COLLECTIONACTION_H_ |
12 |
|
|
|
13 |
|
|
#include <PamLevel2.h> |
14 |
pam-fi |
1.3 |
#include "../../CommonDefs.h" |
15 |
pam-fi |
1.1 |
|
16 |
|
|
/*! @brief An abstract class that defines the interface of a generic collection action. |
17 |
|
|
* |
18 |
|
|
* The CollectionAction abstract class defines an interface for a generic action object |
19 |
|
|
* which can be used to implement common actions that can be done by collections, like |
20 |
|
|
* filling histograms or saving selected events. The structure of this class mimicks that |
21 |
|
|
* of a standard collection: it has a Setup() and a Finalize() methods that are meant |
22 |
|
|
* to be called at the beginning and at the end of the selection procedure, respectively. In |
23 |
|
|
* Setup() one can prepare the analysis actions like instantiating a histogram object (this |
24 |
|
|
* can be done also in the constructor), while in Finalize() the analysis can be closed by, |
25 |
|
|
* eg., writing histograms on a file and closing that file. |
26 |
|
|
* The two methods OnGood() and OnBad() have exactly the same purpose they have in a |
27 |
|
|
* Collection: to define action to perform each time an event is selected as good or bad. |
28 |
|
|
* The class SmartCollection is specially designed to handle CollectionAction objects: see |
29 |
|
|
* the documentation of SmartCollection for info on how these objects are handled. |
30 |
|
|
*/ |
31 |
|
|
class CollectionAction { |
32 |
|
|
public: |
33 |
|
|
|
34 |
|
|
/*! @brief Constructor. |
35 |
|
|
* |
36 |
|
|
* @param actionName The action's name. |
37 |
|
|
*/ |
38 |
|
|
CollectionAction(const char *actionName) : |
39 |
|
|
_actionName(actionName) { |
40 |
|
|
} |
41 |
|
|
/*! @brief Destructor. */ |
42 |
pam-fi |
1.2 |
virtual ~CollectionAction() { |
43 |
|
|
|
44 |
pam-fi |
1.1 |
} |
45 |
|
|
|
46 |
|
|
/*! @brief The initialization routine. |
47 |
|
|
* |
48 |
|
|
* In this routine the initialization procedure is to be defined. SmartCollection objects will call |
49 |
|
|
* Setup() for each CollectionAction object they hold during SmartCollection::Setup(). |
50 |
|
|
* This method is intended for some possible post-constructor initialization, like those who |
51 |
|
|
* need to know the PamLevel2 object (eg., clone trees selection). This method is likely to be |
52 |
|
|
* unnecessary most of the times, so it is implemented as a void function and it's not pure virtual. |
53 |
|
|
* |
54 |
|
|
* @param events The PamLevel2 events which will be analyzed by the collection hosting the action. |
55 |
|
|
*/ |
56 |
|
|
virtual void Setup(PamLevel2 *events) { |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
/*! @brief Routine for selected events. |
60 |
|
|
* |
61 |
|
|
* The concrete implementations define what to do when an event is selected. This is conceptually the |
62 |
|
|
* same as PamCut::OnGood(). Call to this method is automatically done in SmartCollection::OnGood(). |
63 |
|
|
* |
64 |
|
|
* @param event The selected event. |
65 |
|
|
*/ |
66 |
|
|
virtual void OnGood(PamLevel2 *event) = 0; |
67 |
|
|
|
68 |
|
|
/*! @brief Routine for discarded events. |
69 |
|
|
* |
70 |
|
|
* The concrete implementations define what to do when an event is discarded. This is conceptually the |
71 |
|
|
* same as PamCut::OnBad(). Call to this method is automatically done in SmartCollection::OnBad(). This |
72 |
|
|
* method is not pure virtual, since many times there's nothing to do when a cut fails; this way, it's not |
73 |
|
|
* necessary to implement it in derived classes. Current implementation is void. |
74 |
|
|
* |
75 |
|
|
* @param event The selected event. |
76 |
|
|
* @param selectionResult The code describing the reason of cut's failure (collections will automatically pass |
77 |
|
|
* the index of the failed cut as selectionResult). |
78 |
|
|
*/ |
79 |
|
|
virtual void OnBad(PamLevel2 *event, int selectionResult) { |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
/*! @brief The finalization routine. |
83 |
|
|
* |
84 |
|
|
* This method is intended to be called at the end of the analysis. Its implementations contain the finalizing |
85 |
|
|
* procedures, like writing histograms to file or printing reports. It is automatically called by SmartCollection::Finalize(). |
86 |
|
|
*/ |
87 |
|
|
virtual void Finalize() = 0; |
88 |
|
|
|
89 |
pam-fi |
1.2 |
/*! @brief Returns the action name. */ |
90 |
|
|
const char *GetName(){ |
91 |
|
|
return _actionName; |
92 |
|
|
} |
93 |
|
|
|
94 |
pam-fi |
1.1 |
private: |
95 |
|
|
const char* _actionName; |
96 |
|
|
}; |
97 |
|
|
|
98 |
|
|
#endif /* COLLECTIONACTION_H_ */ |