ROOT logo
//*-- Author : Manuel Sanchez
//*-- Modified : 16/9/2003 by R. Holzmann
//*-- Modified : 23/3/99 by D.B. (Dump of events)
//*-- Modified : 26/11/98 by Ilse Koenig
//*-- Modified : 30/03/98 by Manuel Sanchez
//*-- Copyright : GENP (Univ.Santiago de Compostela)

//_HADES_CLASS_DESCRIPTION 
//////////////////////////////////////////////////////////////////////////////
//HLdSource
//
//  Base class for a "data source" which delivery LMD data.
//  The derived class HldFileSource reads the data from a file on disk and
//  the derived class HldRemoteSource getrs the data directly from the
//  Data Adquisition.
//
//  The data in the file need to be unpacked. The user must specify the list 
//  of unpackers (see HldUnpack) to use, this way the user can select which 
//  parts of the data will be retrieved. That also give support to the case of 
//  LMD files not containing all the possible types of data (Rich data, 
//  Mdc data...)
//
//  An example would be:
//  HLmdFileSource *lmdSource=new HLmdFileSource();
//  lmdSource->addUnpacker(new HRichUnpacker);
//
//  This way you only get the Rich data in the files specified in the runtime
//  database
//
///////////////////////////////////////////////////////////////////////////////

#include "hldsource.h"
#include "hldevt.h"
#include "hldsubevt.h"
#include "hrecevent.h"
#include "hldevt.h"
#include "hades.h"
#include "hmessagemgr.h"
#include "htrbnetunpacker.h"

ClassImp(HldSource)
HldEvt*  HldSource::fReadEvent=0;

HldSource::HldSource(void) {
  // Default constructor for a Lmd data source.
  fReadEvent=0;
  fUnpackerList=new TList();
  isDumped=kFALSE;   
  isScanned=kFALSE;
	hubUnpacker = new HTrbNetUnpacker();
}

HldSource::~HldSource(void) {
  //Destructor for a LMD data source
 if (fUnpackerList) {
    fUnpackerList->Delete();
    delete fUnpackerList;
    fUnpackerList = 0;
  }
  if (fReadEvent)
  {
    delete fReadEvent;
    fReadEvent = NULL;
  }
  if(hubUnpacker)
	{
		delete hubUnpacker;
		hubUnpacker = NULL;
	}
}

void HldSource::addUnpacker(HldUnpack *unpacker) {
  // adds an unpacker to the list of unpackers for a LMD source
  fUnpackerList->Add(unpacker);
}

Bool_t HldSource::initUnpacker(void) {
  //Calls the init() function for each unpacker.
	if(!hubUnpacker->init())
	{
		ERROR_msg(HMessageMgr::DET_MDC, "Failed to initialize HTrbNetUnpacker!");
		return kFALSE;
	}
  TIter next(fUnpackerList);
  HldUnpack *unpacker;
  if (!(*fEventAddr)) {
    (*fEventAddr)=new HRecEvent;
  }
  while ( (unpacker=(HldUnpack *)next())!=NULL) {
    if (!unpacker->init()) return kFALSE;
  }
  return kTRUE;
}

Bool_t HldSource::reinit(void) {
  //Calls the reinit() function for each unpacker.
	if(!hubUnpacker->reinit())
	{
		return kFALSE;
	}

  TIter next(fUnpackerList);
  HldUnpack *unpacker;
  while ( (unpacker=(HldUnpack *)next())!=NULL) {
      unpacker->setHldEvt(getEvent());
      if (!unpacker->reinit()) return kFALSE;
  }
  return kTRUE;
}

Bool_t HldSource::finalizeUnpacker(void) {
  //Calls the init() function for each unpacker.
  TIter next(fUnpackerList);
  HldUnpack *unpacker;
  if (!(*fEventAddr)) {
    (*fEventAddr)=new HRecEvent;
  }
  while ( (unpacker=(HldUnpack *)next())!=NULL) {
    if (!unpacker->finalize()) return kFALSE;
  }
  return kTRUE;
}

Bool_t HldSource::finalize(void) {
  return finalizeUnpacker();
}

void HldSource::decodeHeader(HEventHeader *dest) {
  //Decodes the event's header
  dest=((*fEventAddr)->getHeader()); //CHECKME: 
  // dest= gHades->getCurrentEvent()->getHeader();
  dest->setEventSize(fReadEvent->getSize());
  dest->setEventDecoding(fReadEvent->getDecoding());
  dest->setEventSeqNumber(fReadEvent->getSeqNr());
  dest->setDate(fReadEvent->getDate());
  dest->setTime(fReadEvent->getTime());
  dest->setEventRunNumber(fReadEvent->getRunNr());
  dest->setEventPad(fReadEvent->getPad());
  UInt_t trig = fReadEvent->getId();
  dest->setId(trig & 0xF);                     // 4 lower bits taken. What about start/stop run?
  if(fForcedID > 0){                           // force the event header to be labled with a given
      dest->setId(fForcedID & 0xF);             // type (HDataSource::forceID())
  }
  dest->setDownscalingFlag((trig >> 4) & 0x1); // downscaling flag
  dest->setTriggerDecision((trig >> 5) & 0x7); // according to the DAQ docu, it's 3 bit Long_t word
  dest->setVersion((trig >> 12) & 0xF);        // version
  dest->setErrorBit((trig >> 31) & 0x01 );     // error bit
}


EDsState HldSource::scanIt(HldEvt *evt) {
  // dump the whole evt on the screen  
  Bool_t r=kTRUE;

  if (!evt->scanHdr()) r=kFALSE;

  UInt_t *data=evt->getData();
  Int_t t=HMessageMgr::DET_ALL;
  if (!data) {INFO_msg(10,t,"*** No subevent in this event ****\n"); 
              return kDsOk;
  } 
  
  UInt_t *end=evt->getEnd(); 
  HldSubEvt subevt;
  while ( data < end ){ 
    subevt= HldSubEvt(data);
    if (!subevt.scanIt()) r=kFALSE; 
    data= subevt.getPaddedEnd();
  }
  if (!r) return kDsError;
  return kDsOk;
}

EDsState HldSource::showIt(HldEvt *evt){
  // Scan the event.  
  //printf("*******************************************************************\n");
	SEPERATOR_msg("*",66);
  evt->dumpHdr();
	SEPERATOR_msg("*",66);
  //printf("*******************************************************************\n");
  UInt_t *data=evt->getData();
  if (!data) {INFO_msg(10,HMessageMgr::DET_ALL,"*** No subevent in this event ****\n");
              return kDsOk;
  }

  UInt_t *end=evt->getEnd();
  HldSubEvt subevt;
     while ( data < end ){
                subevt= HldSubEvt(data);
                subevt.dumpIt();
                data= subevt.getPaddedEnd();
         }
  return kDsOk;    
}


EDsState HldSource::dumpEvt(void) {
 if (!fReadEvent) return kDsError; 
     else{
    if(!(fReadEvent->swap()) ) return kDsError;  
     return showIt(fReadEvent);   
    
    } 
}

EDsState HldSource::scanEvt(void) {
 if (!fReadEvent) return kDsError; 
     else{
    if(!(fReadEvent->swap()) ) return kDsError;  
     return scanIt(fReadEvent);   
    
    } 
}





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