PoolXMLFileCatalog.h 9.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/

#ifndef POOLXMLFILECATALOG_H
#define POOLXMLFILECATALOG_H

#include <iosfwd>
#include <string>
#include <vector>
#include <map>


#include "xercesc/dom/DOMDocument.hpp"
#include "xercesc/dom/DOMNode.hpp"
#include <xercesc/parsers/XercesDOMParser.hpp>

using namespace xercesc;

namespace pool {


  class XMLDOMErrorMessanger;
  class XMLQueryHandle;
 
 /**
    \class PoolXMLFileCatalog
     
    This class constitutes the core of the 
    XML based FileCatalog API for POOL. It uses the DOM model and 
    the external XercesC library for parsing. 

   \author Maria Girone  

    \note Glossary

    \arg Physical File Name (PFName) - Name referring to physical location of a file
    \arg Logical  File Name (LFNname) - Name referring to the full set of replicas for a file
    \arg File Identifier (FileID) - Unique identifier if a file. Will be generated by the Guid mechanism.  
    \arg File status (prereg) - Flag indicating if it is a registered or pre-registered pfn 
    \arg Job status  (status) - Flag indicating if the application registering files ended correctly (1) or not (0)

  */




  class PoolXMLFileCatalog {

  public:
    
    enum FileNameType { PFNAME, LFNAME };
    enum PFNStatus {NOTEXISTS,REGISTERED};

    struct poolFNs{
      poolFNs(){}
      poolFNs(const std::string& ifname, const std::string& iguid, 
	      const std::string& itype):
	fname(ifname),guid(iguid),filetype(itype){}
      poolFNs(const std::string& ifname, const std::string& iguid):
	fname(ifname),guid(iguid),filetype(""){}
      std::string fname;
      std::string guid;
      std::string filetype;
    };
  
    typedef std::pair<std::string,std::string> poolMeta;
    typedef std::map<std::string,std::string> poolAttr;
  public:
    /** Create a catalog file, initialization of XercesC.
        @param url the URL of the catalog.
    */
    PoolXMLFileCatalog(const std::string& url);

    /** Destructor, 
        set job status from 0 to 1 on new registered file, 
        and commit them on the catalog once again.
        Finally terminate XercesC.   
    */
    virtual ~PoolXMLFileCatalog();
    
    /** Parse the DOM tree of the XML catalog
     */
    void StartXMLFileCatalog();
    

    /** Dump all PFNames of the catalog and their attributes associate to the FileID
	@param FileID the unique file identifier
	@return std::vector<poolFNs>
    */
    std::vector<poolFNs> getAllpfns(const std::string& FileID);

    /** Dump all PFNames of the catalog and their attributes associate to the FileID
	@param query std::string
	@return std::vector<poolFNs>
    */
    std::vector<poolFNs> getAllpfnsbyq(const std::string& query,
				       unsigned int init=0, 
				       unsigned int ntot=0);
    std::vector<poolFNs> getAlllfnsbyq(const std::string& query,
				       unsigned int init=0, 
				       unsigned int ntot=0);
    std::vector<std::vector<poolMeta> > 
      getAllMetaDatabyq(const std::string& query,
			unsigned int init=0, 
			unsigned int ntot=0);

    std::vector<std::string > getAllGuidbyq(const std::string& query,
					    unsigned int init, 
					    unsigned int ntot);
      
    /** Dump all LFNames of the catalog associate to the FileID
	@param FileID std::string the unique file identifier
	@return std::vector<poolFNs>
    */
    std::vector<poolFNs> getAlllfns(const std::string& FileID);

    /** Dump all MetaData of the catalog 
	@param query std::string 
        @return std::vector<poolFNs>
    */
    std::vector<poolMeta> getAllMetaData(const std::string& FileID);

    /** Get the first available PFName or LFName associate with the FileID
        @param fntype FileNameType
        @param FileID std::string
	@return std::string
    */
    std::string getFile_FROM_FileId(const FileNameType &fntype, 
				    const std::string & FileID);

    /** Get the FileID associated to the PFName or LFName
	@param  fntype FileNameType
	@param  FName  std::string
	@return std::string
    */
    std::string getFileID_FROM_File(const FileNameType &fntype, 
				    const std::string & FName);
    
    /// Deleters  
    /** Delete PFName or LFName  from the DOM tree of the catalog associated to the FileiD
        @param fntype FileNameType
        @param FName  srtd::string
    */
    void delFile(const FileNameType &fntype, const std::string & FName);
    /** Delete FileID DOM Node from the catalog 
        @param FileID  srtd::string
    */
    void delFileID(const std::string & FileID);
    
    /// Manipulators
    /** Generate the FileID by the Guid mechanism
	@return std::string
    */
    std::string generateFileID();

