File indexing completed on 2024-04-06 12:19:13
0001 #include "TFile.h"
0002 #include <TROOT.h>
0003 #include <TSystem.h>
0004 #include <TPluginManager.h>
0005 #include <TEnv.h>
0006
0007 #include <string>
0008 #include <iostream>
0009
0010 #include "boost/filesystem/operations.hpp"
0011
0012 #include "FWCore/PluginManager/interface/PluginManager.h"
0013 #include "FWCore/PluginManager/interface/standard.h"
0014 #include "FWCore/Utilities/interface/Exception.h"
0015
0016 int main(int argc, char* argv[]) {
0017
0018
0019
0020
0021 char const* protocols[] = {
0022 "^file:", "^http:", "^ftp:", "^web:", "^gsiftp:", "^sfn:", "^rfio:", "^dcache:", "^dcap:", "^gsidcap:"};
0023
0024 char const* tStorageFactoryFileFunc = "TStorageFactoryFile(char const*, Option_t*, char const*, Int_t)";
0025
0026 try {
0027 edmplugin::PluginManager::configure(edmplugin::standard::config());
0028 } catch (cms::Exception const& e) {
0029 std::cout << e.explainSelf() << std::endl;
0030 return 1;
0031 } catch (boost::system::system_error const& e) {
0032 std::cout << e.what() << std::endl;
0033 return 1;
0034 }
0035
0036 gEnv->SetValue("Root.Stacktrace", "0");
0037
0038 typedef char const* Cp;
0039 Cp* begin = protocols;
0040 Cp* end = &protocols[sizeof(protocols) / sizeof(protocols[0])];
0041 for (Cp* i = begin; i != end; ++i) {
0042 gROOT->GetPluginManager()->AddHandler(
0043 "TFile", *i, "TStorageFactoryFile", "pluginIOPoolTFileAdaptor", tStorageFactoryFileFunc);
0044 gROOT->GetPluginManager()->AddHandler(
0045 "TSystem", *i, "TStorageFactorySystem", "pluginIOPoolTFileAdaptor", "TStorageFactorySystem()");
0046 }
0047
0048 gROOT->GetPluginManager()->Print();
0049
0050 std::string fname("file:bha.root");
0051
0052 if (argc > 1)
0053 fname = argv[1];
0054
0055 {
0056 std::unique_ptr<TFile> g(TFile::Open(fname.c_str(), "recreate", "", 1));
0057 g->Close();
0058 }
0059 try {
0060 Bool_t result = gSystem->AccessPathName(fname.c_str(), kFileExists);
0061 std::cout << "file " << fname << (result ? " does not exist\n" : " exists\n");
0062 char const* err = gSystem->GetErrorStr();
0063 if (err != 0 && *err != '\0')
0064 std::cout << "error was " << err << "\n";
0065
0066 if (!result) {
0067 std::unique_ptr<TFile> f(TFile::Open(fname.c_str()));
0068 std::cout << "file size " << f->GetSize() << std::endl;
0069 f->ls();
0070 }
0071 } catch (cms::Exception& e) {
0072 std::cout << "*ERROR*: " << e.what() << std::endl;
0073 } catch (...) {
0074 std::cout << "*ERROR*\n";
0075 }
0076
0077 return 0;
0078 }