|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// \file ErrorMergerSpec.cxx |
| 13 | +/// \brief Implementation of a data processor to merge the processing errors in one single output |
| 14 | +/// |
| 15 | +/// \author Philippe Pillot, Subatech |
| 16 | + |
| 17 | +#include "ErrorMergerSpec.h" |
| 18 | + |
| 19 | +#include <vector> |
| 20 | + |
| 21 | +#include <gsl/span> |
| 22 | + |
| 23 | +#include "Framework/ConfigParamSpec.h" |
| 24 | +#include "Framework/InitContext.h" |
| 25 | +#include "Framework/InputSpec.h" |
| 26 | +#include "Framework/Lifetime.h" |
| 27 | +#include "Framework/OutputRef.h" |
| 28 | +#include "Framework/OutputSpec.h" |
| 29 | +#include "Framework/ProcessingContext.h" |
| 30 | +#include "Framework/Task.h" |
| 31 | + |
| 32 | +#include "MCHBase/Error.h" |
| 33 | + |
| 34 | +namespace o2 |
| 35 | +{ |
| 36 | +namespace mch |
| 37 | +{ |
| 38 | + |
| 39 | +using namespace o2::framework; |
| 40 | + |
| 41 | +class ErrorMergerTask |
| 42 | +{ |
| 43 | + public: |
| 44 | + //_________________________________________________________________________________________________ |
| 45 | + /// constructor |
| 46 | + ErrorMergerTask(bool preclustering, bool clustering, bool tracking) |
| 47 | + : mPreclustering{preclustering}, |
| 48 | + mClustering{clustering}, |
| 49 | + mTracking{tracking} {} |
| 50 | + |
| 51 | + //_________________________________________________________________________________________________ |
| 52 | + /// prepare the error merger |
| 53 | + void init(InitContext& ic) {} |
| 54 | + |
| 55 | + //_________________________________________________________________________________________________ |
| 56 | + /// run the error merger |
| 57 | + void run(ProcessingContext& pc) |
| 58 | + { |
| 59 | + auto& errors = pc.outputs().make<std::vector<Error>>(OutputRef{"errors"}); |
| 60 | + |
| 61 | + if (mPreclustering) { |
| 62 | + auto preclusteringErrors = pc.inputs().get<gsl::span<Error>>("preclustererrors"); |
| 63 | + errors.insert(errors.end(), preclusteringErrors.begin(), preclusteringErrors.end()); |
| 64 | + } |
| 65 | + |
| 66 | + if (mClustering) { |
| 67 | + auto clusteringErrors = pc.inputs().get<gsl::span<Error>>("clustererrors"); |
| 68 | + errors.insert(errors.end(), clusteringErrors.begin(), clusteringErrors.end()); |
| 69 | + } |
| 70 | + |
| 71 | + if (mTracking) { |
| 72 | + auto trackingErrors = pc.inputs().get<gsl::span<Error>>("trackerrors"); |
| 73 | + errors.insert(errors.end(), trackingErrors.begin(), trackingErrors.end()); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + private: |
| 78 | + bool mPreclustering = true; ///< add preclustering errors |
| 79 | + bool mClustering = true; ///< add clustering errors |
| 80 | + bool mTracking = true; ///< add tracking errors |
| 81 | +}; |
| 82 | + |
| 83 | +//_________________________________________________________________________________________________ |
| 84 | +DataProcessorSpec getErrorMergerSpec(const char* specName, bool preclustering, bool clustering, bool tracking) |
| 85 | +{ |
| 86 | + std::vector<InputSpec> inputSpecs{}; |
| 87 | + if (preclustering) { |
| 88 | + inputSpecs.emplace_back(InputSpec{"preclustererrors", "MCH", "PRECLUSTERERRORS", 0, Lifetime::Timeframe}); |
| 89 | + } |
| 90 | + if (clustering) { |
| 91 | + inputSpecs.emplace_back(InputSpec{"clustererrors", "MCH", "CLUSTERERRORS", 0, Lifetime::Timeframe}); |
| 92 | + } |
| 93 | + if (tracking) { |
| 94 | + inputSpecs.emplace_back(InputSpec{"trackerrors", "MCH", "TRACKERRORS", 0, Lifetime::Timeframe}); |
| 95 | + } |
| 96 | + |
| 97 | + return DataProcessorSpec{ |
| 98 | + specName, |
| 99 | + inputSpecs, |
| 100 | + Outputs{OutputSpec{{"errors"}, "MCH", "ERRORS", 0, Lifetime::Timeframe}}, |
| 101 | + adaptFromTask<ErrorMergerTask>(preclustering, clustering, tracking), |
| 102 | + Options{}}; |
| 103 | +} |
| 104 | + |
| 105 | +} // namespace mch |
| 106 | +} // namespace o2 |
0 commit comments