FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTestOutputHandler.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
9 
10 #include <fstream>
11 
13  : fFileName(filename)
14  , fFileContent()
15  , fFileContentIterator()
16  , fNumberOfLines(0)
17  , fFileAlreadyRead(false)
18 {}
19 
21  : fFileName()
22  , fFileContent()
23  , fFileContentIterator()
24  , fNumberOfLines(0)
25  , fFileAlreadyRead(false)
26 {}
27 
28 FairTestOutputHandler::~FairTestOutputHandler() { remove(fFileName.c_str()); }
29 
30 void FairTestOutputHandler::SetFileName(const std::string& filename)
31 {
32  fFileName = filename;
33  fFileContent.clear();
34  fNumberOfLines = 0;
35  fFileAlreadyRead = false;
36 }
37 
39 {
40  ReadContentFromFile();
41  return fNumberOfLines;
42 }
43 
44 void FairTestOutputHandler::ReadContentFromFile()
45 {
46  if (!fFileAlreadyRead) {
47  fFileContent.clear();
48  fNumberOfLines = 0;
49 
50  std::ifstream ifs(fFileName.c_str());
51  std::string line;
52 
53  while (getline(ifs, line)) {
54  fFileContent.push_back(line);
55  ++fNumberOfLines;
56  }
57  fFileAlreadyRead = true;
58  }
59 }
60 
62 {
63 
64  ReadContentFromFile();
65 
66  return fFileContent[line];
67 }
std::string GetCaptureLine(int line)
void SetFileName(const std::string &filename)