ROOT logo
//*-- Author : Ilse Koenig
//*-- Modified: May 05, 2004 by Peter Zumbruch
//*-- Modified: March 11, 2005 by Y.C.Pachmayer

//_HADES_CLASS_DESCRIPTION 
///////////////////////////////////////////////////////////////////////////////
// HMdcRaw
//
// Unpacked raw data of the MDC
//
// In measurement mode the TDC accepts two hits per channel. The TDC can hereby
// trigger either on two leading edges (hit multiplicity nHits: -1 or -2) or
// on a leading and the trailing edge of a single pulse (nHits: +1 or +2).
// The TDC is able to generate internal calibration events. In this case a
// single channel sends 6 time informations (nHits: +6).
//
// The addresses of the cell can be accessed via the inline functions
//     void setSector(const Int_t n)
//     void setModule(const Int_t n)
//     void setMbo(const Int_t n)
//     void setTdc(const Int_t n)
//     void setAddress(const Int_t sector,const Int_t module,const Int_t mbo,
//                     const Int_t tdc)
//     Int_t getSector(void) const
//     Int_t getModule(void) const
//     Int_t getMbo(void) const
//     Int_t getTdc(void) const
//     void getAddress(Int_t& sector,Int_t& module,Int_t& mbo,Int_t& tdc)
// and the number of hits with the inline function
//     Int_t getNHits(void) const
//
// The inline function clear() sets the data data members to the following
// values:
//          nHits=0;
//          sector=module=mbo=tdc=-1;
//          time1=time2=time3=time4=time5=time6=-999;
//
///////////////////////////////////////////////////////////////////////////////

#include "hmdcraw.h"
#include "hades.h"

ClassImp(HMdcRaw)

  const Int_t HMdcRaw::kDefaultValueTime   = -999;
  const Int_t HMdcRaw::kDefaultValueSector = -1;
  const Int_t HMdcRaw::kDefaultValueModule = -1;
  const Int_t HMdcRaw::kDefaultValueMbo    = -1;
  const Int_t HMdcRaw::kDefaultValueTdc    = -1;

Bool_t HMdcRaw::setTime(const Int_t time,const Int_t mode, const Bool_t noComment)
{
  // Stores the given time in the next data element time* and sets the
  // multiplicity.
  // The TDC can be operated in 2 different modes:
  // mode 0 (default) : trigger on leading and trailing edge
  //                    The multiplicity nHits is incremented by 1.
  // mode 1           : trigger on 2 leading edges:
  //                    The multiplicity nHits is decremented by 1.
  //
  // at maximum one element can only hold 6 times
  // If you try to fill a 7th time kFALSE is returned
  // If gHades exists,
  //    then in addition it is checked in the case of REAL events
  //    whether the number of hits exceeds 2. Also in this case kFALSE is returned
  //    and the time information is not filled,
  //    but the number of hits are increased, so that nHits represents the trials to fill in a time

  if (gHades)
    {
      if (gHades->isReal())
	{
	  if (abs(nHits) >= 2)
	    {
	      if(nHits>0)
	      {
		  nTrialsToFillHits++;
	      }
	      else
	      {
		  nTrialsToFillHits--;
	      }
	      if (!noComment)
		{
		  Warning("setTime()","number of hits for REAL events: %i > 2, datum not filled",abs(nTrialsToFillHits));
		}
	      return kFALSE;
	    }
	}
    }

  switch (nHits)
    {
    case 0:
      time1 = time;
      if (mode)
        { nHits--; nTrialsToFillHits--;}
      else
        { nHits++; nTrialsToFillHits++;}
      break;
    case -1:
      time2 = time;
      nHits--;
      nTrialsToFillHits--;
      break;
      //     case -2:
      //       time3 = time;
      //       nHits--;
      //       break;
    case 1:
      time2 = time;
      nHits++;
      nTrialsToFillHits++;
      break;
    case 2:
      time3 = time;
      nHits++;
      nTrialsToFillHits++;
      break;
    case 3:
      time4 = time;
      nHits++;
      nTrialsToFillHits++;
      break;
    case 4:
      time5 = time;
      nHits++;
      nTrialsToFillHits++;
      break;
    case 5:
      time6 = time;
      nHits++;
      nTrialsToFillHits++;
      break;
    default:
      if (nHits < 0 && !noComment)
      {
          nTrialsToFillHits--;
          Warning("setTime()",
		  "number of hits for REAL events: %i > 2, datum not filled",
		  abs(nTrialsToFillHits));
      }
      if (nHits > 0 && !noComment)
      {
          nTrialsToFillHits++;
	  Warning("setTime()",
		  "number of hits for CALIBRATION events: %i > 6, datum not filled",
		  nTrialsToFillHits);
      }
      return kFALSE;
    }
  return kTRUE;
}

