| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
XMLCatalogTest.cpp
Go to the documentation of this file.
1 #include "XMLFileCatalog.h"
2 #include <iostream>
3 #include <cstdio>
4 #include <ctime>
5 #include <sstream>
6
7 using namespace Gaudi;
8
9 extern "C" int testXMLFileCatalogWrite(int argc, char** argv) {
10 int nwrite = 10;
11 std::string fname = "file:test.xml";
12 if ( argc>1 ) fname = argv[1];
13 if ( argc>2 ) nwrite = ::atol(argv[2]);
14 XMLFileCatalog c(fname,0);
15 c.init();
16 std::vector<std::string> fids;
17 c.getFID(fids);
18 time_t start = time(0);
19 for(size_t n=fids.size(), i=n; i<n+nwrite; ++i) {
20 std::ostringstream txt;
21 if ( 0 == ((i-n)%10000) ) std::cout << i-n << std::endl;
22 std::string fid = c.createFID();
23 c.registerFID(fid);
24 txt << "PFN1_Test_" << i << ".dat";
25 c.registerPFN(fid,txt.str(),"ROOT");
26 c.registerPFN(fid,txt.str(),"ROOT");
27 txt.str("");
28 txt << "PFN2_Test_" << i << ".dat";
29 c.registerPFN(fid,txt.str(),"ROOT");
30 txt.str("");
31 txt << "PFN3_Test_" << i << ".dat";
32 c.registerPFN(fid,txt.str(),"ROOT");
33 txt.str("");
34 txt << "lfn1_Test_" << i << ".dat";
35 c.registerLFN(fid,txt.str());
36 txt.str("");
37 txt << "lfn2_Test_" << i << ".dat";
38 c.registerLFN(fid,txt.str());
39 txt.str("");
40 txt << "lfn3_Test_" << i << ".dat";
41 c.registerLFN(fid,txt.str());
42 c.setMetaData(fid,"Name1","Value1");
43 c.setMetaData(fid,"Name1","Value111");
44 c.setMetaData(fid,"Name2","Value2");
45 c.setMetaData(fid,"Name3","Value3");
46 }
47 time_t end = time(0)-start;
48 std::cout << "Used " << end << " seconds."
49 << " corresponding to " << float(end)/float(nwrite) << " entries/second."
50 << std::endl;
51 if ( c.dirty() ) {
52 c.commit();
53 time_t saved = time(0)-(start+end);
54 std::cout << "Used " << saved << " seconds."
55 << " corresponding to " << float(saved)/float(nwrite) << " entries/second."
56 << std::endl;
57 }
58 else {
59 std::cout << "Error: Catalog is not dirty after inserting records." << std::endl;
60 }
61 return 1;
62 }
63
64 extern "C" int testXMLFileCatalogRead(int argc, char** argv) {
65 std::vector<std::string> fids;
66 std::string fname = "file:test.xml";
67 if ( argc>1 ) fname = argv[1];
68 bool prt = argc<2;
69 time_t start = time(0);
70 XMLFileCatalog c(fname,0);
71 c.init();
72 std::cout << "File loaded in " << time(0)-start << " seconds. " << std::endl;
73 start = time(0);
74 c.getFID(fids);
75 std::cout << "FIDs scanned in " << time(0)-start << " seconds. " << std::endl;
76 start = time(0);
77 size_t mult = prt ? 1 : 10;
78 std::cout << mult*fids.size() << std::endl;
79 for(size_t i=0, tot=(mult*fids.size()); i<tot; ++i) {
80 size_t ent = i%fids.size();
81 if ( ent == 0 ) std::cout << i << std::endl;
82 std::string fid = fids[ent];
83 XMLFileCatalog::Files pfn, lfn;
84 XMLFileCatalog::Attributes attrs;
85 c.getLFN(fid, lfn);
86 for(size_t l1=0; l1<lfn.size(); ++l1) {
87 if ( !c.existsLFN(lfn[l1].first) ) {
88 std::cout << "Error LFN existence of :" << lfn[l1].second << std::endl;
89 }
90 std::string f = c.lookupLFN(lfn[l1].first);
91 if ( f != fid ) {
92 std::cout << "Error LFN lookup of :" << lfn[l1].second << std::endl;
93 }
94 }
95 c.getPFN(fid, pfn);
96 for(size_t l2=0; l2<pfn.size(); ++l2) {
97 if ( !c.existsPFN(pfn[l2].first) ) {
98 std::cout << "Error PFN existence of :" << pfn[l2].second << std::endl;
99 }
100 std::string f = c.lookupPFN(pfn[l2].first);
101 if ( f != fid ) {
102 std::cout << "Error PFN lookup of :" << pfn[l2].second << std::endl;
103 }
104 }
105 c.getMetaData(fid, attrs);
106 size_t n = lfn.size() > pfn.size() ? lfn.size() : pfn.size();
107 n = n > attrs.size() ? n : attrs.size();
108 if ( prt ) {
109 std::cout << "FID:" << fid << std::endl;
110 for(size_t j=0; j<n; ++j) {
111 if ( j < lfn.size() ) std::cout << lfn[j].first << " ";
112 else std::cout << " ";
113 if ( j < pfn.size() ) std::cout << pfn[j].first << " ";
114 else std::cout << " ";
115 if ( j < attrs.size() ) std::cout << attrs[j].first << " " << attrs[j].second << " ";
116 else std::cout << " ";
117 std::cout << std::endl;
118 }
119 }
120 }
121 time_t end = time(0)-start;
122 std::cout << "Used " << end << " seconds (" << (long)fids.size()*mult << " entries)."
123 << " Corresponding to " << float(end)/float(fids.size()*mult) << " entries/second."
124 << std::endl;
125 return 1;
126 }