00001 // @(#)root/base:$Id: TVirtualStreamerInfo.cxx 33175 2010-04-24 21:43:40Z pcanal $ 00002 // Author: Rene Brun 05/02/2007 00003 /************************************************************************* 00004 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * 00005 * All rights reserved. * 00006 * * 00007 * For the licensing terms see $ROOTSYS/LICENSE. * 00008 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00009 *************************************************************************/ 00010 00011 ////////////////////////////////////////////////////////////////////////// 00012 // // 00013 // TVirtualStreamerInfo Abstract Interface class // 00014 // // 00015 // Abstract Interface describing Streamer information for one class. // 00016 // // 00017 ////////////////////////////////////////////////////////////////////////// 00018 00019 #include "TROOT.h" 00020 #include "TClass.h" 00021 #include "TVirtualStreamerInfo.h" 00022 #include "TPluginManager.h" 00023 #include "TStreamerElement.h" 00024 00025 00026 TVirtualStreamerInfo *TVirtualStreamerInfo::fgInfoFactory = 0; 00027 00028 Bool_t TVirtualStreamerInfo::fgCanDelete = kTRUE; 00029 Bool_t TVirtualStreamerInfo::fgOptimize = kTRUE; 00030 Bool_t TVirtualStreamerInfo::fgStreamMemberWise = kTRUE; 00031 00032 ClassImp(TVirtualStreamerInfo) 00033 00034 //______________________________________________________________________________ 00035 TVirtualStreamerInfo::TVirtualStreamerInfo() : fOptimized(kFALSE), fIsBuilt(kFALSE) 00036 { 00037 // Default constructor. 00038 00039 } 00040 00041 //______________________________________________________________________________ 00042 TVirtualStreamerInfo::TVirtualStreamerInfo(TClass *cl) 00043 : TNamed(cl->GetName(),""), fOptimized(kFALSE), fIsBuilt(kFALSE) 00044 { 00045 // Default constructor. 00046 00047 } 00048 00049 //______________________________________________________________________________ 00050 TVirtualStreamerInfo::TVirtualStreamerInfo(const TVirtualStreamerInfo& info) 00051 : TNamed(info), fOptimized(kFALSE), fIsBuilt(kFALSE) 00052 { 00053 //copy constructor 00054 } 00055 00056 //______________________________________________________________________________ 00057 TVirtualStreamerInfo& TVirtualStreamerInfo::operator=(const TVirtualStreamerInfo& info) 00058 { 00059 //assignment operator 00060 if(this!=&info) { 00061 TNamed::operator=(info); 00062 } 00063 return *this; 00064 } 00065 00066 //______________________________________________________________________________ 00067 TVirtualStreamerInfo::~TVirtualStreamerInfo() 00068 { 00069 // Destructor 00070 00071 } 00072 00073 //______________________________________________________________________________ 00074 Bool_t TVirtualStreamerInfo::CanDelete() 00075 { 00076 // static function returning true if ReadBuffer can delete object 00077 return fgCanDelete; 00078 } 00079 00080 //______________________________________________________________________________ 00081 Bool_t TVirtualStreamerInfo::CanOptimize() 00082 { 00083 // static function returning true if optimization can be on 00084 return fgOptimize; 00085 } 00086 00087 //______________________________________________________________________________ 00088 TStreamerBasicType *TVirtualStreamerInfo::GetElementCounter(const char *countName, TClass *cl) 00089 { 00090 // Get pointer to a TStreamerBasicType in TClass *cl 00091 //static function 00092 00093 TObjArray *sinfos = cl->GetStreamerInfos(); 00094 TVirtualStreamerInfo *info = (TVirtualStreamerInfo *)sinfos->At(cl->GetClassVersion()); 00095 00096 if (!info || !info->IsBuilt()) { 00097 // Even if the streamerInfo exist, it could still need to be 'build' 00098 // It is important to figure this out, because 00099 // a) if it is not build, we need to build 00100 // b) if is build, we should not build it (or we could end up in an 00101 // infinite loop, if the element and its counter are in the same 00102 // class! 00103 00104 info = cl->GetStreamerInfo(); 00105 } 00106 if (!info) return 0; 00107 TStreamerElement *element = (TStreamerElement *)info->GetElements()->FindObject(countName); 00108 if (!element) return 0; 00109 if (element->IsA() == TStreamerBasicType::Class()) return (TStreamerBasicType*)element; 00110 return 0; 00111 } 00112 00113 //______________________________________________________________________________ 00114 Bool_t TVirtualStreamerInfo::GetStreamMemberWise() 00115 { 00116 // Return whether the TStreamerInfos will save the collections in 00117 // "member-wise" order whenever possible. The default is to store member-wise. 00118 // kTRUE indicates member-wise storing 00119 // kFALSE inddicates object-wise storing 00120 // 00121 // A collection can be saved member wise when it contain is guaranteed to be 00122 // homogeneous. For example std::vector<THit> can be stored member wise, 00123 // while std::vector<THit*> can not (possible use of polymorphism). 00124 00125 return fgStreamMemberWise; 00126 } 00127 00128 //______________________________________________________________________________ 00129 void TVirtualStreamerInfo::Optimize(Bool_t opt) 00130 { 00131 // This is a static function. 00132 // Set optimization option. 00133 // When this option is activated (default), consecutive data members 00134 // of the same type are merged into an array (faster). 00135 // Optimization must be off in TTree split mode. 00136 00137 fgOptimize = opt; 00138 } 00139 00140 //______________________________________________________________________________ 00141 TVirtualStreamerInfo *TVirtualStreamerInfo::Factory() 00142 { 00143 // Static function returning a pointer to a new TVirtualStreamerInfo object. 00144 // If the Info factory does not exist, it is created via the plugin manager. 00145 // In reality the factory is an empty TStreamerInfo object. 00146 00147 if (!fgInfoFactory) { 00148 TPluginHandler *h; 00149 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualStreamerInfo","TStreamerInfo"))) { 00150 if (h->LoadPlugin() == -1) 00151 return 0; 00152 fgInfoFactory = (TVirtualStreamerInfo*) h->ExecPlugin(0); 00153 } else { 00154 gROOT->GetPluginManager()->Error("FindHandler", 00155 "Cannot find plugin handler for TVirtualStreamerInfo!" 00156 " Does $ROOTSYS/etc/plugins/TVirtualStreamerInfo exist?"); 00157 } 00158 } 00159 00160 if (fgInfoFactory) return fgInfoFactory; 00161 return 0; 00162 } 00163 00164 //______________________________________________________________________________ 00165 void TVirtualStreamerInfo::SetCanDelete(Bool_t opt) 00166 { 00167 // This is a static function. 00168 // Set object delete option. 00169 // When this option is activated (default), ReadBuffer automatically 00170 // delete objects when a data member is a pointer to an object. 00171 // If your constructor is not presetting pointers to 0, you must 00172 // call this static function TStreamerInfo::SetCanDelete(kFALSE); 00173 00174 fgCanDelete = opt; 00175 } 00176 00177 //______________________________________________________________________________ 00178 void TVirtualStreamerInfo::SetFactory(TVirtualStreamerInfo *factory) 00179 { 00180 //static function: Set the StreamerInfo factory 00181 fgInfoFactory = factory; 00182 } 00183 00184 //______________________________________________________________________________ 00185 Bool_t TVirtualStreamerInfo::SetStreamMemberWise(Bool_t enable) 00186 { 00187 // Set whether the TStreamerInfos will save the collections in 00188 // "member-wise" order whenever possible. The default is to store member-wise. 00189 // kTRUE indicates member-wise storing 00190 // kFALSE inddicates object-wise storing 00191 // This function returns the previous value of fgStreamMemberWise. 00192 00193 // A collection can be saved member wise when it contain is guaranteed to be 00194 // homogeneous. For example std::vector<THit> can be stored member wise, 00195 // while std::vector<THit*> can not (possible use of polymorphism). 00196 00197 Bool_t prev = fgStreamMemberWise; 00198 fgStreamMemberWise = enable; 00199 return prev; 00200 } 00201 00202 //______________________________________________________________________________ 00203 void TVirtualStreamerInfo::Streamer(TBuffer &R__b) 00204 { 00205 // Stream an object of class TVirtualStreamerInfo. 00206 00207 TNamed::Streamer(R__b); 00208 }