LSSTApplications  18.1.0
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
lsst.pex::policy::UrnPolicyFile Class Reference

A Policy file in the installation directory of an LSST product, referred to using a URN. More...

#include <UrnPolicyFile.h>

Inheritance diagram for lsst.pex::policy::UrnPolicyFile:
lsst.pex::policy::DefaultPolicyFile lsst.pex::policy::PolicyFile lsst.pex::policy::PolicySource lsst::daf::base::Persistable lsst::daf::base::Citizen

Public Types

enum  { magicSentinel = 0xdeadbeef }
 
typedef unsigned long memId
 Type of the block's ID. More...
 
typedef memId(* memNewCallback) (const memId cid)
 A function used to register a callback. More...
 
typedef memId(* memCallback) (const Citizen *ptr)
 
typedef std::shared_ptr< PersistablePtr
 

Public Member Functions

 UrnPolicyFile (const std::string &urn, bool strictUrn=false, bool strictLoads=true)
 Construct a new policy file reference from a URN. More...
 
virtual boost::filesystem::path getInstallPath (const char *const productName)
 return the file path to the installation directory of a given named product. More...
 
const boost::filesystem::path & getRepositoryPath () const
 return the full file path to the repository directory where this file will found. More...
 
virtual void load (Policy &policy) const
 load the data from this Policy source into a Policy object. More...
 
const std::string getPath () const
 return the file path as a string More...
 
bool exists () const
 return true if the file exists. More...
 
virtual const std::stringgetFormatName ()
 return the name of the format that the data is stored in. More...
 
const std::stringgetFormatName () const
 
std::string repr () const
 Return a string representation of a Citizen. More...
 
void markPersistent (void)
 Mark a Citizen as persistent and not destroyed until process end. More...
 
memId getId () const
 Return the Citizen's ID. More...
 
template<class Archive >
void serialize (Archive &, unsigned int const)
 Template boost::serialization function for the base class. More...
 
virtual void load (Policy &policy)
 load the data from this Policy source into a Policy object More...
 

Static Public Member Functions

static std::string productNameFromUrn (const std::string &urn, bool strictUrn=false)
 Extract the product name from a URN. More...
 
static std::string filePathFromUrn (const std::string &urn, bool strictUrn=false)
 Extract the local file path from a URN. More...
 
static std::string reposFromUrn (const std::string &urn, bool strictUrn=false)
 Extract the repository name from a URN, or "" if none. More...
 
static bool looksLikeUrn (const std::string &s, bool strict=false)
 Does s look like a URN? That is, does it start with URN_PREFIX or URN_PREFIX_ABBREV? More...
 
static boost::filesystem::path installPathFor (const char *const productName)
 return the file path to the installation directory of a given named product. More...
 
static bool hasBeenCorrupted ()
 Check all allocated blocks for corruption. More...
 
static memId getNextMemId ()
 Return the memId of the next object to be allocated. More...
 
static int init ()
 Called once when the memory system is being initialised. More...
 
Census

Provide a list of current Citizens

static int census (int, memId startingMemId=0)
 How many active Citizens are there? More...
 
static void census (std::ostream &stream, memId startingMemId=0)
 Print a list of all active Citizens to stream, sorted by ID. More...
 
static const std::vector< const Citizen * > * census ()
 Return a (newly allocated) std::vector of active Citizens sorted by ID. More...
 
callbackIDs

Set callback Ids.

The old Id is returned

static memId setNewCallbackId (memId id)
 Call the NewCallback when block is allocated. More...
 
static memId setDeleteCallbackId (memId id)
 Call the current DeleteCallback when block is deleted. More...
 
callbacks

Set the New/Delete callback functions; in each case the previously installed callback is returned.

These callback functions return a value which is Added to the previously registered id.

The default callback functions are called default{New,Delete}Callback; you may want to set a break point in these callbacks from your favourite debugger

static memNewCallback setNewCallback (memNewCallback func)
 Set the NewCallback function. More...
 
static memCallback setDeleteCallback (memCallback func)
 Set the DeleteCallback function. More...
 
static memCallback setCorruptionCallback (memCallback func)
 Set the CorruptionCallback function. More...
 

