ZddConverter Class Reference

#include <ZddConverter.h>

List of all members.

Public Member Functions

bool convert (uint32_t *pdata, int size, Event::ZddEvent *evt)

Static Public Member Functions

static ZddConverterinstance (int runMode=2)
static void destroy ()

Private Member Functions

uint32_t * decodeBoard (uint32_t *pevt, Event::ZddEvent *evt)
uint32_t * decodeChannel (uint32_t *pch, ZddChannel *evt)
 ZddConverter (int runMode)
 ~ZddConverter ()
 ZddConverter ()

Private Attributes

int m_runMode

Static Private Attributes

static ZddConverters_instance = 0


Detailed Description

Definition at line 9 of file ZddConverter.h.


Constructor & Destructor Documentation

ZddConverter::ZddConverter ( int  runMode  )  [private]

Definition at line 163 of file ZddConverter.cxx.

00164     : m_runMode(runMode)
00165 {
00166 }

ZddConverter::~ZddConverter (  )  [private]

Definition at line 168 of file ZddConverter.cxx.

00169 {
00170 }

ZddConverter::ZddConverter (  )  [private]

Referenced by instance().


Member Function Documentation

bool ZddConverter::convert ( uint32_t *  pdata,
int  size,
Event::ZddEvent evt 
)

Definition at line 26 of file ZddConverter.cxx.

References decodeBoard().

Referenced by RawDataZddEventCnv::createObj().

00027 {
00028     // for debugging
00029     //std::cout << "RAW buffer size: " << size << std::endl << std::hex;
00030     //for ( int i = 0; i < size; ++i ) {
00031     //    if ( i%8 == 0 ) std::cout << "0x" << std::setw(8) << std::setfill('0') << i << ":";
00032     //    std::cout << " 0x" << std::setw(8) << std::setfill('0') << pdata[i];
00033     //    if ( i%8 == 7 ) std::cout << std::endl;
00034     //}
00035     //std::cout << std::dec << std::endl;
00037 
00038     uint32_t* pend = pdata + size;
00039 
00040     while ( pdata < pend ) {
00041         pdata = decodeBoard(pdata, evt);
00042     }
00043 
00044     if ( pdata != pend ) {
00045         std::cout << "ZddConverter: there are problems within the event data size" << std::endl;
00046         exit(1);
00047     }
00048 
00049     return true;
00050 }

uint32_t * ZddConverter::decodeBoard ( uint32_t *  pevt,
Event::ZddEvent evt 
) [private]

Definition at line 52 of file ZddConverter.cxx.

References ZddBoard::addChannel(), decodeChannel(), ZddBoard::setBoardId(), ZddChannel::setChId(), ZddBoard::setCounter(), ZddBoard::setTimeTag(), and delete_small_size::size.

Referenced by convert().

00053 {
00054     if ( (pevt[0] >> 28) != 10 ) {
00055         std::cout << "ZddConverter get wrong event marker!" << std::endl;
00056         exit(1);
00057     }
00058 
00059     int size = pevt[0] & 0xFFFFFFF;
00060     int board = pevt[1] >> 27;
00061     uint32_t chMask = pevt[1] & 0xFF;
00062 
00063     ZddBoard* zddBoard = new ZddBoard(evt);
00064     zddBoard->setBoardId(board);
00065     zddBoard->setCounter(pevt[2]&0xFFFFFF);
00066     zddBoard->setTimeTag(pevt[3]);
00067 
00068     int  ich = 0;
00069 
00070     uint32_t* pend = pevt + size;
00071     uint32_t* pchannel = pevt + 4;
00072 
00073     while ( pchannel < pend ) {
00074         while ( (chMask&(1<<ich)) == 0 ) {
00075             ++ich;
00076             if ( ich > 7 ) {
00077                 std::cout << "ZddConverter get wrong channel mask!" << std::endl;
00078                 exit(1);
00079             }
00080         }
00081         ZddChannel* zddCh = new ZddChannel();
00082         zddCh->setChId(board*100+ich);
00083         zddBoard->addChannel(zddCh);
00084         pchannel = decodeChannel(pchannel, zddCh);
00085         ++ich;
00086     }
00087 
00088     if ( pchannel != pend ) {
00089         std::cout << "ZddConverter: there are problems within the channel data size" << std::endl;
00090         exit(1);
00091     }
00092 
00093     return pend;
00094 }

