00001 #ifndef CANDBASE_TPL
00002 #define CANDBASE_TPL
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "MessageService/MsgService.h"
00014
00015
00016 template<class mType>
00017 Bool_t CandBase::TestArrayEquality(const char* mbrName, int arrLen,
00018 const mType& thisMbr,
00019 const mType& rhsMbr) const
00020 {
00021
00022
00023 Bool_t isEquivalent = true;
00024 for (int i=0; i < arrLen; i++) {
00025 if (!(thisMbr[i] == rhsMbr[i])) {
00026 isEquivalent = false;
00027 }
00028 }
00029 if (isEquivalent) {
00030 MSG("VCand", Msg::kDebug) << mbrName << " \t[ok]\n";
00031 }
00032 else {
00033 MSG("VCand", Msg::kDebug) << mbrName << " \t[not ok]\n";
00034 return false;
00035 }
00036 return true;
00037 }
00038
00039
00040 template<class chType>
00041 Bool_t CandBase::TestCandHandleDup(const char* chName,
00042 const chType* thisCH,
00043 const chType* rCndCH ) const
00044 {
00045
00046
00047 if (!thisCH && !rCndCH) {
00048 MSG("VCand", Msg::kDebug) << chName << " \t[ok]\n";
00049 return true;
00050 }
00051 else {
00052 if (thisCH == rCndCH) {
00053 MSG("VCand", Msg::kDebug) << chName << " \t[is a shallow copy]\n";
00054 return false;
00055 }
00056 else {
00057 if ( *thisCH == *rCndCH) {
00058 MSG("VCand", Msg::kDebug) << chName << " \t[ok]\n";
00059 }
00060 else {
00061 MSG("VCand", Msg::kDebug) << chName << " \t[not ok]\n";
00062 return false;
00063 }
00064 }
00065 }
00066 return true;
00067 }
00068
00069
00070 template<class _char>
00071 void CandBase::TestDisplayCandBanner(_char* mName) const
00072 {
00073
00074
00075 MSG("VCand", Msg::kDebug) << "\n____________"
00076 << mName << "::IsEquivalent "
00077 << "______________________________\n";
00078 }
00079
00080
00081 template<class mType>
00082 Bool_t CandBase::TestEquality(const char* mbrName,
00083 const mType& thisMbr,
00084 const mType& rhsMbr) const
00085 {
00086
00087
00088 if (thisMbr == rhsMbr){
00089 MSG("VCand", Msg::kDebug) << mbrName << " \t[ok]\n";
00090 }
00091 else {
00092 MSG("VCand", Msg::kDebug) << mbrName << " \t[not ok]\n";
00093 return false;
00094 }
00095 return true;
00096 }
00097
00098
00099 template<class mType>
00100 Bool_t CandBase::TestEquivalence(const char* mName,
00101 const mType& thisMbr,
00102 const mType& rhsMbr) const
00103 {
00104
00105
00106
00107 if (&thisMbr == &rhsMbr) {
00108 MSG("VCand", Msg::kDebug) << mName << " \t[is a shallow copy]\n";
00109 return false;
00110 }
00111 else {
00112 if (thisMbr.IsEquivalent(&rhsMbr)) {
00113 MSG("VCand", Msg::kDebug) << mName << " \t[ok]\n";
00114 }
00115 else {
00116 MSG("VCand", Msg::kDebug) << mName << " \t[not ok]\n";
00117 return false;
00118 }
00119 }
00120 return true;
00121 }
00122
00123
00124 template<class elemType>
00125 Bool_t CandBase::TestGenericElemPtrTObjArrayPtrEquality(
00126 const char* arrName,
00127 const TObjArray* thisTOA,
00128 const TObjArray* rCndTOA) const
00129 {
00130
00131
00132
00133 return TestGenericElemPtrTObjArrayPtrEquivalence<elemType>(arrName,
00134 thisTOA, rCndTOA, false);
00135 }
00136
00137
00138 template<class elemType>
00139 Bool_t CandBase::TestGenericElemPtrTObjArrayPtrEquivalence(
00140 const char* arrName,
00141 const TObjArray* thisTOA,
00142 const TObjArray* rCndTOA,
00143 Bool_t testEquivalence) const
00144 {
00145
00146
00147
00148
00149
00150 if (thisTOA == rCndTOA) {
00151 MSG("VCand", Msg::kDebug) << arrName << " \t[is a shallow copy]\n";
00152 return false;
00153 }
00154 else {
00155 Bool_t isEquivalent = true;
00156 Bool_t isShallow = false;
00157 Bool_t dcastFailed = false;
00158 if (thisTOA->GetEntries() != thisTOA->GetEntries()) {
00159 isEquivalent = false;
00160 }
00161 else {
00162 TIterator* thisIter = thisTOA->MakeIterator();
00163 TIterator* rCndIter = rCndTOA->MakeIterator();
00164 TObject *thisObj, *rCndObj;
00165 while ((thisObj = thisIter->Next()) &&
00166 (rCndObj = rCndIter->Next())) {
00167
00168 if (thisObj == rCndObj) {
00169 isShallow = true;
00170 }
00171 else {
00172 elemType *thisCB = dynamic_cast<elemType*>(thisObj);
00173 elemType *rCndCB = dynamic_cast<elemType*>(rCndObj);
00174 if (thisCB == NULL || rCndCB == NULL) {
00175 isEquivalent = false;
00176 dcastFailed = true;
00177 break;
00178 }
00179 if (testEquivalence) {
00180 if (!thisCB || !rCndCB || !(thisCB->IsEquivalent(rCndCB))) {
00181 isEquivalent = false;
00182 }
00183 }
00184 else {
00185 if ( !(thisObj->IsEqual(rCndObj)) ) {
00186 isEquivalent = false;
00187 }
00188 }
00189 }
00190 }
00191 }
00192 if (isEquivalent) {
00193 if (isShallow) {
00194 MSG("VCand", Msg::kDebug)
00195 << arrName << " \t[shallow copy of TObjArray elements]\n";
00196 }
00197 else {
00198 MSG("VCand", Msg::kDebug) << arrName << " \t[ok]\n";
00199 }
00200 }
00201 else {
00202 if (dcastFailed) {
00203 MSG("VCand", Msg::kDebug)
00204 << arrName << " \t[dynamic cast of elements failed--not ok]\n";
00205 }
00206 else {
00207 MSG("VCand", Msg::kDebug) << arrName << " \t[not ok]\n";
00208 }
00209 return false;
00210 }
00211 }
00212 return true;
00213 }
00214
00215
00216 template<class _char>
00217 void CandBase::TestNothing(_char* mName) const
00218 {
00219
00220
00221 MSG("VCand", Msg::kDebug) << mName << " class: Nothing to test.\n";
00222 }
00223
00224
00225 template<class mType>
00226 Bool_t CandBase::TestPtrEquivalence(const char* mName,
00227 const mType* thisMbr,
00228 const mType* rhsMbr) const
00229 {
00230
00231
00232
00233 if (thisMbr == rhsMbr) {
00234 MSG("VCand", Msg::kDebug) << mName << " \t[is a shallow copy]\n";
00235 return false;
00236 }
00237 else {
00238 if (thisMbr->IsEquivalent(rhsMbr)) {
00239 MSG("VCand", Msg::kDebug) << mName << " \t[ok]\n";
00240 }
00241 else {
00242 MSG("VCand", Msg::kDebug) << mName << " \t[not ok]\n";
00243 return false;
00244 }
00245 }
00246 return true;
00247 }
00248
00249
00250 template<class toaType>
00251 Bool_t CandBase::TestTObjArrayCandHandleDup(const char* arrName,
00252 const toaType& thisTOA,
00253 const toaType& rCndTOA) const
00254 {
00255
00256
00257
00258 Bool_t isEquivalent = true;
00259 Bool_t hasShallowCopies = false;
00260 if (thisTOA.GetEntries() != rCndTOA.GetEntries() ){
00261 isEquivalent = false;
00262 }
00263 else {
00264 TIterator* thisIter = thisTOA.MakeIterator();
00265 TIterator* rCndIter = rCndTOA.MakeIterator();
00266
00267
00268 TObject *thisTObj, *rCndTObj;
00269 while ( ((thisTObj=thisIter->Next()) != NULL) &&
00270 ((rCndTObj=rCndIter->Next()) != NULL) ) {
00271 if (thisTObj == rCndTObj) {
00272 hasShallowCopies = true;
00273 isEquivalent = false;
00274 }
00275 else {
00276 const CandHandle* thisCH =
00277 dynamic_cast<const CandHandle*>(thisTObj);
00278 const CandHandle* rCndCH =
00279 dynamic_cast<const CandHandle*>(rCndTObj);
00280 if(!(*thisCH == *rCndCH)) {
00281 isEquivalent = false;
00282 }
00283 }
00284 }
00285 }
00286
00287 if (hasShallowCopies) {
00288 MSG("VCand", Msg::kDebug) << arrName
00289 << " \t[has shallow copies]\n";
00290 }
00291 else if (isEquivalent) {
00292 MSG("VCand", Msg::kDebug) << arrName << " \t[ok]\n";
00293 }
00294 else {
00295 MSG("VCand", Msg::kDebug) << arrName << " \t[not ok]\n";
00296 return false;
00297 }
00298 return true;
00299 }
00300
00301
00302 template<class toaType>
00303 Bool_t CandBase::TestTObjArrayEquality(const char* arrName,
00304 const toaType& thisTOA,
00305 const toaType& rCndTOA) const
00306 {
00307
00308
00309
00310
00311 return TestTObjArrayPtrEquality(arrName, &thisTOA, &rCndTOA);
00312 }
00313
00314
00315 template<class toaType>
00316 Bool_t CandBase::TestTObjArrayPtrEquality(const char* arrName,
00317 const toaType* thisTOA,
00318 const toaType* rCndTOA ) const
00319 {
00320
00321
00322
00323 return TestTObjArrayPtrEquivalence(arrName, thisTOA, rCndTOA, false);
00324 }
00325
00326
00327 template<class toaType>
00328 Bool_t CandBase::TestTObjArrayPtrEquivalence(const char* arrName,
00329 const toaType* thisTOA,
00330 const toaType* rCndTOA,
00331 Bool_t testEquivalence) const
00332 {
00333
00334
00335
00336
00337 if (thisTOA == rCndTOA) {
00338 MSG("VCand", Msg::kDebug) << arrName << " \t[is a shallow copy]\n";
00339 return false;
00340 }
00341 else {
00342 Bool_t isEquivalent = true;
00343 if (thisTOA->GetEntries() != thisTOA->GetEntries()) {
00344 isEquivalent = false;
00345 }
00346 else {
00347 TIterator* thisIter = thisTOA->MakeIterator();
00348 TIterator* rCndIter = rCndTOA->MakeIterator();
00349 TObject *thisObj, *rCndObj;
00350 while ( (thisObj = thisIter->Next()) &&
00351 (rCndObj = rCndIter->Next()) ) {
00352
00353 if (testEquivalence) {
00354 CandBase *thisCB = dynamic_cast<CandBase*>(thisObj);
00355 CandBase *rCndCB = dynamic_cast<CandBase*>(rCndObj);
00356 if (!thisCB || !rCndCB || !(thisCB->IsEquivalent(rCndCB)) ) {
00357 isEquivalent = false;
00358 }
00359 }
00360 else {
00361 if ( !(thisObj == rCndObj) ) {
00362 isEquivalent = false;
00363 }
00364 }
00365 }
00366 }
00367
00368 if (isEquivalent) {
00369 MSG("VCand", Msg::kDebug) << arrName << " \t[ok]\n";
00370 }
00371 else {
00372 MSG("VCand", Msg::kDebug) << arrName << " \t[not ok]\n";
00373 return false;
00374 }
00375 }
00376 return true;
00377 }
00378
00379 #endif // CANDBASE_TPL