| The Gaudi Framework v32r1 (f65d50dc)

XMLCatalogTest.cpp
Go to the documentation of this file.
1 #include "XMLFileCatalog.h"
2 #include <cstdio>
3 #include <ctime>
4 #include <iostream>
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, nullptr );
15 c.init();
16 std::vector<std::string> fids;
17 c.getFID( fids );
18 time_t start = time( nullptr );
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( nullptr ) - start;
48 std::cout << "Used " << end << " seconds."
49 << " corresponding to " << float( end ) / float( nwrite ) << " entries/second." << std::endl;
50 if ( c.dirty() ) {
51 c.commit();
52 time_t saved = time( nullptr ) - ( start + end );
53 std::cout << "Used " << saved << " seconds."
54 << " corresponding to " << float( saved ) / float( nwrite ) << " entries/second." << std::endl;
55 } else {
56 std::cout << "Error: Catalog is not dirty after inserting records." << std::endl;
57 return 1;
58 }
59 return 0;
60 }
61
62 extern "C" int testXMLFileCatalogRead( int argc, char** argv ) {
63 std::vector<std::string> fids;
64 std::string fname = "file:test.xml";
65 if ( argc > 1 ) fname = argv[1];
66 bool prt = argc < 2;
67 time_t start = time( nullptr );
68 XMLFileCatalog c( fname, nullptr );
69 c.init();
70 std::cout << "File loaded in " << time( nullptr ) - start << " seconds. " << std::endl;
71 start = time( nullptr );
72 c.getFID( fids );
73 std::cout << "FIDs scanned in " << time( nullptr ) - start << " seconds. " << std::endl;
74 start = time( nullptr );
75 size_t mult = prt ? 1 : 10;
76 std::cout << mult * fids.size() << std::endl;
77 for ( size_t i = 0, tot = ( mult * fids.size() ); i < tot; ++i ) {
78 size_t ent = i % fids.size();
79 if ( ent == 0 ) std::cout << i << std::endl;
80 std::string fid = fids[ent];
81 XMLFileCatalog::Files pfn, lfn;
82 XMLFileCatalog::Attributes attrs;
83 c.getLFN( fid, lfn );
84 for ( auto& elem : lfn ) {
85 if ( !c.existsLFN( elem.first ) ) {
86 std::cout << "Error LFN existence of :" << elem.second << std::endl;
87 return 1;
88 }
89 std::string f = c.lookupLFN( elem.first );
90 if ( f != fid ) {
91 std::cout << "Error LFN lookup of :" << elem.second << std::endl;
92 return 1;
93 }
94 }
95 c.getPFN( fid, pfn );
96 for ( auto& elem : pfn ) {
97 if ( !c.existsPFN( elem.first ) ) {
98 std::cout << "Error PFN existence of :" << elem.second << std::endl;
99 return 1;
100 }
101 std::string f = c.lookupPFN( elem.first );
102 if ( f != fid ) {
103 std::cout << "Error PFN lookup of :" << elem.second << std::endl;
104 return 1;
105 }
106 }
107 c.getMetaData( fid, attrs );
108 size_t n = lfn.size() > pfn.size() ? lfn.size() : pfn.size();
109 n = n > attrs.size() ? n : attrs.size();
110 if ( prt ) {
111 std::cout << "FID:" << fid << std::endl;
112 for ( size_t j = 0; j < n; ++j ) {
113 if ( j < lfn.size() )
114 std::cout << lfn[j].first << " ";
115 else
116 std::cout << " ";
117 if ( j < pfn.size() )
118 std::cout << pfn[j].first << " ";
119 else
120 std::cout << " ";
121 if ( j < attrs.size() )
122 std::cout << attrs[j].first << " " << attrs[j].second << " ";
123 else
124 std::cout << " ";
125 std::cout << std::endl;
126 }
127 }
128 }
129 time_t end = time( nullptr ) - start;
130 std::cout << "Used " << end << " seconds (" << (long)fids.size() * mult << " entries)."
131 << " Corresponding to " << float( end ) / float( fids.size() * mult ) << " entries/second." << std::endl;
132 return 0;
133 }
plotSpeedupsPyRoot.time
def time
Definition: plotSpeedupsPyRoot.py:152
gaudirun.c
c
Definition: gaudirun.py:487
gaudirun.argv
list argv
Definition: gaudirun.py:298
std::endl
T endl(T... args)
IOTest.start
def start
Definition: IOTest.py:97
XMLFileCatalog.h
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:121
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:210
std::ostringstream
STL class.
std::ostringstream::str
T str(T... args)
IOTest.end
def end
Definition: IOTest.py:112
plotBacklogPyRoot.argc
argc
Definition: plotBacklogPyRoot.py:142
std::vector::size
T size(T... args)
std::vector< std::string >
testXMLFileCatalogWrite
int testXMLFileCatalogWrite(int argc, char **argv)
Definition: XMLCatalogTest.cpp:9
Gaudi::XMLFileCatalog
This class constitutes the core of the XML based FileCatalog API for POOL.
Definition: XMLFileCatalog.h:27
std::cout
testXMLFileCatalogRead
int testXMLFileCatalogRead(int argc, char **argv)
Definition: XMLCatalogTest.cpp:62
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1