CMS 3D CMS Logo

MCDBInterface.cc

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

Generated on Tue Jun 9 17:36:53 2009 for CMSSW by  doxygen 1.5.4