11 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 23 :
zofits(numTiles, rowPerTile, maxMem)
31 :
zofits(fname, numTiles, rowPerTile, maxMem)
55 for (uint32_t
i=0;
i<1440*1024;
i++)
67 for (uint32_t
i=0;
i<1440*1024;
i++)
82 for (uint32_t
i=0;
i<1024*1440;
i++)
98 if (it->col.name ==
"StartCellData")
101 if (it->col.name ==
"Data")
108 throw std::runtime_error(
"Number of data samples not a multiple of 1440.");
110 gLog <<
___warn___ <<
"WARNING - Number of data samples not a multiple of 1440. Doing it uncalibrated." << std::endl;
121 throw std::runtime_error(
"FACT Calibration requested, but \"StartCellData\" column not found.");
123 gLog <<
___warn___ <<
"WARNING - FACT Calibration requested, but \"StartCellData\" column not found. Doing it uncalibrated." << std::endl;
132 throw std::runtime_error(
"FACT Calibration requested, but \"Data\" column not found.");
134 gLog <<
___warn___ <<
"WARNING - FACT Calibration requested, but \"Data\" column not found. Doing it uncalibrated." << std::endl;
198 const uint32_t catalog_size =
sizeof(int64_t)*2;
201 c.
SetStr(
"XTENSION",
"BINTABLE" ,
"binary table extension");
202 c.
SetInt(
"BITPIX" , 8 ,
"8-bit bytes");
203 c.
SetInt(
"NAXIS" , 2 ,
"2-dimensional binary table");
204 c.
SetInt(
"NAXIS1" , catalog_size ,
"width of table in bytes");
205 c.
SetInt(
"NAXIS2" , 1 ,
"number of rows in table");
206 c.
SetInt(
"PCOUNT" , 0 ,
"size of special data area");
207 c.
SetInt(
"GCOUNT" , 1 ,
"one data group (required keyword)");
208 c.
SetInt(
"TFIELDS" , 1 ,
"number of fields in each row");
209 c.
SetStr(
"CHECKSUM",
"0000000000000000" ,
"Checksum for the whole HDU");
210 c.
SetStr(
"DATASUM" ,
" 0" ,
"Checksum for the data block");
211 c.
SetStr(
"EXTNAME" ,
"ZDrsCellOffsets" ,
"name of this binary table extension");
212 c.
SetStr(
"TTYPE1" ,
"OffsetCalibration" ,
"label for field 1");
213 c.
SetStr(
"ZFORM1" ,
"1474560I" ,
"data format of field: 2-byte INTEGER");
214 c.
SetStr(
"TFORM1" ,
"1QB" ,
"data format of variable length bytes");
215 c.
SetStr(
"ZCTYP1" ,
"FACT" ,
"Compression type FACT");
217 c.
SetBool(
"ZTABLE",
true,
"Table is compressed");
218 c.
SetInt(
"ZNAXIS1", 1024*1440*2,
"Width of uncompressed rows");
219 c.
SetInt(
"ZNAXIS2", 1,
"Number of uncompressed rows");
220 c.
SetInt(
"ZPCOUNT", 0,
"");
221 c.
SetInt(
"ZHEAPPTR", catalog_size,
"");
222 c.
SetInt(
"ZTILELEN", 1,
"Number of rows per tile");
223 c.
SetInt(
"THEAP", catalog_size,
"");
224 c.
SetStr(
"RAWSUM",
" 0",
"Checksum of raw little endian data");
225 c.
SetFloat(
"ZRATIO", 0,
"Compression ratio");
227 c.
SetInt(
"ZSHRINK", 1,
"Catalog shrink factor");
232 const off_t here_I_am = tellp();
235 seekp(here_I_am + catalog_size);
240 #if GCC_VERSION < 40603 241 c.
SetStr(
"RAWSUM", std::to_string((
long long unsigned int)(rawsum.
val())));
243 c.
SetStr(
"RAWSUM", std::to_string(rawsum.
val()));
248 std::vector<char> compressed_calib(1024*1440*2 + compressed_header_size + 8);
249 char* data_start = compressed_calib.data() + compressed_header_size;
251 compressed_size += compressed_header_size;
258 th.
size = compressed_size;
265 memset(compressed_calib.data()+compressed_size, 0, 8-compressed_size%8);
266 datasum.
add(compressed_calib.data(), compressed_size + 8-compressed_size%8);
271 std::vector<uint64_t> catalog(2,0);
275 std::vector<char> swappedCatalog(catalog_size);
276 revcpy<sizeof(int64_t)>(swappedCatalog.data(), (
char*)(catalog.data()), 2);
277 datasum.
add(swappedCatalog.data(), catalog_size);
279 write(swappedCatalog.data(), catalog_size);
282 c.
SetFloat(
"ZRATIO", (
float)(1024*1440*2)/(
float)(compressed_size));
283 c.
SetInt(
"PCOUNT", compressed_size);
289 #if GCC_VERSION < 40603 290 c.
SetStr(
"DATASUM", std::to_string((
long long unsigned int)(datasum.
val())));
292 c.
SetStr(
"DATASUM", std::to_string(datasum.
val()));
302 seekp(here_I_am + catalog_size);
303 write(compressed_calib.data(), compressed_size);
316 const int16_t* startCell =
reinterpret_cast<int16_t*
>(target_location +
fStartCellsOffset);
317 int16_t*
data =
reinterpret_cast<int16_t*
>(target_location +
fDataOffset);
319 for (uint32_t ch=0; ch<1440; ch++)
321 if (startCell[ch] < 0)
327 const int16_t modStart = startCell[ch]%1024;
330 const int16_t* cal = off+modStart;
333 if (modStart+fNumSlices > 1024)
335 while (cal < off+1024)
340 while (data<end_stride)
349 if (size == 1440*1024)
352 std::ostringstream
str;
353 str <<
"Cannot load calibration with anything else than 1440 pixels and 1024 samples per pixel. Got a total size of " <<
size;
355 throw std::runtime_error(str.str());
bool SetInt(const std::string &key, int64_t i, const std::string &comment="")
std::vector< int32_t > fOffset
int32_t fNumSlices
Number of samples per pixel per event.
virtual bool WriteDrsOffsetsTable()
Uncompressed version of the DrsCalibration table.
uint32_t compressHUFFMAN16(char *dest, const char *src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems)
bool VerifyCalibrationSize(uint32_t size)
Checks if the size of the input calibration is ok.
static uint32_t DefaultMaxMemory(const uint32_t &_n=0)
bool SetBool(const std::string &key, bool b, const std::string &comment="")
int32_t fDataOffset
Offset in bytes for the data.
static uint32_t DefaultMaxNumTiles(const uint32_t &_n=0)
void Memcpy(char *dest) const
int32_t fStartCellsOffset
Offset in bytes for the startcell data.
void SetDrsCalibration(const std::vector< int16_t > &vec)
assign a given drs offset calibration
virtual bool WriteTableHeader(const char *name="DATA")
void SetDrsCalibration(const std::vector< float > &calib)
assign a given drs offset calibration
void SetDrsCalibration(const DrsCalibration &drs)
assign a given drs offset calibration
bool SetStr(const std::string &key, std::string s, const std::string &comment="")
std::string str(bool complm=true) const
std::vector< int16_t > fOffsetCalibration
The calibration itself.
bool SetFloat(const std::string &key, double f, int p, const std::string &comment="")
std::vector< CompressedColumn > fRealColumns
Vector hosting the columns of the file.
static uint32_t DefaultNumRowsPerTile(const uint32_t &_n=0)
factofits(const char *fname, uint32_t numTiles=DefaultMaxNumTiles(), uint32_t rowPerTile=DefaultNumRowsPerTile(), uint32_t maxMem=DefaultMaxMemory())
virtual void DrsOffsetCalibrate(char *target_location)
Apply the drs offset calibration (overload of super-method)
factofits(uint32_t numTiles=DefaultMaxNumTiles(), uint32_t rowPerTile=DefaultNumRowsPerTile(), uint32_t maxMem=DefaultMaxMemory())
constructors
virtual bool IsOffsetCalibration()
whether or not a calibration was given to the file writer
bool add(const char *buf, size_t len, bool big_endian=true)
Checksum WriteHeader(std::ostream &fout)
void SetBlockSize(uint64_t size)
bool WriteTableHeader(const char *name="DATA")
Overload of the super function.