Belle II Software  release-05-02-19
OpenFile.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: CDC group *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/logging/Logger.h>
12 #include <framework/utilities/FileSystem.h>
13 #include <cdc/utilities/OpenFile.h>
14 
15 #include <boost/iostreams/device/file.hpp>
16 #include <boost/iostreams/filter/gzip.hpp>
17 
18 using namespace std;
19 using namespace boost;
20 
21 namespace Belle2 {
26  namespace CDC {
27 // Open a file
28  void openFileA(std::ifstream& ifs, const std::string& fileName0)
29  {
30  std::string fileName1 = "/data/cdc/" + fileName0;
31  std::string fileName = FileSystem::findFile(fileName1, true);
32 
33  if (fileName == "") {
34  fileName = FileSystem::findFile(fileName0, true);
35  }
36 
37  if (fileName == "") {
38  B2FATAL("CDC::openFile: " << fileName0 << " not exist!");
39  } else {
40  B2INFO("CDC::openFile: open " << fileName);
41  ifs.open(fileName.c_str());
42  if (!ifs) B2FATAL("CDC::openFile: cannot open " << fileName << " !");
43  }
44  }
45 
46 // Open a file using boost (to be able to read a gzipped file)
47  void openFileB(boost::iostreams::filtering_istream& ifs, const std::string& fileName0)
48  {
49  std::string fileName1 = "/data/cdc/" + fileName0;
50  std::string fileName = FileSystem::findFile(fileName1, true);
51 
52  if (fileName == "") {
53  fileName = FileSystem::findFile(fileName0, true);
54  }
55 
56  if (fileName == "") {
57  B2FATAL("CDC::openFile: " << fileName0 << " not exist!");
58  } else {
59  B2INFO("CDC::openFile: open " << fileName);
60  if ((fileName.rfind(".gz") != string::npos) && (fileName.length() - fileName.rfind(".gz") == 3)) {
61  ifs.push(boost::iostreams::gzip_decompressor());
62  }
63  ifs.push(boost::iostreams::file_source(fileName));
64  if (!ifs) B2FATAL("CDC::openFile: cannot open " << fileName << " !");
65  }
66  }
67  }
69 }
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDC::openFileB
void openFileB(boost::iostreams::filtering_istream &ifs, const std::string &fileName0)
Open a file using boost (to be able to read a gzipped file)
Definition: OpenFile.cc:47
Belle2::CDC::openFileA
void openFileA(std::ifstream &ifs, const std::string &fileName0)
Open a file.
Definition: OpenFile.cc:28