Gaudi Framework, version v20r2

Generated: 18 Jul 2008

XMLCatalogTest.cpp

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

Generated at Fri Jul 18 11:59:26 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004