16 : fData(nullptr), fBanksN(0), fBankList(nullptr), fAllocatedByUs(false)
125 if(
fData ==
nullptr) {
153 int status =
FindBank(name, &bklen, &bktype, pdata);
175 std::array<unsigned, 17> TID_SIZE = {0, 1, 1, 1, 2, 2, 4, 4, 4, 4, 8, 1, 0, 0, 0, 0, 0};
177 if(((pbkh->fFlags & (1 << 4)) > 0)) {
182 if(pbk32 ==
nullptr) {
186 if(name[0] == pbk32->
fName[0] && name[1] == pbk32->
fName[1] && name[2] == pbk32->
fName[2] &&
187 name[3] == pbk32->
fName[3]) {
189 if(TID_SIZE[pbk32->
fType & 0xFF] == 0) {
195 *bktype = pbk32->
fType;
202 if(name[0] == pbk->
fName[0] && name[1] == pbk->
fName[1] && name[2] == pbk->
fName[2] &&
203 name[3] == pbk->
fName[3]) {
205 if(TID_SIZE[pbk->
fType & 0xFF] == 0) {
211 *bktype = pbk->
fType;
214 pbk =
reinterpret_cast<TMidas_BANK*
>(
reinterpret_cast<char*
>(pbk + 1) + (((pbk->
fDataSize) + 7) & ~7));
215 }
while(
reinterpret_cast<char*
>(pbk) <
reinterpret_cast<char*
>(pbkh) + pbkh->fDataSize +
sizeof(
TMidas_BANK_HEADER));
233 std::cout <<
"Event start:" << std::endl;
245 std::cout <<
"Message event \"" <<
fData <<
"\"" << std::endl;
247 std::cout <<
"TMidasEvent::Print: Use SetBankList() before Print() to print bank data" << std::endl;
249 std::cout <<
"Banks: " <<
fBankList << std::endl;
251 for(
int i = 0; i <
fBanksN * 4; i += 4) {
254 void* pdata =
nullptr;
257 std::cout <<
"Bank " <<
fBankList[i] <<
fBankList[i + 1] <<
fBankList[i + 2] <<
fBankList[i + 3] <<
", length " << std::setw(6) << bankLength <<
", type " << bankType << std::endl;
260 if(strlen(option) > 1) {
261 highlight = atoi(option + 1);
264 if(option[0] ==
'a' && (found != 0)) {
267 for(
int j = 0; j < bankLength; j++) {
269 std::cout << ALERTTEXT << hex((reinterpret_cast<uint16_t*>(pdata))[j], 4) <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
271 std::cout << hex((reinterpret_cast<uint16_t*>(pdata))[j], 4) << ((j % 10 == 9) ?
'\n' :
' ');
274 std::cout << std::endl;
277 for(
int j = 0; j < bankLength; j++) {
279 std::cout << ALERTTEXT << hex((reinterpret_cast<uint32_t*>(pdata))[j], 8) <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
281 std::cout << hex((reinterpret_cast<uint32_t*>(pdata))[j], 8) << ((j % 10 == 9) ?
'\n' :
' ');
284 std::cout << std::endl;
287 for(
int j = 0; j < bankLength; j++) {
289 std::cout << ALERTTEXT << hex((reinterpret_cast<uint32_t*>(pdata))[j], 8) <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
291 std::cout << hex((reinterpret_cast<uint32_t*>(pdata))[j], 8) << ((j % 10 == 9) ?
'\n' :
' ');
294 std::cout << std::endl;
297 for(
int j = 0; j < bankLength; j++) {
299 std::cout << ALERTTEXT << (reinterpret_cast<float*>(pdata))[j] <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
301 std::cout << (reinterpret_cast<float*>(pdata))[j] << ((j % 10 == 9) ?
'\n' :
' ');
304 std::cout << std::endl;
307 for(
int j = 0; j < bankLength; j++) {
309 std::cout << ALERTTEXT << (reinterpret_cast<double*>(pdata))[j] <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
311 std::cout << (reinterpret_cast<double*>(pdata))[j] << ((j % 10 == 9) ?
'\n' :
' ');
314 std::cout << std::endl;
317 std::cout <<
"TMidasEvent::Print: Do not know how to print bank of type " << bankType << std::endl;
358 char* pdata =
nullptr;
368 if(pmbk32 ==
nullptr) {
375 if(pmbk ==
nullptr) {
399 if(*pbk ==
nullptr) {
402 *pbk =
reinterpret_cast<TMidas_BANK*
>(
reinterpret_cast<char*
>(*pbk + 1) + ((((*pbk)->fDataSize) + 7) & ~7));
405 *pdata =
reinterpret_cast<char*
>((*pbk) + 1);
407 if(
reinterpret_cast<char*
>(*pbk) >=
422 if(*pbk ==
nullptr) {
425 uint32_t length = (*pbk)->fDataSize;
426 uint32_t length_adjusted = (length + 7) & ~7;
427 *pbk =
reinterpret_cast<TMidas_BANK32*
>(
reinterpret_cast<char*
>(*pbk + 1) + length_adjusted);
430 auto* bk4 =
reinterpret_cast<TMidas_BANK32*
>((
reinterpret_cast<char*
>(*pbk)) + 4);
432 if((*pbk)->fType > 17) {
433 if(bk4->fType <= 17) {
443 *pdata =
reinterpret_cast<char*
>((*pbk) + 1);
445 if(
reinterpret_cast<char*
>(*pbk) >=
reinterpret_cast<char*
>(event) + event->fDataSize +
sizeof(
TMidas_BANK_HEADER)) {
459#define QWORD_SWAP(x) \
462 _tmp = *((BYTE*)(x)); \
463 *((BYTE*)(x)) = *(((BYTE*)(x)) + 7); \
464 *(((BYTE*)(x)) + 7) = _tmp; \
465 _tmp = *(((BYTE*)(x)) + 1); \
466 *(((BYTE*)(x)) + 1) = *(((BYTE*)(x)) + 6); \
467 *(((BYTE*)(x)) + 6) = _tmp; \
468 _tmp = *(((BYTE*)(x)) + 2); \
469 *(((BYTE*)(x)) + 2) = *(((BYTE*)(x)) + 5); \
470 *(((BYTE*)(x)) + 5) = _tmp; \
471 _tmp = *(((BYTE*)(x)) + 3); \
472 *(((BYTE*)(x)) + 3) = *(((BYTE*)(x)) + 4); \
473 *(((BYTE*)(x)) + 4) = _tmp; \
478#define DWORD_SWAP(x) \
481 _tmp = *((BYTE*)(x)); \
482 *((BYTE*)(x)) = *(((BYTE*)(x)) + 3); \
483 *(((BYTE*)(x)) + 3) = _tmp; \
484 _tmp = *(((BYTE*)(x)) + 1); \
485 *(((BYTE*)(x)) + 1) = *(((BYTE*)(x)) + 2); \
486 *(((BYTE*)(x)) + 2) = _tmp; \
491#define WORD_SWAP(x) \
494 _tmp = *((BYTE*)(x)); \
495 *((BYTE*)(x)) = *(((BYTE*)(x)) + 1); \
496 *(((BYTE*)(x)) + 1) = _tmp; \
516 void* pdata =
nullptr;
527 if(pbh->
fFlags < 0x10000 && !force) {
566 type =
static_cast<uint16_t
>(pbk32->
fType);
578 pbk32 =
reinterpret_cast<TMidas_BANK32*
>(
reinterpret_cast<char*
>(pbk32 + 1) + (((pbk32->
fDataSize) + 7) & ~7));
582 pbk =
reinterpret_cast<TMidas_BANK*
>(
reinterpret_cast<char*
>(pbk + 1) + (((pbk->
fDataSize) + 7) & ~7));
591 pdata = (
reinterpret_cast<char*
>(pdata)) + 2;
600 pdata = (
reinterpret_cast<char*
>(pdata)) + 4;
606 pdata = (
reinterpret_cast<char*
>(pdata)) + 8;
std::string hex(T val, int width=-1)
bool IsBank32() const
returns "true" if event uses 32-bit banks
int IterateBank32(TMidas_BANK32 **, char **pdata) const
iterate through 32-bit data banks
TMidas_EVENT_HEADER * GetEventHeader()
return pointer to the event header
int fBanksN
number of banks in this event
int SetBankList()
create the list of data banks, return number of banks
void SetData(uint32_t size, char *data)
set an externally allocated data buffer
void Clear(Option_t *opt="") override
clear event for reuse
char * GetData() override
return pointer to the data buffer
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
void Print(const char *option="") const override
show all event information
~TMidasEvent() override
destructor
uint32_t GetTimeStamp() const override
return the time stamp (unix time in seconds)
int FindBank(const char *name, int *bklen, int *bktype, void **pdata) const
TMidasEvent()
default constructor
TMidasEvent & operator=(const TMidasEvent &)
assignement operator
bool fAllocatedByUs
"true" if we own the data buffer
int LocateBank(const void *unused, const char *name, void **pdata) const
char * fData
event data buffer
uint32_t GetSerialNumber() const
return the serial number
uint16_t GetTriggerMask() const
return the triger mask
int SwapBytes(bool) override
convert event data between little-endian (Linux-x86) and big endian (MacOS-PPC)
TMidas_EVENT_HEADER fEventHeader
event header
bool IsGoodSize() const
validate the event length
uint32_t GetDataSize() const override
return the event size
void Copy(TObject &) const override
copy helper
char * fBankList
list of bank names in this event
void SwapBytesEventHeader()
convert event header between little-endian (Linux-x86) and big endian (MacOS-PPC)
void Clear(Option_t *="") override
clear event for reuse
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
char fName[4]
bank name // NOLINT(*-avoid-c-arrays)
char fName[4]
bank name // NOLINT(*-avoid-c-arrays)