00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "TLeafS.h"
00018 #include "TBranch.h"
00019 #include "TClonesArray.h"
00020 #include "Riostream.h"
00021
00022 ClassImp(TLeafS)
00023
00024
00025 TLeafS::TLeafS(): TLeaf()
00026 {
00027
00028
00029
00030 fValue = 0;
00031 fPointer = 0;
00032 fMinimum = 0;
00033 fMaximum = 0;
00034 fLenType = 2;
00035 }
00036
00037
00038 TLeafS::TLeafS(TBranch *parent, const char *name, const char *type)
00039 :TLeaf(parent,name,type)
00040 {
00041
00042
00043
00044
00045 fLenType = 2;
00046 fMinimum = 0;
00047 fMaximum = 0;
00048 fValue = 0;
00049 fPointer = 0;
00050 }
00051
00052
00053 TLeafS::~TLeafS()
00054 {
00055
00056
00057
00058 if (ResetAddress(0,kTRUE)) delete [] fValue;
00059 }
00060
00061
00062
00063 void TLeafS::Export(TClonesArray *list, Int_t n)
00064 {
00065
00066
00067
00068 Int_t j = 0;
00069 for (Int_t i=0;i<n;i++) {
00070 memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], 2*fLen);
00071 j += fLen;
00072 }
00073 }
00074
00075
00076
00077 void TLeafS::FillBasket(TBuffer &b)
00078 {
00079
00080
00081
00082 Int_t i;
00083 Int_t len = GetLen();
00084 if (fPointer) fValue = *fPointer;
00085 if (IsRange()) {
00086 if (fValue[0] > fMaximum) fMaximum = fValue[0];
00087 }
00088 if (IsUnsigned()) {
00089 for (i=0;i<len;i++) b << (UShort_t)fValue[i];
00090 } else {
00091 b.WriteFastArray(fValue,len);
00092 }
00093 }
00094
00095
00096
00097 const char *TLeafS::GetTypeName() const
00098 {
00099
00100
00101
00102 if (fIsUnsigned) return "UShort_t";
00103 return "Short_t";
00104 }
00105
00106
00107
00108 Double_t TLeafS::GetValue(Int_t i) const
00109 {
00110
00111
00112
00113
00114 if (fIsUnsigned) return (UShort_t)fValue[i];
00115 return fValue[i];
00116 }
00117
00118
00119 void TLeafS::Import(TClonesArray *list, Int_t n)
00120 {
00121
00122
00123
00124 const Short_t kShortUndefined = -9999;
00125 Int_t j = 0;
00126 char *clone;
00127 for (Int_t i=0;i<n;i++) {
00128 clone = (char*)list->UncheckedAt(i);
00129 if (clone) memcpy(&fValue[j],clone + fOffset, 2*fLen);
00130 else memcpy(&fValue[j],&kShortUndefined, 2*fLen);
00131 j += fLen;
00132 }
00133 }
00134
00135
00136 void TLeafS::PrintValue(Int_t l) const
00137 {
00138
00139
00140 if (fIsUnsigned) {
00141 UShort_t *uvalue = (UShort_t*)GetValuePointer();
00142 printf("%u",uvalue[l]);
00143 } else {
00144 Short_t *value = (Short_t*)GetValuePointer();
00145 printf("%d",value[l]);
00146 }
00147 }
00148
00149
00150 void TLeafS::ReadBasket(TBuffer &b)
00151 {
00152
00153
00154
00155 if (!fLeafCount && fNdata == 1) {
00156 b >> fValue[0];
00157 }else {
00158 if (fLeafCount) {
00159 Long64_t entry = fBranch->GetReadEntry();
00160 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
00161 fLeafCount->GetBranch()->GetEntry(entry);
00162 }
00163 Int_t len = Int_t(fLeafCount->GetValue());
00164 if (len > fLeafCount->GetMaximum()) {
00165 printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
00166 len = fLeafCount->GetMaximum();
00167 }
00168 fNdata = len*fLen;
00169 b.ReadFastArray(fValue,len*fLen);
00170 } else {
00171 b.ReadFastArray(fValue,fLen);
00172 }
00173 }
00174 }
00175
00176
00177 void TLeafS::ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
00178 {
00179
00180
00181
00182 if (n*fLen == 1) {
00183 b >> fValue[0];
00184 } else {
00185 b.ReadFastArray(fValue,n*fLen);
00186 }
00187
00188 Int_t j = 0;
00189 for (Int_t i=0;i<n;i++) {
00190 memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], 2*fLen);
00191 j += fLen;
00192 }
00193 }
00194
00195
00196 void TLeafS::ReadValue(istream &s)
00197 {
00198
00199 if (fIsUnsigned) {
00200 UShort_t *uvalue = (UShort_t*)GetValuePointer();
00201 for (Int_t i=0;i<fLen;i++) s >> uvalue[i];
00202 } else {
00203 Short_t *value = (Short_t*)GetValuePointer();
00204 for (Int_t i=0;i<fLen;i++) s >> value[i];
00205 }
00206 }
00207
00208
00209 void TLeafS::SetAddress(void *add)
00210 {
00211
00212
00213
00214 if (ResetAddress(add) && (add!=fValue)) {
00215 delete [] fValue;
00216 }
00217 if (add) {
00218 if (TestBit(kIndirectAddress)) {
00219 fPointer = (Short_t**) add;
00220 Int_t ncountmax = fLen;
00221 if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
00222 if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
00223 ncountmax > fNdata || *fPointer == 0) {
00224 if (*fPointer) delete [] *fPointer;
00225 if (ncountmax > fNdata) fNdata = ncountmax;
00226 *fPointer = new Short_t[fNdata];
00227 }
00228 fValue = *fPointer;
00229 } else {
00230 fValue = (Short_t*)add;
00231 }
00232 } else {
00233 fValue = new Short_t[fNdata];
00234 fValue[0] = 0;
00235 }
00236 }