ROOT logo
//*-- Author : Walter Karig
//*-- Modified : 08/07/2010 by M. Weber
//*-- Modified : 03/05/2005 by Ilse Koenig
//*-- Modified : 16/09/2003 by T.Wojcik
//*-- Modified : 24/11/2002 by Dusan Zovinec
//*-- Modified : 18/12/2001 by Ilse Koenig
//*-- Modified : 29/11/2000 by Ilse Koenig
//*-- Modified : 13/11/2000 by M. Golubeva
//*-- Modified : 05/06/98 by Manuel Sanchez


#include "hades.h"
#include "hcategory.h"
#include "hdatasource.h"
#include "hdebug.h"
#include "hdetector.h"
#include "hevent.h"
#include "heventheader.h"
#include "hldsubevt.h"
#include "hspectrometer.h"
#include "htboxchan.h"
#include "htboxunpacker.h"

using namespace std;

ClassImp(HTBoxUnpacker)

//_HADES_CLASS_DESCRIPTION
//////////////////////////////////////////////////////////////////
//
// HTBoxUnpacker
//
// Unpacker used to read Scalers data from .hld files
// Fills the TBox category.
//
//////////////////////////////////////////////////////////////////

HTBoxUnpacker::HTBoxUnpacker(Int_t id)
{
   fSubEvtId = id;
   fCat      = NULL;

   fLoc.set(1, 0);
}

Bool_t HTBoxUnpacker::init(void)
{

   // Creates the TBox category for the scalers, if not yet existing

   fCat = (HCategory*)gHades->getCurrentEvent()->getCategory(catTBoxChan);
   if (NULL == fCat) {
      fCat = gHades->getSetup()->getDetector("TBox")->buildCategory(catTBoxChan);
      if (NULL != fCat) {
         gHades->getCurrentEvent()->addCategory(catTBoxChan, fCat, "TBox");
      } else {
         Error("init", "Can not build output category");
         return kFALSE;
      }
   }
   return kTRUE;
}

Int_t HTBoxUnpacker::execute()
{

   // Unpacks the scaler data and fills the TBox data category


#if DEBUG_LEVEL>4
   gDebuger->enterFunc("HTBoxUnpacker::execute\n");
#endif

   // scalers are written every second (decoupled from calibration
   //if (!(gHades->isCalibration())) {  // no calibration event, nothing to be done for scalers
   //  return 1;
   //}

   UInt_t* data       = 0;
   UInt_t* end        = 0;

   UInt_t uTrbNetAdress;        // TrbNetAdress
   UInt_t uSubBlockSize;        // BlockSize of SubSubEvent
   UInt_t uSubBlockSizeTest;    // BlockSize of SubSubEvent
   UInt_t uSubBlockSizeScalers; // BlockSize of Scaler words
   UInt_t trbExtensionSize;     // number of TRB extension words

   HTBoxChan* ptboxchan = NULL;

   if (pSubEvt) {

      trbExtensionSize = 0;

      data = pSubEvt->getData();
      end  = pSubEvt->getEnd();

#if DEBUG_LEVEL>4
      Info("execute", "TBOX: Next SubEvt. data between: %p and %p\n", data, end);
      pSubEvt->dumpIt();
#endif


      // loop over data words in Subevent -> standard HUB word (SubSubEvent)
      while (data != end) {


#if DEBUG_LEVEL>2
         Info("execute", "standard HUB word: %08x\n", *data);
#endif

         uSubBlockSize = (*data >> 16) & 0xFF;     // No. of the data words from one TRB board
         uSubBlockSizeScalers = uSubBlockSize - 4;
         uTrbNetAdress = *data       & 0xFFFF;     // TRB net Adddress

         // if no CTS TRB -> skip data
         if (uTrbNetAdress > 0x00FF) {
            data += uSubBlockSize;
         } else {


            // first header of data (TRB header -> not used, sub block size)
            // control the SubSubEvent size
            ++data;

#if DEBUG_LEVEL>2
            Info("execute", "first data header: %08x (%p)\n", *data, data);
#endif

            uSubBlockSizeTest = *data & 0xFF;

            if (uSubBlockSize != uSubBlockSizeTest) {
               Error("execute", "check of SubBlockSize failed : %04x != %04x", uSubBlockSize, *(data + 1) & 0xFF);
               return -1;
            }

            // second header of data (31-16 data version, 15-0 number of extension words)
            ++data;

#if DEBUG_LEVEL>2
            Info("execute", "second data header: %08x (%p)\n", *data, data);
#endif

            trbExtensionSize = *data       & 0xFFFF;

            // loop over TRB extensions
            if (trbExtensionSize != 0) {
               for (UInt_t ii = 0; ii < trbExtensionSize; ii++) {
                  ++data;
                  if (trbExtensionSize < 128) {
                  } else {
                     Error("execute", "too many TRB extension words (maximum = 128)");
                     return -1;
                  }
               }
            }



            // Latches (skip this data word)
            ++data;

#if DEBUG_LEVEL>2
            Info("execute", "Latch data word: %08x (%p)\n", *data, data);
#endif

            // empty data word
            ++data;


            // scaler information
            for (UInt_t i = 0; i < uSubBlockSizeScalers ; i++) {

               ++data;


               //Function for filling TBoxChan category for given number of scalers

               if (NULL != fCat) {
                  ptboxchan = (HTBoxChan*)fCat->getNewSlot(fLoc);
                  if (NULL != ptboxchan) {
                     ptboxchan = new(ptboxchan) HTBoxChan;
                     ptboxchan->setScalerData(i, *data);
                     if(i==0){ // time in spill should be set in the eventheader
                         Double_t time_ns = 5.* (*data); // time in ns
                         gHades->getCurrentEvent()->getHeader()->setTimeInSpill(time_ns);
                     }
                     if(i==1){ // time to last trigger should be set in the eventheader
                         Double_t time_ns = 5.* (*data); // time in ns
                         gHades->getCurrentEvent()->getHeader()->setTimeToLastTrigger(time_ns);
                     }
                     if(i==2){ // time to last anti conicidence should be set in the eventheader
                         Double_t time_ns = 5.* (*data); // time in ns
                         gHades->getCurrentEvent()->getHeader()->setTimeToLastAntiCoinc(time_ns);
                     }
                  } else {
                     Error("fillScalers", "Can not get new slot for HTBoxChan");
                     continue;
                  }
               }

#if DEBUG_LEVEL>2
               Info("execute", "Scaler data word %i:  %08x (%p)\n", i, *data, data);
#endif


            }
         }//end CTS TRB

         ++data;
      }
   }


#if DEBUG_LEVEL>4
   gDebuger->leaveFunc("HTBoxUnpacker::execute\n");
#endif

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