ROOT logo
//*****************************************************************************
// File: $RCSfile: $
//
// Author: Joern Wuestenfeld
//
// Version: $Revision $
// Modified by $Author $
//
//
//*****************************************************************************
//_HADES_CLASS_DESCRIPTION
///////////////////////////////////////////////////////////////////////////////
// HMdcUnpacker
//
// setDoBitFlipCorr(Bool_t do=kTRUE,TString version="auto") enables (default) or
// disables the bit flip corrections. By default the version is recognized by
// the filename (year,dayOfYear) ("auto"). The versions can be set manually
//  version :   "auto"   by filename (works on standard file names like
//               be1222210203001.hld (containing evtbuilder),
//               be12222102030_10.hld (grep files, no evtbuilder but _xx*.hld)
//               and an of the above with .hld.f_ (filtered files))
//              "apr12"  for beam data apr12  (does no analyze filenames)
//*****************************************************************************
#include "hmdcunpacker.h"
#include "hmdcunpackerpar.h"
#include "hmdcdataword.h"
#include "hevent.h"
#include "hldsubevt.h"
#include "heventheader.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hcategory.h"
#include "hmessagemgr.h"
#include "hmdcdetector.h"
#include "hmdcrawstruct.h"
#include "hmdclookupgeom.h"
#include "hmdcraw.h"
#include "hparset.h"
#include "hmdcdef.h"
#include "htrbnetunpacker.h"
#include "hmdcoepaddrcorrpar.h"
#include "hmdcoepstatusdata.h"
#include "hldsource.h"
#include "hspectrometer.h"
#include "htime.h"


#include "TRegexp.h"

ClassImp(HMdcUnpacker)

    HMdcUnpacker::HMdcUnpacker(Int_t id, Bool_t dbg, Bool_t consisCheck)
    : HldUnpack()
{
    // Default constructor.
    // id = sub event id for which the unpacker is called
    // dbg = debug flag
    // consisCheck = enable consistency checking of dataword
    setDefaults();
    debugMode = dbg;
    consistencyCheck = consisCheck;
    subEvtId = id;
}

HMdcUnpacker::HMdcUnpacker(HMdcUnpacker &unp)
: HldUnpack(unp)
{
    // Copy constructor
    debugMode = unp.debugMode;
    continueDecodingAfterInconsistency = unp.continueDecodingAfterInconsistency;
    consistencyCheck = unp.consistencyCheck;
    subEvtId = unp.subEvtId;
    noComment = unp.noComment;
    pUnpackerPar = unp.pUnpackerPar;
    rawc = unp.rawc;
    pRawCat = unp.pRawCat;
    pDetector = unp.pDetector;
    decodeVersion = unp.decodeVersion;
    doAddrCorrection = unp.doAddrCorrection;
    mdcDataWordCatPersistency = unp.mdcDataWordCatPersistency;
    pMdcOepStatusCat = unp.pMdcOepStatusCat;
    fillOepStatus = unp.fillOepStatus;
    mdcOepStatusCatPersistency = unp.mdcOepStatusCatPersistency;;
    doBitFlipCorr = unp.doBitFlipCorr;
    bitFlipVersion = unp.bitFlipVersion;
    trbNetUnpacker  = unp.trbNetUnpacker;
}

HMdcUnpacker::~HMdcUnpacker(void)
{
    // Destructor
    if(dataword)
    {
	delete dataword;
	dataword = NULL;
    }
}

Bool_t HMdcUnpacker::init(void)
{
    // Initialization routine.
    // Retrieves pointers to the following objects:
    //			- unpacker parameters
    //			- raw structure
    //			- address correction table
    //			- category for raw - level information
    //			- category for debug information (if requested)

    // get Pointer to runtime database
    HRuntimeDb *rtdb = gHades->getRuntimeDb();

    if (kTRUE == debugMode) {
	gHades->getMsg()->info(9,HMessageMgr::DET_MDC,GetName(),"responsible for : 0x%x",subEvtId);
    }
    if((pDetector = gHades->getSetup()->getDetector("Mdc")) == NULL)
    {
	ERROR_msg(HMessageMgr::DET_MDC, "Could not get pointer to Mdc detector!");
	return kFALSE;
    }

    // 1. Parameter container
    pUnpackerPar = (HMdcUnpackerPar *)rtdb->getContainer("MdcUnpackerPar");
    if(!pUnpackerPar)
    {
	ERROR_msg(HMessageMgr::DET_MDC, "Could not get MdcUnpackerPar container!");
	return kFALSE;
    }

    // 2. Raw Struct
    rawc = (HMdcRawStruct *)rtdb->getContainer("MdcRawStruct");
    if(!rawc)
    {
	ERROR_msg(HMessageMgr::DET_MDC, "Could not get MdcRawStruct container!");
	return kFALSE;
    }

    // need implicit initialization if not yet done, i.e. not set to static
    if(!rawc->isStatic())
    {
	((HParSet*)rawc)->init();
    }

    // 3. Lookup table for channel to wire/layer mapping
    lookupGeom = (HMdcLookupGeom *)rtdb->getContainer("MdcLookupGeom");
    if(!lookupGeom)
    {
	ERROR_msg(HMessageMgr::DET_MDC, "Could not get MdcLookupGeom container!");
	return kFALSE;
    }


    // 3. Address correction parameters
    addrCorrPar = (HMdcOepAddrCorrPar*)rtdb->getContainer("MdcOepAddrCorrPar");
    if(!addrCorrPar)
    {
	ERROR_msg(HMessageMgr::DET_MDC, "Could not get MdcOepAddrCorrPar container!");
	return kFALSE;
    }

    // 4. initialize trbNetUnpacker
    if (NULL == trbNetUnpacker) {
	if (gHades->getDataSource()) {
	    HDataSource* source = gHades->getDataSource();
	    if (source->InheritsFrom("HldSource")) {
		trbNetUnpacker = ((HldSource *)gHades->getDataSource())->getTrbNetUnpacker();
	    } else {
		Warning("init", "DataSource not inherited from HldSource! trbNetUnpacker == 0 ");
	    }
	} else {
	    Warning("init", "Could not retrieve DataSource! trbNetUnpacker == 0 ");
	}
    }
    if(!trbNetUnpacker)
    {
	ERROR_msg(HMessageMgr::DET_MDC, "Failed to accquire pointer to HTrbNetUnpacker!");
	return kFALSE;
    }
    /*  if(!trbNetUnpacker->init())
     {
     ERROR_msg(HMessageMgr::DET_MDC, "Failed to initialize HTrbNetUnpacker!");
     return kFALSE;
     }*/
    // initialize categories
    // 1. catMdcRaw
    if(!(pRawCat = initCategory(catMdcRaw, "catMdcRaw")))
    {
	ERROR_msg(HMessageMgr::DET_MDC, "Could not create MdcRaw category");
	return kFALSE;
    }

    // 2. catMdcDataWord
    if(fillDataWord)
    {
	pMdcDataWordCat = initCategory(catMdcDataWord,"catMdcDataWord");
	if(!pMdcDataWordCat)
	{
	    ERROR_msg(HMessageMgr::DET_MDC, "Could not create MdcDataWord category");
	    return kFALSE;
	}
    }
    // 3. catMdcOepStatus
    if(fillOepStatus)
    {
	pMdcOepStatusCat = initCategory(catMdcOepStatus,"catMdcOepStatus");
	if(!pMdcOepStatusCat)
	{
	    ERROR_msg(HMessageMgr::DET_MDC, "Could not create MdcOepStatusData category");
	    return kFALSE;
	}
    }
    // set persistencies
    if(fillDataWord)
    {
	pMdcDataWordCat->setPersistency(mdcDataWordCatPersistency);
    }
    if(fillOepStatus)
    {
	pMdcOepStatusCat->setPersistency(mdcOepStatusCatPersistency);
    }
    return kTRUE;
}

Bool_t HMdcUnpacker::reinit(void)
{
    // reinit function, called for every new file once.
    // Creates dataword depending on data version
    Int_t tmp;

    // Check if decode version changed (from file to file)
    // dataword may change then!
    tmp = pUnpackerPar->getDecodeVersion();
    if(decodeVersion == -1)
    {
	decodeVersion = tmp;
    }
    else
    {
	if(decodeVersion != tmp)
	{
	    delete dataword;
	    dataword = NULL;
	    decodeVersion = tmp;
	}
    }
    if((decodeVersion < 0) || (decodeVersion > MAX_OEP_DECODE_VERSIONS-1))
    {
	ERROR_msg(HMessageMgr::DET_MDC, "Invalid decode version!\nExiting!\n");
	exit(EXIT_FAILURE);
    }
    doAddrCorrection = pUnpackerPar->getDoAddrCorr();
    tdcMode = pUnpackerPar->getTdcMode();
    doMapOutUnusedChannels = pUnpackerPar->getMapUnusedChannels();
    // Initialize dataword only if not yet done
    // Required if Hades eventloop is called more than once.
    if(dataword == NULL)
    {
	switch(decodeVersion)
	{
	case 0:
	case 1:
	    dataword = new HMdcDataword();
	    break;
	default:
	    ERROR_msg(HMessageMgr::DET_MDC, "No valid decoding version defined!\nExiting!!!\n");
	    exit(EXIT_FAILURE);
	}
	dataword->setQuietMode(noComment);
    }

    return kTRUE;
}

