Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmake/SC_Targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ macro(SC_ADDEXEC execname)
message(SEND_ERROR "SC_ADDEXEC usage error - expected STATIC LINK_LIBRARIES targets (${_lib})")
endif()
endif()
# Executables consume their dependencies but do not publish an
# interface to downstream targets.
target_link_libraries(${execname} PRIVATE ${_lib})
endforeach()
target_link_libraries(${execname} PRIVATE ${${_arg_prefix}_LINK_LIBRARIES})
endif()
Expand Down Expand Up @@ -74,6 +77,11 @@ macro(SC_ADDLIB _addlib_target)
message(SEND_ERROR "SC_ADDLIB usage error - expected (static) LINK_LIBRARIES targets (${_lib})")
endif()
endif()
# Schema libraries are consumed directly by generated test programs.
# Publish their link requirements explicitly; the legacy unscoped
# signature does not reliably provide a transitive interface with
# current CMake versions.
target_link_libraries(${_addlib_target} PUBLIC ${_lib})
endforeach()
target_link_libraries(${_addlib_target} ${_lib})
endif()
Expand All @@ -93,4 +101,3 @@ endmacro()
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

2 changes: 1 addition & 1 deletion include/cllazyfile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(LAZY_HDRS
p21HeaderSectionReader.h
lazyDataSectionReader.h
lazyInstMgr.h
lazySupport.h
lazyTypes.h
sectionReader.h
instMgrHelper.h
Expand All @@ -24,4 +25,3 @@ install(FILES ${LAZY_HDRS}
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

5 changes: 1 addition & 4 deletions include/cllazyfile/headerSectionReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ class SC_LAZYFILE_EXPORT headerSectionReader: public sectionReader {
}

virtual ~headerSectionReader() {
//FIXME delete each instance?! maybe add to clear, since it iterates over everything already
//enum clearHow { rawData, deletePointers }
_headerInstances->clear();
_headerInstances->clear( true );
delete _headerInstances;
}
};

#endif //HEADERSECTIONREADER_H

5 changes: 3 additions & 2 deletions include/cllazyfile/instMgrHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class SC_LAZYFILE_EXPORT mgrNodeHelper: public MgrNodeBase {
_id = id;
}
inline SDAI_Application_instance * GetSTEPentity() {
return _lim->loadInstance( _id, true );
/* Attribute resolution must not convert a batch-owned cache hit
* into a process-lifetime retained instance. */
return _lim->loadInstance( _id, true, false );
}
};

