| The Gaudi Framework v28r2-patches (bc4ad17a)

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

- File List
- File Members

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,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."
50 << std::endl;
51 if ( c.dirty() ) {
52 c.commit();
53 time_t saved = time(nullptr)-(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 return 1;
61 }
62 return 0;
63 }
64
65 extern "C" int testXMLFileCatalogRead(int argc, char** argv) {
66 std::vector<std::string> fids;
67 std::string fname = "file:test.xml";
68 if ( argc>1 ) fname = argv[1];
69 bool prt = argc<2;
70 time_t start = time(nullptr);
71 XMLFileCatalog c(fname,nullptr);
72 c.init();
73 std::cout << "File loaded in " << time(nullptr)-start << " seconds. " << std::endl;
74 start = time(nullptr);
75 c.getFID(fids);
76 std::cout << "FIDs scanned in " << time(nullptr)-start << " seconds. " << std::endl;
77 start = time(nullptr);
78 size_t mult = prt ? 1 : 10;
79 std::cout << mult*fids.size() << std::endl;
80 for(size_t i=0, tot=(mult*fids.size()); i<tot; ++i) {
81 size_t ent = i%fids.size();
82 if ( ent == 0 ) std::cout << i << std::endl;
83 std::string fid = fids[ent];
84 XMLFileCatalog::Files pfn, lfn;
85 XMLFileCatalog::Attributes attrs;
86 c.getLFN(fid, lfn);
87 for(auto & elem : lfn) {
88 if ( !c.existsLFN(elem.first) ) {
89 std::cout << "Error LFN existence of :" << elem.second << std::endl;
90 return 1;
91 }
92 std::string f = c.lookupLFN(elem.first);
93 if ( f != fid ) {
94 std::cout << "Error LFN lookup of :" << elem.second << std::endl;
95 return 1;
96 }
97 }
98 c.getPFN(fid, pfn);
99 for(auto & elem : pfn) {
100 if ( !c.existsPFN(elem.first) ) {
101 std::cout << "Error PFN existence of :" << elem.second << std::endl;
102 return 1;
103 }
104 std::string f = c.lookupPFN(elem.first);
105 if ( f != fid ) {
106 std::cout << "Error PFN lookup of :" << elem.second << std::endl;
107 return 1;
108 }
109 }
110 c.getMetaData(fid, attrs);
111 size_t n = lfn.size() > pfn.size() ? lfn.size() : pfn.size();
112 n = n > attrs.size() ? n : attrs.size();
113 if ( prt ) {
114 std::cout << "FID:" << fid << std::endl;
115 for(size_t j=0; j<n; ++j) {
116 if ( j < lfn.size() ) std::cout << lfn[j].first << " ";
117 else std::cout << " ";
118 if ( j < pfn.size() ) std::cout << pfn[j].first << " ";
119 else std::cout << " ";
120 if ( j < attrs.size() ) std::cout << attrs[j].first << " " << attrs[j].second << " ";
121 else std::cout << " ";
122 std::cout << std::endl;
123 }
124 }
125 }
126 time_t end = time(nullptr)-start;
127 std::cout << "Used " << end << " seconds (" << (long)fids.size()*mult << " entries)."
128 << " Corresponding to " << float(end)/float(fids.size()*mult) << " entries/second."
129 << std::endl;
130 return 0;
131 }
Gaudi::XMLFileCatalog::registerPFN
void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override
Create a FileID and Node of the physical file name with all the attributes.
Definition: XMLFileCatalog.cpp:383
gaudirun.c
c
Definition: gaudirun.py:391
Gaudi::XMLFileCatalog::lookupPFN
std::string lookupPFN(CSTR fid) const override
Lookup file identifier by physical file name.
Definition: XMLFileCatalog.h:53
gaudirun.argv
list argv
Definition: gaudirun.py:227
std::endl
T endl(T...args)
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:146
XMLFileCatalog.h
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:122
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:217
Gaudi::XMLFileCatalog::lookupLFN
std::string lookupLFN(CSTR lfn) const override
Lookup file identifier by logical file name.
Definition: XMLFileCatalog.h:57
Gaudi::XMLFileCatalog::existsPFN
bool existsPFN(CSTR pfn) const override
Return the status of a physical file name.
Definition: XMLFileCatalog.h:51
std::ostringstream
STL class.
Gaudi::XMLFileCatalog::getMetaData
void getMetaData(CSTR fid, Attributes &attr) const override
Dump all MetaData of the catalog for a given file ID.
Definition: XMLFileCatalog.cpp:276
IOTest.start
start
Definition: IOTest.py:88
std::ostringstream::str
T str(T...args)
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:50
Gaudi::XMLFileCatalog::existsLFN
bool existsLFN(CSTR lfn) const override
Return the status of a logical file name.
Definition: XMLFileCatalog.h:55
Gaudi::XMLFileCatalog::getLFN
void getLFN(CSTR fid, Files &files) const override
Dump all logical file names of the catalog associate to the FileID.
Definition: XMLFileCatalog.cpp:270
plotBacklogPyRoot.argc
argc
Definition: plotBacklogPyRoot.py:128
std::vector::size
T size(T...args)
Gaudi::XMLFileCatalog::setMetaData
void setMetaData(CSTR fid, CSTR name, CSTR value) const override
Insert/update metadata item.
Definition: XMLFileCatalog.cpp:294
std::vector< std::string >
Gaudi::XMLFileCatalog::registerLFN
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and Node of the logical file name with all the attributes.
Definition: XMLFileCatalog.cpp:413
Gaudi::XMLFileCatalog::commit
void commit() override
Save DOM catalog to file.
Definition: XMLFileCatalog.cpp:441
testXMLFileCatalogWrite
int testXMLFileCatalogWrite(int argc, char **argv)
Definition: XMLCatalogTest.cpp:9
Gaudi::XMLFileCatalog::init
void init() override
Parse the DOM tree of the XML catalog.
Definition: XMLFileCatalog.cpp:211
Gaudi::XMLFileCatalog::registerFID
void registerFID(CSTR fid) const override
Create a FileID and Node.
Definition: XMLFileCatalog.cpp:336
Gaudi::XMLFileCatalog::getPFN
void getPFN(CSTR fid, Files &files) const override
Dump all physical file names of the catalog and their attributes associate to the FileID...
Definition: XMLFileCatalog.cpp:264
Gaudi::XMLFileCatalog
This class constitutes the core of the XML based FileCatalog API for POOL.
Definition: XMLFileCatalog.h:25
Gaudi::XMLFileCatalog::dirty
bool dirty() const override
Check if the catalog should be updated.
Definition: XMLFileCatalog.h:49
Gaudi::XMLFileCatalog::createFID
std::string createFID() const override
Catalog interface.
Definition: XMLFileCatalog.cpp:193
std::cout
testXMLFileCatalogRead
int testXMLFileCatalogRead(int argc, char **argv)
Definition: XMLCatalogTest.cpp:65
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::XMLFileCatalog::getFID
void getFID(Strings &fids) const override
Dump all file Identifiers.
Definition: XMLFileCatalog.cpp:257