    /** create a DOM Node for a PFName or LFName with all the attributes
        as grandchild of an existing FileID Node
	@param fntype FileNameType
        @param FileID std::string
        @param FName  std::string
    */
    void setFile_onFileID(const FileNameType& fntype, 
			  const std::string & FileID, 
			  const std::string & FName, 
			  const std::string & filetype);

    /** create a DOM Node for a FileID, if it does not exist,  
        and DOM Node of the PFName with all the attributes
        @param FileID std::string
        @param PFName std::string
	@param ftype  std::string
    */    
    void insertFile(const std::string& FileID, 
		    const std::string& PFName, 
		    const std::string& ftype);

    /** create a DOM Node for a FileID and DOM Node of the PFName 
	with all the attributes 
        @param FileID std::string
        @param PFName std::string
	@param ftype  std::string
    */        
    void registerFile(const std::string& FileID, 
		      const std::string& PFName, 
		      const std::string& ftype);

    /** set PFNRequest to REGISTERED for PFName , return the FileID
	@param PFName std::string
	@return std::string
    */
    std::string registerFile(const std::string& PFName);
    
      /// Store information on the XML File
    /** Print on catalog the DOM tree
    */
    void storeOn();
    
    /// Status 
    
    /** Return the status of a PFName
	@param PFName std::string
	@return PFNStatus
    */
    PFNStatus statusPFN(const std::string & PFName);

    /** Return the status of a LFName
	@param LFName std::string
	@return bool
    */
    bool existsLFN(const std::string & LFNname);

    /** Return the status of a FileID
	@param FileID std::string
	@return bool
    */
    bool existsFileID( const std::string & FileID); 

    /** Check if the catalog is read-only
	@return bool
    */
    bool isitReadOnly();

    /** Check if the catalog should be updated 
	@return bool
    */
    bool getUpdate();

    /** Set the catalog to be or not to be update
	@param isupdated bool
    */
    void setUpdate(bool isupdated);

    /** Re-start the catalog as it was at the beginning 
     */
    void getback();

    std::string getGuidMeta(const std::string& fid, 
			    const std::string& attr_name); 

    void setGuidMeta(const std::string& fid, 
		     const std::string& attr_name, 
		     const std::string& attr_value);

    void setGuidMeta(const std::string& attr_name, 
		     const std::string& attr_value);

    void dropGuidMetas();
    void dropGuidMetas(const std::string& attr_name);
    void dropMetas(const std::string& fid);

    poolAttr& getMeta();

    void setMeta(const std::vector<std::string>& name, 
		 const std::vector<std::string>& type);

    std::string getfiletype(const std::string& pfn);

  private:
    DOMNode*   getNode(const std::string & nodename, 
		       const std::string & attr,
		       const std::string & attrname);

    DOMNode*   getChild(DOMNode* Parent, const std::string& ChildTagName);

    DOMNode*   getChildAttr(DOMNode* Parent, 
			    const std::string& ChildTagName, 
			    const std::string& ChildAttr);

    DOMNode*   getChildwithAttr(DOMNode* Parent, 
				const std::string &ChildTagName, 
				const std::string &attrib , 
				const std::string &attv);

    void        setAttr(DOMNode* Node, 
			const std::string & attrib , 
			const std::string & attvalue);

    std::string getAttr(DOMNode* Node, const std::string & attrib);

    void        selectType(FileNameType fntype,std::string & daughter,
			   std::string & grandaug);
    
    std::string getfile(bool backup);

    bool finding(XMLQueryHandle& qhandle, unsigned int i);

  private:
    bool read_only;
    bool update;
    DOMDocument* doc;
    XercesDOMParser *parser;
    XMLDOMErrorMessanger *errMessanger;
    unsigned int index_l;
    
  private:
    static const std::string MainNode;
    static const std::string METANode;
    static const std::string ParentNodeName;
    static const std::string DaughtPNodeName;
    static const std::string DaughtLNodeName;
    static const std::string GranDaPNodeName;
    static const std::string GranDaLNodeName;
    static const std::string FileAtt_type;
    static const std::string FileAtt_ID;
    static const std::string FileAtt_name;
    static const std::string FileAtt_fitype;
    
    static const std::string MetaNode;
    static const std::string FileAtt_attname;
    static const std::string FileAtt_attvalu;
    
  private:
    static int NumberOfIstances;
    std::string m_file;
    
  private:
    unsigned int nmeta;
    unsigned int imeta;
    bool fmeta;

  private:
    poolAttr  metaGuid;
    poolAttr  metadata;

  private:
    std::map<std::string, DOMNode *> mem_pfn;
    std::map<std::string, DOMNode *> mem_lfn;
    std::map<std::string, DOMNode *> mem_fid;
    typedef std::map<std::string, DOMNode *>::iterator  mem_iter;
    
  };

} /* ns pool */

#endif