mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
New filename structure (#38)
* WIP * WIP * linking names * define for hdf5 * minor * addressed comments
This commit is contained in:

committed by
Dhanya Thattil

parent
6b7d9445aa
commit
1a9755ad0b
@ -47,14 +47,13 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
|
||||
/**
|
||||
* Print all member values
|
||||
*/
|
||||
void PrintMembers(TLogLevel level = logDEBUG1);
|
||||
void PrintMembers(TLogLevel level = logDEBUG1) override;
|
||||
|
||||
/**
|
||||
* Create file
|
||||
* @param fnum current frame index to include in file name
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int CreateFile(uint64_t fnum);
|
||||
int CreateFile() override;
|
||||
|
||||
/**
|
||||
* Create master file
|
||||
@ -71,17 +70,17 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
|
||||
*/
|
||||
int CreateMasterFile(bool mfwenable, bool en, uint32_t size,
|
||||
uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp,
|
||||
uint64_t ap);
|
||||
uint64_t ap) override;
|
||||
|
||||
/**
|
||||
* Close Current File
|
||||
*/
|
||||
void CloseCurrentFile();
|
||||
void CloseCurrentFile() override;
|
||||
|
||||
/**
|
||||
* Close all Files
|
||||
*/
|
||||
void CloseAllFiles();
|
||||
void CloseAllFiles() override;
|
||||
|
||||
/**
|
||||
* Write data to file
|
||||
@ -91,7 +90,7 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
|
||||
* @param nump number of packets caught
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump);
|
||||
int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) override;
|
||||
|
||||
|
||||
|
||||
@ -101,7 +100,7 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
|
||||
* Get Type
|
||||
* @return type
|
||||
*/
|
||||
fileFormat GetFileType();
|
||||
fileFormat GetFileType() override;
|
||||
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
|
||||
#include "ansi.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
@ -33,43 +34,39 @@ class BinaryFileStatic {
|
||||
* @param fpath file path
|
||||
* @param fnameprefix file name prefix (includes scan and position variables)
|
||||
* @param findex file index
|
||||
* @param frindexenable frame index enable
|
||||
* @param fnum frame number index
|
||||
* @param subfindex sub file index
|
||||
* @param dindex readout index
|
||||
* @param numunits number of units per readout. eg. eiger has 2 udp units per readout
|
||||
* @param unitindex unit index
|
||||
* @returns complete file name created
|
||||
*/
|
||||
static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable,
|
||||
uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0)
|
||||
{
|
||||
std::ostringstream osfn;
|
||||
osfn << fpath << "/" << fnameprefix;
|
||||
if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex);
|
||||
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << fnum;
|
||||
osfn << "_" << findex;
|
||||
osfn << ".raw";
|
||||
return osfn.str();
|
||||
static std::string CreateFileName(char *fpath, char *fprefix,
|
||||
uint64_t findex, uint64_t subfindex,
|
||||
int dindex, int numunits = 1,
|
||||
int unitindex = 0) {
|
||||
std::ostringstream os;
|
||||
os << fpath << "/" << fprefix << "_d"
|
||||
<< (dindex * numunits + unitindex) << "_f" << subfindex << '_'
|
||||
<< findex << ".raw";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create file names for master file
|
||||
* @param fpath file path
|
||||
* @param fnameprefix file name prefix (includes scan and position variables)
|
||||
* @param findex file index
|
||||
* @returns master file name
|
||||
*/
|
||||
std::string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex)
|
||||
{
|
||||
std::ostringstream osfn;
|
||||
osfn << fpath << "/" << fnameprefix;
|
||||
osfn << "_master";
|
||||
osfn << "_" << findex;
|
||||
osfn << ".raw";
|
||||
return osfn.str();
|
||||
static std::string CreateMasterFileName(char *fpath, char *fnameprefix,
|
||||
uint64_t findex) {
|
||||
std::ostringstream os;
|
||||
os << fpath << "/" << fnameprefix << "_master"
|
||||
<< "_" << findex << ".raw";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Close File
|
||||
* @param fd file pointer
|
||||
*/
|
||||
|
@ -50,6 +50,8 @@ class File : private virtual slsDetectorDefs {
|
||||
*/
|
||||
std::string GetCurrentFileName();
|
||||
|
||||
|
||||
void resetSubFileIndex();
|
||||
/**
|
||||
* Print all member values
|
||||
*/
|
||||
@ -81,30 +83,19 @@ class File : private virtual slsDetectorDefs {
|
||||
|
||||
/**
|
||||
* Create file
|
||||
* @param fnum current frame index to include in file name
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
virtual int CreateFile(uint64_t fnum){
|
||||
FILE_LOG(logERROR) << "This is a generic function CreateFile that should be "
|
||||
"overloaded by a derived class";
|
||||
return OK;
|
||||
}
|
||||
virtual int CreateFile() = 0;
|
||||
|
||||
/**
|
||||
* Close Current File
|
||||
*/
|
||||
virtual void CloseCurrentFile() {
|
||||
FILE_LOG(logERROR) << "This is a generic function CloseCurrentFile that should be "
|
||||
"overloaded by a derived class";
|
||||
}
|
||||
virtual void CloseCurrentFile() = 0;
|
||||
|
||||
/**
|
||||
* Close Files
|
||||
*/
|
||||
virtual void CloseAllFiles() {
|
||||
FILE_LOG(logERROR) << "This is a generic function that should be overloaded "
|
||||
"by a derived class";
|
||||
}
|
||||
virtual void CloseAllFiles() = 0;
|
||||
|
||||
/**
|
||||
* Write data to file
|
||||
@ -113,11 +104,7 @@ class File : private virtual slsDetectorDefs {
|
||||
* @param nump number of packets caught
|
||||
* @param OK or FAIL
|
||||
*/
|
||||
virtual int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||
FILE_LOG(logERROR) << "This is a generic function WriteToFile that "
|
||||
"should be overloaded by a derived class";
|
||||
return FAIL;
|
||||
}
|
||||
virtual int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) = 0;
|
||||
|
||||
/**
|
||||
* Create master file
|
||||
@ -134,11 +121,7 @@ class File : private virtual slsDetectorDefs {
|
||||
*/
|
||||
virtual int CreateMasterFile(bool mfwenable, bool en, uint32_t size,
|
||||
uint32_t nx, uint32_t ny, uint64_t at, uint64_t st,
|
||||
uint64_t sp, uint64_t ap) {
|
||||
FILE_LOG(logERROR) << "This is a generic function CreateMasterFile that "
|
||||
"should be overloaded by a derived class";
|
||||
return OK;
|
||||
}
|
||||
uint64_t sp, uint64_t ap) = 0;
|
||||
|
||||
// HDf5 specific
|
||||
/**
|
||||
@ -150,6 +133,7 @@ class File : private virtual slsDetectorDefs {
|
||||
FILE_LOG(logERROR) << "This is a generic function SetNumberofPixels that "
|
||||
"should be overloaded by a derived class";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End of Acquisition
|
||||
@ -193,6 +177,9 @@ class File : private virtual slsDetectorDefs {
|
||||
/** File Index */
|
||||
uint64_t* fileIndex;
|
||||
|
||||
/** Sub file index */
|
||||
uint64_t subFileIndex{0};
|
||||
|
||||
/** Over write enable */
|
||||
bool* overWriteEnable;
|
||||
|
||||
|
@ -69,7 +69,7 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt
|
||||
* @param fnum current frame index to include in file name
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int CreateFile(uint64_t fnum);
|
||||
int CreateFile();
|
||||
|
||||
/**
|
||||
* Close Current File
|
||||
|
@ -40,26 +40,24 @@ public:
|
||||
* @param fpath file path
|
||||
* @param fnameprefix file name prefix (includes scan and position variables)
|
||||
* @param findex file index
|
||||
* @param frindexenable frame index enable
|
||||
* @param fnum frame number index
|
||||
* @param subfindex sub file index
|
||||
* @param dindex readout index
|
||||
* @param numunits number of units per readout. eg. eiger has 2 udp units per readout
|
||||
* @param unitindex unit index
|
||||
* @returns complete file name created
|
||||
*/
|
||||
static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable,
|
||||
uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0)
|
||||
{
|
||||
std::ostringstream osfn;
|
||||
osfn << fpath << "/" << fnameprefix;
|
||||
if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex);
|
||||
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << fnum;
|
||||
osfn << "_" << findex;
|
||||
osfn << ".h5";
|
||||
return osfn.str();
|
||||
static std::string CreateFileName(char *fpath, char *fprefix,
|
||||
uint64_t findex, uint64_t subfindex,
|
||||
int dindex, int numunits = 1,
|
||||
int unitindex = 0) {
|
||||
std::ostringstream os;
|
||||
os << fpath << "/" << fprefix << "_d"
|
||||
<< (dindex * numunits + unitindex) << "_f" << subfindex << '_'
|
||||
<< findex << ".h5";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create master file name
|
||||
* @param fpath file path
|
||||
* @param fnameprefix file name prefix (includes scan and position variables)
|
||||
@ -68,12 +66,10 @@ public:
|
||||
*/
|
||||
static std::string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex)
|
||||
{
|
||||
std::ostringstream osfn;
|
||||
osfn << fpath << "/" << fnameprefix;
|
||||
osfn << "_master";
|
||||
osfn << "_" << findex;
|
||||
osfn << ".h5";
|
||||
return osfn.str();
|
||||
std::ostringstream os;
|
||||
os << fpath << "/" << fnameprefix << "_master"
|
||||
<< "_" << findex << ".h5";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +107,7 @@ public:
|
||||
delete fd;
|
||||
fd = 0;
|
||||
}
|
||||
} catch(Exception error) {
|
||||
} catch(const Exception& error) {
|
||||
FILE_LOG(logERROR) << "Could not close HDF5 handles of index " << ind;
|
||||
error.printErrorStack();
|
||||
}
|
||||
@ -129,7 +125,7 @@ public:
|
||||
delete fd;
|
||||
fd = 0;
|
||||
}
|
||||
} catch(Exception error) {
|
||||
} catch(const Exception& error) {
|
||||
FILE_LOG(logERROR) << "Could not close master HDF5 handles";
|
||||
error.printErrorStack();
|
||||
}
|
||||
@ -177,7 +173,7 @@ public:
|
||||
dset->write(buf, dtype, memspace, *dspace);
|
||||
memspace.close();
|
||||
}
|
||||
catch(Exception error){
|
||||
catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not write to file in object " << ind;
|
||||
error.printErrorStack();
|
||||
return 1;
|
||||
@ -239,7 +235,7 @@ public:
|
||||
dset_para[13]->write((char*)storage, parameterDataTypes[13], memspace, *dspace_para);
|
||||
}i=14;
|
||||
}
|
||||
catch(Exception error){
|
||||
catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not write parameters (index:" << i << ") to file in object " << ind;
|
||||
error.printErrorStack();
|
||||
return 1;
|
||||
@ -282,7 +278,7 @@ public:
|
||||
dspace_para = new DataSpace(dset_para[0]->getSpace());
|
||||
|
||||
}
|
||||
catch(Exception error){
|
||||
catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not extend dataset in object " << ind;
|
||||
error.printErrorStack();
|
||||
return 1;
|
||||
@ -417,7 +413,7 @@ public:
|
||||
|
||||
fd->close();
|
||||
|
||||
} catch(Exception error) {
|
||||
} catch(const Exception& error) {
|
||||
FILE_LOG(logERROR) << "Could not create master HDF5 handles";
|
||||
error.printErrorStack();
|
||||
if (fd) fd->close();
|
||||
@ -521,7 +517,7 @@ public:
|
||||
dset_para.push_back(ds);
|
||||
}
|
||||
}
|
||||
catch(Exception error){
|
||||
catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not create HDF5 handles in object " << ind;
|
||||
error.printErrorStack();
|
||||
if (fd) fd->close();
|
||||
@ -675,8 +671,9 @@ public:
|
||||
|
||||
//source file name
|
||||
std::string srcFileName = HDF5FileStatic::CreateFileName(fpath, fnameprefix, findex,
|
||||
frindexenable, framesSaved, dindex, numunits, i);
|
||||
j, dindex, numunits, i);
|
||||
|
||||
FILE_LOG(logERROR) << srcFileName;
|
||||
// find relative path
|
||||
std::string relative_srcFileName = srcFileName;
|
||||
{
|
||||
@ -688,7 +685,7 @@ public:
|
||||
//source dataset name
|
||||
std::ostringstream osfn;
|
||||
osfn << "/data";
|
||||
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << framesSaved;
|
||||
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << j;
|
||||
std::string srcDatasetName = osfn.str();
|
||||
|
||||
//source dataspace
|
||||
@ -861,7 +858,7 @@ public:
|
||||
newDataset->write(data_out,datatype);
|
||||
newfd->close();
|
||||
oldfd->close();
|
||||
} catch(Exception error){
|
||||
} catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not copy virtual files";
|
||||
error.printErrorStack();
|
||||
free(data_out);
|
||||
|
Reference in New Issue
Block a user