Int_t HMdcUnpacker::execute(void)
{
    // This function is called for each event
    // It does the unpacking of the data from the hld file into the RAW category.
    //
    // return values: always 1 (philosophy: a wrong sub event should not affect the other sub events)

    UInt_t *data;
    UInt_t *end;
    Int_t diff;
    Int_t addr;

    if (pSubEvt)
    {
	/*
	 if(debugMode && !noComment)
	 {
	 gHades->getMsg()->info(1,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x - trigger typ 0x%x",
	 gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId,
	 gHades->getCurrentEvent()->getHeader()->getId());
	 }
	 */
	data = pSubEvt->getData();
	end  = pSubEvt->getEnd();
	diff = (end - data);

	if((gHades->getCurrentEvent()->getHeader()->getId() == 14) && (!noComment))
	{
	    gHades->getMsg()->info(5,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x - trigger typ 0x%x",
				   gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId,
				   gHades->getCurrentEvent()->getHeader()->getId());
	}
	if(diff < 0)
	{
	    if(!noComment)
	    {
		gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x - negative eventsize (%i) ... skipping subevent!",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId,diff);
		return -1;
	    } else {
		return -1;
	    }
	}
	// data loop
	while(data < end)
	{
	    dataword->clearData();
	    switch(*data & 0xf000)
	    {
		// Data from MDC HUB -> debug information goes via common global unpacker
	    case 0x1000:
		decodeTrbNet(data);
		// move datapointer to end of TRBNet data block
		data+=((*data&0xffff0000)>>16)+1;
		break;
		// Data from Sub Event Builder
	    case 0x5000:
		if((*data & 0xffff) == 0x5555)
		{
		    decodeTrbNet(data,subEvtId);
		    // move datapointer to end of TRBNet data block
		    data+=((*data&0xffff0000)>>16)+1;
		} else {
		    return 1;
		}
		break;
	    case 0x2000:
		if(!dataword->subHeader(data,decodeVersion,consistencyCheck))
		{
		    if(debugMode && !noComment)
		    {
			gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x could not decode subHeader, 0x%x ... skipping rest of subevent",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId,*data);
		    }
		    return 1;
		}
		// Check address if listed as wrong assigned.
		if(doAddrCorrection)
		{
		    addr = dataword->getAddress();
		    if(addrCorrPar->checkAddress(&addr))
		    {
			/*							if(debugMode && !noComment)
			 {
			 gHades->getMsg()->info(1,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x corrected address 0x%x -> 0x%x",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId,dataword->getAddress(),addr);
			 }*/
			dataword->setAddress(addr);
		    }
		}
		if(data+dataword->getSubEventSize() > end)
		{
		    if(!noComment)
		    {
			gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x could not identify new header!? Wrong number of datawords from 0x%8x",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId, *data);
			gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x .... skipping rest of this subevent!\n",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId);
		    }
		    return 1;
		}
		data++;
		for(Int_t i=0;i<dataword->getSubEventSize();i++)
		{
		    // loop over all datawords from one MBO/OEP
		    if(!dataword->decode(*data,consistencyCheck))
		    {
			if(!noComment && debugMode)
			{
			    dataword->dump();
			}
			if (continueDecodingAfterInconsistency)
			{
			    data++;
			    continue;
			}
			if(!noComment)
			{
			    gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"                    ...... skipping unpacking of the rest of this subevent!!!");
			}
			return 1;
		    }
		    if(!checkConsistency(dataword->getSector(), dataword->getModule(), dataword->getMboAddress(), dataword->getTdcNumber(), dataword->getChannel()))
		    {
			if(!noComment)
			{
			    gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Inconsistent data detected skipping dataword 0x%x from 0x%x",*data, dataword->getAddress());
			}
			data++;
			continue;
		    }
		    // fill data to HMdcRaw category including all checks
		    if((dataword->getDecodeType() & 0x2) == 0)
		    {
			switch(fillData())
			{
			case 0:
			    break;
			case 1:
			    // can not get slot for HMdcRaw
			    if(!noComment)
			    {
				gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"Can not get slot for data!\n");
				gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x .... skipping rest of this subevent!\n",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId, *data);
			    }
			    badEventsCounter++;
			    return 1;
			case 2:
			    // can not get slot for Module, disabled?
			    if(!noComment)
			    {
				gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"Module %d disabled in setup!", dataword->getModule());
			    }
			    badEventsCounter++;
			    break;
			case 3:
			    if(!noComment)
                            {
			      gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Mbo or tdc channel number out of bounds!");
                            }
			    break;
			default:
			    gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"unknown return value by fillData() ... exiting!");
			    exit(EXIT_FAILURE);
			}
		    }
		    else
		    {
			if(fillOepStatus)
			{
			    switch(fillStatus())
			    {
			    case 0:
				break;
			    case 1:
				badEventsCounter++;
				if(!noComment && debugMode)
				{
				    gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"Module %d disabled in setup!", dataword->getModule());
				}
				break;
			    case 2:
				badEventsCounter++;
				if(!noComment && debugMode)
				{
				    gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"Could not create new object for OepStatusData!");
				}
				break;
			    default:
				break;
			    }
			}
		    }
		    data++;
		}
		break;
	    default:
		data++;
		break;
	    }
	}
    }
    else
    {
	if(!noComment & debugMode)
	{
	    gHades->getMsg()->info(5,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x - no data set",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId);
	}
    }


    //-----------------------------------------------------------------------
    if(doBitFlipCorr){
	Int_t hour,minute,second,month,day,year;


	if(bitFlipVersion.CompareTo("auto")  == 0 ) {
	    Int_t runid = gHades->getDataSource()->getCurrentRunId();
	    HTime::runIdToBrokenTime(runid,year,month,day,hour,minute,second);
	    year-=2000;
	}
	if(bitFlipVersion.CompareTo("apr12") == 0){
	    // 19.3.2012- 13.5.2012
	    year  = 12;
	    month = 4;
	    day   = 1 ;
	}
        if(bitFlipVersion.CompareTo("mar19") == 0){
	    //
	    year  = 19;
	    month = 3;
	    day   = 1 ;
	}

	if(pRawCat){
	    HMdcRaw* pRaw=0;
	    for(Int_t i = 0; i < pRawCat->getEntries(); i++){
		pRaw = (HMdcRaw*)pRawCat->getObject(i);
		if(pRaw){
		    correctBitFlip(pRaw,year,month,day);
		}
	    }
	}
    }
    //-----------------------------------------------------------------------



    return 1;
}


Bool_t HMdcUnpacker::finalize(void)
{
    // Called at the end of the event loop.
    // Should do nothing!
    if(!noComment && debugMode)
    {
	gHades->getMsg()->info(5,HMessageMgr::DET_MDC,GetName(),"0x%x: number of skipped events: %d\n",subEvtId,badEventsCounter);
    }
    return kTRUE;
}