uint32_t * ZddConverter::decodeChannel ( uint32_t *  pch,
ZddChannel evt 
) [private]

Definition at line 96 of file ZddConverter.cxx.

References ZddChannel::addFragments(), ZddFragment::length, ZddFragment::sample, ZddChannel::setScanCode(), delete_small_size::size, and ZddFragment::start_index.

Referenced by decodeBoard().

00097 {
00098     uint32_t* pend = pch + pch[0];
00099     uint32_t* pfrag = pch + 1;
00100 
00101     ZddFragment zddFrag;
00102 
00103     int nCtrlWord = 0;  //FIXME: check the good/skip transfrom, N < 14
00104 
00105     int lstat = 0;
00106     int index = 0;
00107     int samples = 800; // FIXME: writing 800 here is a bad idea
00108 
00109     while ( pfrag < pend ) {
00110         uint32_t& ctrl_word = pfrag[0];
00111         int  size = (ctrl_word & 0x1FFFFF) * 4;  //from words to bytes
00112 
00113         if ( ctrl_word >> 31 ) {  //fragment passed threshold
00114 
00115             if ( ctrl_word == 0xFEFEFEFE ) break; // CAEN FW bug discovered June 2014, not much serious:
00116                                                   // not really a control word, end of channel instead
00117 
00118             // previous treatment by Jaheng
00119             if ( (pfrag + size/4 + 1) > pend ) {  //FIXME: error ZDD data
00120                 std::cout << "BAD ZDD RAW DATA!" << std::endl;
00121                 //exit(1);
00122                 break;
00123             }
00124             zddFrag.start_index = index;
00125             zddFrag.length = size;
00126             zddFrag.sample = new unsigned char[size];
00127             memcpy(zddFrag.sample, pfrag+1, size);
00128             zddCh->addFragments(zddFrag);
00129             pfrag += size/4 + 1;
00130             if ( lstat < 0 ) ++nCtrlWord;
00131             lstat = 1;
00132         }
00133         else {  //fragment skipped
00134             pfrag += 1;
00135             if ( lstat > 0 ) ++ nCtrlWord;
00136             lstat = -1;
00137         }
00138 
00139         index += size;
00140 /* Following check UNNEEDED
00141         if ( nCtrlWord == 14 ) {  //FIXME: to be fixed
00142             if ( pfrag < pend ) {
00143                 zddFrag.start_index = index;
00144                 zddFrag.length = (pend-pfrag)*4;
00145                 zddFrag.sample = new unsigned char[zddFrag.length];
00146                 memcpy(zddFrag.sample, pfrag, zddFrag.length);
00147                 zddCh->addFragments(zddFrag);
00148             }
00149             break;
00150         }
00151 */
00152     }
00153 
00154     if ( index < samples ) {
00155         zddCh->setScanCode(-1); // mark channel as "Incomplete scan"
00156 //        std::cout << "ZDD MISS channelId=" << zddCh->getChId()
00157 //                  << " missing samples:" << samples-index << " marked INCOMPLETE SCAN" << std::endl;
00158     }
00159 
00160     return pend;
00161 }

void ZddConverter::destroy (  )  [static]

Definition at line 18 of file ZddConverter.cxx.

References s_instance.

Referenced by RawDataZddEventCnv::~RawDataZddEventCnv().

00019 {
00020     if ( s_instance != 0 ) {
00021         delete s_instance;
00022         s_instance = 0;
00023     }
00024 }

ZddConverter * ZddConverter::instance ( int  runMode = 2  )  [static]

Definition at line 9 of file ZddConverter.cxx.

References s_instance, and ZddConverter().

Referenced by RawDataZddEventCnv::initialize().

00010 {
00011     if ( s_instance == 0 ) {
00012         s_instance = new ZddConverter(runMode);
00013     }
00014 
00015     return s_instance;
00016 }


Member Data Documentation

int ZddConverter::m_runMode [private]

Definition at line 31 of file ZddConverter.h.

ZddConverter * ZddConverter::s_instance = 0 [static, private]

Definition at line 33 of file ZddConverter.h.

Referenced by destroy(), and instance().


Generated on Tue Nov 29 23:36:22 2016 for BOSS_7.0.2 by  doxygen 1.4.7