Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
XMLCatalogTest.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include "XMLFileCatalog.h"
12 #include <cstdio>
13 #include <ctime>
14 #include <iostream>
15 #include <sstream>
16 
17 using namespace Gaudi;
18 
19 extern "C" int testXMLFileCatalogWrite( int argc, char** argv ) {
20  int nwrite = 10;
21  std::string fname = "file:test.xml";
22  if ( argc > 1 ) fname = argv[1];
23  if ( argc > 2 ) nwrite = ::atol( argv[2] );
24  XMLFileCatalog c( fname, nullptr );
25  c.init();
27  c.getFID( fids );
28  time_t start = time( nullptr );
29  for ( size_t n = fids.size(), i = n; i < n + nwrite; ++i ) {
31  if ( 0 == ( ( i - n ) % 10000 ) ) std::cout << i - n << std::endl;
32  std::string fid = c.createFID();
33  c.registerFID( fid );
34  txt << "PFN1_Test_" << i << ".dat";
35  c.registerPFN( fid, txt.str(), "ROOT" );
36  c.registerPFN( fid, txt.str(), "ROOT" );
37  txt.str( "" );
38  txt << "PFN2_Test_" << i << ".dat";
39  c.registerPFN( fid, txt.str(), "ROOT" );
40  txt.str( "" );
41  txt << "PFN3_Test_" << i << ".dat";
42  c.registerPFN( fid, txt.str(), "ROOT" );
43  txt.str( "" );
44  txt << "lfn1_Test_" << i << ".dat";
45  c.registerLFN( fid, txt.str() );
46  txt.str( "" );
47  txt << "lfn2_Test_" << i << ".dat";
48  c.registerLFN( fid, txt.str() );
49  txt.str( "" );
50  txt << "lfn3_Test_" << i << ".dat";
51  c.registerLFN( fid, txt.str() );
52  c.setMetaData( fid, "Name1", "Value1" );
53  c.setMetaData( fid, "Name1", "Value111" );
54  c.setMetaData( fid, "Name2", "Value2" );
55  c.setMetaData( fid, "Name3", "Value3" );
56  }
57  time_t end = time( nullptr ) - start;
58  std::cout << "Used " << end << " seconds."
59  << " corresponding to " << float( end ) / float( nwrite ) << " entries/second." << std::endl;
60  if ( c.dirty() ) {
61  c.commit();
62  time_t saved = time( nullptr ) - ( start + end );
63  std::cout << "Used " << saved << " seconds."
64  << " corresponding to " << float( saved ) / float( nwrite ) << " entries/second." << std::endl;
65  } else {
66  std::cout << "Error: Catalog is not dirty after inserting records." << std::endl;
67  return 1;
68  }
69  return 0;
70 }
71 
72 extern "C" int testXMLFileCatalogRead( int argc, char** argv ) {
74  std::string fname = "file:test.xml";
75  if ( argc > 1 ) fname = argv[1];
76  bool prt = argc < 2;
77  time_t start = time( nullptr );
78  XMLFileCatalog c( fname, nullptr );
79  c.init();
80  std::cout << "File loaded in " << time( nullptr ) - start << " seconds. " << std::endl;
81  start = time( nullptr );
82  c.getFID( fids );
83  std::cout << "FIDs scanned in " << time( nullptr ) - start << " seconds. " << std::endl;
84  start = time( nullptr );
85  size_t mult = prt ? 1 : 10;
86  std::cout << mult * fids.size() << std::endl;
87  for ( size_t i = 0, tot = ( mult * fids.size() ); i < tot; ++i ) {
88  size_t ent = i % fids.size();
89  if ( ent == 0 ) std::cout << i << std::endl;
90  std::string fid = fids[ent];
91  XMLFileCatalog::Files pfn, lfn;
92  XMLFileCatalog::Attributes attrs;
93  c.getLFN( fid, lfn );
94  for ( auto& elem : lfn ) {
95  if ( !c.existsLFN( elem.first ) ) {
96  std::cout << "Error LFN existence of :" << elem.second << std::endl;
97  return 1;
98  }
99  std::string f = c.lookupLFN( elem.first );
100  if ( f != fid ) {
101  std::cout << "Error LFN lookup of :" << elem.second << std::endl;
102  return 1;
103  }
104  }
105  c.getPFN( fid, pfn );
106  for ( auto& elem : pfn ) {
107  if ( !c.existsPFN( elem.first ) ) {
108  std::cout << "Error PFN existence of :" << elem.second << std::endl;
109  return 1;
110  }
111  std::string f = c.lookupPFN( elem.first );
112  if ( f != fid ) {
113  std::cout << "Error PFN lookup of :" << elem.second << std::endl;
114  return 1;
115  }
116  }
117  c.getMetaData( fid, attrs );
118  size_t n = lfn.size() > pfn.size() ? lfn.size() : pfn.size();
119  n = n > attrs.size() ? n : attrs.size();
120  if ( prt ) {
121  std::cout << "FID:" << fid << std::endl;
122  for ( size_t j = 0; j < n; ++j ) {
123  if ( j < lfn.size() )
124  std::cout << lfn[j].first << " ";
125  else
126  std::cout << " ";
127  if ( j < pfn.size() )
128  std::cout << pfn[j].first << " ";
129  else
130  std::cout << " ";
131  if ( j < attrs.size() )
132  std::cout << attrs[j].first << " " << attrs[j].second << " ";
133  else
134  std::cout << " ";
135  std::cout << std::endl;
136  }
137  }
138  }
139  time_t end = time( nullptr ) - start;
140  std::cout << "Used " << end << " seconds (" << (long)fids.size() * mult << " entries)."
141  << " Corresponding to " << float( end ) / float( fids.size() * mult ) << " entries/second." << std::endl;
142  return 0;
143 }
std::string
STL class.
testXMLFileCatalogWrite
int testXMLFileCatalogWrite(int argc, char **argv)
Definition: XMLCatalogTest.cpp:19
plotBacklogPyRoot.argc
argc
Definition: plotBacklogPyRoot.py:173
std::vector< std::string >
std::vector::size
T size(T... args)
testXMLFileCatalogRead
int testXMLFileCatalogRead(int argc, char **argv)
Definition: XMLCatalogTest.cpp:72
gaudirun.c
c
Definition: gaudirun.py:525
IOTest.start
start
Definition: IOTest.py:108
ProduceConsume.j
j
Definition: ProduceConsume.py:101
std::cout
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:180
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:234
std::ostringstream
STL class.
std::endl
T endl(T... args)
Gaudi::XMLFileCatalog
Definition: XMLFileCatalog.h:37
std::ostringstream::str
T str(T... args)
IOTest.end
end
Definition: IOTest.py:123
gaudirun.argv
list argv
Definition: gaudirun.py:327
XMLFileCatalog.h