Expand All @@ -58,4 +60,3 @@ class SC_LAZYFILE_EXPORT instMgrAdapter: public InstMgrBase {


#endif //INSTMGRHELPER_H

4 changes: 2 additions & 2 deletions include/cllazyfile/judyLArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class judyLArray {
* getLastValue() will return the entry before the one that was deleted
* \sa isEmpty()
*/
bool removeEntry( JudyKey * key ) {
if( judy_slot( _judyarray, key, _depth * JUDY_key_size ) ) {
bool removeEntry( JudyKey key ) {
if( judy_slot( _judyarray, reinterpret_cast<const unsigned char *>( &key ), _depth * JUDY_key_size ) ) {
_lastSlot = ( JudyValue * ) judy_del( _judyarray );
return true;
} else {
Expand Down
9 changes: 8 additions & 1 deletion include/cllazyfile/lazyFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class SC_LAZYFILE_EXPORT lazyFileReader {
#endif
fileTypeEnum _fileType;
fileID _fileID;
lazyFileOffset _fileSize;
bool _valid;

void initP21();

Expand All @@ -48,6 +50,12 @@ class SC_LAZYFILE_EXPORT lazyFileReader {
fileID ID() const {
return _fileID;
}
lazyFileOffset fileSize() const {
return _fileSize;
}
bool valid() const {
return _valid;
}
instancesLoaded_t * getHeaderInstances();

lazyFileReader( std::string fname, lazyInstMgr * i, fileID fid );
Expand All @@ -64,4 +72,3 @@ class SC_LAZYFILE_EXPORT lazyFileReader {
};

#endif //LAZYFILEREADER_H

120 changes: 108 additions & 12 deletions include/cllazyfile/lazyInstMgr.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#ifndef LAZYINSTMGR_H
#define LAZYINSTMGR_H

#include <cctype>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <assert.h>

#include "cllazyfile/lazyDataSectionReader.h"
#include "cllazyfile/lazyFileReader.h"
#include "cllazyfile/lazyTypes.h"
#include "cllazyfile/lazySupport.h"

#include "clstepcore/Registry.h"
#include "sc_export.h"
Expand All @@ -19,6 +23,7 @@

class Registry;
class instMgrAdapter;
class lazyRefs;

class SC_LAZYFILE_EXPORT lazyInstMgr {
protected:
Expand Down Expand Up @@ -61,49 +66,115 @@ class SC_LAZYFILE_EXPORT lazyInstMgr {

lazyFileReaderVec_t _files;

/** All indexed DATA instance IDs in deterministic file order. */
instanceRefs _allInstances;

Registry * _headerRegistry, * _mainRegistry;
bool _ownsMainRegistry;
ErrorDescriptor * _errors;

unsigned long _lazyInstanceCount, _loadedInstanceCount;
uint64_t _cacheHighWater, _cacheHits, _cacheMisses, _materializations, _evictions;
uint64_t _activeBatches;
uint64_t _residentSourceBytes, _sourceBytesHighWater;
int _longestTypeNameLen;
std::string _longestTypeName;

std::map<instanceID, size_t> _pinCounts;
std::map<instanceID, uint64_t> _instanceSourceBytes;
std::map<std::string, std::string> _materializationTypeAliases;
std::set<instanceID> _batchOwnedInstances;
std::set<instanceID> _permanentlyLoadedInstances;
std::set<instanceID> _instancesLoading;
std::set<instanceID> _deferredInverseInstances;
size_t _batchLoadDepth;

LazyProgressCallback _progressCallback;
LazyCancellationCallback _cancellationCallback;
LazyDiagnosticCallback _diagnosticCallback;
std::map<std::string, uint64_t> _diagnosticCounts;
bool _cancelled;

instMgrAdapter * _ima;

friend class LazyInstanceBatch;
friend class lazyRefs;
void releaseBatch( const std::vector<instanceID> & instances );
void resolveDeferredInverses();
bool isMaterializing( instanceID id ) const {
return _instancesLoading.count( id ) != 0;
}
void deferInverseResolution( instanceID id ) {
_deferredInverseInstances.insert( id );
}
SDAI_Application_instance * cachedInstance( instanceID id );
std::vector<instanceID> dependencyClosure( const std::vector<instanceID> & roots );

#ifdef _MSC_VER
#pragma warning( pop )
#endif

public:
lazyInstMgr();
~lazyInstMgr();
void openFile( std::string fname );
bool openFile( std::string fname );

void addLazyInstance( namedLazyInstance inst );
InstMgrBase * getAdapter() {
return ( InstMgrBase * ) _ima;
}

/** Register an explicit source-keyword substitution used only when
* materializing an SDAI object. The lazy type index retains the
* original Part 21 keyword. This is intended for known,
* attribute-compatible exporter aliases, not arbitrary recovery. */
void setMaterializationTypeAlias( std::string source, const std::string & target ) {
for( std::string::iterator c = source.begin(); c != source.end(); ++c ) {
*c = static_cast<char>( toupper( static_cast<unsigned char>( *c ) ) );
}
_materializationTypeAliases[source] = target;
}

std::string materializationType( std::string source ) const {
std::string key = source;
for( std::string::iterator c = key.begin(); c != key.end(); ++c ) {
*c = static_cast<char>( toupper( static_cast<unsigned char>( *c ) ) );
}
std::map<std::string, std::string>::const_iterator alias =
_materializationTypeAliases.find( key );
return alias == _materializationTypeAliases.end() ? source : alias->second;
}

instanceRefs_t * getFwdRefs() {
return & _fwdInstanceRefs;
}

instanceRefs_t * getRevRefs() {
return & _revInstanceRefs;
}
LazyInstanceIdView instancesByType( std::string type, bool caseSensitive = false );
LazyInstanceIdView allInstances() const {
return LazyInstanceIdView( &_allInstances );
}
LazyInstanceIdView forwardReferences( instanceID id );
LazyInstanceIdView reverseReferences( instanceID id );
/** Copy the exact indexed source record for an instance. Returns an
* empty string when the ID is missing or ambiguous. */
std::string sourceRecord( instanceID id );

/// returns a vector containing the instances that match `type`
instanceTypes_t::cvector * getInstances( std::string type, bool caseSensitive = false ) { /*const*/
if( !caseSensitive ) {
std::string::iterator it = type.begin();
for( ; it != type.end(); ++it ) {
*it = toupper( *it );
*it = static_cast<char>( toupper( static_cast<unsigned char>( *it ) ) );
}
}
return _instanceTypes->find( type.c_str() );
}
/// get the number of instances of a certain type
unsigned int countInstances( std::string type ) {
instanceTypes_t::cvector * v = _instanceTypes->find( type.c_str() );
unsigned int countInstances( std::string type, bool caseSensitive = false ) {
instanceTypes_t::cvector * v = getInstances( type, caseSensitive );
if( !v ) {
return 0;
}
Expand All @@ -123,21 +194,46 @@ class SC_LAZYFILE_EXPORT lazyInstMgr {
return _loadedInstanceCount;
}

LazyCacheStatistics cacheStatistics() const;

void setProgressCallback( const LazyProgressCallback & callback ) {
_progressCallback = callback;
}
void setCancellationCallback( const LazyCancellationCallback & callback ) {
_cancellationCallback = callback;
}
void setDiagnosticCallback( const LazyDiagnosticCallback & callback ) {
_diagnosticCallback = callback;
}
bool cancelled() const {
return _cancelled;
}
void observeScan( fileID file, lazyFileOffset offset, lazyFileOffset fileSize );
void emitDiagnostic( LazyDiagnostic diagnostic );
uint64_t diagnosticCount( const std::string & key ) const;
const std::map<std::string, uint64_t> & diagnosticCounts() const {
return _diagnosticCounts;
}
void validateReferences();

/// get the number of data sections that have been identified
unsigned int countDataSections() {
return _dataSections.size();
}

///builds the registry using the given initFunct
const Registry * initRegistry( CF_init initFunct ) {
setRegistry( new Registry( initFunct ) );
assert( _mainRegistry == 0 );
_mainRegistry = new Registry( initFunct );
_ownsMainRegistry = true;
return _mainRegistry;
}

/// set the registry to one already initialized
void setRegistry( Registry * reg ) {
assert( _mainRegistry == 0 );
_mainRegistry = reg;
_ownsMainRegistry = false;
}

const Registry * getHeaderRegistry() const {
Expand Down Expand Up @@ -165,8 +261,12 @@ class SC_LAZYFILE_EXPORT lazyInstMgr {
/** returns a pointer to an instance, loading it if necessary.
* \param id the instance number to look for
* \param reSeek if true, reset file position to current position when done. only necessary when loading an instance with dependencies; excessive use will cause a performance hit
* \param promoteCached if true, a cached instance requested outside a batch is retained for legacy callers
*/
SDAI_Application_instance * loadInstance( instanceID id, bool reSeek = false );
SDAI_Application_instance * loadInstance( instanceID id, bool reSeek = false, bool promoteCached = true );

LazyInstanceBatch loadBatch( instanceID root );
LazyInstanceBatch loadBatch( const std::vector<instanceID> & roots );

//list all instances that one instance depends on (recursive)
instanceSet * instanceDependencies( instanceID id );
Expand All @@ -183,11 +283,8 @@ class SC_LAZYFILE_EXPORT lazyInstMgr {
std::cerr << "Error at " << __FILE__ << ":" << __LINE__ << " - multiple instances (" << cv->size() << ") with one instanceID (" << id << ") not supported yet." << std::endl;
return 0;
}
positionAndSection ps = cv->at( 0 );
//extract p, s, call
long int off = ps & 0xFFFFFFFFFFFFULL;
sectionID sid = ps >> 48;
return _dataSections[sid]->getType( off );
instancePosition pos = cv->at( 0 );
return _dataSections[pos.section]->getType( pos.begin );
}
std::cerr << "Error at " << __FILE__ << ":" << __LINE__ << " - instanceID " << id << " not found." << std::endl;
return 0;
Expand Down Expand Up @@ -218,4 +315,3 @@ class SC_LAZYFILE_EXPORT lazyInstMgr {
};

#endif //LAZYINSTMGR_H

8 changes: 4 additions & 4 deletions include/cllazyfile/lazyP21DataSectionReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

class SC_LAZYFILE_EXPORT lazyP21DataSectionReader: public lazyDataSectionReader {
protected:
/** Index the instances in an Edition 1 SCOPE and leave the stream at
* the owning entity's record. */
bool indexScope();
public:
lazyP21DataSectionReader( lazyFileReader * parent, std::ifstream & file, std::streampos start, sectionID sid );

void findSectionStart() {
_sectionStart = findNormalString( "DATA", true );
}
void findSectionStart();
/** gets information (start, end, name, etc) about the next
* instance in the file and returns it in a namedLazyInstance
* \sa p21HeaderSectionReader::nextInstance()
Expand All @@ -22,4 +23,3 @@ class SC_LAZYFILE_EXPORT lazyP21DataSectionReader: public lazyDataSectionReader
};

#endif //LAZYP21DATASECTIONREADER_H

Loading
Loading