|
| 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 | +/// |
| 13 | +/// \file HelperGraph.h |
| 14 | +/// \author Jakub Muszyński jakub.milosz.muszynski@cern.ch |
| 15 | +/// \brief Graph helper |
| 16 | + |
| 17 | +#ifndef QC_MODULE_FIT_FITHELPERGRAPH_H |
| 18 | +#define QC_MODULE_FIT_FITHELPERGRAPH_H |
| 19 | + |
| 20 | +#include <memory> |
| 21 | +#include <string> |
| 22 | +#include <type_traits> |
| 23 | + |
| 24 | +#include <TGraph.h> |
| 25 | +#include "QualityControl/QcInfoLogger.h" |
| 26 | + |
| 27 | +namespace o2::quality_control_modules::fit::helper |
| 28 | +{ |
| 29 | + |
| 30 | +/// \brief Factory that forwards ctor arguments to the chosen GraphType. |
| 31 | +/// Example: |
| 32 | +/// auto g = makeGraph<TGraphErrors>("name","title",n,x,y,ex,ey); |
| 33 | +/// \author Jakub Muszyński jakub.milosz.muszynski@cern.ch |
| 34 | +template <typename GraphType, typename... CtorArgs> |
| 35 | +inline auto makeGraph(const std::string& name, |
| 36 | + const std::string& title, |
| 37 | + CtorArgs&&... args) |
| 38 | +{ |
| 39 | + static_assert(std::is_base_of_v<TObject, GraphType>, |
| 40 | + "GraphType must inherit from TObject / ROOT graph class"); |
| 41 | + auto ptr = std::make_unique<GraphType>(std::forward<CtorArgs>(args)...); |
| 42 | + ptr->SetNameTitle(name.c_str(), title.c_str()); |
| 43 | + return ptr; |
| 44 | +} |
| 45 | + |
| 46 | +/// \brief Publishes graph through the QC ObjectsManager. |
| 47 | +/// \author Jakub Muszyński jakub.milosz.muszynski@cern.ch |
| 48 | +template <typename GraphType, |
| 49 | + typename ManagerType, |
| 50 | + typename PublicationPolicyType, |
| 51 | + typename... CtorArgs> |
| 52 | +inline auto registerGraph(ManagerType manager, |
| 53 | + PublicationPolicyType publicationPolicy, |
| 54 | + const std::string& defaultDrawOption, |
| 55 | + const std::string& name, |
| 56 | + const std::string& title, |
| 57 | + CtorArgs&&... args) |
| 58 | +{ |
| 59 | + auto ptrGraph = makeGraph<GraphType>(name, title, |
| 60 | + std::forward<CtorArgs>(args)...); |
| 61 | + manager->startPublishing(ptrGraph.get(), publicationPolicy); |
| 62 | + |
| 63 | + if (!defaultDrawOption.empty()) { |
| 64 | + manager->setDefaultDrawOptions(ptrGraph.get(), defaultDrawOption); |
| 65 | + } |
| 66 | + ILOG(Info, Support) << "Registered graph \"" << name |
| 67 | + << "\" with publication policy " << int(publicationPolicy) |
| 68 | + << ENDM; |
| 69 | + return ptrGraph; |
| 70 | +} |
| 71 | + |
| 72 | +} // namespace o2::quality_control_modules::fit::helper |
| 73 | +#endif // QC_MODULE_FIT_FITHELPERGRAPH_H |
0 commit comments