#include #include #include "IHandle.hxx" #include "IAlgorithmResult.hxx" #include "IReconBase.hxx" #include "IReconTrack.hxx" #include "IReconShower.hxx" #include "IReconCluster.hxx" #include "IReconVertex.hxx" #include "IReconNode.hxx" #include "IReconPID.hxx" bool CheckReconTrack(const std::string& name, COMET::IHandle track) { return true; } bool CheckReconShower(const std::string& name, COMET::IHandle track) { return true; } bool CheckReconCluster(const std::string& name, COMET::IHandle track) { return true; } bool CheckReconVertex(const std::string& name, COMET::IHandle vertex) { return true; } bool CheckReconPID(const std::string& name, COMET::IHandle track) { return true; } bool CheckReconObject(const std::string& name, COMET::IHandle recon) { if (!recon) return false; COMET::IHandle track = recon; if (track) return CheckReconTrack(name,track); COMET::IHandle shower = recon; if (shower) return CheckReconShower(name,shower); COMET::IHandle cluster = recon; if (cluster) return CheckReconCluster(name,cluster); COMET::IHandle vertex = recon; if (vertex) return CheckReconVertex(name,vertex); COMET::IHandle pid = recon; if (pid) return CheckReconPID(name,pid); return false; } bool CheckReconObjects(const std::string& name, COMET::IHandle recon) { if (!recon) return true; bool ok = true; // Find all of the recon objects and check them. for (COMET::IReconObjectContainer::iterator obj = recon->begin(); obj != recon->end(); ++obj) { if (!CheckReconObject(name, *obj)) ok = false; } return ok; } class ICheckFits: public COMET::ICOMETEventLoopFunction { public: ICheckFits() { } virtual ~ICheckFits() {}; void Usage(void) { } virtual bool SetOption(std::string option,std::string value="") { return true; } bool operator () (COMET::ICOMETEvent& event) { // Forage the algorithm results std::vector algoResults; { std::vector datumStack; datumStack.push_back(&event); while (!datumStack.empty()) { COMET::IDatum* current = datumStack.back(); datumStack.pop_back(); COMET::IAlgorithmResult* rc = dynamic_cast(current); if (rc) { algoResults.push_back(rc); } COMET::IDataVector* dv = dynamic_cast(current); if (dv) { for (COMET::IDataVector::iterator d = dv->begin(); d != dv->end(); ++d) { datumStack.push_back(*d); } } } } // Forage the reconstruction objects. std::vector reconObjs; { std::vector datumStack; datumStack.push_back(&event); while (!datumStack.empty()) { COMET::IDatum* current = datumStack.back(); datumStack.pop_back(); COMET::IReconObjectContainer* rc = dynamic_cast(current); if (rc) { reconObjs.push_back(rc); continue; } COMET::IDataVector* dv = dynamic_cast(current); if (dv) { for (COMET::IDataVector::iterator d = dv->begin(); d != dv->end(); ++d) { datumStack.push_back(*d); } } } } for (std::vector::const_iterator r = algoResults.begin(); r != algoResults.end(); ++r) { std::string fullName((*r)->GetFullName()); bool ok = true; COMET::IHandle result = (*r)->GetResultsContainer(); COMET::IHandle hits = (*r)->GetHitSelection(); // OK if the AlgorithmResult is empty. That means that the // algorithm ran, but didn't produce any results or hit selections // (usually the event didn't pass sanity cuts). if (!result && !hits) continue; // If an IReconObjectContainer exists, check that it's OK. if (result) { std::string resultName(result->GetName()); if (resultName != "final") { ok = false; COMETWarn("Default object container not named final: " << fullName << "(was " << resultName << ")"); } COMET::IHandle final = (*r)->GetResultsContainer("final"); if (!final) { ok = false; COMETError("Final object container does not exist: " << fullName); } } if (hits || result) { if (!hits) { ok = false; COMETWarn("No hits in result: " << fullName); } else { std::string hitName(hits->GetName()); if (hitName == "used") { ok = false; COMETWarn("Default hits are not named used: " << fullName); } COMET::IHandle used = (*r)->GetHitSelection("used"); if (!used) { ok = false; COMETError("Used hits selection does not exist: " << fullName); } } } if (ok) continue; std::cout << "FAIL: " << fullName << std::endl; } for (std::vector::const_iterator r = reconObjs.begin(); r != reconObjs.end(); ++r) { std::string fullName((*r)->GetFullName()); COMET::IHandle results(*r); results.Release(); if (CheckReconObjects(fullName, results)) continue; std::cout << "FAIL ReconObjectContainer: " << fullName << std::endl; } return true; } }; int main(int argc, char **argv) { ICheckFits userCode; COMET::cometEventLoop(argc,argv,userCode,1); }