151 int status =
FindBank(name, &bklen, &bktype, pdata);
162static const unsigned TID_SIZE[] = {0, 1, 1, 1, 2, 2, 4, 4, 4, 4, 8, 1, 0, 0, 0, 0, 0, 8, 8};
179 if (((pbkh->
fFlags & (1<<5)) > 0)) {
183 memcpy(&dname, name, 4);
185 if (*((uint32_t *) pbk32->
fName) == dname) {
192 *bktype = pbk32->
fType;
208 if (name[0]==pbk32a->
fName[0] &&
209 name[1]==pbk32a->
fName[1] &&
210 name[2]==pbk32a->
fName[2] &&
211 name[3]==pbk32a->
fName[3]) {
218 *bktype = pbk32a->
fType;
222 }
else if (((pbkh->
fFlags & (1<<4)) > 0)) {
226 memcpy(&dname, name, 4);
228 if (*((uint32_t *) pbk32->
fName) == dname) {
235 *bktype = pbk32->
fType;
251 if (name[0]==pbk32->
fName[0] &&
252 name[1]==pbk32->
fName[1] &&
253 name[2]==pbk32->
fName[2] &&
254 name[3]==pbk32->
fName[3]) {
261 *bktype = pbk32->
fType;
268 if (name[0]==pbk->
fName[0] &&
269 name[1]==pbk->
fName[1] &&
270 name[2]==pbk->
fName[2] &&
271 name[3]==pbk->
fName[3]) {
278 *bktype = pbk->
fType;
300 printf(
"Event start:\n");
316 printf(
"TMidasEvent::Print: Use SetBankList() before Print() to print bank data\n");
322 for (
int i = 0; i <
fBanksN * 4; i += 4)
329 printf(
"Bank %c%c%c%c, length %6d, type %2d\n",
331 bankLength, bankType);
333 if (option[0] ==
'a' && found)
337 for (
int j = 0; j < bankLength; j++)
338 printf(
"0x%04x%c", ((uint16_t*)pdata)[j], (j%10==9)?
'\n':
' ');
342 for (
int j = 0; j < bankLength; j++)
343 printf(
"0x%08x%c", ((uint32_t*)pdata)[j], (j%10==9)?
'\n':
' ');
347 for (
int j = 0; j < bankLength; j++)
348 printf(
"0x%08x%c", ((uint32_t*)pdata)[j], (j%10==9)?
'\n':
' ');
352 for (
int j = 0; j < bankLength; j++)
353 printf(
"%.8g%c", ((
float*)pdata)[j], (j%10==9)?
'\n':
' ');
357 for (
int j = 0; j < bankLength; j++)
358 printf(
"%.16g%c", ((
double*)pdata)[j], (j%10==9)?
'\n':
' ');
362 printf(
"TMidasEvent::Print: Do not know how to print bank of type %d\n", bankType);
392 printf(
"Found FIXED-style event. Skipping.\n");
462 *pbk = (
TMidas_BANK *) ((
char*) (*pbk + 1) + ((((*pbk)->fDataSize)+7) & ~7));
464 *pdata = (
char*)((*pbk) + 1);
485 uint32_t length_adjusted = (length+7) & ~7;
487 *pbk = (
TMidas_BANK32 *) ((
char*) (*pbk + 1) + length_adjusted);
511 *pdata = (
char*)((*pbk) + 1);
532 uint32_t length_adjusted = (length+7) & ~7;
558 *pdata = (
char*)((*pbk) + 1);
574#define QWORD_SWAP(x) { BYTE _tmp; \
575_tmp= *((BYTE *)(x)); \
576*((BYTE *)(x)) = *(((BYTE *)(x))+7); \
577*(((BYTE *)(x))+7) = _tmp; \
578_tmp= *(((BYTE *)(x))+1); \
579*(((BYTE *)(x))+1) = *(((BYTE *)(x))+6); \
580*(((BYTE *)(x))+6) = _tmp; \
581_tmp= *(((BYTE *)(x))+2); \
582*(((BYTE *)(x))+2) = *(((BYTE *)(x))+5); \
583*(((BYTE *)(x))+5) = _tmp; \
584_tmp= *(((BYTE *)(x))+3); \
585*(((BYTE *)(x))+3) = *(((BYTE *)(x))+4); \
586*(((BYTE *)(x))+4) = _tmp; }
590#define DWORD_SWAP(x) { BYTE _tmp; \
591_tmp= *((BYTE *)(x)); \
592*((BYTE *)(x)) = *(((BYTE *)(x))+3); \
593*(((BYTE *)(x))+3) = _tmp; \
594_tmp= *(((BYTE *)(x))+1); \
595*(((BYTE *)(x))+1) = *(((BYTE *)(x))+2); \
596*(((BYTE *)(x))+2) = _tmp; }
600#define WORD_SWAP(x) { BYTE _tmp; \
601_tmp= *((BYTE *)(x)); \
602*((BYTE *)(x)) = *(((BYTE *)(x))+1); \
603*(((BYTE *)(x))+1) = _tmp; }
634 if (pbh->
fFlags < 0x10000 && ! force)
658 fprintf(stderr,
"TMidasEvent::SwapBytes() cannot swap bk_init32a data, sorry. bye!\n");
675 type = (uint16_t) pbk32->
fType;
699 while (pdata < pbk) {
701 pdata = ((
char*)pdata) + 2;
708 while (pdata < pbk) {
710 pdata = ((
char*)pdata) + 4;
714 while (pdata < pbk) {
716 pdata = ((
char*)pdata) + 8;
721 while (pdata < pbk) {
723 pdata = ((
char*)pdata) + 8;
736 static uint32_t endian = 0x12345678;
737 static bool once =
true;
738 static bool gDoByteSwap =
false;
741 gDoByteSwap = *(
char*)(&endian) != 0x78;
758 event->SwapBytesEventHeader();
765 rd = reader->
Read((
char*)
event->GetData(),
event->GetDataSize());
767 if (rd != (
int)
event->GetDataSize())
772 event->SwapBytes(
false);
782 printf(
"TMidasFile: error on write event header, return %d, size requested %d\n", wr, (
int)
sizeof(
TMidas_EVENT_HEADER));
789 printf(
"TMidasFile: error on write event header, return %d, size requested %d\n", wr, (
int)event->
GetDataSize());
bool TMWriteEvent(TMWriterInterface *writer, TMidasEvent *event)
static const unsigned TID_MAX
static const unsigned TID_SIZE[]
bool TMReadEvent(TMReaderInterface *reader, TMidasEvent *event)
virtual int Read(void *buf, int count)=0
virtual int Write(const void *buf, int count)=0
int FindBank(const char *bankName, int *bankLength, int *bankType, void **bankPtr) const
int SwapBytes(bool)
convert event data between little-endian (Linux-x86) and big endian (MacOS-PPC)
bool IsBank32() const
returns "true" if event uses bk_init32() banks
int IterateBank32(TMidas_BANK32 **, char **pdata) const
iterate through 32-bit data banks
TMidas_EVENT_HEADER * GetEventHeader()
return pointer to the event header
void Clear()
clear event for reuse
uint32_t GetDataSize() const
return the event size
int fBanksN
number of banks in this event
int SetBankList()
create the list of data banks, return number of banks
int IterateBank32a(TMidas_BANK32a **, char **pdata) const
iterate through 32-bit data banks
void AllocateData()
allocate data buffer using the existing event header
const char * GetBankList() const
return a list of data banks
int IterateBank(TMidas_BANK **, char **pdata) const
iterate through 16-bit data banks
uint16_t GetEventId() const
return the event id
int LocateBank(const void *unused, const char *bankName, void **bankPtr) const
bool IsBank32a() const
returns "true" if event uses bk_init32a() banks
uint32_t GetTimeStamp() const
return the time stamp (unix time in seconds)
TMidasEvent()
default constructor
TMidasEvent & operator=(const TMidasEvent &)
assignement operator
void SetData(uint32_t dataSize, char *dataBuffer)
set an externally allocated data buffer
bool fAllocatedByUs
"true" if we own the data buffer
char * fData
event data buffer
void Print(const char *option="") const
show all event information
uint32_t GetSerialNumber() const
return the serial number
uint16_t GetTriggerMask() const
return the triger mask
TMidas_EVENT_HEADER fEventHeader
event header
bool IsGoodSize() const
validate the event length
void Copy(const TMidasEvent &)
copy helper
char * GetData()
return pointer to the data buffer
char * fBankList
list of bank names in this event
void SwapBytesEventHeader()
convert event header between little-endian (Linux-x86) and big endian (MacOS-PPC)
uint32_t fType
type of data (see midas.h TID_xxx)
uint32_t fType
type of data (see midas.h TID_xxx)
uint16_t fType
type of data (see midas.h TID_xxx)
uint32_t fDataSize
event size in bytes
uint16_t fTriggerMask
event trigger mask
uint16_t fEventId
event id
uint32_t fSerialNumber
event serial number
uint32_t fTimeStamp
event timestamp in seconds