Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:22

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   /* TestMain tfileTest zip-member:file:bha.zip#bha
0018      TestMain tfileTest rfio:suncmsc.cern.ch:/data/valid/test/vincenzo/testPool/evData/EVD0_EventData.56709894d26a11d78dd20040f45cca94.1.h300eemm.TestSignalHits
0019      TestMain tfileTest zip-member:rfio:suncmsc.cern.ch:/data/valid/test/vincenzo/testZip/test1.zip#file.5 */
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   // set our own root plugin
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();  // use option="a" to see ctors
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 }