00001 //************************************ 00002 //* Generators interface with the LCG MCDB 00003 //* 00004 //* Hector Naves Sordo 00005 //* 00006 //* First version: 25/10/06 00007 //* 00008 //************************************ 00009 #include "GeneratorInterface/MadGraphInterface/interface/MCDBInterface.h" 00010 #include "FWCore/PluginManager/interface/PluginManager.h" 00011 #include "FWCore/PluginManager/interface/standard.h" 00012 #include "Utilities/StorageFactory/interface/Storage.h" 00013 00014 // Makes a local copy of a CASTOR file. 00015 // This code is a modified version of 00016 // Utilities/StorageFactory/test/any.cpp by Vincenzo Innocente 00017 void mcdbGetInputFile(std::string &madGraphInputFile, int &mcdbArticleID) { 00018 00019 // Parse the filename from the MCDB CASTOR PATH 00020 // Needed for the local name. 00021 int mcdbPathLength = madGraphInputFile.size(); 00022 int mcdbStartFromHere = madGraphInputFile.rfind("/",mcdbPathLength); 00023 std::string mcdbLocalFileName = madGraphInputFile.substr(mcdbStartFromHere + 1); 00024 00025 // Parse the MCDB Article Number from the MCDB CASTOR PATH 00026 int mcdbStartArticleIDFromHere = madGraphInputFile.rfind("/", mcdbStartFromHere - 1); 00027 std::string mcdbArticleIDFromPath = madGraphInputFile.substr(mcdbStartArticleIDFromHere + 1, (mcdbStartFromHere - mcdbStartArticleIDFromHere) - 1); 00028 00029 std::cout << "MCDBInterface: MCDB input file..." << std::endl; 00030 00031 // Makes the local copy of the CASTOR file 00032 edmplugin::PluginManager::configure(edmplugin::standard::config()); 00033 00034 IOOffset mcdbFileSize = -1; 00035 StorageFactory::get()->enableAccounting(true); 00036 bool mcdbFileExists = StorageFactory::get()->check(madGraphInputFile, &mcdbFileSize); 00037 00038 std::cout << "MCDB Article ID: " << mcdbArticleIDFromPath << std::endl; 00039 std::cout << "Retrieving file: " << madGraphInputFile << std::endl; 00040 std::cout << " Size: " << mcdbFileSize << std::endl; 00041 00042 if (!mcdbFileExists) { 00043 std::cerr << "Error: Cannot open MCDB input file" << std::endl; 00044 throw edm::Exception(edm::errors::Configuration,"OpenMCDBFileError") 00045 <<" Cannot open MCDB input file, check file name and path."; 00046 } 00047 00048 Storage *mcdbFile = StorageFactory::get()->open(madGraphInputFile); 00049 char mcdbBuf [1024]; 00050 IOSize mcdbNSize; 00051 00052 std::ofstream mcdbLocalFileCopy; 00053 mcdbLocalFileCopy.open(mcdbLocalFileName.c_str()); 00054 while ((mcdbNSize = mcdbFile->read (mcdbBuf, sizeof (mcdbBuf)))) 00055 mcdbLocalFileCopy.write(mcdbBuf, mcdbNSize); 00056 00057 mcdbLocalFileCopy.close(); 00058 std::cout << "MCDBInterface: MCDB stats:\n" << StorageAccount::summaryText () <<std::endl <<std::endl; 00059 00060 // Once the local copy of the file is done, we only need the filename and the Article ID... 00061 madGraphInputFile = mcdbLocalFileName; 00062 mcdbArticleID = atoi(mcdbArticleIDFromPath.c_str()); 00063 }