void HMdcUnpacker::correctBitFlip (HMdcRaw* pRaw,Int_t year,Int_t month,Int_t day)
{

    if( year >= 12 ) // need update later
    {
	// apr12 beamtime and following, as long as
	// there is no other setting
        Int_t sec,mod,mbo,chan;
        pRaw->getAddress(sec,mod,mbo,chan);

        //---------------- CAL DATA --------------------------------------
	if(pRaw->getNHits() == 6) {
	    Int_t time1 = pRaw->getTime(1); // + 2048;
	    Int_t time2 = pRaw->getTime(2); // + 2048;
	    Int_t time3 = pRaw->getTime(3);
	    Int_t time4 = pRaw->getTime(4);
	    Int_t time5 = pRaw->getTime(5);
	    Int_t time6 = pRaw->getTime(6);
	    if(sec == 0 && mod == 2 && mbo == 14) {
		if(time6 < 512)              time6 |= 512;
		if(time5 - time6 <  200)     time5 |= 512;
		if(time4 - time5 <  200)     time4 |= 512;
		Int_t at2 = 2048;
		Int_t at3 = time4-time3<1024 ? 0 : 2048;
		if(time3+at3 - time4     <  200) time3 |= 512;
		if(time2+at2 - time3-at3 <  200) time2 |= 512;
		if(time1     - time2-at2 <  200) time1 |= 512;
	    } else if(sec == 0 && mod == 2 && mbo == 13 && chan >= 80 && chan <= 87) {
		time5 |= 1024;
		time4 |= 1024;
		time3 |= 1024;
	    } else if(sec == 0 && mod == 3 && mbo == 13 && chan >= 32 && chan <= 39) {
		time5 |= 1024;
		time4 |= 1024;
		time3 |= 1024;
	    } else if(sec == 4 && mod == 3 && mbo == 4 && chan >= 88 && chan <= 95) {
		time5 |= 1024;
		time4 |= 1024;
		Int_t at3 = time4-time3<1024 ? 0 : 2048;
		if(time3+at3 < 2000) time3 |= 1024;
	    } else return;
            pRaw->setTimeNew(time1,1);
            pRaw->setTimeNew(time2,2);
            pRaw->setTimeNew(time3,3);
            pRaw->setTimeNew(time4,4);
            pRaw->setTimeNew(time5,5);
            pRaw->setTimeNew(time6,6);
	}
        //----------------------------------------------------------------

        //---------------- REAL DATA -------------------------------------
	if(pRaw->getNHits() == 2) {
	    Int_t time1 = pRaw->getTime(1);
	    Int_t time2 = pRaw->getTime(2);
	    pRaw->getAddress(sec,mod,mbo,chan);
	    if(sec == 0 && mod == 2 && mbo == 14) {
		if(time1 < time2) time1 |= 512;
		else if(time1-time2 > 512) time2 |= 512;
		else {
		    Int_t cut = chan<28||chan>31 ? 2350:2580;
		    if(time1+time2 < cut && time1<1535 && time2<1535) {  //fix3
			time1 += 512;
			time2 += 512;
		    }
		}
	    } else if(sec == 0 && mod == 2 && mbo == 13 && chan >= 80 && chan <= 87) {
		if(time1 < time2) {
		    if(time2 < 1024) time1 |= 1024;
		    else             time2 ^= 1024;
		} else if(time1-time2 > 1024) time2 |= 1024;
		else if(time1+time2 < 2000) {
		    time1 |= 1024;
		    time2 |= 1024;
		}
	    } else if(sec == 0 && mod == 3 && mbo == 13 && chan >= 32 && chan <= 39) {
		if(time1 < 580) {
		    time1 |= 1024;
		    time2 |= 1024;
		} else if(time1 < 1024) {
		    time1 += 512;
		    time2 += 512;
		} else if(time1 > 1700) {
		    time1 ^= 512;
		    time2 ^= 512;
		}
		if(time1 < time2) {
		    if(time1 < 1024) time1 |= 1024;
		    else             time2 ^= 1024;
		}
            } else if(sec == 3 && mod == 1 && mbo == 15 && chan >= 88) {
                if(year >= 14) {
		    time1 |= 1024;
		    time2 |= 1024;
                }
	    } else if(sec == 4 && mod == 3 && mbo == 4 && chan >= 88 && chan <= 95) {
		if(time1 < time2) {
		    if(time1 < 1024) time1 |= 1024;
		    if(time2 > 1536) time2 ^= 1024;
		} else if(time1 < 768) {
		    time1 |= 1024;
		    time2 |= 1024;
		} else if(time1 < 1024) {
		    time1 += 512;
		    time2 += 512;
		}
	    } else return;
            pRaw->setTimeNew(time1,1);
            pRaw->setTimeNew(time2,2);
	}
        //----------------------------------------------------------------

    }
}
HCategory *HMdcUnpacker::initCategory(Cat_t cat, const char *catname, const char *detector)
{
    // inits the container cat
    // looks first whether it already exists
    // otherwise it is created
    // default for detector is "Mdc"
    // catname is used for Error handling

    HCategory * category = 0;

    category = (HCategory*)(((HEvent*)(gHades->getCurrentEvent()))->getCategory(cat));

    if (!category)
    {
	category=(HCategory*)((HMdcDetector*)(((HSpectrometer*)(gHades->getSetup()))->getDetector(detector))->buildCategory(cat));

	if (!category)
	{
	    return NULL;
	}

	if (!((HEvent*)(gHades->getCurrentEvent()))->addCategory(cat,category,detector))
	{
	    return NULL;
	}
    }
    return category;
}

Int_t HMdcUnpacker::fillData(void)
{
    // Converts the content of the already decoded dataword via the lookup table HMdcEvReadout
    // to sector/module/mbo/tdc coordinates.
    // Then, if available the information is stored in a new or added to an existing
    // data slot of HMdcRaw
    // If activated, the raw data is written by fillMdcDataWord()

    // check if detected chamber is enabled in the setup
    if(!pDetector->getModule(dataword->getSector(), dataword->getModule()))
    {
	return 2;
    }
    Int_t nMBo           = (*rawc)[dataword->getSector()][dataword->getModule()].getSize();
    if(dataword->getMboAddress() < 0 || dataword->getMboAddress() > nMBo - 1 )
    {
        return 3;
    }
    Int_t maxTdc = (*rawc)[dataword->getSector()][dataword->getModule()][dataword->getMboAddress()].getNTdcs();
    Int_t tdcCh  = dataword->getTdcNumber()*8 + dataword->getChannel();
    if(tdcCh < 0 || tdcCh > maxTdc - 1) {
        return 3;
    }
    
    // first check if wire is connected / exists
    // for real data and calibration data the check
    // is made in a different way
    if(doMapOutUnusedChannels)
    {
	Bool_t isCalibration =  gHades->getCurrentEvent()->getHeader()->getId() == 9 ? kTRUE : kFALSE;
	if(!isCalibration){
	    if(
	       ((*lookupGeom)[dataword->getSector()][dataword->getModule()][dataword->getMboAddress()][tdcCh].getNLayer() < 0) &&
	       ((*lookupGeom)[dataword->getSector()][dataword->getModule()][dataword->getMboAddress()][tdcCh].getNCell()  < 0) )
	    {
		return 3;
	    }
	}
    }

    // second get a free or existing slot

    static HMdcRaw *pMdcRaw;
    pMdcRaw = NULL;
    pMdcRaw = getFreeOrExistingSlot(dataword->getSector(), dataword->getModule(), dataword->getMboAddress(),tdcCh);
    if (!pMdcRaw) return 1; // cannot get slot

    // fill the time to this slot

    if (!pMdcRaw->setTime(dataword->getTime(),tdcMode, noComment))
    {
	if(!noComment)
	{
	    gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x - error filling slot for dataword 0x%08x   at sector %d, module %d-->",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId,dataword->getCodedDataword(decodeVersion),dataword->getSector(),dataword->getModule());
	    gHades->getMsg()->info(1,HMessageMgr::DET_MDC,GetName(),"time1 %d, time2 %d -> time %d",pMdcRaw->getTime(1),pMdcRaw->getTime(2),dataword->getTime());
	}
    }
    // fill dataWord to category HMdcDataWord
    if(fillDataWord)
    {
	fillMdcDataWord(dataword->getSector(), dataword->getModule(), dataword->getMboAddress(), dataword->getTdcNumber()*8 + dataword->getChannel());
    }
    if(dataword->getDecodeType()==4)
    {
	pMdcRaw = NULL;
	pMdcRaw = getFreeOrExistingSlot(dataword->getSector(), dataword->getModule(), dataword->getMboAddress(),tdcCh);
	if (!pMdcRaw) return 1; // cannot get slot

	// fill the time to this slot

	if (!pMdcRaw->setTime(dataword->getTime1(),tdcMode, noComment))
	{
	    if(!noComment)
	    {
		gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x - error filling slot for dataword 0x%08x at sector %d, module %d -->",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId,dataword->getCodedDataword(decodeVersion),dataword->getSector(),dataword->getModule());
		gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"time1 %d, time2 %d -> time %d",pMdcRaw->getTime(1),pMdcRaw->getTime(2),dataword->getTime());
	    }
	}
    }
    return 0;
}


void HMdcUnpacker::setDefaults(void)
{
    // Define defaults for all internal variables.

    continueDecodingAfterInconsistency = kFALSE;
    consistencyCheck 			= kFALSE;
    dataword				= NULL;
    decodeVersion			= -1;
    doAddrCorrection 			= kFALSE;
    fillDataWord			= kFALSE;
    module				= 0;
    noComment				= kFALSE;
    pUnpackerPar			= NULL;
    rawc 				= NULL;
    sector				= 0;
    tdcMode				= 0;
    badEventsCounter 			= 0;
    pDetector				= NULL;
    pMdcOepStatusCat                    = NULL;
    fillOepStatus                       = kFALSE;
    mdcOepStatusCatPersistency          = kFALSE;
    doMapOutUnusedChannels              = kTRUE;
    doBitFlipCorr                       = kTRUE;
    bitFlipVersion                      = "auto";
    trbNetUnpacker                      = NULL;
}