Static Public Attributes

static const std::string EXT_PAF
 
static const std::string EXT_XML
 the PAF file extension, ".paf" More...
 
static const boost::regex SPACE_RE
 the XML file extension, ".xml" More...
 
static const boost::regex COMMENT
 reg-exp for an empty line More...
 
static const boost::regex CONTENTID
 reg-exp for the start of a comment More...
 
static SupportedFormats::Ptr defaultFormats
 returns true if the given string containing a content identifier indicates that it contains dictionary data. More...
 
static const std::string URN_PREFIX
 The prefix that a Policy URN starts with. More...
 
static const std::string URN_PREFIX_ABBREV
 The prefix that a Policy URN starts with. More...
 

Protected Attributes

boost::filesystem::path _file
 the path to the underlying policy file More...
 
SupportedFormats::Ptr _formats
 

Detailed Description

A Policy file in the installation directory of an LSST product, referred to using a URN.

For use of URN references in PAF-formatted policy files, see Policy Authoring Format.

The syntax is urn:eupspkg:[PRODUCT_NAME][:REPOSITORY]:PATH, although "urn:eupspkg:" may optionally be abbreviated with "@". PRODUCT_NAME is the name of an LSST product (see DefaultPolicyFile for more details on LSST product installation dirs), and REPOSITORY is a subdirectory, which other references within the Policy will be relative to (see Policy for more details on repositories).

For example:

Caveat: Only supports Dictionary's "DictionaryFile" directive if the value is prefixed like a normal URN reference with "@urn:eupspkg:" or "@@".

Definition at line 68 of file UrnPolicyFile.h.

Member Typedef Documentation

◆ memCallback

typedef memId(* lsst::daf::base::Citizen::memCallback) (const Citizen *ptr)
inherited

Definition at line 61 of file Citizen.h.

◆ memId

typedef unsigned long lsst::daf::base::Citizen::memId
inherited

Type of the block's ID.

Definition at line 58 of file Citizen.h.

◆ memNewCallback

typedef memId(* lsst::daf::base::Citizen::memNewCallback) (const memId cid)
inherited

A function used to register a callback.

Definition at line 60 of file Citizen.h.

◆ Ptr

Definition at line 77 of file Persistable.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited
Enumerator
magicSentinel 

Definition at line 88 of file Citizen.h.

Constructor & Destructor Documentation

◆ UrnPolicyFile()

lsst.pex::policy::UrnPolicyFile::UrnPolicyFile ( const std::string urn,
bool  strictUrn = false,
bool  strictLoads = true 
)
inlineexplicit

Construct a new policy file reference from a URN.

Basically, the only required element is a colon, separating the product directory from the local path.

Parameters
urnThe URN of the policy file. A prefix such as "urn:eupspkg:" or "@" is optional.
strictUrnif true, the URN must strictly begin with "@urn:eupspkg:" or "urn:eupspkg:".
strictLoadsif true (default), load() will throw an exception if it encounters recoverable parsing errors in the underlying file (or any of the files it references). Otherwise, the loaded Policy will be incomplete. This is identical to the strict argument to Policy's loadPolicyFiles().

Definition at line 85 of file UrnPolicyFile.h.

88  : DefaultPolicyFile(productNameFromUrn(urn, strictUrn).c_str(),
89  filePathFromUrn(urn, strictUrn),
90  reposFromUrn(urn, strictUrn),
91  strictLoads),
92  _urn(urn) {}
static std::string reposFromUrn(const std::string &urn, bool strictUrn=false)
Extract the repository name from a URN, or "" if none.
static std::string filePathFromUrn(const std::string &urn, bool strictUrn=false)
Extract the local file path from a URN.
DefaultPolicyFile(const char *const productName, const std::string &filepath, const std::string &repos="", bool strict=true)
define a default policy file
static std::string productNameFromUrn(const std::string &urn, bool strictUrn=false)
Extract the product name from a URN.

Member Function Documentation

◆ census() [1/3]

int lsst::daf::base::Citizen::census ( int  ,
memId  startingMemId = 0 
)
staticinherited

How many active Citizens are there?

Parameters
startingMemIdDon't print Citizens with lower IDs

