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))
18#include <atomic>
19#include <memory>
20#include <TFile.h>
21
22using namespace o2::gpu;
23
24std::weak_ptr<GPUROOTDumpCore> GPUROOTDumpCore::sInstance;
25std::atomic_flag GPUROOTDumpBase::mMutex = ATOMIC_FLAG_INIT;
26
27GPUROOTDumpCore::GPUROOTDumpCore(GPUROOTDumpCore::GPUROOTDumpCorePrivate)
28{
29}
30
32{
33 if (mFile) {
34 mFile->cd();
35 for (uint32_t i = 0; i < mBranches.size(); i++) {
36 mBranches[i]->write();
37 }
38 mFile->Close();
39 }
40}
41
42std::shared_ptr<GPUROOTDumpCore> GPUROOTDumpCore::getAndCreate(const char* filename)
43{
44 static std::atomic_flag lock = ATOMIC_FLAG_INIT;
45 while (lock.test_and_set(std::memory_order_acquire)) {
46 }
47 std::shared_ptr<GPUROOTDumpCore> retVal = sInstance.lock();
48 if (!retVal) {
49 retVal = std::make_shared<GPUROOTDumpCore>(GPUROOTDumpCorePrivate());
50 sInstance = retVal;
51 }
52 if (*filename != 0 && retVal->mFileName != "" && retVal->mFileName != filename) {
53 throw std::runtime_error("GPUROOTDump reinitialized with different file name");
54 }
55 retVal->mFileName = filename;
56 lock.clear(std::memory_order_release);
57 return retVal;
58}
59
61{
62 std::shared_ptr<GPUROOTDumpCore> p = GPUROOTDumpCore::get().lock();
63 if (!p) {
64 throw std::runtime_error("No instance of GPUROOTDumpCore exists");
65 }
66 p->mBranches.emplace_back(this);
67 if (!p->mFile) {
68 if (p->mFileName == "") {
69 throw std::runtime_error("GPUROOTDump output file name not set");
70 }
71 std::remove(p->mFileName.c_str());
72 p->mFile.reset(new TFile(p->mFileName.c_str(), "recreate"));
73 }
74 p->mFile->cd();
75}
76
77#endif
int32_t i
int32_t retVal
static std::atomic_flag mMutex
GPUROOTDumpCore(const GPUROOTDumpCore &)=delete
std::string filename()