Project
Loading...
Searching...
No Matches
GPUROOTDumpCore.cxx
Go to the documentation of this file.
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
14
15#include "GPUROOTDumpCore.h"
16
17#if (!defined(GPUCA_STANDALONE) || defined(GPUCA_BUILD_QA)) && !defined(GPUCA_GPUCODE)
18#include <atomic>
19#include <memory>
20#include <TFile.h>
21
22using namespace o2::gpu;
23
24std::weak_ptr<GPUROOTDumpCore> GPUROOTDumpCore::sInstance;
25
26GPUROOTDumpCore::GPUROOTDumpCore(GPUROOTDumpCore::GPUROOTDumpCorePrivate)
27{
28}
29
31{
32 if (mFile) {
33 for (uint32_t i = 0; i < mBranches.size(); i++) {
34 mBranches[i]->write();
35 }
36 mFile->Close();
37 }
38}
39
40std::shared_ptr<GPUROOTDumpCore> GPUROOTDumpCore::getAndCreate()
41{
42 static std::atomic_flag lock = ATOMIC_FLAG_INIT;
43 while (lock.test_and_set(std::memory_order_acquire)) {
44 }
45 std::shared_ptr<GPUROOTDumpCore> retVal = sInstance.lock();
46 if (!retVal) {
47 retVal = std::make_shared<GPUROOTDumpCore>(GPUROOTDumpCorePrivate());
48 sInstance = retVal;
49 }
50 lock.clear(std::memory_order_release);
51 return retVal;
52}
53
55{
56 std::shared_ptr<GPUROOTDumpCore> p = GPUROOTDumpCore::get().lock();
57 if (!p) {
58 throw std::runtime_error("No instance of GPUROOTDumpCore exists");
59 }
60 p->mBranches.emplace_back(this);
61 if (!p->mFile) {
62 std::remove("gpudebug.root");
63 p->mFile.reset(new TFile("gpudebug.root", "recreate"));
64 }
65 p->mFile->cd();
66}
67
68#endif
int32_t i
int32_t retVal
GPUROOTDumpCore(const GPUROOTDumpCore &)=delete