Definition at line 238 of file Citizen.cc.

240  {
241  if (startingMemId == 0) { // easy
242  ReadGuard guard(citizenLock);
243  return _activeCitizens.size();
244  }
245 
246  int n = 0;
247  ReadGuard guard(citizenLock);
248  for (table::iterator cur = _activeCitizens.begin(); cur != _activeCitizens.end(); cur++) {
249  if (cur->first->_CitizenId >= startingMemId) {
250  n++;
251  }
252  }
253 
254  return n;
255 }
T end(T... args)
T size(T... args)
T begin(T... args)

◆ census() [2/3]

void lsst::daf::base::Citizen::census ( std::ostream stream,
memId  startingMemId = 0 
)
staticinherited

Print a list of all active Citizens to stream, sorted by ID.

Parameters
streamstream to print to
startingMemIdDon't print Citizens with lower IDs

Definition at line 259 of file Citizen.cc.

261  {
262  ReadGuard guard(citizenLock);
263 
265 
266  for (std::vector<Citizen const*>::const_iterator citizen = leaks->begin(), end = leaks->end();
267  citizen != end; ++citizen) {
268  if ((*citizen)->getId() >= startingMemId) {
269  stream << (*citizen)->repr() << "\n";
270  }
271  }
272 }
STL class.
STL class.
T begin(T... args)
int end
static const std::vector< const Citizen * > * census()
Return a (newly allocated) std::vector of active Citizens sorted by ID.
Definition: Citizen.cc:287

◆ census() [3/3]

std::vector< dafBase::Citizen const * > const * lsst::daf::base::Citizen::census ( )
staticinherited

Return a (newly allocated) std::vector of active Citizens sorted by ID.

You are responsible for deleting it; or you can say std::unique_ptr<std::vector<Citizen const*> const> leaks(Citizen::census()); and not bother (that becomes std::unique_ptr in C++11)

Definition at line 287 of file Citizen.cc.

287  {
289  ReadGuard guard(citizenLock);
290  vec->reserve(_activeCitizens.size());
291 
292  for (table::iterator cur = _activeCitizens.begin(); cur != _activeCitizens.end(); cur++) {
293  vec->push_back(dynamic_cast<Citizen const*>(cur->first));
294  }
295 
296  std::sort(vec->begin(), vec->end(), cmpId);
297 
298  return vec;
299 }
T end(T... args)
T push_back(T... args)
T size(T... args)
STL class.
T begin(T... args)
T sort(T... args)
T reserve(T... args)

◆ exists()

bool lsst.pex::policy::PolicyFile::exists ( ) const
inlineinherited

return true if the file exists.

Definition at line 181 of file PolicyFile.h.

181 { return boost::filesystem::exists(_file); }
boost::filesystem::path _file
the path to the underlying policy file
Definition: PolicyFile.h:226

◆ filePathFromUrn()

static std::string lsst.pex::policy::UrnPolicyFile::filePathFromUrn ( const std::string urn,
bool  strictUrn = false 
)
static

Extract the local file path from a URN.

For example,

  • "@urn:eupspkg:product:repos:PATH/TO/FILE.PAF"
  • "@@product:repos:PATH/TO/FILE.PAF"
  • "@product:PATH/TO/FILE.PAF"

◆ getFormatName() [1/2]

virtual const std::string& lsst.pex::policy::PolicyFile::getFormatName ( )
virtualinherited

return the name of the format that the data is stored in.

This may cause the first few records of the source to be read. In this implementation, once the format is definitely determined, the format name is cached internally, preventing re-determination on the next call to this function.

Exceptions
IOErrorif an error occurs while reading the first few characters of the source stream.

Implements lsst.pex::policy::PolicySource.

◆ getFormatName() [2/2]

const std::string& lsst.pex::policy::PolicyFile::getFormatName ( ) const
inlineinherited

Definition at line 193 of file PolicyFile.h.

193  {
194  return const_cast<PolicyFile*>(this)->getFormatName();
195  }
PolicyFile(const std::string &filepath, const SupportedFormats::Ptr &fmts=defaultFormats)
create a Policy file that points a file with given path.
virtual const std::string & getFormatName()
return the name of the format that the data is stored in.