void HMdcUnpacker::setQuietMode(Bool_t quiet, Bool_t warn)
{
    // switch to disable all error messages and warnings from hmdcunpacker AND hmdcdataword
    // quiet = kTRUE : messaging switch of
    //       = kFALSE: messages are displayed

    noComment = quiet;
    if (kTRUE == quiet && kTRUE == debugMode)
    {
	if(warn)gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"SubEvtId 0x%x - no further messages printed!",subEvtId);
    }
}

void HMdcUnpacker::setContinueDecodingAfterInconsistency(Bool_t cont)
{
    // this function is only for debugging use!
    // the decoding of the data words continue even if there is
    // unconsistency in the datawords
    // cont = kTRUE : continue
    // cont = kFALSE: skip event

    continueDecodingAfterInconsistency=cont;
}

HMdcRaw* HMdcUnpacker::getFreeOrExistingSlot(Int_t sector, Int_t module, Int_t mbo, Int_t tdc)
{
    // get a free or existing slot from the HMdcRaw category
    // at the location of HLocation loc
    // returns the pointer to the (new) HMdcRaw object
    // NULL if it couldn't be done

    HLocation loc;
    loc.set(4, 0, 0, 0, 0);

    // filling the data to the location
    // set location indexes

    loc[0] = sector;
    loc[1] = module;
    loc[2] = mbo;
    loc[3] = tdc;

    HMdcRaw *pMdcRaw = (HMdcRaw*) pRawCat->getObject(loc);
    if (!pMdcRaw)
    {
	pMdcRaw = (HMdcRaw*) pRawCat->getSlot(loc);
	if (pMdcRaw)
	{
	    pMdcRaw = new (pMdcRaw) HMdcRaw();
	    //setAddress to sector,module,mbo and tdc
	    pMdcRaw->setAddress(sector,module,mbo,tdc);
	}
	else
	{
	    if(!noComment)
	    {
		gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x - can't get slot for s: %i m: %i mb: %i tdc: %i",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(), subEvtId, sector,module,mbo,tdc);
		gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"                           ...... skipping unpacking of the rest of the subevent!!!");
	    }
	    if (debugMode)
	    {
		pSubEvt->dumpIt();
	    }
	}
    }
    return pMdcRaw;
}

Int_t HMdcUnpacker::fillMdcDataWord(Int_t sector,Int_t module,Int_t mbo,Int_t tdc)
{
    // function for filling the category HMdcDataword
    // Return 1 on success, -2 on failure.

    Int_t entry=0;
    UChar_t maxentry;

    maxentry=8;

    HLocation dataLoc;
    dataLoc.set(5,0,0,0,0,0);
    //set location indexes

    dataLoc[0] = sector;
    dataLoc[1] = module;
    dataLoc[2] = mbo;
    dataLoc[3] = tdc;
    dataLoc[4] = entry;

    if(!pDetector->getModule(sector,module))
    {
	return 1;
    }
    HMdcDataword *pMdcDataWord=NULL;

    for (entry = 0; entry < maxentry; entry++)
    {
	pMdcDataWord = NULL;

	dataLoc[4] = entry;
	pMdcDataWord = (HMdcDataword*) pMdcDataWordCat->getObject(dataLoc);
	if (!pMdcDataWord)
	{
	    break;
	}
    }

    if (pMdcDataWord)
    {
	if (entry==maxentry-1)
	{
	    if(!noComment)
	    {
		gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x too many entries to the same location (entries >%i)", gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId,maxentry);
	    }
	}
	else
	{
	    if(!noComment)
	    {
		gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x can't get slot for MdcDataword",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId);
		gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"          ... but continue unpacking for the rest of this subevent");
	    }
	}
	return -2;
    }
    else
    {
	pMdcDataWord = (HMdcDataword*) pMdcDataWordCat->getSlot(dataLoc);
	if (pMdcDataWord)
	{
	    pMdcDataWord = new (((HMdcDataword*)pMdcDataWord)) HMdcDataword(*((HMdcDataword*)dataword));
	    ((HMdcDataword*)pMdcDataWord)->setAddress(sector,module,mbo,tdc,entry);
	}
    }
    if(!pMdcDataWord)
    {
	if(!noComment)
	{
	    gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Event: %i - SubEvtId 0x%x can't get slot for MdcDataword at %d %d %d %d %d",gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(),subEvtId,sector,module,mbo,tdc,entry);
	    gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"          ... but continue unpacking for the rest of this subevent");
	}
	return -2;
    }
    return 1;
}


Int_t HMdcUnpacker::fillStatus(void)
{
    // function for filling the category HMdcDataword
    // Return 1 on success, -2 on failure.
    HLocation dataLoc;
    Int_t addr=0;
    dataLoc.set(3,0,0,0);
    //set location indexes

    dataLoc[0] = dataword->getSector();
    dataLoc[1] = dataword->getModule();
    dataLoc[2] = dataword->getMboAddress();

    addr = (dataword->getModule() << 8) + (dataword->getSector() << 4) + dataword->getMboAddress() ;
    if(!pDetector->getModule(dataword->getSector(),dataword->getModule()))
    {
	return 1;
    }
    HMdcOepStatusData *pMdcOepStatusData = NULL;
    pMdcOepStatusData = (HMdcOepStatusData*) pMdcOepStatusCat->getObject(dataLoc);
    if (!pMdcOepStatusData)
    {
	pMdcOepStatusData = (HMdcOepStatusData*) pMdcOepStatusCat->getSlot(dataLoc);
	if(pMdcOepStatusData)
	{
	    pMdcOepStatusData = new (pMdcOepStatusData)HMdcOepStatusData();
	}
	else
	{
	    gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"%d %d %d",dataLoc[0],dataLoc[1],dataLoc[2]);
	    return 2;
	}
    }
    if(!pMdcOepStatusData->setStatusWord(dataword->getStatusCode(),addr,dataword->getStatusData()))
    {
	if(debugMode && !noComment)
	{
	    gHades->getMsg()->error(10,HMessageMgr::DET_MDC,GetName(),"Invalid status word %d at index &d decoded!",dataword->getStatusData(),dataword->getStatusCode());
	}
    }
    return 0;
}

