static uint64_t local_actOnFileSet(cubepm_t cubepm, uint64_t pSkip, uint64_t pAct, stai_t *data, cubepmMode_t mode) { uint64_t numPartsActTotal = UINT64_C(0); int firstFile, lastFile; local_calcFirstLastFile(cubepm, pSkip, pAct, &firstFile, &lastFile); for (int i = 0; i < firstFile; i++) pSkip -= (uint64_t)cubepm_getNPLocal(cubepm, i); for (int i = firstFile; i <= lastFile; i++) { uint64_t pSkipFile, pActFile, actualAct; cubepm_open(cubepm, mode, i); local_calcSkipActFile(cubepm, pSkip, pAct, i, &pSkipFile, &pActFile); actualAct = local_actOnSingleFile(cubepm, pSkip, pAct, data); cubepm_close(cubepm); local_rebaseStaisData(data, actualAct); numPartsActTotal += actualAct; pSkip -= pSkipFile; pAct -= pActFile; } local_rebaseStaisData(data, -((int64_t)numPartsActTotal)); return numPartsActTotal; }
extern uint64_t art_read(art_t art, uint64_t pSkip, uint64_t pRead, stai_t *data) { uint64_t numPartsReadTotal = UINT64_C(0); int firstFile, lastFile; assert(art != NULL); assert(pSkip + pRead <= artHeader_getNumParticlesTotal(art->header)); local_calcFirstLast(art->numParticlesInFile, art->numFiles - 1, pSkip, pRead, &firstFile, &lastFile); pSkip -= ((uint64_t)firstFile) * art->numParticlesInFile; for (int i = firstFile; i <= lastFile; i++) { uint64_t pSkipFile, pReadFile, actualRead; art_open(art, ART_MODE_READ, i); local_calcSkipAct(art->numParticlesInThisFile, pSkip, pRead, &pSkipFile, &pReadFile); actualRead = art_readFromFile(art, i, pSkipFile, pReadFile, data); assert(actualRead == pReadFile); art_close(art); local_rebaseStaisData(data, actualRead); numPartsReadTotal += actualRead; pSkip -= pSkipFile; pRead -= pReadFile; } local_rebaseStaisData(data, -((int64_t)numPartsReadTotal)); return numPartsReadTotal; }
extern uint64_t art_write(art_t art, uint64_t pSkip, uint64_t pWrite, stai_t *data) { uint64_t numPartsWriteTotal = UINT64_C(0); int firstFile, lastFile; assert(art != NULL); assert(pSkip + pWrite <= artHeader_getNumParticlesTotal(art->header)); local_calcFirstLast(art->numParticlesInFile, art->numFiles - 1, pSkip, pWrite, &firstFile, &lastFile); pSkip -= ((uint64_t)firstFile) * art->numParticlesInFile; for (int i = firstFile; i <= lastFile; i++) { uint64_t pSkipFile, pWriteFile, actualWrite; art_open(art, ART_MODE_WRITE, i); local_calcSkipAct(art->numParticlesInThisFile, pSkip, pWrite, &pSkipFile, &pWriteFile); actualWrite = art_writeToFile(art, i, pSkipFile, pWriteFile, data); assert(actualWrite == pWriteFile); art_close(art); local_rebaseStaisData(data, actualWrite); numPartsWriteTotal += actualWrite; pSkip -= pSkipFile; pWrite -= pWriteFile; } local_rebaseStaisData(data, -((int64_t)numPartsWriteTotal)); return numPartsWriteTotal; }
extern uint64_t art_readFromFile(art_t art, int fileNumber, uint64_t pSkip, uint64_t pRead, stai_t *data) { bool wasOpened; uint64_t numPartsReadTotal = UINT64_C(0); int firstPage, lastPage; wasOpened = (art->f == NULL) ? false : true; art_open(art, ART_MODE_READ, fileNumber); local_calcFirstLast(art->numParticlesInPage, art->numPagesInThisFile, pSkip, pRead, &firstPage, &lastPage); pSkip -= ((uint64_t)firstPage) * art->numParticlesInPage; for (int i = firstPage; i <= lastPage; i++) { uint64_t pSkipPage, pReadPage, actualRead; local_calcSkipAct(art->numParticlesInPage, pSkip, pRead, &pSkipPage, &pReadPage); actualRead = art_readFromPage(art, i, pSkipPage, pReadPage, data); assert(actualRead == pReadPage); local_rebaseStaisData(data, actualRead); numPartsReadTotal += actualRead; pSkip -= pSkipPage; pRead -= pReadPage; } local_rebaseStaisData(data, -((int64_t)numPartsReadTotal)); if (!wasOpened) art_close(art); return numPartsReadTotal; }
extern uint64_t art_writeToFile(art_t art, int fileNumber, uint64_t pSkip, uint64_t pWrite, stai_t *data) { bool wasOpened; uint64_t numPartsWriteTotal = UINT64_C(0); int firstPage, lastPage; wasOpened = (art->f == NULL) ? false : true; art_open(art, ART_MODE_WRITE, fileNumber); local_calcFirstLast(art->numParticlesInPage, art->numPagesInThisFile, pSkip, pWrite, &firstPage, &lastPage); pSkip -= ((uint64_t)firstPage) * art->numParticlesInPage; for (int i = firstPage; i <= lastPage; i++) { uint64_t pSkipPage, pWritePage, actualWrite; local_calcSkipAct(art->numParticlesInPage, pSkip, pWrite, &pSkipPage, &pWritePage); actualWrite = art_writeToPage(art, i, pSkipPage, pWritePage, data); assert(actualWrite == pWritePage); local_rebaseStaisData(data, actualWrite); numPartsWriteTotal += actualWrite; pSkip -= pSkipPage; pWrite -= pWritePage; } local_rebaseStaisData(data, -((int64_t)numPartsWriteTotal)); if (!wasOpened) art_close(art); return numPartsWriteTotal; }