◆ getId()

dafBase::Citizen::memId lsst::daf::base::Citizen::getId ( ) const
inherited

Return the Citizen's ID.

Definition at line 206 of file Citizen.cc.

206 { return _CitizenId; }

◆ getInstallPath()

fs::path lsst.pex::policy::DefaultPolicyFile::getInstallPath ( const char *const  productName)
virtualinherited

return the file path to the installation directory of a given named product.

This implementation uses the implementation provided by DefaultPolicyFile::installPathFor().

Exceptions
lsst::pex::exception::NotFoundErrorif the environement variable is not defined.

Definition at line 51 of file DefaultPolicyFile.cc.

51  {
52  return DefaultPolicyFile::installPathFor(productName);
53 }
static boost::filesystem::path installPathFor(const char *const productName)
return the file path to the installation directory of a given named product.

◆ getNextMemId()

dafBase::Citizen::memId lsst::daf::base::Citizen::getNextMemId ( )
staticinherited

Return the memId of the next object to be allocated.

Definition at line 209 of file Citizen.cc.

209 { return _nextMemId(); }

◆ getPath()

const std::string lsst.pex::policy::PolicyFile::getPath ( ) const
inlineinherited

return the file path as a string

Definition at line 176 of file PolicyFile.h.

176 { return _file.string(); }
boost::filesystem::path _file
the path to the underlying policy file
Definition: PolicyFile.h:226

◆ getRepositoryPath()

const boost::filesystem::path& lsst.pex::policy::DefaultPolicyFile::getRepositoryPath ( ) const
inlineinherited

return the full file path to the repository directory where this file will found.

Definition at line 107 of file DefaultPolicyFile.h.

107 { return _repos; }

◆ hasBeenCorrupted()

bool lsst::daf::base::Citizen::hasBeenCorrupted ( )
staticinherited

Check all allocated blocks for corruption.

Definition at line 316 of file Citizen.cc.

316  {
317  ReadGuard guard(citizenLock);
318  for (table::iterator cur = _activeCitizens.begin(); cur != _activeCitizens.end(); cur++) {
319  if (cur->first->_hasBeenCorrupted()) {
320  return true;
321  }
322  }
323  for (table::iterator cur = _persistentCitizens.begin(); cur != _persistentCitizens.end(); cur++) {
324  if (cur->first->_hasBeenCorrupted()) {
325  return true;
326  }
327  }
328 
329  return false;
330 }
T end(T... args)
T begin(T... args)

◆ init()

int lsst::daf::base::Citizen::init ( )
staticinherited

Called once when the memory system is being initialised.

Definition at line 196 of file Citizen.cc.

196  {
197  volatile int dummy = 1;
198  return dummy;
199 }

◆ installPathFor()

fs::path lsst.pex::policy::DefaultPolicyFile::installPathFor ( const char *const  productName)
staticinherited

return the file path to the installation directory of a given named product.

In this implementation, the installation directory will be taken from the value of an environment variable PRODUCTNAME_DIR where PRODUCTNAME is the given name of the product with all letters converted to upper case.

Definition at line 64 of file DefaultPolicyFile.cc.