Bool_t HMdcUnpacker::checkConsistency(Int_t sector, Int_t module, Int_t mbo, Int_t tdc, Int_t channel)
{
    HMdcRawMothStru t = (*rawc)[sector][module][mbo];
    if((t.getNTdcs()) < tdc*8+channel)
	return kFALSE;
    return kTRUE;
}
 hmdcunpacker.cc:1
 hmdcunpacker.cc:2
 hmdcunpacker.cc:3
 hmdcunpacker.cc:4
 hmdcunpacker.cc:5
 hmdcunpacker.cc:6
 hmdcunpacker.cc:7
 hmdcunpacker.cc:8
 hmdcunpacker.cc:9
 hmdcunpacker.cc:10
 hmdcunpacker.cc:11
 hmdcunpacker.cc:12
 hmdcunpacker.cc:13
 hmdcunpacker.cc:14
 hmdcunpacker.cc:15
 hmdcunpacker.cc:16
 hmdcunpacker.cc:17
 hmdcunpacker.cc:18
 hmdcunpacker.cc:19
 hmdcunpacker.cc:20
 hmdcunpacker.cc:21
 hmdcunpacker.cc:22
 hmdcunpacker.cc:23
 hmdcunpacker.cc:24
 hmdcunpacker.cc:25
 hmdcunpacker.cc:26
 hmdcunpacker.cc:27
 hmdcunpacker.cc:28
 hmdcunpacker.cc:29
 hmdcunpacker.cc:30
 hmdcunpacker.cc:31
 hmdcunpacker.cc:32
 hmdcunpacker.cc:33
 hmdcunpacker.cc:34
 hmdcunpacker.cc:35
 hmdcunpacker.cc:36
 hmdcunpacker.cc:37
 hmdcunpacker.cc:38
 hmdcunpacker.cc:39
 hmdcunpacker.cc:40
 hmdcunpacker.cc:41
 hmdcunpacker.cc:42
 hmdcunpacker.cc:43
 hmdcunpacker.cc:44
 hmdcunpacker.cc:45
 hmdcunpacker.cc:46
 hmdcunpacker.cc:47
 hmdcunpacker.cc:48
 hmdcunpacker.cc:49
 hmdcunpacker.cc:50
 hmdcunpacker.cc:51
 hmdcunpacker.cc:52
 hmdcunpacker.cc:53
 hmdcunpacker.cc:54
 hmdcunpacker.cc:55
 hmdcunpacker.cc:56
 hmdcunpacker.cc:57
 hmdcunpacker.cc:58
 hmdcunpacker.cc:59
 hmdcunpacker.cc:60
 hmdcunpacker.cc:61
 hmdcunpacker.cc:62
 hmdcunpacker.cc:63
 hmdcunpacker.cc:64
 hmdcunpacker.cc:65
 hmdcunpacker.cc:66
 hmdcunpacker.cc:67
 hmdcunpacker.cc:68
 hmdcunpacker.cc:69
 hmdcunpacker.cc:70
 hmdcunpacker.cc:71
 hmdcunpacker.cc:72
 hmdcunpacker.cc:73
 hmdcunpacker.cc:74
 hmdcunpacker.cc:75
 hmdcunpacker.cc:76
 hmdcunpacker.cc:77
 hmdcunpacker.cc:78
 hmdcunpacker.cc:79
 hmdcunpacker.cc:80
 hmdcunpacker.cc:81
 hmdcunpacker.cc:82
 hmdcunpacker.cc:83
 hmdcunpacker.cc:84
 hmdcunpacker.cc:85
 hmdcunpacker.cc:86
 hmdcunpacker.cc:87
 hmdcunpacker.cc:88
 hmdcunpacker.cc:89
 hmdcunpacker.cc:90
 hmdcunpacker.cc:91
 hmdcunpacker.cc:92
 hmdcunpacker.cc:93
 hmdcunpacker.cc:94
 hmdcunpacker.cc:95
 hmdcunpacker.cc:96
 hmdcunpacker.cc:97
 hmdcunpacker.cc:98
 hmdcunpacker.cc:99
 hmdcunpacker.cc:100
 hmdcunpacker.cc:101
 hmdcunpacker.cc:102
 hmdcunpacker.cc:103
 hmdcunpacker.cc:104
 hmdcunpacker.cc:105
 hmdcunpacker.cc:106
 hmdcunpacker.cc:107
 hmdcunpacker.cc:108
 hmdcunpacker.cc:109
 hmdcunpacker.cc:110
 hmdcunpacker.cc:111
 hmdcunpacker.cc:112
 hmdcunpacker.cc:113
 hmdcunpacker.cc:114
 hmdcunpacker.cc:115
 hmdcunpacker.cc:116
 hmdcunpacker.cc:117
 hmdcunpacker.cc:118
 hmdcunpacker.cc:119
 hmdcunpacker.cc:120
 hmdcunpacker.cc:121
 hmdcunpacker.cc:122
 hmdcunpacker.cc:123
 hmdcunpacker.cc:124
 hmdcunpacker.cc:125
 hmdcunpacker.cc:126
 hmdcunpacker.cc:127
 hmdcunpacker.cc:128
 hmdcunpacker.cc:129
 hmdcunpacker.cc:130
 hmdcunpacker.cc:131
 hmdcunpacker.cc:132
 hmdcunpacker.cc:133
 hmdcunpacker.cc:134
 hmdcunpacker.cc:135
 hmdcunpacker.cc:136
 hmdcunpacker.cc:137
 hmdcunpacker.cc:138
 hmdcunpacker.cc:139
 hmdcunpacker.cc:140
 hmdcunpacker.cc:141
 hmdcunpacker.cc:142
 hmdcunpacker.cc:143
 hmdcunpacker.cc:144
 hmdcunpacker.cc:145
 hmdcunpacker.cc:146
 hmdcunpacker.cc:147
 hmdcunpacker.cc:148
 hmdcunpacker.cc:149
 hmdcunpacker.cc:150
 hmdcunpacker.cc:151
 hmdcunpacker.cc:152
 hmdcunpacker.cc:153
 hmdcunpacker.cc:154
 hmdcunpacker.cc:155
 hmdcunpacker.cc:156
 hmdcunpacker.cc:157
 hmdcunpacker.cc:158
 hmdcunpacker.cc:159
 hmdcunpacker.cc:160
 hmdcunpacker.cc:161
 hmdcunpacker.cc:162
 hmdcunpacker.cc:163
 hmdcunpacker.cc:164
 hmdcunpacker.cc:165
 hmdcunpacker.cc:166
 hmdcunpacker.cc:167
 hmdcunpacker.cc:168
 hmdcunpacker.cc:169
 hmdcunpacker.cc:170
 hmdcunpacker.cc:171
 hmdcunpacker.cc:172
 hmdcunpacker.cc:173
 hmdcunpacker.cc:174
 hmdcunpacker.cc:175
 hmdcunpacker.cc:176
 hmdcunpacker.cc:177
 hmdcunpacker.cc:178
 hmdcunpacker.cc:179
 hmdcunpacker.cc:180
 hmdcunpacker.cc:181
 hmdcunpacker.cc:182
 hmdcunpacker.cc:183
 hmdcunpacker.cc:184
 hmdcunpacker.cc:185
 hmdcunpacker.cc:186
 hmdcunpacker.cc:187
 hmdcunpacker.cc:188
 hmdcunpacker.cc:189
 hmdcunpacker.cc:190
 hmdcunpacker.cc:191
 hmdcunpacker.cc:192
 hmdcunpacker.cc:193
 hmdcunpacker.cc:194
 hmdcunpacker.cc:195
 hmdcunpacker.cc:196
 hmdcunpacker.cc:197
 hmdcunpacker.cc:198
 hmdcunpacker.cc:199
 hmdcunpacker.cc:200
 hmdcunpacker.cc:201
 hmdcunpacker.cc:202
 hmdcunpacker.cc:203
 hmdcunpacker.cc:204
 hmdcunpacker.cc:205
 hmdcunpacker.cc:206
 hmdcunpacker.cc:207
 hmdcunpacker.cc:208
 hmdcunpacker.cc:209
 hmdcunpacker.cc:210
 hmdcunpacker.cc:211
 hmdcunpacker.cc:212
 hmdcunpacker.cc:213
 hmdcunpacker.cc:214
 hmdcunpacker.cc:215
 hmdcunpacker.cc:216
 hmdcunpacker.cc:217
 hmdcunpacker.cc:218
 hmdcunpacker.cc:219
 hmdcunpacker.cc:220
 hmdcunpacker.cc:221
 hmdcunpacker.cc:222
 hmdcunpacker.cc:223
 hmdcunpacker.cc:224
 hmdcunpacker.cc:225
 hmdcunpacker.cc:226
 hmdcunpacker.cc:227
 hmdcunpacker.cc:228
 hmdcunpacker.cc:229
 hmdcunpacker.cc:230
 hmdcunpacker.cc:231
 hmdcunpacker.cc:232
 hmdcunpacker.cc:233
 hmdcunpacker.cc:234
 hmdcunpacker.cc:235
 hmdcunpacker.cc:236
 hmdcunpacker.cc:237
 hmdcunpacker.cc:238
 hmdcunpacker.cc:239
 hmdcunpacker.cc:240
 hmdcunpacker.cc:241
 hmdcunpacker.cc:242
 hmdcunpacker.cc:243
 hmdcunpacker.cc:244
 hmdcunpacker.cc:245
 hmdcunpacker.cc:246
 hmdcunpacker.cc:247
 hmdcunpacker.cc:248
 hmdcunpacker.cc:249
 hmdcunpacker.cc:250
 hmdcunpacker.cc:251
 hmdcunpacker.cc:252
 hmdcunpacker.cc:253
 hmdcunpacker.cc:254
 hmdcunpacker.cc:255
 hmdcunpacker.cc:256
 hmdcunpacker.cc:257
 hmdcunpacker.cc:258
 hmdcunpacker.cc:259
 hmdcunpacker.cc:260
 hmdcunpacker.cc:261
 hmdcunpacker.cc:262
 hmdcunpacker.cc:263
 hmdcunpacker.cc:264
 hmdcunpacker.cc:265
 hmdcunpacker.cc:266
 hmdcunpacker.cc:267
 hmdcunpacker.cc:268
 hmdcunpacker.cc:269
 hmdcunpacker.cc:270
 hmdcunpacker.cc:271
 hmdcunpacker.cc:272
 hmdcunpacker.cc:273
 hmdcunpacker.cc:274
 hmdcunpacker.cc:275
 hmdcunpacker.cc:276
 hmdcunpacker.cc:277
 hmdcunpacker.cc:278
 hmdcunpacker.cc:279
 hmdcunpacker.cc:280
 hmdcunpacker.cc:281
 hmdcunpacker.cc:282
 hmdcunpacker.cc:283
 hmdcunpacker.cc:284
 hmdcunpacker.cc:285
 hmdcunpacker.cc:286
 hmdcunpacker.cc:287
 hmdcunpacker.cc:288
 hmdcunpacker.cc:289
 hmdcunpacker.cc:290
 hmdcunpacker.cc:291
 hmdcunpacker.cc:292
 hmdcunpacker.cc:293
 hmdcunpacker.cc:294
 hmdcunpacker.cc:295
 hmdcunpacker.cc:296
 hmdcunpacker.cc:297
 hmdcunpacker.cc:298
 hmdcunpacker.cc:299
 hmdcunpacker.cc:300
 hmdcunpacker.cc:301
 hmdcunpacker.cc:302
 hmdcunpacker.cc:303
 hmdcunpacker.cc:304
 hmdcunpacker.cc:305
 hmdcunpacker.cc:306
 hmdcunpacker.cc:307
 hmdcunpacker.cc:308
 hmdcunpacker.cc:309
 hmdcunpacker.cc:310
 hmdcunpacker.cc:311
 hmdcunpacker.cc:312
 hmdcunpacker.cc:313
 hmdcunpacker.cc:314
 hmdcunpacker.cc:315
 hmdcunpacker.cc:316
 hmdcunpacker.cc:317
 hmdcunpacker.cc:318
 hmdcunpacker.cc:319
 hmdcunpacker.cc:320
 hmdcunpacker.cc:321
 hmdcunpacker.cc:322
 hmdcunpacker.cc:323
 hmdcunpacker.cc:324
 hmdcunpacker.cc:325
 hmdcunpacker.cc:326
 hmdcunpacker.cc:327
 hmdcunpacker.cc:328
 hmdcunpacker.cc:329
 hmdcunpacker.cc:330
 hmdcunpacker.cc:331
 hmdcunpacker.cc:332
 hmdcunpacker.cc:333
 hmdcunpacker.cc:334
 hmdcunpacker.cc:335
 hmdcunpacker.cc:336
 hmdcunpacker.cc:337
 hmdcunpacker.cc:338
 hmdcunpacker.cc:339
 hmdcunpacker.cc:340
 hmdcunpacker.cc:341
 hmdcunpacker.cc:342
 hmdcunpacker.cc:343
 hmdcunpacker.cc:344
 hmdcunpacker.cc:345
 hmdcunpacker.cc:346
 hmdcunpacker.cc:347
 hmdcunpacker.cc:348
 hmdcunpacker.cc:349
 hmdcunpacker.cc:350
 hmdcunpacker.cc:351
 hmdcunpacker.cc:352
 hmdcunpacker.cc:353
 hmdcunpacker.cc:354
 hmdcunpacker.cc:355
 hmdcunpacker.cc:356
 hmdcunpacker.cc:357
 hmdcunpacker.cc:358
 hmdcunpacker.cc:359
 hmdcunpacker.cc:360
 hmdcunpacker.cc:361
 hmdcunpacker.cc:362
 hmdcunpacker.cc:363
 hmdcunpacker.cc:364
 hmdcunpacker.cc:365
 hmdcunpacker.cc:366
 hmdcunpacker.cc:367
 hmdcunpacker.cc:368
 hmdcunpacker.cc:369
 hmdcunpacker.cc:370
 hmdcunpacker.cc:371
 hmdcunpacker.cc:372
 hmdcunpacker.cc:373
 hmdcunpacker.cc:374
 hmdcunpacker.cc:375
 hmdcunpacker.cc:376
 hmdcunpacker.cc:377
 hmdcunpacker.cc:378
 hmdcunpacker.cc:379
 hmdcunpacker.cc:380
 hmdcunpacker.cc:381
 hmdcunpacker.cc:382
 hmdcunpacker.cc:383
 hmdcunpacker.cc:384
 hmdcunpacker.cc:385
 hmdcunpacker.cc:386
 hmdcunpacker.cc:387
 hmdcunpacker.cc:388
 hmdcunpacker.cc:389
 hmdcunpacker.cc:390
 hmdcunpacker.cc:391
 hmdcunpacker.cc:392
 hmdcunpacker.cc:393
 hmdcunpacker.cc:394
 hmdcunpacker.cc:395
 hmdcunpacker.cc:396
 hmdcunpacker.cc:397
 hmdcunpacker.cc:398
 hmdcunpacker.cc:399
 hmdcunpacker.cc:400
 hmdcunpacker.cc:401
 hmdcunpacker.cc:402
 hmdcunpacker.cc:403
 hmdcunpacker.cc:404
 hmdcunpacker.cc:405
 hmdcunpacker.cc:406
 hmdcunpacker.cc:407
 hmdcunpacker.cc:408
 hmdcunpacker.cc:409
 hmdcunpacker.cc:410
 hmdcunpacker.cc:411
 hmdcunpacker.cc:412
 hmdcunpacker.cc:413
 hmdcunpacker.cc:414
 hmdcunpacker.cc:415
 hmdcunpacker.cc:416
 hmdcunpacker.cc:417
 hmdcunpacker.cc:418
 hmdcunpacker.cc:419
 hmdcunpacker.cc:420
 hmdcunpacker.cc:421
 hmdcunpacker.cc:422
 hmdcunpacker.cc:423
 hmdcunpacker.cc:424
 hmdcunpacker.cc:425
 hmdcunpacker.cc:426
 hmdcunpacker.cc:427
 hmdcunpacker.cc:428
 hmdcunpacker.cc:429
 hmdcunpacker.cc:430
 hmdcunpacker.cc:431
 hmdcunpacker.cc:432
 hmdcunpacker.cc:433
 hmdcunpacker.cc:434
 hmdcunpacker.cc:435
 hmdcunpacker.cc:436
 hmdcunpacker.cc:437
 hmdcunpacker.cc:438
 hmdcunpacker.cc:439
 hmdcunpacker.cc:440
 hmdcunpacker.cc:441
 hmdcunpacker.cc:442
 hmdcunpacker.cc:443
 hmdcunpacker.cc:444
 hmdcunpacker.cc:445
 hmdcunpacker.cc:446
 hmdcunpacker.cc:447
 hmdcunpacker.cc:448
 hmdcunpacker.cc:449
 hmdcunpacker.cc:450
 hmdcunpacker.cc:451
 hmdcunpacker.cc:452
 hmdcunpacker.cc:453
 hmdcunpacker.cc:454
 hmdcunpacker.cc:455
 hmdcunpacker.cc:456
 hmdcunpacker.cc:457
 hmdcunpacker.cc:458
 hmdcunpacker.cc:459
 hmdcunpacker.cc:460
 hmdcunpacker.cc:461
 hmdcunpacker.cc:462
 hmdcunpacker.cc:463
 hmdcunpacker.cc:464
 hmdcunpacker.cc:465
 hmdcunpacker.cc:466
 hmdcunpacker.cc:467
 hmdcunpacker.cc:468
 hmdcunpacker.cc:469
 hmdcunpacker.cc:470
 hmdcunpacker.cc:471
 hmdcunpacker.cc:472
 hmdcunpacker.cc:473
 hmdcunpacker.cc:474
 hmdcunpacker.cc:475
 hmdcunpacker.cc:476
 hmdcunpacker.cc:477
 hmdcunpacker.cc:478
 hmdcunpacker.cc:479
 hmdcunpacker.cc:480
 hmdcunpacker.cc:481
 hmdcunpacker.cc:482
 hmdcunpacker.cc:483
 hmdcunpacker.cc:484
 hmdcunpacker.cc:485
 hmdcunpacker.cc:486
 hmdcunpacker.cc:487
 hmdcunpacker.cc:488
 hmdcunpacker.cc:489
 hmdcunpacker.cc:490
 hmdcunpacker.cc:491
 hmdcunpacker.cc:492
 hmdcunpacker.cc:493
 hmdcunpacker.cc:494
 hmdcunpacker.cc:495
 hmdcunpacker.cc:496
 hmdcunpacker.cc:497
 hmdcunpacker.cc:498
 hmdcunpacker.cc:499
 hmdcunpacker.cc:500
 hmdcunpacker.cc:501
 hmdcunpacker.cc:502
 hmdcunpacker.cc:503
 hmdcunpacker.cc:504
 hmdcunpacker.cc:505
 hmdcunpacker.cc:506
 hmdcunpacker.cc:507
 hmdcunpacker.cc:508
 hmdcunpacker.cc:509
 hmdcunpacker.cc:510
 hmdcunpacker.cc:511
 hmdcunpacker.cc:512
 hmdcunpacker.cc:513
 hmdcunpacker.cc:514
 hmdcunpacker.cc:515
 hmdcunpacker.cc:516
 hmdcunpacker.cc:517
 hmdcunpacker.cc:518
 hmdcunpacker.cc:519
 hmdcunpacker.cc:520
 hmdcunpacker.cc:521
 hmdcunpacker.cc:522
 hmdcunpacker.cc:523
 hmdcunpacker.cc:524
 hmdcunpacker.cc:525
 hmdcunpacker.cc:526
 hmdcunpacker.cc:527
 hmdcunpacker.cc:528
 hmdcunpacker.cc:529
 hmdcunpacker.cc:530
 hmdcunpacker.cc:531
 hmdcunpacker.cc:532
 hmdcunpacker.cc:533
 hmdcunpacker.cc:534
 hmdcunpacker.cc:535
 hmdcunpacker.cc:536
 hmdcunpacker.cc:537
 hmdcunpacker.cc:538
 hmdcunpacker.cc:539
 hmdcunpacker.cc:540
 hmdcunpacker.cc:541
 hmdcunpacker.cc:542
 hmdcunpacker.cc:543
 hmdcunpacker.cc:544
 hmdcunpacker.cc:545
 hmdcunpacker.cc:546
 hmdcunpacker.cc:547
 hmdcunpacker.cc:548
 hmdcunpacker.cc:549
 hmdcunpacker.cc:550
 hmdcunpacker.cc:551
 hmdcunpacker.cc:552
 hmdcunpacker.cc:553
 hmdcunpacker.cc:554
 hmdcunpacker.cc:555
 hmdcunpacker.cc:556
 hmdcunpacker.cc:557
 hmdcunpacker.cc:558
 hmdcunpacker.cc:559
 hmdcunpacker.cc:560
 hmdcunpacker.cc:561
 hmdcunpacker.cc:562
 hmdcunpacker.cc:563
 hmdcunpacker.cc:564
 hmdcunpacker.cc:565
 hmdcunpacker.cc:566
 hmdcunpacker.cc:567
 hmdcunpacker.cc:568
 hmdcunpacker.cc:569
 hmdcunpacker.cc:570
 hmdcunpacker.cc:571
 hmdcunpacker.cc:572
 hmdcunpacker.cc:573
 hmdcunpacker.cc:574
 hmdcunpacker.cc:575
 hmdcunpacker.cc:576
 hmdcunpacker.cc:577
 hmdcunpacker.cc:578
 hmdcunpacker.cc:579
 hmdcunpacker.cc:580
 hmdcunpacker.cc:581
 hmdcunpacker.cc:582
 hmdcunpacker.cc:583
 hmdcunpacker.cc:584
 hmdcunpacker.cc:585
 hmdcunpacker.cc:586
 hmdcunpacker.cc:587
 hmdcunpacker.cc:588
 hmdcunpacker.cc:589
 hmdcunpacker.cc:590
 hmdcunpacker.cc:591
 hmdcunpacker.cc:592
 hmdcunpacker.cc:593
 hmdcunpacker.cc:594
 hmdcunpacker.cc:595
 hmdcunpacker.cc:596
 hmdcunpacker.cc:597
 hmdcunpacker.cc:598
 hmdcunpacker.cc:599
 hmdcunpacker.cc:600
 hmdcunpacker.cc:601
 hmdcunpacker.cc:602
 hmdcunpacker.cc:603
 hmdcunpacker.cc:604
 hmdcunpacker.cc:605
 hmdcunpacker.cc:606
 hmdcunpacker.cc:607
 hmdcunpacker.cc:608
 hmdcunpacker.cc:609
 hmdcunpacker.cc:610
 hmdcunpacker.cc:611
 hmdcunpacker.cc:612
 hmdcunpacker.cc:613
 hmdcunpacker.cc:614
 hmdcunpacker.cc:615
 hmdcunpacker.cc:616
 hmdcunpacker.cc:617
 hmdcunpacker.cc:618
 hmdcunpacker.cc:619
 hmdcunpacker.cc:620
 hmdcunpacker.cc:621
 hmdcunpacker.cc:622
 hmdcunpacker.cc:623
 hmdcunpacker.cc:624
 hmdcunpacker.cc:625
 hmdcunpacker.cc:626
 hmdcunpacker.cc:627
 hmdcunpacker.cc:628
 hmdcunpacker.cc:629
 hmdcunpacker.cc:630
 hmdcunpacker.cc:631
 hmdcunpacker.cc:632
 hmdcunpacker.cc:633
 hmdcunpacker.cc:634
 hmdcunpacker.cc:635
 hmdcunpacker.cc:636
 hmdcunpacker.cc:637
 hmdcunpacker.cc:638
 hmdcunpacker.cc:639
 hmdcunpacker.cc:640
 hmdcunpacker.cc:641
 hmdcunpacker.cc:642
 hmdcunpacker.cc:643
 hmdcunpacker.cc:644
 hmdcunpacker.cc:645
 hmdcunpacker.cc:646
 hmdcunpacker.cc:647
 hmdcunpacker.cc:648
 hmdcunpacker.cc:649
 hmdcunpacker.cc:650
 hmdcunpacker.cc:651
 hmdcunpacker.cc:652
 hmdcunpacker.cc:653
 hmdcunpacker.cc:654
 hmdcunpacker.cc:655
 hmdcunpacker.cc:656
 hmdcunpacker.cc:657
 hmdcunpacker.cc:658
 hmdcunpacker.cc:659
 hmdcunpacker.cc:660
 hmdcunpacker.cc:661
 hmdcunpacker.cc:662
 hmdcunpacker.cc:663
 hmdcunpacker.cc:664
 hmdcunpacker.cc:665
 hmdcunpacker.cc:666
 hmdcunpacker.cc:667
 hmdcunpacker.cc:668
 hmdcunpacker.cc:669
 hmdcunpacker.cc:670
 hmdcunpacker.cc:671
 hmdcunpacker.cc:672
 hmdcunpacker.cc:673
 hmdcunpacker.cc:674
 hmdcunpacker.cc:675
 hmdcunpacker.cc:676
 hmdcunpacker.cc:677
 hmdcunpacker.cc:678
 hmdcunpacker.cc:679
 hmdcunpacker.cc:680
 hmdcunpacker.cc:681
 hmdcunpacker.cc:682
 hmdcunpacker.cc:683
 hmdcunpacker.cc:684
 hmdcunpacker.cc:685
 hmdcunpacker.cc:686
 hmdcunpacker.cc:687
 hmdcunpacker.cc:688
 hmdcunpacker.cc:689
 hmdcunpacker.cc:690
 hmdcunpacker.cc:691
 hmdcunpacker.cc:692
 hmdcunpacker.cc:693
 hmdcunpacker.cc:694
 hmdcunpacker.cc:695
 hmdcunpacker.cc:696
 hmdcunpacker.cc:697
 hmdcunpacker.cc:698
 hmdcunpacker.cc:699
 hmdcunpacker.cc:700
 hmdcunpacker.cc:701
 hmdcunpacker.cc:702
 hmdcunpacker.cc:703
 hmdcunpacker.cc:704
 hmdcunpacker.cc:705
 hmdcunpacker.cc:706
 hmdcunpacker.cc:707
 hmdcunpacker.cc:708
 hmdcunpacker.cc:709
 hmdcunpacker.cc:710
 hmdcunpacker.cc:711
 hmdcunpacker.cc:712
 hmdcunpacker.cc:713
 hmdcunpacker.cc:714
 hmdcunpacker.cc:715
 hmdcunpacker.cc:716
 hmdcunpacker.cc:717
 hmdcunpacker.cc:718
 hmdcunpacker.cc:719
 hmdcunpacker.cc:720
 hmdcunpacker.cc:721
 hmdcunpacker.cc:722
 hmdcunpacker.cc:723
 hmdcunpacker.cc:724
 hmdcunpacker.cc:725
 hmdcunpacker.cc:726
 hmdcunpacker.cc:727
 hmdcunpacker.cc:728
 hmdcunpacker.cc:729
 hmdcunpacker.cc:730
 hmdcunpacker.cc:731
 hmdcunpacker.cc:732
 hmdcunpacker.cc:733
 hmdcunpacker.cc:734
 hmdcunpacker.cc:735
 hmdcunpacker.cc:736
 hmdcunpacker.cc:737
 hmdcunpacker.cc:738
 hmdcunpacker.cc:739
 hmdcunpacker.cc:740
 hmdcunpacker.cc:741
 hmdcunpacker.cc:742
 hmdcunpacker.cc:743
 hmdcunpacker.cc:744
 hmdcunpacker.cc:745
 hmdcunpacker.cc:746
 hmdcunpacker.cc:747
 hmdcunpacker.cc:748
 hmdcunpacker.cc:749
 hmdcunpacker.cc:750
 hmdcunpacker.cc:751
 hmdcunpacker.cc:752
 hmdcunpacker.cc:753
 hmdcunpacker.cc:754
 hmdcunpacker.cc:755
 hmdcunpacker.cc:756
 hmdcunpacker.cc:757
 hmdcunpacker.cc:758
 hmdcunpacker.cc:759
 hmdcunpacker.cc:760
 hmdcunpacker.cc:761
 hmdcunpacker.cc:762
 hmdcunpacker.cc:763
 hmdcunpacker.cc:764
 hmdcunpacker.cc:765
 hmdcunpacker.cc:766
 hmdcunpacker.cc:767
 hmdcunpacker.cc:768
 hmdcunpacker.cc:769
 hmdcunpacker.cc:770
 hmdcunpacker.cc:771
 hmdcunpacker.cc:772
 hmdcunpacker.cc:773
 hmdcunpacker.cc:774
 hmdcunpacker.cc:775
 hmdcunpacker.cc:776
 hmdcunpacker.cc:777
 hmdcunpacker.cc:778
 hmdcunpacker.cc:779
 hmdcunpacker.cc:780
 hmdcunpacker.cc:781
 hmdcunpacker.cc:782
 hmdcunpacker.cc:783
 hmdcunpacker.cc:784
 hmdcunpacker.cc:785
 hmdcunpacker.cc:786
 hmdcunpacker.cc:787
 hmdcunpacker.cc:788
 hmdcunpacker.cc:789
 hmdcunpacker.cc:790
 hmdcunpacker.cc:791
 hmdcunpacker.cc:792
 hmdcunpacker.cc:793
 hmdcunpacker.cc:794
 hmdcunpacker.cc:795
 hmdcunpacker.cc:796
 hmdcunpacker.cc:797
 hmdcunpacker.cc:798
 hmdcunpacker.cc:799
 hmdcunpacker.cc:800
 hmdcunpacker.cc:801
 hmdcunpacker.cc:802
 hmdcunpacker.cc:803
 hmdcunpacker.cc:804
 hmdcunpacker.cc:805
 hmdcunpacker.cc:806
 hmdcunpacker.cc:807
 hmdcunpacker.cc:808
 hmdcunpacker.cc:809
 hmdcunpacker.cc:810
 hmdcunpacker.cc:811
 hmdcunpacker.cc:812
 hmdcunpacker.cc:813
 hmdcunpacker.cc:814
 hmdcunpacker.cc:815
 hmdcunpacker.cc:816
 hmdcunpacker.cc:817
 hmdcunpacker.cc:818
 hmdcunpacker.cc:819
 hmdcunpacker.cc:820
 hmdcunpacker.cc:821
 hmdcunpacker.cc:822
 hmdcunpacker.cc:823
 hmdcunpacker.cc:824
 hmdcunpacker.cc:825
 hmdcunpacker.cc:826
 hmdcunpacker.cc:827
 hmdcunpacker.cc:828
 hmdcunpacker.cc:829
 hmdcunpacker.cc:830
 hmdcunpacker.cc:831
 hmdcunpacker.cc:832
 hmdcunpacker.cc:833
 hmdcunpacker.cc:834
 hmdcunpacker.cc:835
 hmdcunpacker.cc:836
 hmdcunpacker.cc:837
 hmdcunpacker.cc:838
 hmdcunpacker.cc:839
 hmdcunpacker.cc:840
 hmdcunpacker.cc:841
 hmdcunpacker.cc:842
 hmdcunpacker.cc:843
 hmdcunpacker.cc:844
 hmdcunpacker.cc:845
 hmdcunpacker.cc:846
 hmdcunpacker.cc:847
 hmdcunpacker.cc:848
 hmdcunpacker.cc:849
 hmdcunpacker.cc:850
 hmdcunpacker.cc:851
 hmdcunpacker.cc:852
 hmdcunpacker.cc:853
 hmdcunpacker.cc:854
 hmdcunpacker.cc:855
 hmdcunpacker.cc:856
 hmdcunpacker.cc:857
 hmdcunpacker.cc:858
 hmdcunpacker.cc:859
 hmdcunpacker.cc:860
 hmdcunpacker.cc:861
 hmdcunpacker.cc:862
 hmdcunpacker.cc:863
 hmdcunpacker.cc:864
 hmdcunpacker.cc:865
 hmdcunpacker.cc:866
 hmdcunpacker.cc:867
 hmdcunpacker.cc:868
 hmdcunpacker.cc:869
 hmdcunpacker.cc:870
 hmdcunpacker.cc:871
 hmdcunpacker.cc:872
 hmdcunpacker.cc:873
 hmdcunpacker.cc:874
 hmdcunpacker.cc:875
 hmdcunpacker.cc:876
 hmdcunpacker.cc:877
 hmdcunpacker.cc:878
 hmdcunpacker.cc:879
 hmdcunpacker.cc:880
 hmdcunpacker.cc:881
 hmdcunpacker.cc:882
 hmdcunpacker.cc:883
 hmdcunpacker.cc:884
 hmdcunpacker.cc:885
 hmdcunpacker.cc:886
 hmdcunpacker.cc:887
 hmdcunpacker.cc:888
 hmdcunpacker.cc:889
 hmdcunpacker.cc:890
 hmdcunpacker.cc:891
 hmdcunpacker.cc:892
 hmdcunpacker.cc:893
 hmdcunpacker.cc:894
 hmdcunpacker.cc:895
 hmdcunpacker.cc:896
 hmdcunpacker.cc:897
 hmdcunpacker.cc:898
 hmdcunpacker.cc:899
 hmdcunpacker.cc:900
 hmdcunpacker.cc:901
 hmdcunpacker.cc:902
 hmdcunpacker.cc:903
 hmdcunpacker.cc:904
 hmdcunpacker.cc:905
 hmdcunpacker.cc:906
 hmdcunpacker.cc:907
 hmdcunpacker.cc:908
 hmdcunpacker.cc:909
 hmdcunpacker.cc:910
 hmdcunpacker.cc:911
 hmdcunpacker.cc:912
 hmdcunpacker.cc:913
 hmdcunpacker.cc:914
 hmdcunpacker.cc:915
 hmdcunpacker.cc:916
 hmdcunpacker.cc:917
 hmdcunpacker.cc:918
 hmdcunpacker.cc:919
 hmdcunpacker.cc:920
 hmdcunpacker.cc:921
 hmdcunpacker.cc:922
 hmdcunpacker.cc:923
 hmdcunpacker.cc:924
 hmdcunpacker.cc:925
 hmdcunpacker.cc:926
 hmdcunpacker.cc:927
 hmdcunpacker.cc:928
 hmdcunpacker.cc:929
 hmdcunpacker.cc:930
 hmdcunpacker.cc:931
 hmdcunpacker.cc:932
 hmdcunpacker.cc:933
 hmdcunpacker.cc:934
 hmdcunpacker.cc:935
 hmdcunpacker.cc:936
 hmdcunpacker.cc:937
 hmdcunpacker.cc:938
 hmdcunpacker.cc:939
 hmdcunpacker.cc:940
 hmdcunpacker.cc:941
 hmdcunpacker.cc:942
 hmdcunpacker.cc:943
 hmdcunpacker.cc:944
 hmdcunpacker.cc:945
 hmdcunpacker.cc:946
 hmdcunpacker.cc:947
 hmdcunpacker.cc:948
 hmdcunpacker.cc:949
 hmdcunpacker.cc:950
 hmdcunpacker.cc:951
 hmdcunpacker.cc:952
 hmdcunpacker.cc:953
 hmdcunpacker.cc:954
 hmdcunpacker.cc:955
 hmdcunpacker.cc:956
 hmdcunpacker.cc:957
 hmdcunpacker.cc:958
 hmdcunpacker.cc:959
 hmdcunpacker.cc:960
 hmdcunpacker.cc:961
 hmdcunpacker.cc:962
 hmdcunpacker.cc:963
 hmdcunpacker.cc:964
 hmdcunpacker.cc:965
 hmdcunpacker.cc:966
 hmdcunpacker.cc:967
 hmdcunpacker.cc:968
 hmdcunpacker.cc:969
 hmdcunpacker.cc:970
 hmdcunpacker.cc:971
 hmdcunpacker.cc:972
 hmdcunpacker.cc:973
 hmdcunpacker.cc:974
 hmdcunpacker.cc:975
 hmdcunpacker.cc:976
 hmdcunpacker.cc:977
 hmdcunpacker.cc:978
 hmdcunpacker.cc:979