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;
17
18namespace Belle2 {
23 namespace CDC {
24// Open a file
25 void openFileA(std::ifstream& ifs, const std::string& fileName0)
26 {
27 std::string fileName1 = "/data/cdc/" + fileName0;
28 std::string fileName = FileSystem::findFile(fileName1, true);
29
30 if (fileName == "") {
31 fileName = FileSystem::findFile(fileName0, true);
32 }
33
34 if (fileName == "") {
35 B2FATAL("CDC::openFile: " << fileName0 << " not exist!");
36 } else {
37 B2INFO("CDC::openFile: open " << fileName);
38 ifs.open(fileName.c_str());
39 if (!ifs) B2FATAL("CDC::openFile: cannot open " << fileName << " !");
40 }
41 }
42
43// Open a file using boost (to be able to read a gzipped file)
44 void openFileB(boost::iostreams::filtering_istream& ifs, const std::string& fileName0)
45 {
46 std::string fileName1 = "/data/cdc/" + fileName0;
47 std::string fileName = FileSystem::findFile(fileName1, true);
48
49 if (fileName == "") {
50 fileName = FileSystem::findFile(fileName0, true);
51 }
52
53 if (fileName == "") {
54 B2FATAL("CDC::openFile: " << fileName0 << " not exist!");
55 } else {
56 B2INFO("CDC::openFile: open " << fileName);
57 if ((fileName.rfind(".gz") != string::npos) && (fileName.length() - fileName.rfind(".gz") == 3)) {
58 ifs.push(boost::iostreams::gzip_decompressor());
59 }
60 ifs.push(boost::iostreams::file_source(fileName));
61 if (!ifs) B2FATAL("CDC::openFile: cannot open " << fileName << " !");
62 }
63 }
64 }
66}
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:44
void openFileA(std::ifstream &ifs, const std::string &fileName0)
Open a file.
Definition: OpenFile.cc:25
Abstract base class for different kinds of events.
STL namespace.