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

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;
}
}

To see what paths a package contains see locatePackage command

Also refer to the Academy for further information.

armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174