Skip to content

Commit 0dd66e3

Browse files
ChristianTackeGSIdennisklein
authored andcommitted
chore(parbase): Refactor print/close
1 parent 6adb758 commit 0dd66e3

4 files changed

Lines changed: 30 additions & 31 deletions

File tree

fairroot/parbase/FairParAsciiFileIo.cxx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
///////////////////////////////////////////////////////////////////////////////
2020
#include "FairParAsciiFileIo.h"
2121

22-
#include "FairDetParIo.h" // for FairDetParIo
2322
#include "FairGenericParAsciiFileIo.h"
2423
#include "FairRuntimeDb.h" // for FairRuntimeDb
2524

@@ -135,25 +134,16 @@ void FairParAsciiFileIo::close()
135134
file->close();
136135
delete file;
137136
file = 0;
138-
filename = "";
139-
}
140-
if (detParIoList) {
141-
detParIoList->Delete();
142137
}
138+
FairParIo::close();
143139
}
144140

145141
void FairParAsciiFileIo::print()
146142
{
147143
// prints information about the file and the detector I/Os
148144
if (check()) {
149145
cout << "Ascii I/O " << filename << " is open\n";
150-
TIter next(detParIoList);
151-
FairDetParIo* io;
152-
cout << "detector I/Os: ";
153-
while ((io = static_cast<FairDetParIo*>(next()))) {
154-
cout << " " << io->GetName();
155-
}
156-
cout << '\n';
146+
FairParIo::print();
157147
} else {
158148
cout << "No file open\n";
159149
}

fairroot/parbase/FairParIo.cxx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <TCollection.h> // for TIter
2424
#include <TList.h> // for TList
25+
#include <iostream>
2526

2627
FairParIo::FairParIo()
2728
: TObject()
@@ -40,7 +41,6 @@ FairParIo::~FairParIo()
4041
if (detParIoList) {
4142
detParIoList->Delete();
4243
delete detParIoList;
43-
detParIoList = 0;
4444
}
4545
}
4646

@@ -76,5 +76,23 @@ void FairParIo::removeDetParIo(Text_t* detName)
7676
// removes input/output class for a detector
7777
TObject* p = detParIoList->FindObject(detName);
7878
delete p;
79-
p = 0;
79+
}
80+
81+
void FairParIo::close()
82+
{
83+
filename = "";
84+
if (detParIoList) {
85+
detParIoList->Delete();
86+
}
87+
}
88+
89+
void FairParIo::print()
90+
{
91+
TIter next(detParIoList);
92+
FairDetParIo* io;
93+
std::cout << "detector I/Os: ";
94+
while ((io = static_cast<FairDetParIo*>(next()))) {
95+
std::cout << " " << io->GetName();
96+
}
97+
std::cout << '\n';
8098
}

fairroot/parbase/FairParIo.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -9,12 +9,12 @@
99
#define FAIRPARIO_H
1010

1111
#include <Rtypes.h> // for Bool_t, Text_t, etc
12+
#include <TList.h> // for TList
1213
#include <TObject.h> // for TObject
1314
#include <TString.h> // for TString
1415

1516
class FairDetParIo;
1617
class FairRtdbRun;
17-
class TList;
1818

1919
class FairParIo : public TObject
2020
{
@@ -25,12 +25,12 @@ class FairParIo : public TObject
2525

2626
public:
2727
FairParIo();
28-
virtual ~FairParIo();
28+
~FairParIo() override;
2929
virtual FairDetParIo* getDetParIo(const Text_t*);
3030
virtual void setDetParIo(FairDetParIo*);
3131
virtual void removeDetParIo(Text_t*);
3232
void setInputNumber(Int_t);
33-
virtual void close() { ; }
33+
virtual void close();
3434

3535
// returns the filename
3636
const char* getFilename() { return filename.Data(); }
@@ -41,7 +41,7 @@ class FairParIo : public TObject
4141
virtual void setDetParIo(Text_t*) { ; }
4242

4343
// prints information about input/output
44-
virtual void print() { ; }
44+
virtual void print();
4545

4646
// checks if the input/output is open
4747
virtual Bool_t check() { return kFALSE; }
@@ -51,7 +51,7 @@ class FairParIo : public TObject
5151

5252
// sets global file pointer in ROOT if input/output is a ROOT-file
5353
// (code in FairParRootFileIo)
54-
virtual void cd() { ; }
54+
virtual void cd() {}
5555

5656
// set and get for flag autoWritable
5757
void setAutoWritable(Bool_t f = kTRUE) { autoWritable = f; }

fairroot/parbase/FairParRootFileIo.cxx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
//////////////////////////////////////////////////////////////////////////////
2525
#include "FairParRootFileIo.h"
2626

27-
#include "FairDetParIo.h" // for FairDetParIo
2827
#include "FairGenericParRootFileIo.h"
2928
#include "FairRtdbRun.h" // for FairRtdbRun
3029
#include "FairRuntimeDb.h" // for FairRuntimeDb
@@ -260,24 +259,16 @@ void FairParRootFileIo::close()
260259
delete file;
261260
file = 0;
262261
}
263-
if (detParIoList) {
264-
detParIoList->Delete();
265-
}
262+
FairParIo::close();
266263
}
267264

268265
void FairParRootFileIo::print()
269266
{
270267
// prints the content of a open ROOT file and the list of detector I/Os
271268
if (file) {
272269
file->ls();
273-
TIter next(detParIoList);
274-
FairDetParIo* io;
275270
cout << "Root file I/O " << file->GetName() << " is open\n";
276-
cout << "detector I/Os: ";
277-
while ((io = static_cast<FairDetParIo*>(next()))) {
278-
cout << " " << io->GetName();
279-
}
280-
cout << '\n';
271+
FairParIo::print();
281272
} else {
282273
cout << "No ROOT file open\n";
283274
}

0 commit comments

Comments
 (0)