#include #include #include #include "IReconBase.hxx" #include "IReconNode.hxx" #include "IReconState.hxx" #include "IRealDatum.hxx" #include "IIntegerDatum.hxx" ClassImp(COMET::IReconBase); namespace { // This keeps track of the previous IReconBase unique identifier. static UInt_t gReconBaseId = 0; } COMET::IReconBase::IReconBase() : IDataVector("", "Reconstruction Object"), fQuality(0), fState(NULL), fNodes(NULL), fStatus(0), fNDOF(0) { SetUniqueID(++gReconBaseId); SetComposite(false); } COMET::IReconBase::IReconBase(const char* name, const char* title) : IDataVector(name,title), fQuality(0), fState(NULL), fNodes(NULL), fStatus(0), fNDOF(0) { SetUniqueID(++gReconBaseId); SetComposite(false); } COMET::IReconBase::IReconBase(const COMET::IReconBase& object) : IDataVector(object.GetName(), object.GetTitle()), fState(NULL), fNodes(NULL) { SetUniqueID(++gReconBaseId); fQuality = object.GetQuality(); fStatus = object.GetStatus(); fNDOF = object.GetNDOF(); if (object.GetHits()) { COMET::IHitSelection* hits = new IHitSelection(); std::copy(object.GetHits()->begin(), object.GetHits()->end(), std::back_inserter(*hits)); AddHits(hits); } if (object.GetConstituents()) { AddConstituents(object.GetConstituents()); } // Explicitly look for IRealDatum and IIntegerDatum objects and copy them. for (COMET::IReconBase::const_iterator obj = object.begin(); obj != object.end(); ++obj) { COMET::IDatum* datum = dynamic_cast(*obj); // Copy any IRealDatum objects. COMET::IRealDatum *rDatum = dynamic_cast(datum); if (rDatum) { COMET::IRealDatum* nDatum = new IRealDatum(*rDatum); AddDatum(nDatum); continue; } // Copy any IIntegerDatum objects. COMET::IIntegerDatum *iDatum = dynamic_cast(datum); if (iDatum) { COMET::IIntegerDatum* nDatum = new IIntegerDatum(*iDatum); AddDatum(nDatum); continue; } } // Don't copy the nodes and the state since they depend of the object type } COMET::IReconBase::~IReconBase() { if (fNodes) delete fNodes; if (fState) delete fState; } COMET::IReconBase::Status COMET::IReconBase::GetStatus() const { // Notice that this returns both the status bits and the deetector bits. return fStatus; } bool COMET::IReconBase::IsComposite() const { return TestBit(kCompositeObject); } /// Mark this as a composite object. void COMET::IReconBase::SetComposite(bool comp) { SetBit(kCompositeObject,comp); } void COMET::IReconBase::SetStatus(COMET::IReconBase::Status status) { fStatus |= (status & kStatusMask); } void COMET::IReconBase::ClearStatus(COMET::IReconBase::Status status) { fStatus &= ~ (status & kStatusMask); } bool COMET::IReconBase::CheckStatus(COMET::IReconBase::Status status) const { return 0 != (fStatus & (status & kStatusMask)); } COMET::IReconBase::Status COMET::IReconBase::GetDetectors() const { return (fStatus & kDetectorMask); } void COMET::IReconBase::AddDetector(COMET::IReconBase::Status status) { fStatus |= (status & kDetectorMask); } bool COMET::IReconBase::UsesDetector(COMET::IReconBase::Status status) const{ return 0 != (fStatus & (status & kDetectorMask)); } void COMET::IReconBase::RemoveDetector(COMET::IReconBase::Status status) { fStatus &= ~(status & kDetectorMask); } COMET::IHandle COMET::IReconBase::GetHits() const { return Get("hits"); } void COMET::IReconBase::AddHits(COMET::IHitSelection* hits) { IDatum* h = FindDatum("hits"); while (h) { erase(h); delete h; h = FindDatum("hits"); } hits->SetName("hits"); AddDatum(hits); } void COMET::IReconBase::AddConstituent(COMET::IHandle obj) { COMET::IHandle container = Get("constituents"); if (!container) { // Make sure that there aren't any data vector entries with a // conflicting name. IDatum* h = FindDatum("constituents"); while (h) { erase(h); delete h; h = FindDatum("constituents"); } // Create the needed object. COMET::IReconObjectContainer* c = new IReconObjectContainer("constituents", "Constituents of this object"); AddDatum(c); // And fill the handle so the creation happens transparently. container = Get("constituents"); } container->push_back(obj); } void COMET::IReconBase::AddConstituents( COMET::IHandle objs) { COMET::IReconObjectContainer::const_iterator it; for (it = objs->begin(); it!= objs->end(); ++it) { AddConstituent((*it)); } } COMET::IHandle COMET::IReconBase::GetConstituents() const { return Get("constituents"); } std::string COMET::IReconBase::ConvertStatus() const { std::string strStatus("("); bool notFirst = false; if (CheckStatus(kRan)) { strStatus+= "ran"; notFirst = true; } if (CheckStatus(kSuccess)) { if (notFirst) strStatus+=":"; strStatus+= "success"; notFirst = true; } if (CheckStatus(kChi2Fit)) { if (notFirst) strStatus+=":"; strStatus+= "chi2"; notFirst = true; } if (CheckStatus(kLikelihoodFit)) { if (notFirst) strStatus+=":"; strStatus+= "likelihood"; notFirst = true; } if (CheckStatus(kKalmanFit)) { if (notFirst) strStatus+=":"; strStatus+= "kalman"; notFirst = true; } if (CheckStatus(kGenFit)) { if (notFirst) strStatus+=":"; strStatus+= "genfit"; notFirst = true; } if (CheckStatus(kNeuralNet)) { if (notFirst) strStatus+=":"; strStatus+= "neuralnet"; notFirst = true; } if (CheckStatus(kHough)) { if (notFirst) strStatus+=":"; strStatus+= "hough"; notFirst = true; } strStatus+= ")"; return strStatus; } std::string COMET::IReconBase::ConvertDetector() const { std::string strDet("("); bool notFirst = false; /*if (UsesDetector(kP0D)) { strDet+= "P0D"; notFirst = true; } if (UsesDetector(kTPC1)) { if (notFirst) strDet+="-"; strDet+= "TPC1"; notFirst = true; } if (UsesDetector(kTPC2)) { if (notFirst) strDet+="-"; strDet+= "TPC2"; notFirst = true; } if (UsesDetector(kTPC3)) { if (notFirst) strDet+="-"; strDet+= "TPC3"; notFirst = true; } if (UsesDetector(kFGD1)) { if (notFirst) strDet+="-"; strDet+= "FGD1"; notFirst = true; } if (UsesDetector(kFGD2)) { if (notFirst) strDet+="-"; strDet+= "FGD2"; notFirst = true; } if (UsesDetector(kDSECal)) { if (notFirst) strDet+="-"; strDet+= "DSECal"; notFirst = true; } if (UsesDetector(kRightTECal)) { if (notFirst) strDet+="-"; strDet+= "RTECal"; notFirst = true; } if (UsesDetector(kTopTECal)) { if (notFirst) strDet+="-"; strDet+= "TTECal"; notFirst = true; } if (UsesDetector(kLeftTECal)) { if (notFirst) strDet+="-"; strDet+= "LTECal"; notFirst = true; } if (UsesDetector(kBottomTECal)) { if (notFirst) strDet+="-"; strDet+= "BTECal"; notFirst = true; } if (UsesDetector(kRightPECal)) { if (notFirst) strDet+="-"; strDet+= "RPECal"; notFirst = true; } if (UsesDetector(kTopPECal)) { if (notFirst) strDet+="-"; strDet+= "TPECal"; notFirst = true; } if (UsesDetector(kLeftPECal)) { if (notFirst) strDet+="-"; strDet+= "LPECal"; notFirst = true; } if (UsesDetector(kBottomPECal)) { if (notFirst) strDet+="-"; strDet+= "BPECal"; notFirst = true; } if (UsesDetector(kRightSMRD)) { if (notFirst) strDet+="-"; strDet+= "RSMRD"; notFirst = true; } if (UsesDetector(kTopSMRD)) { if (notFirst) strDet+="-"; strDet+= "TSMRD"; notFirst = true; } if (UsesDetector(kLeftSMRD)) { if (notFirst) strDet+="-"; strDet+= "LSMRD"; notFirst = true; } if (UsesDetector(kBottomSMRD)) { if (notFirst) strDet+="-"; strDet+= "BSMRD"; notFirst = true; }*/ if (UsesDetector(kCDC)) { if (notFirst) strDet+="-"; strDet+= "CDC"; notFirst = true; } if (UsesDetector(kCTH)) { if (notFirst) strDet+="-"; strDet+= "CTH"; notFirst = true; } if (UsesDetector(kStrawTrk)) { if (notFirst) strDet+="-"; strDet+= "StrawTrk"; notFirst = true; } if (UsesDetector(kECAL)) { if (notFirst) strDet+="-"; strDet+= "ECAL"; notFirst = true; } if (UsesDetector(kCosmicVeto)) { if (notFirst) strDet+="-"; strDet+= "CosmicVeto"; notFirst = true; } strDet+= ")"; return strDet; } void COMET::IReconBase::ls(Option_t *opt) const { ls_base(opt); TROOT::IncreaseDirLevel(); std::string option(opt); if (fState) { TROOT::IncreaseDirLevel(); fState->ls(opt); TROOT::DecreaseDirLevel(); } if (fNodes && option.find("dump") != std::string::npos) { TROOT::IncreaseDirLevel(); fNodes->ls(opt); TROOT::DecreaseDirLevel(); } TROOT::IncreaseDirLevel(); for (const_iterator v = begin(); v != end(); ++v) { (*v)->ls(opt); }; TROOT::DecreaseDirLevel(); TROOT::DecreaseDirLevel(); } void COMET::IReconBase::ls_base(Option_t *opt) const { COMET::IData::ls(opt); TROOT::IncreaseDirLevel(); TROOT::IndentLevel(); std::cout << "Status: " << ConvertStatus(); std::string tmp; tmp = GetAlgorithmName(); if (tmp == "") tmp = "not-set"; if (tmp != "") std::cout << " Algorithm: \"" << tmp << "\""; tmp = ConvertDetector(); if (tmp == "()") tmp = "(not-set)"; std::cout << " In: " << tmp; std::cout << std::endl; TROOT::IndentLevel(); std::ios::fmtflags save = std::cout.flags(); std::cout << "Quality: " << std::setprecision(4) << GetQuality() << " for " << GetNDOF() << " d.o.f." << std::endl; std::cout.flags(save); TROOT::DecreaseDirLevel(); } // Add all of the contents to the browser. void COMET::IReconBase::Browse(TBrowser *b) { COMET::IDataVector::Browse(b); if (!b) return; b->Add(fNodes,"Nodes"); b->Add(fState,"State"); } ClassImp(COMET::IReconObjectContainer); COMET::IReconObjectContainer::IReconObjectContainer() : COMET::IDatum("unnamed","Recon Object Container") {} COMET::IReconObjectContainer::IReconObjectContainer(const char* name, const char* title) : COMET::IDatum(name,title) {} COMET::IReconObjectContainer::~IReconObjectContainer() {} void COMET::IReconObjectContainer::push_back( COMET::IHandle data) { std::string name = data->GetName(); if (name == "unnamed") data->SetName(data->ClassName()); std::vector< COMET::IHandle >::push_back(data); } void COMET::IReconObjectContainer::ls(Option_t* opt) const { COMET::IDatum::ls(opt); TROOT::IncreaseDirLevel(); for (const_iterator t = begin(); t != end(); ++t) { t->ls(opt); } TROOT::DecreaseDirLevel(); } // Add all of the contents to the browser. void COMET::IReconObjectContainer::Browse(TBrowser *b) { if (!b) return; for (iterator i = begin(); i != end(); ++i) { TObject* obj = COMET::GetPointer(*i); if (!obj) continue; std::string name = obj->ClassName(); if (obj->GetName()) name = obj->GetName(); b->Add(obj,name.c_str()); } }