Int_t HMdcRaw::getTime(const Int_t n) const {
  // Returns the time of nth hit (1<=n<=6)
  switch (n) {
    case 1: return time1;
    case 2: return time2;
    case 3: return time3;
    case 4: return time4;
    case 5: return time5;
    case 6: return time6;
    default:
      Error("getTime()","time number: %i out of range [1,6]",n);
      return -1;
  }
}


Bool_t HMdcRaw::setTimeNew(const Int_t time, const Int_t nrtime)
{
  // sets new time value: setTimeNew(timevalue, timeindex)
  // only possible if abs(nHits)>=nrtime
  // return kTRUE if everything is fine, else kFALSE if the number of times is not ok
  if(abs(nHits)>=nrtime)
    {
      switch (nrtime)
	{
	case 1:
	  time1=time;
	  break;
	case 2:
	  time2=time;
	  break;
	case 3:
	  time3=time;
	  break;
	case 4:
	  time4=time;
	  break;
	case 5:
	  time5=time;
	  break;
	case 6:
	  time6=time;
	  break;
	default:
	  {
	    Error("setTimeNew()","number of times not ok, because: %i !=casevalue", nrtime);
	    return kFALSE;
	  }
	}
    }
  else
    {
      Error("setTimeNew()","number of times %i exceeds allowed nHits %i", nrtime,nHits);
      return kFALSE;
    }
  return kTRUE;
}
 hmdcraw.cc:1
 hmdcraw.cc:2
 hmdcraw.cc:3
 hmdcraw.cc:4
 hmdcraw.cc:5
 hmdcraw.cc:6
 hmdcraw.cc:7
 hmdcraw.cc:8
 hmdcraw.cc:9
 hmdcraw.cc:10
 hmdcraw.cc:11
 hmdcraw.cc:12
 hmdcraw.cc:13
 hmdcraw.cc:14
 hmdcraw.cc:15
 hmdcraw.cc:16
 hmdcraw.cc:17
 hmdcraw.cc:18
 hmdcraw.cc:19
 hmdcraw.cc:20
 hmdcraw.cc:21
 hmdcraw.cc:22
 hmdcraw.cc:23
 hmdcraw.cc:24
 hmdcraw.cc:25
 hmdcraw.cc:26
 hmdcraw.cc:27
 hmdcraw.cc:28
 hmdcraw.cc:29
 hmdcraw.cc:30
 hmdcraw.cc:31
 hmdcraw.cc:32
 hmdcraw.cc:33
 hmdcraw.cc:34
 hmdcraw.cc:35
 hmdcraw.cc:36
 hmdcraw.cc:37
 hmdcraw.cc:38
 hmdcraw.cc:39
 hmdcraw.cc:40
 hmdcraw.cc:41
 hmdcraw.cc:42
 hmdcraw.cc:43
 hmdcraw.cc:44
 hmdcraw.cc:45
 hmdcraw.cc:46
 hmdcraw.cc:47
 hmdcraw.cc:48
 hmdcraw.cc:49
 hmdcraw.cc:50
 hmdcraw.cc:51
 hmdcraw.cc:52
 hmdcraw.cc:53
 hmdcraw.cc:54
 hmdcraw.cc:55
 hmdcraw.cc:56
 hmdcraw.cc:57
 hmdcraw.cc:58
 hmdcraw.cc:59
 hmdcraw.cc:60
 hmdcraw.cc:61
 hmdcraw.cc:62
 hmdcraw.cc:63
 hmdcraw.cc:64
 hmdcraw.cc:65
 hmdcraw.cc:66
 hmdcraw.cc:67
 hmdcraw.cc:68
 hmdcraw.cc:69
 hmdcraw.cc:70
 hmdcraw.cc:71
 hmdcraw.cc:72
 hmdcraw.cc:73
 hmdcraw.cc:74
 hmdcraw.cc:75
 hmdcraw.cc:76
 hmdcraw.cc:77
 hmdcraw.cc:78
 hmdcraw.cc:79
 hmdcraw.cc:80
 hmdcraw.cc:81
 hmdcraw.cc:82
 hmdcraw.cc:83
 hmdcraw.cc:84
 hmdcraw.cc:85
 hmdcraw.cc:86
 hmdcraw.cc:87
 hmdcraw.cc:88
 hmdcraw.cc:89
 hmdcraw.cc:90
 hmdcraw.cc:91
 hmdcraw.cc:92
 hmdcraw.cc:93
 hmdcraw.cc:94
 hmdcraw.cc:95
 hmdcraw.cc:96
 hmdcraw.cc:97
 hmdcraw.cc:98
 hmdcraw.cc:99
 hmdcraw.cc:100
 hmdcraw.cc:101
 hmdcraw.cc:102
 hmdcraw.cc:103
 hmdcraw.cc:104
 hmdcraw.cc:105
 hmdcraw.cc:106
 hmdcraw.cc:107
 hmdcraw.cc:108
 hmdcraw.cc:109
 hmdcraw.cc:110
 hmdcraw.cc:111
 hmdcraw.cc:112
 hmdcraw.cc:113
 hmdcraw.cc:114
 hmdcraw.cc:115
 hmdcraw.cc:116
 hmdcraw.cc:117
 hmdcraw.cc:118
 hmdcraw.cc:119
 hmdcraw.cc:120
 hmdcraw.cc:121
 hmdcraw.cc:122
 hmdcraw.cc:123
 hmdcraw.cc:124
 hmdcraw.cc:125
 hmdcraw.cc:126
 hmdcraw.cc:127
 hmdcraw.cc:128
 hmdcraw.cc:129
 hmdcraw.cc:130
 hmdcraw.cc:131
 hmdcraw.cc:132
 hmdcraw.cc:133
 hmdcraw.cc:134
 hmdcraw.cc:135
 hmdcraw.cc:136
 hmdcraw.cc:137
 hmdcraw.cc:138
 hmdcraw.cc:139
 hmdcraw.cc:140
 hmdcraw.cc:141
 hmdcraw.cc:142
 hmdcraw.cc:143
 hmdcraw.cc:144
 hmdcraw.cc:145
 hmdcraw.cc:146
 hmdcraw.cc:147
 hmdcraw.cc:148
 hmdcraw.cc:149
 hmdcraw.cc:150
 hmdcraw.cc:151
 hmdcraw.cc:152
 hmdcraw.cc:153
 hmdcraw.cc:154
 hmdcraw.cc:155
 hmdcraw.cc:156
 hmdcraw.cc:157
 hmdcraw.cc:158
 hmdcraw.cc:159
 hmdcraw.cc:160
 hmdcraw.cc:161
 hmdcraw.cc:162
 hmdcraw.cc:163
 hmdcraw.cc:164
 hmdcraw.cc:165
 hmdcraw.cc:166
 hmdcraw.cc:167
 hmdcraw.cc:168
 hmdcraw.cc:169
 hmdcraw.cc:170
 hmdcraw.cc:171
 hmdcraw.cc:172
 hmdcraw.cc:173
 hmdcraw.cc:174
 hmdcraw.cc:175
 hmdcraw.cc:176
 hmdcraw.cc:177
 hmdcraw.cc:178
 hmdcraw.cc:179
 hmdcraw.cc:180
 hmdcraw.cc:181
 hmdcraw.cc:182
 hmdcraw.cc:183
 hmdcraw.cc:184
 hmdcraw.cc:185
 hmdcraw.cc:186
 hmdcraw.cc:187
 hmdcraw.cc:188
 hmdcraw.cc:189
 hmdcraw.cc:190
 hmdcraw.cc:191
 hmdcraw.cc:192
 hmdcraw.cc:193
 hmdcraw.cc:194
 hmdcraw.cc:195
 hmdcraw.cc:196
 hmdcraw.cc:197
 hmdcraw.cc:198
 hmdcraw.cc:199
 hmdcraw.cc:200
 hmdcraw.cc:201
 hmdcraw.cc:202
 hmdcraw.cc:203
 hmdcraw.cc:204
 hmdcraw.cc:205
 hmdcraw.cc:206
 hmdcraw.cc:207
 hmdcraw.cc:208
 hmdcraw.cc:209
 hmdcraw.cc:210
 hmdcraw.cc:211