Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of common TRestRawToSignalProcesss::FRead #108

Open
jgalan opened this issue May 23, 2023 · 2 comments
Open

Implementation of common TRestRawToSignalProcesss::FRead #108

jgalan opened this issue May 23, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@jgalan
Copy link
Member

jgalan commented May 23, 2023

We could perhaps simplify the code of external to raw signal processes if we introduce a template method inside TRestRawToSignalProcess::FRead.

Each time we read, it is required to increase the variable totalBytesRead. This could also be encapsulated in the base class. And probably totalBytesReaded could be made private.

For example:

    char buffer[CTAG_SZ];
    if (fread(buffer, sizeof(char), CTAG_SZ, fInputBinFile) != CTAG_SZ) {
        printf("Error: could not read first ACQ prefix.\n");
        exit(1);
    }
    totalBytesReaded += CTAG_SZ * sizeof(char);

could be replaced by:

char buffer[CTAG_SZ];
FRead( buffer, sizeof(char), CTAG_SZ);

For example:

    if (fread(&tmp, sizeof(int32_t), 1, fInputBinFile) != 1) {
        printf("Error: could not read timestamp.\n");
        exit(1);
    }
    totalBytesReaded += sizeof(int32_t);

could be replaced by:

int32_t tmp;
FRead( tmp, sizeof(int32_t), 1);

or even

int32_t tmp;
FReadOne( tmp, sizeof(int32_t));

or

tmp = FRead<int32_t>();
@jgalan jgalan added the enhancement New feature or request label May 23, 2023
@juanangp
Copy link
Member

juanangp commented May 23, 2023

I think that to do a template for fread is overcomplicated, in case that you want to automatically increase totalBytesReaded I would suggest something like this:

void FRead( void* buffer, std::size_t size, std::size_t count ){
  if ( fread(buffer, size, count, fInputBinFile) != count){
    printf("Error: could not read %d bytes.\n", size*count);
    exit(1);
  }
totalBytesReaded += size*count;
}

Then in the example above you just do:

char buffer[CTAG_SZ];
FRead( buffer, sizeof(char), CTAG_SZ);

@nkx111
Copy link
Member

nkx111 commented May 23, 2023

There is already an FRead() implemented in this PR: #33, which shall be working in normal cases. However it was a little problematic to reach the original goal of online analysis. I don't know why... So the PR has not been merged yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants