/*! \file \version $Id: TAGdataDsc.cxx,v 1.12 2003/06/19 17:44:21 mueller Exp $ \brief Implementation of TAGdataDsc. */ #include "TClass.h" #include "TList.h" #include "TATOFroot.h" #include "TATOFaction.h" #include "TATOFdataDsc.h" /*! \class TATOFdataDsc TATOFdataDsc.hxx "TATOFdataDsc.hxx" \brief Persistent descriptor for data object . ** */ ClassImp(TATOFdataDsc); //------------------------------------------+----------------------------------- //! Default constructor. TATOFdataDsc::TATOFdataDsc(const char* name, TATOFdata* p_data) : TATOFnamed(name, 0), fpObject(0), fpObjectClass(0), fpProducer(0), fpConsumerList(0) { if (!gTATOFroot) Fatal("TATOFdataDsc()", "TATOFroot not instantiated"); SetBit(kMustCleanup); if (name==0 || name[0]==0) SetName(gTATOFroot->DefaultDataDscName()); if (gTATOFroot->FindDataDsc(GetName())) { Warning("TATOFdataDsc()", "Data descriptor with name '%s' already exists", GetName()); } gTATOFroot->ListOfDataDsc()->Add(this); if (p_data) { fpObject = p_data; fpObjectClass = p_data->IsA(); SetTitle(p_data->IsA()->GetName()); } } //------------------------------------------+----------------------------------- //! Destructor. TATOFdataDsc::~TATOFdataDsc() { delete fpObject; } //------------------------------------------+----------------------------------- //! Set data object. void TATOFdataDsc::SetObject(TATOFdata* p_data) { delete fpObject; fpObject = p_data; if (p_data == 0) ResetBit(kValid); return; } //------------------------------------------+----------------------------------- //! Set producer action. void TATOFdataDsc::SetProducer(TATOFaction* p_action) { fpProducer = p_action; return; } //------------------------------------------+----------------------------------- //! Set consumer action. void TATOFdataDsc::SetConsumer(TATOFaction* p_action) { if (!fpConsumerList) fpConsumerList = new TList(); fpConsumerList->Add(p_action); return; } //------------------------------------------+----------------------------------- //! Generate data object and return a pointer to it. TATOFdata* TATOFdataDsc::GenerateObject(Int_t* p_se,Int_t i_nw) { if (!Valid()) Generate(p_se,i_nw); return Object(); } //------------------------------------------+----------------------------------- //! Invalidate data object. void TATOFdataDsc::Clear(Option_t*) { if (fpObject) fpObject->Clear(); ResetBit(kValid|kEof|kFail); return; } //------------------------------------------+----------------------------------- //! Generate data object. Bool_t TATOFdataDsc::Generate(Int_t* p_se,Int_t i_nw) { if (Valid()) return kTRUE; if (fpProducer) { fpProducer->Process(p_se,i_nw); } else { Error("Generate()", "no action registered for '%s'", GetName()); SetBit(kFail); } return TestBit(kValid); } /*------------------------------------------+---------------------------------*/ //! ostream insertion. void TATOFdataDsc::ToStream(ostream& os, Option_t* option) const { os << "TATOFdataDsc: " << "'" << GetName() << "'" << endl; if (fpObjectClass) { os << " object class: " << fpObjectClass->GetName() << endl; } if (fpProducer) { os << " producer: " << fpProducer->IsA()->GetName() << " '" << fpProducer->GetName() << "'" << endl; } if (fpConsumerList) { const char* pref = " consumer: "; for (TObjLink* lnk = fpConsumerList->FirstLink(); lnk; lnk=lnk->Next()) { TObject* p = lnk->GetObject(); os << pref << p->IsA()->GetName() << " '" << p->GetName() << "'" << endl; pref = " "; } } return; } //------------------------------------------+----------------------------------- //! Cleanup dangling object references to TObject \a p_obj . void TATOFdataDsc::RecursiveRemove(TObject* p_obj) { if (fpProducer == p_obj) fpProducer = 0; if (fpConsumerList) while (fpConsumerList->Remove(p_obj)); return; }