//----------------------------------------------------------------------------- // Jan 11 2001 P.Murat: STNTUPLE utility routines //----------------------------------------------------------------------------- #include "evt/Event.hh" #include "Bbos/bank_interface.hh" #include "Stntuple/base/TStnArrayI.hh" #include "Stntuple/data/TTdcHeader.hh" #include "Stntuple/mod/StntupleUtilities.hh" //_____________________________________________________________________________ Int_t StntupleUnpackTdcBank(TRYBOS_BANK* bank, TStnArrayI& a) { // unpack YBOS TDC bank into a TStnArrayI int loc, iloc, nblk, nw, nw_blk, nw_total, ntdc, loc_blk, loc_hdr; int loc_data, ver; TTdcHeader* header; if (! bank) return 0; nw_total = 0; nblk = bank->iw(0); ver = bank->bank_version(); if (ver == 0) { //----------------------------------------------------------------------------- // old TDC format : define total number of the data words to be copied //----------------------------------------------------------------------------- for (int iblk=0; iblkiw(iblk+1); nw_blk = bank->iw(iblk+2)-loc_blk; if (nw_blk > 0) { ntdc = bank->iw(loc_blk); for (int itdc=0; itdciw(loc+1)-bank->iw(loc); //----------------------------------------------------------------------------- // forget about redundancy and rely on that TDC header has its ID in it //----------------------------------------------------------------------------- nw_total += nw; } } } a.Reserve(nw_total); // now loop over the data blocks // another time and copy the data for (int iblk=0; iblkiw(iblk+1); nw_blk = bank->iw(iblk+2)-loc_blk; if (nw_blk > 0) { ntdc = bank->iw(loc_blk); for (int itdc=0; itdciw(loc+1)-bank->iw(loc); // forget about redundancy and rely // on that TDC header has its ID in it if (nw > 0) { loc_data = loc_blk+bank->iw(loc); a.Append(&bank->iw(loc_data),nw); } } } } } else if (ver == 1) { //----------------------------------------------------------------------------- // new TDC format : define total number of the data words to be copied //----------------------------------------------------------------------------- for (int iblk=0; iblkiw(iblk+1); nw_blk = bank->iw(iblk+2)-loc_blk; if (nw_blk > 0) { ntdc = bank->iw(loc_blk); for (int itdc=0; itdciw(loc+1)-1; header = (TTdcHeader*) &bank->iw(loc_hdr); nw = header->NDataWords(); nw_total += (1+nw); } } } a.Reserve(nw_total); // now loop over the data blocks // another time and copy the data for (int iblk=0; iblkiw(iblk+1); nw_blk = bank->iw(iblk+2)-loc_blk; if (nw_blk > 0) { ntdc = bank->iw(loc_blk); for (int itdc=0; itdciw(loc+1)-1; a.Append(&bank->iw(loc_hdr),1); header = (TTdcHeader*) &bank->iw(loc_hdr); nw = header->NDataWords(); if (nw > 0) { loc_data = loc_blk+bank->iw(loc); a.Append(&bank->iw(loc_data),nw); } } } } loc = 0; } return 0; }