64  {
65  std::string productName_DIR(productName);
66 
67  // transform to upper case
68  std::transform(productName_DIR.begin(), productName_DIR.end(),
69  productName_DIR.begin(),
70  std::ptr_fun<int, int>( std::toupper ));
71 
72  // append _DIR
73  productName_DIR += "_DIR";
74 
75  // get installation directory from environment
76  const char *ipath = getenv(productName_DIR.c_str());
77  if (ipath == 0)
79  productName_DIR + ": environment variable not set");
80 
81  return fs::path(ipath);
82 }
STL class.
T getenv(T... args)
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
T toupper(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
T transform(T... args)

◆ load() [1/2]

void lsst.pex::policy::DefaultPolicyFile::load ( Policy policy) const
virtualinherited

load the data from this Policy source into a Policy object.

This implementation will automatically de-reference any file include directives in the policy file.

Parameters
policythe policy object to load the data into
Exceptions
ParserExceptionif an error occurs while parsing the data
IOErrorif an I/O error occurs while reading from the source stream.

Reimplemented from lsst.pex::policy::PolicyFile.

Definition at line 93 of file DefaultPolicyFile.cc.

93  {
94  PolicyFile::load(policy);
95  policy.loadPolicyFiles(_repos, _strict);
96 }
virtual void load(Policy &policy) const
load the data from this Policy source into a Policy object

◆ load() [2/2]

virtual void lsst.pex::policy::PolicyFile::load ( Policy policy)
inlinevirtualinherited

load the data from this Policy source into a Policy object

Parameters
policythe policy object to load the data into
Exceptions
ParserExceptionif an error occurs while parsing the data
IOErrorif an I/O error occurs while reading from the source stream.

Implements lsst.pex::policy::PolicySource.

Definition at line 206 of file PolicyFile.h.

206  {
207  ((const PolicyFile*) this)->load(policy); // delegate to const version
208  }
PolicyFile(const std::string &filepath, const SupportedFormats::Ptr &fmts=defaultFormats)
create a Policy file that points a file with given path.

◆ looksLikeUrn()

static bool lsst.pex::policy::UrnPolicyFile::looksLikeUrn ( const std::string s,
bool  strict = false 
)
static

Does s look like a URN? That is, does it start with URN_PREFIX or URN_PREFIX_ABBREV?

Parameters
sthe string to be tested
strictif false, "@" will be accepted as a substitute for "urn:eupspkg:"; if true, urn:eupspkg must be present.

◆ markPersistent()

void lsst::daf::base::Citizen::markPersistent ( void  )
inherited

Mark a Citizen as persistent and not destroyed until process end.

Definition at line 225 of file Citizen.cc.

225  {
226  WriteGuard guard(citizenLock);
227  _persistentCitizens[this] = _activeCitizens[this];
228  _activeCitizens.erase(this);
229 }
T erase(T... args)

◆ productNameFromUrn()

static std::string lsst.pex::policy::UrnPolicyFile::productNameFromUrn ( const std::string urn,
bool  strictUrn = false 
)
static

Extract the product name from a URN.

For example,

  • @urn:eupspkg:PRODUCT:repos:path/to/file.paf
  • @@PRODUCT:repos:path/to/file.paf
  • @PRODUCT:path/to/file.paf

◆ reposFromUrn()

static std::string lsst.pex::policy::UrnPolicyFile::reposFromUrn ( const std::string urn,
bool  strictUrn = false 
)
static

Extract the repository name from a URN, or "" if none.

For example,

  • "@urn:eupspkg:product:REPOS:path/to/file.paf"
  • "@@product:REPOS:path/to/file.paf"
  • "@product:path/to/file.paf" – no repository, returns ""

◆ repr()

std::string lsst::daf::base::Citizen::repr ( ) const
inherited

Return a string representation of a Citizen.

Definition at line 219 of file Citizen.cc.

219  {
220  return boost::str(boost::format("%d: %08x %s") % _CitizenId % this %
221  lsst::utils::demangleType(_typeName));
222 }
std::string demangleType(std::string const _typeName)
Definition: Demangle.cc:113
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168

◆ serialize()

template<class Archive >
void lsst::daf::base::Persistable::serialize ( Archive &  ,
unsigned int  const 
)
inlineinherited

Template boost::serialization function for the base class.

Doesn't actually do anything, since there is no data associated with the base. Inline to allow expansion wherever needed.

Definition at line 87 of file Persistable.h.

87 {}

◆ setCorruptionCallback()

dafBase::Citizen::memCallback lsst::daf::base::Citizen::setCorruptionCallback ( Citizen::memCallback  func)
staticinherited

Set the CorruptionCallback function.

Parameters
funcfunction be called when block is found to be corrupted

Definition at line 391 of file Citizen.cc.

393  {
394  Citizen::memCallback old = _corruptionCallback;
395  _corruptionCallback = func;
396 
397  return old;
398 }
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:61

◆ setDeleteCallback()

dafBase::Citizen::memCallback lsst::daf::base::Citizen::setDeleteCallback ( Citizen::memCallback  func)
staticinherited

Set the DeleteCallback function.

Parameters
funcfunction be called when desired block is deleted

Definition at line 381 of file Citizen.cc.

383  {
384  Citizen::memCallback old = _deleteCallback;
385  _deleteCallback = func;
386 
387  return old;
388 }
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:61

◆ setDeleteCallbackId()

dafBase::Citizen::memId lsst::daf::base::Citizen::setDeleteCallbackId ( Citizen::memId  id)
staticinherited

Call the current DeleteCallback when block is deleted.

Parameters
idDesired ID

Definition at line 347 of file Citizen.cc.

348  {
349  WriteGuard guard(citizenLock);
350  Citizen::memId oldId = _deleteId;
351  _deleteId = id;
352 
353  return oldId;
354 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:58
table::Key< int > id
Definition: Detector.cc:166

◆ setNewCallback()

dafBase::Citizen::memNewCallback lsst::daf::base::Citizen::setNewCallback ( Citizen::memNewCallback  func)
staticinherited

Set the NewCallback function.

Parameters
funcThe new function to be called when a designated block is allocated

Definition at line 371 of file Citizen.cc.

373  {
374  Citizen::memNewCallback old = _newCallback;
375  _newCallback = func;
376 
377  return old;
378 }
memId(* memNewCallback)(const memId cid)
A function used to register a callback.
Definition: Citizen.h:60

◆ setNewCallbackId()

dafBase::Citizen::memId lsst::daf::base::Citizen::setNewCallbackId ( Citizen::memId  id)
staticinherited

Call the NewCallback when block is allocated.

Parameters
idDesired ID

Definition at line 337 of file Citizen.cc.

338  {
339  WriteGuard guard(citizenLock);
340  Citizen::memId oldId = _newId;
341  _newId = id;
342 
343  return oldId;
344 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:58
table::Key< int > id
Definition: Detector.cc:166

Member Data Documentation

◆ _file

boost::filesystem::path lsst.pex::policy::PolicyFile::_file
protectedinherited

the path to the underlying policy file

Definition at line 226 of file PolicyFile.h.

◆ _formats

SupportedFormats::Ptr lsst.pex::policy::PolicySource::_formats
protectedinherited

Definition at line 142 of file PolicySource.h.

◆ COMMENT

const boost::regex lsst.pex::policy::PolicyFile::COMMENT
staticinherited

reg-exp for an empty line

Definition at line 215 of file PolicyFile.h.

◆ CONTENTID

const boost::regex lsst.pex::policy::PolicyFile::CONTENTID
staticinherited

reg-exp for the start of a comment

reg-exp for a Policy content identifier, "<?cfg [format] [content] ?>"

Definition at line 220 of file PolicyFile.h.

◆ defaultFormats

SupportedFormats::Ptr lsst.pex::policy::PolicySource::defaultFormats
staticinherited

returns true if the given string containing a content identifier indicates that it contains dictionary data.

Dictionary data has a content id of "<?cfg ... dictionary ?>" (where ... indicates the format); policy data has an id of "<?cfg ... policy ?>". a default set of formats

Definition at line 135 of file PolicySource.h.

◆ EXT_PAF

const std::string lsst.pex::policy::PolicyFile::EXT_PAF
staticinherited

Definition at line 211 of file PolicyFile.h.

◆ EXT_XML

const std::string lsst.pex::policy::PolicyFile::EXT_XML
staticinherited

the PAF file extension, ".paf"

Definition at line 212 of file PolicyFile.h.

◆ SPACE_RE

const boost::regex lsst.pex::policy::PolicyFile::SPACE_RE
staticinherited

the XML file extension, ".xml"

Definition at line 214 of file PolicyFile.h.

◆ URN_PREFIX

const std::string lsst.pex::policy::UrnPolicyFile::URN_PREFIX
static

The prefix that a Policy URN starts with.

May be abbreviated as "@".

Definition at line 125 of file UrnPolicyFile.h.

◆ URN_PREFIX_ABBREV

const std::string lsst.pex::policy::UrnPolicyFile::URN_PREFIX_ABBREV
static

The prefix that a Policy URN starts with.

May be abbreviated as "@".

Definition at line 126 of file UrnPolicyFile.h.


The documentation for this class was generated from the following file: