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