Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CObject.cxx

Go to the documentation of this file.
00001 //
00002 // CObject class
00003 //
00004 // Tetsuo Arisawa 2000/06/16
00005 // for HistoDisplay v.1.62 class
00006 //
00007 // Version 2.0,  2000/08/28
00008 // Added Draw() and Paint().
00009 // Version 3.0   2000/09/01
00010 // Adding ReadObject().
00011 // Version 3.1   2000/09/05
00012 // free() is added. Care for deleting TPad.
00013 // Version 3.2   2000/09/08
00014 // Draw and Pain are updated.
00015 // Version 3.3   2000/09/15
00016 // Version 3.4   2001/02/27
00017 // GetTitle() is added.
00018 // 
00019 #include <iostream>
00020 
00021 #include "CObject.h"
00022 #include "TFile.h"
00023 #include "TMapFile.h"
00024 #include "TSocket.h"
00025 #include "TMessage.h"
00026 #include "TVirtualPad.h"
00027 #include "TPad.h"
00028 #include "TObject.h" // kCanDelete, ResetBit, AppendPad
00029 
00030 #ifdef CDF
00031 #include "EdmUtilities/CdfClassImp.hh"
00032 CdfClassImp(CObject)
00033 #else
00034 ClassImp(CObject)
00035 #endif
00036   
00037   using std::cout;
00038 using std::endl;
00039 
00040 CObject::CObject():TObject() {}
00041 
00042 CObject::CObject( TObject *obj, const TObject *inputsource):
00043   fTObject(obj), fInputSource(inputsource) {
00044 
00045   if ( fTObject ) fName = fTObject->GetName();
00046 }
00047 
00048 CObject::CObject( const CObject &cobj):
00049   TObject(cobj), fTObject(cobj.fTObject), fInputSource(cobj.fInputSource) {
00050 
00051   if ( fTObject ) fName = fTObject->GetName();
00052 }
00053 
00054 
00055 CObject::~CObject()
00056 {
00057   free();
00058 }
00059 
00060 const char* CObject::GetName() const
00061 { 
00062   return fName.Data();
00063 }
00064 
00065 ULong_t CObject::Hash() const
00066 {
00067   if ( fTObject ) return fTObject->Hash();
00068   else return 0;
00069 }
00070 
00071 
00072 Bool_t CObject::IsEqual(const TObject* obj2) const
00073 {
00074   //if ( !obj2 || ! obj2->InheritsFrom(CObject::Class()) ) return kFALSE;
00075   //return fTObject->IsEqual(((CObject*)obj2)->GetTObject());
00076   if ( obj2 && obj2->InheritsFrom( CObject::Class() ) ) {
00077     if ( fTObject &&
00078          fTObject->IsEqual( ((CObject*)obj2)->GetTObject() ) )
00079       return kTRUE;
00080     else return kFALSE;
00081   }
00082   else {
00083     return kFALSE;
00084   }
00085 
00086 }
00087 
00088 
00089 Int_t CObject::Compare(const TObject *obj) const
00090 {
00091   if (this == obj) return 0;
00092   if (CObject::Class() != obj->IsA()) return -1;
00093   return TString(GetName()).CompareTo(obj->GetName());
00094 }
00095 
00096 
00097 void CObject::SetTObject( TObject *obj )
00098 {
00099   if ( fTObject != obj ) {
00100     free();
00101     fTObject = obj;
00102   } //if ( fTObject != obj )
00103 }
00104 
00105 
00106 void CObject::Draw( Option_t *option )
00107 {
00108   if ( ! fTObject ) return;
00109 
00110   ResetBit( kCanDelete );
00111   AppendPad( option );
00112 
00113 }
00114 
00115 void CObject::Paint( Option_t *option )
00116 {
00117   if ( ! fTObject ) return;
00118   fTObject->Paint( option );
00119 }
00120 
00121 
00122 
00123 void CObject::ReadObject()
00124 {
00125   SetTObject( GetNewObj( GetName(), fInputSource ) );
00126 }
00127 
00128 
00129  
00130 TObject* CObject::GetNewObj(const char* objName, const TObject* inputobj)
00131 {
00132 
00133   //cout << " In GetNewObj" << endl;
00134 
00135   TObject *obj = 0;
00136 
00137   if (inputobj) {
00138 
00139     if ( inputobj->IsA() == TMapFile::Class() ) {
00140       TMapFile *mfile = (TMapFile*)inputobj;
00141       if (mfile) obj = (TObject*)mfile->Get( objName );
00142     }
00143     else if ( inputobj->IsA() == TFile::Class() ) {
00144       TFile *rfile = (TFile*)inputobj;
00145       if (rfile) obj = (TObject*)rfile->Get( objName );
00146     }
00147     else if ( inputobj->IsA() == TSocket::Class() ) {
00148       TSocket *socket = (TSocket*)inputobj;
00149 
00150       if ( socket && socket->IsValid() ) {
00151 
00152         Int_t count = 0;
00153         Int_t maxcount = 5;
00154 
00155         while ( !obj && count < maxcount ) {
00156 
00157           socket->Send( objName );
00158           TMessage *message = NULL;
00159           socket->Recv(message);
00160           if ( message && message->What() == kMESS_OBJECT) {
00161             obj = (TObject*)message->ReadObject(message->GetClass());
00162           }
00163           delete message;
00164 
00165           count++;
00166         } //while ( !obj && count < maxcount )
00167 
00168 
00169         if ( ! obj ) {
00170           cout << " Failed to get " << objName
00171                << " after " << maxcount << " tries." << endl;
00172         } //if ( ! obj )
00173         else {
00174           if ( count > 1 ) cout << " The object " << objName
00175                                 << " is sent from the socket by " << count
00176                                 << " tries." << endl;
00177         } //else of if ( ! obj )
00178 
00179       } //if ( socket && socket->IsValid() )
00180       else {
00181         cout << "no connection to socket..." << endl;
00182       } //else // if ( socket && socket->IsValid() )
00183 
00184     } // TMapFile,TFile, TSocket
00185 
00186     else {
00187 
00188       cout << " No inputobj " << endl;
00189 
00190     } // else // TMapFile,TFile, TSocket
00191 
00192   } // if(inputobj)
00193 
00194   return obj;
00195 
00196 }
00197 
00198 
00199 void CObject::free()
00200 {
00201   //cout << " In CObject free " << endl;
00202   if ( !fTObject ) return;
00203 
00204   if ( fTObject->InheritsFrom( TPad::Class() ) )
00205     ResetAllkCanDelete( (TPad*)fTObject );
00206 
00207   delete fTObject;
00208   fTObject = 0;
00209 
00210 }
00211 
00212 
00213 void CObject::ResetAllkCanDelete( TVirtualPad *pad )
00214 {
00215   if ( !pad ) return;
00216 
00217   TObjLink *link = pad->GetListOfPrimitives()->FirstLink();
00218 
00219   while( link ) {
00220     TObject *obj = link->GetObject();
00221     if ( obj ) { 
00222       if ( ! obj->TestBit( kCanDelete ) ) obj->SetBit( kCanDelete );
00223       if ( obj->InheritsFrom( TPad::Class() ) ) 
00224         ResetAllkCanDelete( (TPad*) obj );
00225     }
00226     link = link->Next();
00227   } // while( link )
00228 
00229 }
00230 
00231 CObject &CObject::operator=( const CObject &cobj )
00232 {
00233   if (this != &cobj) {
00234     //if ( fTObject ) delete fTObject;
00235     //fTObject = cobj.fTObject;
00236     SetTObject( cobj.fTObject );
00237     fInputSource = cobj.fInputSource;
00238   }
00239   return *this;
00240 }
00241 
00242 

Generated on Mon Feb 15 11:06:32 2010 for loon by  doxygen 1.3.9.1