Belle II Software development
OpenFile.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/logging/Logger.h>
10#include <framework/utilities/FileSystem.h>
11#include <cdc/utilities/OpenFile.h>
12
13#include <boost/iostreams/device/file.hpp>
14#include <boost/iostreams/filter/gzip.hpp>
15
16using namespace std;
17using namespace boost;
18
19namespace Belle2 {
24 namespace CDC {
25// Open a file
26 void openFileA(std::ifstream& ifs, const std::string& fileName0)
27 {
28 std::string fileName1 = "/data/cdc/" + fileName0;
29 std::string fileName = FileSystem::findFile(fileName1, true);
30
31 if (fileName == "") {
32 fileName = FileSystem::findFile(fileName0, true);
33 }
34
35 if (fileName == "") {
36 B2FATAL("CDC::openFile: " << fileName0 << " not exist!");
37 } else {
38 B2INFO("CDC::openFile: open " << fileName);
39 ifs.open(fileName.c_str());
40 if (!ifs) B2FATAL("CDC::openFile: cannot open " << fileName << " !");
41 }
42 }
43
44// Open a file using boost (to be able to read a gzipped file)
45 void openFileB(boost::iostreams::filtering_istream& ifs, const std::string& fileName0)
46 {
47 std::string fileName1 = "/data/cdc/" + fileName0;
48 std::string fileName = FileSystem::findFile(fileName1, true);
49
50 if (fileName == "") {
51 fileName = FileSystem::findFile(fileName0, true);
52 }
53
54 if (fileName == "") {
55 B2FATAL("CDC::openFile: " << fileName0 << " not exist!");
56 } else {
57 B2INFO("CDC::openFile: open " << fileName);
58 if ((fileName.rfind(".gz") != string::npos) && (fileName.length() - fileName.rfind(".gz") == 3)) {
59 ifs.push(boost::iostreams::gzip_decompressor());
60 }
61 ifs.push(boost::iostreams::file_source(fileName));
62 if (!ifs) B2FATAL("CDC::openFile: cannot open " << fileName << " !");
63 }
64 }
65 }
67}
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:151
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:45
void openFileA(std::ifstream &ifs, const std::string &fileName0)
Open a file.
Definition: OpenFile.cc:26
Abstract base class for different kinds of events.
STL namespace.