Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
XMLCatalogTest.cpp File Reference
#include "XMLFileCatalog.h"
#include <cstdio>
#include <ctime>
#include <iostream>
#include <sstream>
Include dependency graph for XMLCatalogTest.cpp:

Go to the source code of this file.

Functions

int testXMLFileCatalogWrite (int argc, char **argv)
 
int testXMLFileCatalogRead (int argc, char **argv)
 

Function Documentation

int testXMLFileCatalogRead ( int  argc,
char **  argv 
)

Definition at line 62 of file XMLCatalogTest.cpp.

62  {
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 }
list argv
Definition: gaudirun.py:294
T endl(T...args)
constexpr double second
STL class.
start
Definition: IOTest.py:97
T size(T...args)
This class constitutes the core of the XML based FileCatalog API for POOL.
int testXMLFileCatalogWrite ( int  argc,
char **  argv 
)

Definition at line 9 of file XMLCatalogTest.cpp.

9  {
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();
17  c.getFID( fids );
18  time_t start = time( nullptr );
19  for ( size_t n = fids.size(), i = n; i < n + nwrite; ++i ) {
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 }
list argv
Definition: gaudirun.py:294
T endl(T...args)
STL class.
start
Definition: IOTest.py:97
T size(T...args)
This class constitutes the core of the XML based FileCatalog API for POOL.