slsdetectorgroup / aare

Data analysis library for PSI hybrid detectors
Other
0 stars 0 forks source link

API for reading files #17

Closed erikfrojdh closed 6 months ago

erikfrojdh commented 7 months ago

I somehow think the current API is a bit cumbersome to use with the multiple templates. It would be great to be able to do something like this

using aare::File;

auto f = File("data/test_numpy_file.npy");  
auto data = f.read<double>();               //if this is not a double I should get a runtime error

//I'm not sure File needs to be templated but the other option would be to do 
auto f = File<double>("data/test_numpy_file.npy"); // runtime error would be here
auto data = f.read();      

//Or even leave out the templates altogether at this level.  Not sure how to do reasonable  
//fast computation from this though.
auto f = File("data/test_numpy_file.npy"); // runtime error would be here
auto data = f.read();      

Another thing to offer efficient loading is the ability to read a frame into an existing buffer

char* buffer // comes from somewhere
auto f = File("data/test_numpy_file.npy");
f.read_into(buffer, n_frames);
erikfrojdh commented 7 months ago

This is a bit connected to the current hierarchy as well. It feels like we have one level to much:

  1. FileHandler which creates a
  2. FileFactory which creates a
  3. File

I think it should be enough to have a File which internally holds a pointer to a FileInterface/Imlementation which is how the actual loading is done. This would leave us with

  1. File, top level API for dealing with files (has a pointer to the actual implementation as a private member)
  2. JsonFile/RawFile/NumpyFile all inherits from FileInterface or something similar

Another option would be to solve it with type erasure to to have the different types of files inherit from the FileInterface on the other hand I don't think we will use third party implementations for reading

Bechir-Brahem commented 6 months ago

should be fixed with #56