| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

# XMLCatalogTest.cpp

Go to the documentation of this file.

    00001 #include "XMLFileCatalog.h"
    00002 #include <iostream>
    00003 #include <cstdio>
    00004 #include <ctime>
    00005 #include <sstream>
    00006
    00007 using namespace Gaudi;
    00008
    00009 extern "C" int testXMLFileCatalogWrite(int argc, char** argv)   {
    00010   int nwrite = 10;
    00011   std::string fname = "file:test.xml";
    00012   if ( argc>1 ) fname = argv[1];
    00013   if ( argc>2 ) nwrite = ::atol(argv[2]);
    00014   XMLFileCatalog c(fname,0);
    00015   c.init();
    00016   std::vector<std::string> fids;
    00017   c.getFID(fids);
    00018   time_t start = time(0);
    00019   for(size_t n=fids.size(), i=n; i<n+nwrite; ++i)  {
    00020     std::ostringstream txt;
    00021     if ( 0 == ((i-n)%10000) ) std::cout << i-n << std::endl;
    00022     std::string fid = c.createFID();
    00023     c.registerFID(fid);
    00024     txt << "PFN1_Test_" << i << ".dat";
    00025     c.registerPFN(fid,txt.str(),"ROOT");
    00026     c.registerPFN(fid,txt.str(),"ROOT");
    00027     txt.str("");
    00028     txt << "PFN2_Test_" << i << ".dat";
    00029     c.registerPFN(fid,txt.str(),"ROOT");
    00030     txt.str("");
    00031     txt << "PFN3_Test_" << i << ".dat";
    00032     c.registerPFN(fid,txt.str(),"ROOT");
    00033     txt.str("");
    00034     txt << "lfn1_Test_" << i << ".dat";
    00035     c.registerLFN(fid,txt.str());
    00036     txt.str("");
    00037     txt << "lfn2_Test_" << i << ".dat";
    00038     c.registerLFN(fid,txt.str());
    00039     txt.str("");
    00040     txt << "lfn3_Test_" << i << ".dat";
    00041     c.registerLFN(fid,txt.str());
    00042     c.setMetaData(fid,"Name1","Value1");
    00043     c.setMetaData(fid,"Name1","Value111");
    00044     c.setMetaData(fid,"Name2","Value2");
    00045     c.setMetaData(fid,"Name3","Value3");
    00046   }
    00047   time_t end = time(0)-start;
    00048   std::cout << "Used " << end << " seconds."
    00049             << " corresponding to " << float(end)/float(nwrite) << " entries/second."
    00050             << std::endl;
    00051   if ( c.dirty() )  {
    00052     c.commit();
    00053     time_t saved = time(0)-(start+end);
    00054     std::cout << "Used " << saved << " seconds."
    00055               << " corresponding to " << float(saved)/float(nwrite) << " entries/second."
    00056               << std::endl;
    00057   }
    00058   else {
    00059     std::cout << "Error: Catalog is not dirty after inserting records." << std::endl;
    00060   }
    00061   return 1;
    00062 }
    00063
    00064 extern "C" int testXMLFileCatalogRead(int argc, char** argv)  {
    00065   std::vector<std::string> fids;
    00066   std::string fname = "file:test.xml";
    00067   if ( argc>1 ) fname = argv[1];
    00068   bool prt = argc<2;
    00069   time_t start = time(0);
    00070   XMLFileCatalog c(fname,0);
    00071   c.init();
    00072   std::cout << "File loaded in " << time(0)-start << " seconds. " << std::endl;
    00073   start = time(0);
    00074   c.getFID(fids);
    00075   std::cout << "FIDs scanned in " << time(0)-start << " seconds. " << std::endl;
    00076   start = time(0);
    00077   size_t mult = prt ? 1 : 10;
    00078   std::cout << mult*fids.size() << std::endl;
    00079   for(size_t i=0, tot=(mult*fids.size()); i<tot; ++i)  {
    00080     size_t ent = i%fids.size();
    00081     if ( ent == 0 ) std::cout << i << std::endl;
    00082     std::string fid = fids[ent];
    00083     XMLFileCatalog::Files pfn, lfn;
    00084     XMLFileCatalog::Attributes attrs;
    00085     c.getLFN(fid, lfn);
    00086     for(size_t l1=0; l1<lfn.size(); ++l1)  {
    00087       if ( !c.existsLFN(lfn[l1].first) )  {
    00088         std::cout << "Error LFN existence of :" << lfn[l1].second << std::endl;
    00089       }
    00090       std::string f = c.lookupLFN(lfn[l1].first);
    00091       if ( f != fid )  {
    00092         std::cout << "Error LFN lookup of :" << lfn[l1].second << std::endl;
    00093       }
    00094     }
    00095     c.getPFN(fid, pfn);
    00096     for(size_t l2=0; l2<pfn.size(); ++l2)  {
    00097       if ( !c.existsPFN(pfn[l2].first) )  {
    00098         std::cout << "Error PFN existence of :" << pfn[l2].second << std::endl;
    00099       }
    00100       std::string f = c.lookupPFN(pfn[l2].first);
    00101       if ( f != fid )  {
    00102         std::cout << "Error PFN lookup of :" << pfn[l2].second << std::endl;
    00103       }
    00104     }
    00105     c.getMetaData(fid, attrs);
    00106     size_t n = lfn.size() > pfn.size() ? lfn.size() : pfn.size();
    00107     n = n > attrs.size() ? n : attrs.size();
    00108     if ( prt ) {
    00109       std::cout << "FID:" << fid << std::endl;
    00110       for(size_t j=0; j<n; ++j)  {
    00111         if ( j < lfn.size() )  std::cout << lfn[j].first << "   ";
    00112         else  std::cout << "                   ";
    00113         if ( j < pfn.size() )  std::cout << pfn[j].first << "   ";
    00114         else  std::cout << "                   ";
    00115         if ( j < attrs.size() )  std::cout << attrs[j].first << " " << attrs[j].second << "   ";
    00116         else  std::cout << "                  ";
    00117         std::cout << std::endl;
    00118       }
    00119     }
    00120   }
    00121   time_t end = time(0)-start;
    00122   std::cout << "Used " << end << " seconds (" << (long)fids.size()*mult << " entries)."
    00123             << " Corresponding to " << float(end)/float(fids.size()*mult) << " entries/second."
    00124             << std::endl;
    00125   return 1;
    00126 }

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines