Gaudi Framework, version v21r11

Home   Generated: 30 Sep 2010

XMLCatalogTest.cpp

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

Generated at Thu Sep 30 09:57:40 2010 for Gaudi Framework, version v21r11 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004