|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | +#include "Framework/runDataProcessing.h" |
| 11 | +#include "Framework/AnalysisTask.h" |
| 12 | +#include "Framework/AnalysisDataModel.h" |
| 13 | +#include "Analysis/configurableCut.h" |
| 14 | + |
| 15 | +using namespace o2; |
| 16 | +using namespace o2::framework; |
| 17 | +using namespace o2::framework::expressions; |
| 18 | + |
| 19 | +/// This task demonstrates how to use configurable to wrap classes |
| 20 | +/// use it with supplied configuration: "configurableObject.json" |
| 21 | + |
| 22 | +struct ConfigurableObjectDemo { |
| 23 | + Configurable<configurableCut> cut{"cut", {0.5, 1}, "generic cut"}; |
| 24 | + MutableConfigurable<configurableCut> mutable_cut{"mutable_cut", {1., 2}, "generic cut"}; |
| 25 | + void init(InitContext const&){}; |
| 26 | + void process(aod::Collision const&, aod::Tracks const& tracks) |
| 27 | + { |
| 28 | + LOGF(INFO, "Cut1: %.3f; Cut2: %.3f", cut, mutable_cut); |
| 29 | + for (auto& track : tracks) { |
| 30 | + if (track.globalIndex() % 500 == 0) { |
| 31 | + std::string decision1; |
| 32 | + std::string decision2; |
| 33 | + if (cut->method(std::abs(track.eta()))) { |
| 34 | + decision1 = "true"; |
| 35 | + } else { |
| 36 | + decision1 = "false"; |
| 37 | + } |
| 38 | + if (mutable_cut->method(std::abs(track.eta()))) { |
| 39 | + decision2 = "true"; |
| 40 | + } else { |
| 41 | + decision2 = "false"; |
| 42 | + } |
| 43 | + LOGF(INFO, "Cut1: %s; Cut2: %s", decision1, decision2); |
| 44 | + if (decision2 == "false") { |
| 45 | + mutable_cut->setState(-1); |
| 46 | + } else { |
| 47 | + mutable_cut->setState(1); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +WorkflowSpec defineDataProcessing(ConfigContext const&) |
| 55 | +{ |
| 56 | + return WorkflowSpec{ |
| 57 | + adaptAnalysisTask<ConfigurableObjectDemo>("configurable-demo")}; |
| 58 | +} |
0 commit comments