#include "ICOMETLog.hxx" #include "IMidasBank.hxx" #include "IMidasObj.hxx" ClassImp(COMET::IMidasObj); //_____________________________________________________________________________ COMET::IMidasObj::IMidasObj(UShort_t rawDataVer, /* = 0 */ UShort_t invalid_code, /* = 0 */ const IMidasBank* parent /* = 0 */) : fParent(parent), fRawDataVer(rawDataVer), fInvalidCode(invalid_code) { // Default constructor COMETTrace("IMidasObj: Default ctor at:" << (void*) this); this->Connect(); } //_____________________________________________________________________________ COMET::IMidasObj::IMidasObj(const COMET::IMidasObj& from) : fParent(0), fRawDataVer(0), fInvalidCode(0) { // Copy constructor COMETTrace("IMidasObj: Copy ctor at:" << (void*) this); this->Clone(from); } //_____________________________________________________________________________ COMET::IMidasObj::~IMidasObj() { this->Disconnect(); COMETTrace("COMET::IMidasObj: dtor at:" << (void*) this); } //_____________________________________________________________________________ void COMET::IMidasObj::BankDeleted() { if ( fParent ) { COMETWarn("COMET::IMidasObj: Parent object has been deleted which makes this object invalid"); fParent = 0; fInvalidCode = DeletedParent; } } //_____________________________________________________________________________ void COMET::IMidasObj::Clone(const COMET::IMidasObj& from) { this->Disconnect(); this->fParent = from.fParent; this->fRawDataVer = from.fRawDataVer; this->fInvalidCode = from.fInvalidCode; this->Connect(); } //_____________________________________________________________________________ void COMET::IMidasObj::Connect() { if ( fParent ) { if ( fParent->IsNotZombie() ) fParent->ConnectChildObj(this); else { COMETError("IMidasObj: Attempting to connect to a deleted IMidasBank. Please investigate!"); fParent = 0; fInvalidCode = DeletedParent; } } } //_____________________________________________________________________________ void COMET::IMidasObj::Disconnect() { if ( fParent ) { if ( fParent->IsNotZombie() ) fParent->DisconnectChildObj(this); else COMETError("IMidasObj: Attempting to disconnect from a deleted IMidasBank. Please investigate!"); } fParent = 0; } //_____________________________________________________________________________ const char* COMET::IMidasObj::GetInvalidReason() const { if ( this->GetInvalidCode() == NotInvalid ) return "Not invalid"; if ( this->GetInvalidCode() == DeletedParent ) return "Parent IMidasBank deleted"; if ( this->GetInvalidCode() == IteratorOutOfRange ) return "Object produced by out of range iterator"; if ( this->GetInvalidCode() == UnknownInvalid ) return "Object declared invalid but code given was itself invalid"; return "Invalid for some unknown reason (should not happen)"; } //_____________________________________________________________________________ Bool_t COMET::IMidasObj::NotValid(const char* calledMethod /*= 0 */) const { if ( this->IsValid() ) return false; std::string action("access"); if ( calledMethod ) { action = "call method "; action += calledMethod; action += " of"; } COMETWarn("COMET::IMidasObj::Attempting to " << action << " an invalid object (" << this->GetInvalidReason() << ")"); return true; } //_____________________________________________________________________________ void COMET::IMidasObj::SetInvalidCode(UShort_t invalid_code) { if ( ! this->IsValid() ) { COMETWarn("COMET::IMidasObj::Attempting to set invalid code to " << invalid_code << " on an already invalid object (" << this->GetInvalidReason() << ")"); return; } if ( ! invalid_code != DeletedParent && ! invalid_code != IteratorOutOfRange ) { COMETWarn("COMET::IMidasObj::Attempting to set invalid code to " << invalid_code << " which is itself an invalid code" ); invalid_code = UnknownInvalid; } fInvalidCode = invalid_code; }