]>
Commit | Line | Data |
---|---|---|
4ff26233 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | //______________________________________________________________________________ | |
17 | // Producer task that exchanges data with other task using exchange containers | |
18 | //______________________________________________________________________________ | |
19 | // | |
20 | #include "TaskExchange.h" | |
21 | ||
22 | #include "AliAnalysisManager.h" | |
23 | #include "TList.h" | |
24 | #include "TObjArray.h" | |
25 | ||
26 | ClassImp(TaskProducer) | |
27 | ||
28 | //________________________________________________________________________ | |
29 | TaskProducer::TaskProducer() // All data members should be initialised here | |
30 | :AliAnalysisTaskSE(), | |
31 | fOutput(0), | |
32 | fExchangedData(0) | |
33 | { | |
34 | // Dummy constructor ALWAYS needed for I/O. | |
35 | } | |
36 | ||
37 | //________________________________________________________________________ | |
38 | TaskProducer::TaskProducer(const char *name) // All data members should be initialised here | |
39 | :AliAnalysisTaskSE(name), | |
40 | fOutput(0), | |
41 | fExchangedData(0) | |
42 | { | |
43 | // Constructor | |
44 | // Define input and output slots here (never in the dummy constructor) | |
45 | // Input slot #0 works with a TChain - it is connected to the default input container | |
46 | ||
47 | // Output slot #1 used to publish the task private data | |
48 | DefineOutput(1, TList::Class()); | |
49 | ||
50 | // Output slot #2 used to publish the exchanged data | |
51 | DefineOutput(2, TObjArray::Class()); // Type can be anything else | |
52 | } | |
53 | ||
54 | //________________________________________________________________________ | |
55 | TaskProducer::~TaskProducer() | |
56 | { | |
57 | // Destructor. Clean-up the output list, but not the histograms that are put inside | |
58 | // (the list is owner and will clean-up these histograms). Protect in PROOF case. | |
59 | if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) { | |
60 | delete fOutput; | |
61 | } | |
62 | delete fExchangedData; | |
63 | } | |
64 | ||
65 | //________________________________________________________________________ | |
66 | void TaskProducer::UserCreateOutputObjects() | |
67 | { | |
68 | // Create histograms | |
69 | // Called once (on the worker node) | |
70 | ||
71 | fOutput = new TList(); | |
72 | fOutput->SetOwner(); // IMPORTANT! | |
73 | ||
74 | // fOutput->Add(fHistPt); | |
75 | // fOutput->Add(fHistEta); | |
76 | // NEW HISTO added to fOutput here | |
77 | ||
78 | // Data to be exchanged can be initialized here, but updated in UserExec | |
79 | fExchangedData = new TObjArray(); | |
80 | fExchangedData->SetOwner(); | |
81 | ||
82 | PostData(1, fOutput); // Post data for ALL output slots >0 here, to get at least an empty histogram | |
83 | // Do NOT post data for the exchange containers ! | |
84 | // PostData(2, fExchangedData); | |
85 | } | |
86 | ||
87 | //________________________________________________________________________ | |
88 | void TaskProducer::UserExec(Option_t *) | |
89 | { | |
90 | // Main loop | |
91 | // Called for each event | |
92 | ||
93 | //Here we fill the private output | |
94 | // ... | |
95 | PostData(1, fOutput); | |
96 | ||
97 | // And publish the exchanged data | |
98 | fExchangedData->Delete(); | |
99 | TNamed *data = new TNamed(Form("<data by %s, ev. %d>", GetName(), fEntry), ""); | |
100 | fExchangedData->Add(data); | |
101 | PostData(2, fExchangedData); | |
102 | Printf(" -- %s published: %s", GetName(), data->GetName()); | |
103 | } | |
104 | ||
105 | //______________________________________________________________________________ | |
106 | // Consumer task reading data produced by other task | |
107 | //______________________________________________________________________________ | |
108 | // | |
109 | ClassImp(TaskConsumer) | |
110 | ||
111 | //________________________________________________________________________ | |
112 | TaskConsumer::TaskConsumer() // All data members should be initialised here | |
113 | :AliAnalysisTaskSE(), | |
114 | fOutput(0), | |
115 | fImported1(0), | |
116 | fImported2(0) | |
117 | { | |
118 | // Dummy constructor ALWAYS needed for I/O. | |
119 | } | |
120 | ||
121 | //________________________________________________________________________ | |
122 | TaskConsumer::TaskConsumer(const char *name) // All data members should be initialised here | |
123 | :AliAnalysisTaskSE(name), | |
124 | fOutput(0), | |
125 | fImported1(0), | |
126 | fImported2(0) | |
127 | { | |
128 | // Constructor | |
129 | // Define input and output slots here (never in the dummy constructor) | |
130 | // Input slot #0 works with a TChain - it is connected to the default input container | |
131 | ||
132 | // Input slot #1 reads from an exchange container | |
133 | DefineInput(1, TObjArray::Class()); | |
134 | // Input slot #2 reads from an exchange container | |
135 | DefineInput(2, TObjArray::Class()); | |
136 | ||
137 | // Output slot #0 is reserved | |
138 | // Output slot #1 used to publish the task private data | |
139 | DefineOutput(1, TList::Class()); | |
140 | } | |
141 | ||
142 | //________________________________________________________________________ | |
143 | TaskConsumer::~TaskConsumer() | |
144 | { | |
145 | // Destructor. Clean-up the output list, but not the histograms that are put inside | |
146 | // (the list is owner and will clean-up these histograms). Protect in PROOF case. | |
147 | if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) { | |
148 | delete fOutput; | |
149 | } | |
150 | // Do not delete the imported data - we are not owners | |
151 | } | |
152 | ||
153 | //________________________________________________________________________ | |
154 | void TaskConsumer::UserCreateOutputObjects() | |
155 | { | |
156 | // Create histograms | |
157 | // Called once (on the worker node) | |
158 | ||
159 | fOutput = new TList(); | |
160 | fOutput->SetOwner(); // IMPORTANT! | |
161 | ||
162 | // fOutput->Add(fHistPt); | |
163 | // fOutput->Add(fHistEta); | |
164 | // NEW HISTO added to fOutput here | |
165 | ||
166 | PostData(1, fOutput); // Post data for ALL output slots >0 here, to get at least an empty histogram | |
167 | } | |
168 | ||
169 | //________________________________________________________________________ | |
170 | void TaskConsumer::UserExec(Option_t *) | |
171 | { | |
172 | // Main loop | |
173 | // Called for each event | |
174 | // This is how we get the actual exchange data | |
175 | TObjArray *exchange1 = (TObjArray*)GetInputData(1); | |
176 | if (!exchange1) { | |
177 | Error("UserExec", "Task %s could not read the exchanged data for slot 1", GetName()); | |
178 | return; | |
179 | } | |
180 | fImported1 = (TNamed*)exchange1->At(0); | |
181 | TObjArray *exchange2 = (TObjArray*)GetInputData(1); | |
182 | if (!exchange2) { | |
183 | Error("UserExec", "Task %s could not read the exchanged data for slot 2", GetName()); | |
184 | return; | |
185 | } | |
186 | fImported2 = (TNamed*)exchange2->At(0); | |
187 | Printf(" -- imported: %s and %s", fImported1->GetName(), fImported2->GetName()); | |
188 | ||
189 | //Here we fill the private output | |
190 | // ... | |
191 | PostData(1, fOutput); | |
192 | } |