ROOT logo
//*-- Author : Walter Karig 
//*-- Modified : 05/06/98 by Manuel Sanchez
//*-- Modified : 28/5/2000 by R. Holzmann
//
using namespace std;
#include "htofunpacker99.h"
#include "htofraw.h"
#include "hdebug.h"
#include "hades.h"
#include "hevent.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hcategory.h"
#include "hldsubevt.h"
#include <iostream> 
#include <iomanip>

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////
//HTofUnpacker99
//
//  This is the HUnpacker used to read Nov 99 TOF data from LMD files
//
//////////////////////////////////

HTofUnpacker99::HTofUnpacker99(void) {
  pRawCat=NULL;
  pTofData = NULL;
}

HTofUnpacker99::~HTofUnpacker99(void) {
}

Bool_t HTofUnpacker99::init(void) {
  pRawCat=gHades->getCurrentEvent()->getCategory(catTofRaw);
  if (!pRawCat) {
    pRawCat=gHades->getSetup()->getDetector("Tof")->buildCategory(catTofRaw);
    if (!pRawCat) {
      return kFALSE;
    } else {
      gHades->getCurrentEvent()->addCategory(catTofRaw,pRawCat,"Tof");
    }
  }
  return kTRUE;
}

Int_t HTofUnpacker99::execute() {

  Int_t i = fill();
  return i;
}


Int_t HTofUnpacker99::fill() {

  //  cout << "In HTofUnpacker99::fill()" << endl;

  if(pTofData) {
    delete [] pTofData;
    pTofData = NULL;
  }

  //  if(pSubEvt) cout << "pSubEvt exists" << endl;
  //  else cout << "pSubEvt doesn't exist" << endl;


  if(pSubEvt) {

    UInt_t channels,geo;
    UInt_t tdcCh,time;
    Int_t cursor;
    Int_t j;
    UInt_t tdcCounter;

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

    Int_t length = pSubEvt->getEnd() - pSubEvt->getData();

    //    printf(" length = %i \n",length);  

    pTofData = new UInt_t[length];
    UInt_t *pointer = pSubEvt->getData();
    for(j=0;j<length;j++) pTofData[j] = pointer[j];
    cursor = 0;

//
// start of loop over TOF TDC's inside TOF subevent
//

    tdcCounter = 0;

    while(cursor<length) {
      geo = (UInt_t) byte(1,pTofData[cursor]) >> 3;
      channels = (UInt_t) byte(3,pTofData[cursor++]);

      //   cout<<"geo = "<<geo<<"  channels = "<<channels<<"  chanEnd ="<<
      //   	(UInt_t)(byte(3,pTofData[cursor+channels]))<<endl;


   /*if(channels!=((UInt_t)(byte(3,pTofData[cursor+channels])))) {
	cout << "Error in TDC" << geo << " has happened" << endl;
	return 0;
      }*/

      tdcCh = 0;
      time = 0;

//
//start of loop over data words inside TOF TDC
//

      for(j=cursor; j < (Int_t)(cursor+channels); j++) {
	tdcCh = (tdcCh | (pTofData[j] & 0x001f0000)) >> 16;
        time = (pTofData[j] & 0xfff ) % 0xfff;


	//	loc[0] = 3;


//for September test
	
	if(geo==3||geo==4||geo==5||geo==6) loc[0] = 2; 
	if(geo==8||geo==9||geo==10||geo==11) loc[0] = 5;

	if(geo==3||geo==5||geo==8||geo==10) loc[1] = tdcCh/8;
	if(geo==4||geo==6||geo==9||geo==11) loc[1] = tdcCh/8 + 4;

	loc[2] = tdcCh%8;

	//      	cout<<"tdcCh = "<<tdcCh<<"   time = "<<time<<endl;

/*
//        if(geo==5||geo==7) loc[1] = tdcCh/8;

	if(geo==7) {
	  if(tdcCh/8==0 || tdcCh/8==2) loc[1] = 2;
	  if(tdcCh/8==1 || tdcCh/8==3) loc[1] = 3;
	}

	if(geo==6||geo==8) loc[1] = tdcCh/8 + 4;

	loc[2] = tdcCh%8;
*/


	//	if(HTofRaw *pCell= (HTofRaw*) pRawCat->getSlot(loc)) {

	HTofRaw *pCell = (HTofRaw*) pRawCat->getObject(loc);

        if (pCell == NULL) { 
	  pCell = (HTofRaw*) pRawCat->getSlot(loc);
	  if (pCell != NULL) {
	    pCell = new(pCell) HTofRaw;   // needed to get a streamer
	                                    // for HTree::Fill() 
	    pCell->setRightTime(0.0);
	    pCell->setLeftTime(0.0);
	    pCell->setRightCharge(0.0);
	    pCell->setLeftCharge(0.0);
	    pCell->setSector((Char_t) loc[0]);
	    pCell->setModule((Char_t)loc[1]);
	    pCell->setCell((Char_t)loc[2]);
	  } else return kFALSE;
        }

	if(pCell != NULL) {

/*	  if(geo==6) {
	    pCell->setLeftTime((Float_t) time);
            pCell->setModule((Char_t)loc[1]);
            pCell->setCell((Char_t)loc[2]);
	  }

	  if(geo==8){
	    pCell->setRightTime((Float_t) time);
            pCell->setModule((Char_t)loc[1]);
            pCell->setCell((Char_t)loc[2]);
	  }

	  if(geo==7) {

	    if(tdcCh/8==0||tdcCh/8==1) {
	      pCell->setLeftTime((Float_t) time);
	      pCell->setModule((Char_t)loc[1]);
	      pCell->setCell((Char_t)loc[2]);
	    }

	    if(tdcCh/8==2||tdcCh/8==3) {
	      pCell->setRightTime((Float_t) time);
	      pCell->setModule((Char_t)loc[1]);
	      pCell->setCell((Char_t)loc[2]);
	    }
	  }*/

	  if(geo==3||geo==4||geo==8||geo==9) {
	    pCell->setRightTime((Float_t) time);
	    pCell->setSector((Char_t) loc[0]);
	    pCell->setModule((Char_t) loc[1]);
	    pCell->setCell((Char_t) loc[2]);
	  }

	  if(geo==5||geo==6||geo==10||geo==11) {
	    pCell->setLeftTime((Float_t) time);
	    pCell->setSector((Char_t) loc[0]);
	    pCell->setModule((Char_t) loc[1]);
	    pCell->setCell((Char_t) loc[2]);
	  }

	}

//
//end of loop over data words inside TOF TDC
//

      }	

      cursor += channels + 1;
      tdcCounter++;

//
//end of loop over TOF TDC's inside TOF subevent
//

    }

  }  

return kTRUE;

}           

