XMLFileCatalog.h 5.03 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
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/

#ifndef POOL_XMLFILECATALOG_H
#define POOL_XMLFILECATALOG_H
#include "FileCatalog/FCImpl.h"
#include "FileCatalog/FCBuf.h"

#ifdef HAVE_GAUDI_PLUGINSVC
#include "Gaudi/PluginService.h"
#endif

namespace pool { 

/**
 *        @class XMLFileCatalog XMLFileCatalog.h XMLCatalog/XMLFileCatalog.h 
 *          This class is the concrete implementation of the 
 *          POOL XML based File Catalog 
 *
 *       @Author: Maria Girone
 */

class PoolXMLFileCatalog;
class XMLMetaDataCatalog; 
class XMLFileCatalog: public FCImpl{
 public:
#ifdef HAVE_GAUDI_PLUGINSVC
typedef Gaudi::PluginService::Factory0<FCImpl*> Factory;
#endif
  /**Default constructor.
   */
  XMLFileCatalog();

  /**virtual destructor.
   */
  virtual ~XMLFileCatalog();

  //
  //Connection and transaction control operations.
  //   

  /** XMLFileCatalog connection method.
      @param url [IN] std::string standard URL of the XML catalog.
  */
  virtual void connect();

  /** Close the connection to the XMLFileCatalog.
   */
  virtual void disconnect() const;
  /** Start the catalog transaction.
   */
  virtual void start() const;
  /** Commit the catalog transaction.
      @param cm [IN] catalog commit mode.
      REFRESH mode: catalog will be reinitialised on next transaction start.
      ONHOLD mode: catalog will not be reinitialised on next transaction start.
   */
  virtual void commit(FileCatalog::CommitMode cm=FileCatalog::REFRESH) const;

  /**Rollback the catalog transaction.
   */
  virtual void rollback() const;  

  //
  //File registration operations
  //
  
  /**Register a PFN when a new file is created, 
     returns the corresponding std::string 
     @param  pfn [IN] the Physical file name
     @param  filetype [IN] the filetype pf the PFN
     @param  fid [OUT] Guid of the file
  */
  virtual void registerPFN(const std::string& pfn, 
			   const std::string& filetype,
			   FileCatalog::FileID& fid ) const;   

  /** Register LFN 
      @param pfn PFN
      @param lfn LFN
  */
  virtual void registerLFN(const std::string& pfn, 
			   const std::string& lfn) const;


 /** Add a replica file name in the catalog.
     @param pfn [IN] the PFN of the master copy file.
     @param rpf [IN] the PFN of the replica to be added in the catalog. 
  */
  virtual void addReplicaPFN(const std::string& pfn, 
			     const std::string& rpf) const;

 /** Add a mapping in the catalog.
     @param guid [IN] the Guid of the file.
     @param pf   [IN] the PFN of the file to be added in the catalog. 
  */
  virtual void addPFNtoGuid(const FileCatalog::FileID& guid, 
			    const std::string& pf, 
			    const std::string& filetype) const;

  /** Rename a PFN in the catalog. The use case is the file is moved.
      @param pfn [IN] old PFN.
      @param newpf [IN] new PFN.
  */
  virtual void renamePFN(const std::string& pfn, 
			 const std::string& newpfn) const;
  
  /** Lookup the fileID with given PFN.
      @param pfn [IN] PFN.
      @param fid [OUT] FileID, return empty string if not found.
      @param ftype [OUT] file type , return empty string if not found.
   */
  virtual void lookupFileByPFN(const std::string& pfn, 
			       FileCatalog::FileID& fid, 
			       std::string& ftype) const;
  
  /** Lookup the FileID with given LFN.
      @param lfn [IN] LFN.
      @param fid [OUT] FileID.
   */
  virtual void lookupFileByLFN(const std::string& lfn, 
			       FileCatalog::FileID& fid) const;

  /** Lookup the PFN of a file with given std::string in the catalog.
      Throws exception when the file is nonexistant.
      @param fid [IN] FileID
      @param omode [IN] FileOpenMode(read,write,update).
      @param amode [IN] FileAccessPattern(sequential,random,partial random).
      A hint to decide on how to ship and/or replicate the file. 
      @param pfn [OUT] PFN.
      @param filetype [OUT] file type.
   */
  virtual void lookupBestPFN(const FileCatalog::FileID& fid, 
			     const FileCatalog::FileOpenMode& omode,
			     const FileCatalog::FileAccessPattern& amode,
			     std::string& pfn,
			     std::string& filetype) const; 

  virtual void insertPFN(PFNEntry& pentry) const;
  virtual void insertLFN(LFNEntry& lentry) const;
  virtual void deletePFN(const std::string& pfn) const;
  virtual void deleteLFN(const std::string& lfn) const;
  virtual void deleteEntry(const FileCatalog::FileID& guid) const;

  virtual bool isReadOnly() const;
 
  virtual bool retrievePFN(const std::string& query, 
			   FCBuf<PFNEntry>& buf, 
			   const size_t& start );
  virtual bool retrieveLFN(const std::string& query, 
			   FCBuf<LFNEntry>& buf, 
			   const size_t& start );
  virtual bool retrieveGuid(const std::string& query, 
			     FCBuf<FileCatalog::FileID>& buf, 
			     const size_t& start );
  
 private:
  friend class XMLMetaDataCatalog;

 private:
  void ClassHandle() const;
  static PoolXMLFileCatalog* castConnectionHandle(PoolXMLFileCatalog* con);

 private:
  mutable PoolXMLFileCatalog* XMLcon;
  mutable bool is_started;
  mutable bool to_be_updated;
  mutable bool dontstart;
    
  
};
} /* ns pool */

#endif