Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-01 22:41:13

0001 #include "Utilities/StorageFactory/test/Test.h"
0002 #include "Utilities/StorageFactory/interface/Storage.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include <cmath>
0005 #include <limits>
0006 #include <vector>
0007 
0008 int main(int argc, char** argv) try {
0009   initTest();
0010 
0011   if (argc != 2) {
0012     std::cerr << "usage: " << argv[0] << " FILE...\n";
0013     return EXIT_FAILURE;
0014   }
0015 
0016   using namespace edm::storage;
0017   StorageFactory::getToModify()->enableAccounting(true);
0018   std::vector<std::unique_ptr<Storage>> storages;
0019   std::vector<IOOffset> sizes;
0020   for (int i = 1; i < argc; ++i) {
0021     IOOffset size = -1;
0022     bool exists = StorageFactory::get()->check(argv[i], &size);
0023 
0024     std::cout << argv[i] << " exists = " << exists << ", size = " << size << std::endl;
0025 
0026     if (exists) {
0027       storages.push_back(StorageFactory::get()->open(argv[i], IOFlags::OpenRead | IOFlags::OpenUnbuffered));
0028       sizes.push_back(size);
0029     }
0030   }
0031 
0032   if (sizes.empty())
0033     return EXIT_SUCCESS;
0034 
0035   std::cout << "stats:\n" << StorageAccount::summaryText(true) << std::endl;
0036 
0037   IOSize n;
0038   char buf[10000];
0039   IOSize maxBufSize = sizeof(buf);
0040   int niter = 100000;
0041 
0042   while (niter--)
0043     for (size_t i = 0; i < sizes.size(); ++i) {
0044       double bfract = double(rand()) / double(std::numeric_limits<int>::max());
0045       double pfract = double(rand()) / double(std::numeric_limits<int>::max());
0046       IOSize bufSize = static_cast<IOSize>(maxBufSize * bfract);
0047       IOOffset pos = static_cast<IOOffset>((sizes[i] - bufSize) * pfract);
0048       // std::cout << "read " << bufSize << " at " << pos << std::endl;
0049       storages[i]->position(pos);
0050       n = storages[i]->read(buf, bufSize);
0051       if (n != bufSize) {
0052         std::cerr << "error for " << i << " (" << argv[i + 1] << "): tried to read " << bufSize << " bytes at " << pos
0053                   << "; got " << n << " bytes\n";
0054         break;
0055       }
0056     }
0057 
0058   for (size_t i = 0; i < sizes.size(); ++i) {
0059     storages[i]->close();
0060   }
0061 
0062   std::cout << StorageAccount::summaryText(true) << std::endl;
0063   return EXIT_SUCCESS;
0064 } catch (cms::Exception const& e) {
0065   std::cerr << e.explainSelf() << std::endl;
0066   return EXIT_FAILURE;
0067 } catch (std::exception const& e) {
0068   std::cerr << e.what() << std::endl;
0069   return EXIT_FAILURE;
0070 }