How to locate package data files

Due to the distributed nature of the ArmarX package structure the location of package dependent data files is different on each system. Hence, ArmarX provides the ArmarXDataPath methods that allow to locate the local absolute file path of files which are stored in an ArmarX package data directory.

Assuming you have a file "myDataFile.txt" stored in the data directory of your package "MyArmarXPackage". On your filesystem the location looks like this:

${Package_DIR}/data/MyArmarXPackage/myDirectory/myDataFile.txt
uint8_t data[1]

In order to access the file, you will need the absolute filename. With the ArmarXPackageFinder in combination with the ArmarXDataPath methods this is easy:

std::string packageName("MyArmarXPackage");
armarx::CMakePackageFinder finder(packageName);
if (finder.packageFound())
{
ARMARX_INFO << "Package found...";
std::string packageDataDir = finder.getDataDir();
// add the data directory to the search list of ArmarXDataPath
ArmarXDataPath::addDataPaths(packageDataDir);
std::string relativeFilename("myDirectory/myDataFile.txt");
std::string absoluteFilename;
if (ArmarXDataPath::getAbsolutePath(relativeFilename, absoluteFilename))
{
ARMARX_INFO << "Located file at:" << absoluteFilename;
}
}
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181

To see what paths a package contains see locatePackage command

Also refer to the Academy for further information.