ClassImp(HTofUnpacker99) 








 htofunpacker99.cc:1
 htofunpacker99.cc:2
 htofunpacker99.cc:3
 htofunpacker99.cc:4
 htofunpacker99.cc:5
 htofunpacker99.cc:6
 htofunpacker99.cc:7
 htofunpacker99.cc:8
 htofunpacker99.cc:9
 htofunpacker99.cc:10
 htofunpacker99.cc:11
 htofunpacker99.cc:12
 htofunpacker99.cc:13
 htofunpacker99.cc:14
 htofunpacker99.cc:15
 htofunpacker99.cc:16
 htofunpacker99.cc:17
 htofunpacker99.cc:18
 htofunpacker99.cc:19
 htofunpacker99.cc:20
 htofunpacker99.cc:21
 htofunpacker99.cc:22
 htofunpacker99.cc:23
 htofunpacker99.cc:24
 htofunpacker99.cc:25
 htofunpacker99.cc:26
 htofunpacker99.cc:27
 htofunpacker99.cc:28
 htofunpacker99.cc:29
 htofunpacker99.cc:30
 htofunpacker99.cc:31
 htofunpacker99.cc:32
 htofunpacker99.cc:33
 htofunpacker99.cc:34
 htofunpacker99.cc:35
 htofunpacker99.cc:36
 htofunpacker99.cc:37
 htofunpacker99.cc:38
 htofunpacker99.cc:39
 htofunpacker99.cc:40
 htofunpacker99.cc:41
 htofunpacker99.cc:42
 htofunpacker99.cc:43
 htofunpacker99.cc:44
 htofunpacker99.cc:45
 htofunpacker99.cc:46
 htofunpacker99.cc:47
 htofunpacker99.cc:48
 htofunpacker99.cc:49
 htofunpacker99.cc:50
 htofunpacker99.cc:51
 htofunpacker99.cc:52
 htofunpacker99.cc:53
 htofunpacker99.cc:54
 htofunpacker99.cc:55
 htofunpacker99.cc:56
 htofunpacker99.cc:57
 htofunpacker99.cc:58
 htofunpacker99.cc:59
 htofunpacker99.cc:60
 htofunpacker99.cc:61
 htofunpacker99.cc:62
 htofunpacker99.cc:63
 htofunpacker99.cc:64
 htofunpacker99.cc:65
 htofunpacker99.cc:66
 htofunpacker99.cc:67
 htofunpacker99.cc:68
 htofunpacker99.cc:69
 htofunpacker99.cc:70
 htofunpacker99.cc:71
 htofunpacker99.cc:72
 htofunpacker99.cc:73
 htofunpacker99.cc:74
 htofunpacker99.cc:75
 htofunpacker99.cc:76
 htofunpacker99.cc:77
 htofunpacker99.cc:78
 htofunpacker99.cc:79
 htofunpacker99.cc:80
 htofunpacker99.cc:81
 htofunpacker99.cc:82
 htofunpacker99.cc:83
 htofunpacker99.cc:84
 htofunpacker99.cc:85
 htofunpacker99.cc:86
 htofunpacker99.cc:87
 htofunpacker99.cc:88
 htofunpacker99.cc:89
 htofunpacker99.cc:90
 htofunpacker99.cc:91
 htofunpacker99.cc:92
 htofunpacker99.cc:93
 htofunpacker99.cc:94
 htofunpacker99.cc:95
 htofunpacker99.cc:96
 htofunpacker99.cc:97
 htofunpacker99.cc:98
 htofunpacker99.cc:99
 htofunpacker99.cc:100
 htofunpacker99.cc:101
 htofunpacker99.cc:102
 htofunpacker99.cc:103
 htofunpacker99.cc:104
 htofunpacker99.cc:105
 htofunpacker99.cc:106
 htofunpacker99.cc:107
 htofunpacker99.cc:108
 htofunpacker99.cc:109
 htofunpacker99.cc:110
 htofunpacker99.cc:111
 htofunpacker99.cc:112
 htofunpacker99.cc:113
 htofunpacker99.cc:114
 htofunpacker99.cc:115
 htofunpacker99.cc:116
 htofunpacker99.cc:117
 htofunpacker99.cc:118
 htofunpacker99.cc:119
 htofunpacker99.cc:120
 htofunpacker99.cc:121
 htofunpacker99.cc:122
 htofunpacker99.cc:123
 htofunpacker99.cc:124
 htofunpacker99.cc:125
 htofunpacker99.cc:126
 htofunpacker99.cc:127
 htofunpacker99.cc:128
 htofunpacker99.cc:129
 htofunpacker99.cc:130
 htofunpacker99.cc:131
 htofunpacker99.cc:132
 htofunpacker99.cc:133
 htofunpacker99.cc:134
 htofunpacker99.cc:135
 htofunpacker99.cc:136
 htofunpacker99.cc:137
 htofunpacker99.cc:138
 htofunpacker99.cc:139
 htofunpacker99.cc:140
 htofunpacker99.cc:141
 htofunpacker99.cc:142
 htofunpacker99.cc:143
 htofunpacker99.cc:144
 htofunpacker99.cc:145
 htofunpacker99.cc:146
 htofunpacker99.cc:147
 htofunpacker99.cc:148
 htofunpacker99.cc:149
 htofunpacker99.cc:150
 htofunpacker99.cc:151
 htofunpacker99.cc:152
 htofunpacker99.cc:153
 htofunpacker99.cc:154
 htofunpacker99.cc:155
 htofunpacker99.cc:156
 htofunpacker99.cc:157
 htofunpacker99.cc:158
 htofunpacker99.cc:159
 htofunpacker99.cc:160
 htofunpacker99.cc:161
 htofunpacker99.cc:162
 htofunpacker99.cc:163
 htofunpacker99.cc:164
 htofunpacker99.cc:165
 htofunpacker99.cc:166
 htofunpacker99.cc:167
 htofunpacker99.cc:168
 htofunpacker99.cc:169
 htofunpacker99.cc:170
 htofunpacker99.cc:171
 htofunpacker99.cc:172
 htofunpacker99.cc:173
 htofunpacker99.cc:174
 htofunpacker99.cc:175
 htofunpacker99.cc:176
 htofunpacker99.cc:177
 htofunpacker99.cc:178
 htofunpacker99.cc:179
 htofunpacker99.cc:180
 htofunpacker99.cc:181
 htofunpacker99.cc:182
 htofunpacker99.cc:183
 htofunpacker99.cc:184
 htofunpacker99.cc:185
 htofunpacker99.cc:186
 htofunpacker99.cc:187
 htofunpacker99.cc:188
 htofunpacker99.cc:189
 htofunpacker99.cc:190
 htofunpacker99.cc:191
 htofunpacker99.cc:192
 htofunpacker99.cc:193
 htofunpacker99.cc:194
 htofunpacker99.cc:195
 htofunpacker99.cc:196
 htofunpacker99.cc:197
 htofunpacker99.cc:198
 htofunpacker99.cc:199
 htofunpacker99.cc:200
 htofunpacker99.cc:201
 htofunpacker99.cc:202
 htofunpacker99.cc:203
 htofunpacker99.cc:204
 htofunpacker99.cc:205
 htofunpacker99.cc:206
 htofunpacker99.cc:207
 htofunpacker99.cc:208
 htofunpacker99.cc:209
 htofunpacker99.cc:210
 htofunpacker99.cc:211
 htofunpacker99.cc:212
 htofunpacker99.cc:213
 htofunpacker99.cc:214
 htofunpacker99.cc:215
 htofunpacker99.cc:216
 htofunpacker99.cc:217
 htofunpacker99.cc:218
 htofunpacker99.cc:219
 htofunpacker99.cc:220
 htofunpacker99.cc:221
 htofunpacker99.cc:222
 htofunpacker99.cc:223
 htofunpacker99.cc:224
 htofunpacker99.cc:225
 htofunpacker99.cc:226
 htofunpacker99.cc:227
 htofunpacker99.cc:228
 htofunpacker99.cc:229
 htofunpacker99.cc:230
 htofunpacker99.cc:231
 htofunpacker99.cc:232
 htofunpacker99.cc:233
 htofunpacker99.cc:234
 htofunpacker99.cc:235
 htofunpacker99.cc:236
 htofunpacker99.cc:237
 htofunpacker99.cc:238
 htofunpacker99.cc:239
 htofunpacker99.cc:240