ROOT logo
// @(#)root/base:$Id$
// Author: Rene Brun   05/02/2007
/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TVirtualStreamerInfo   Abstract Interface class                      //
//                                                                      //
// Abstract Interface describing Streamer information for one class.    //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TROOT.h"
#include "TSystem.h"
#include "TClass.h"
#include "TVirtualMutex.h"
#include "TInterpreter.h"
#include "TVirtualStreamerInfo.h"
#include "TPluginManager.h"
#include "TStreamerElement.h"
#include "TError.h"


TVirtualStreamerInfo *TVirtualStreamerInfo::fgInfoFactory    = 0;

Bool_t  TVirtualStreamerInfo::fgCanDelete        = kTRUE;
Bool_t  TVirtualStreamerInfo::fgOptimize         = kTRUE;
Bool_t  TVirtualStreamerInfo::fgStreamMemberWise = kTRUE;

ClassImp(TVirtualStreamerInfo)

//______________________________________________________________________________
TVirtualStreamerInfo::TVirtualStreamerInfo() : fOptimized(kFALSE), fIsBuilt(kFALSE), fIsCompiled(kFALSE)
{
   // Default constructor.

}

//______________________________________________________________________________
TVirtualStreamerInfo::TVirtualStreamerInfo(TClass *cl)
   : TNamed(cl->GetName(),""), fOptimized(kFALSE), fIsBuilt(kFALSE), fIsCompiled(kFALSE)
{
   // Default constructor.

}

//______________________________________________________________________________
TVirtualStreamerInfo::TVirtualStreamerInfo(const TVirtualStreamerInfo& info)
  : TNamed(info), fOptimized(kFALSE), fIsBuilt(kFALSE), fIsCompiled(kFALSE)
{
   //copy constructor
}

//______________________________________________________________________________
TVirtualStreamerInfo& TVirtualStreamerInfo::operator=(const TVirtualStreamerInfo& info)
{
   //assignment operator
   if(this!=&info) {
      TNamed::operator=(info);
   } 
   return *this;
}

//______________________________________________________________________________
TVirtualStreamerInfo::~TVirtualStreamerInfo()
{
   // Destructor

}

//______________________________________________________________________________
Bool_t TVirtualStreamerInfo::CanDelete()
{
   // static function returning true if ReadBuffer can delete object
   return fgCanDelete;
}

//______________________________________________________________________________
Bool_t TVirtualStreamerInfo::CanOptimize()
{
   // static function returning true if optimization can be on
   return fgOptimize;
}

//______________________________________________________________________________
TStreamerBasicType *TVirtualStreamerInfo::GetElementCounter(const char *countName, TClass *cl)
{
   // Get pointer to a TStreamerBasicType in TClass *cl
   //static function

   TVirtualStreamerInfo *info;
   {
      R__LOCKGUARD(gCINTMutex);
      TObjArray *sinfos = cl->GetStreamerInfos();
      info = (TVirtualStreamerInfo *)sinfos->At(cl->GetClassVersion());
   }

   if (!info || !info->IsCompiled()) {
      // Even if the streamerInfo exist, it could still need to be 'build'
      // It is important to figure this out, because
      //   a) if it is not build, we need to build
      //   b) if is build, we should not build it (or we could end up in an
      //      infinite loop, if the element and its counter are in the same
      //      class!
      // Checking IsCompiled is sufficint here even-though it is set only at
      // the end of the call to Build as this function has an
      // internal recursion prevention (setting and testing kBuildRunning).
      info = cl->GetStreamerInfo();
   }
   if (!info) return 0;
   TStreamerElement *element = (TStreamerElement *)info->GetElements()->FindObject(countName);
   if (!element) return 0;
   if (element->IsA() == TStreamerBasicType::Class()) return (TStreamerBasicType*)element;
   return 0;
}

//______________________________________________________________________________
Bool_t TVirtualStreamerInfo::GetStreamMemberWise()
{
   // Return whether the TStreamerInfos will save the collections in
   // "member-wise" order whenever possible.    The default is to store member-wise.
   // kTRUE indicates member-wise storing
   // kFALSE inddicates object-wise storing
   //
   // A collection can be saved member wise when it contain is guaranteed to be
   // homogeneous.  For example std::vector<THit> can be stored member wise,
   // while std::vector<THit*> can not (possible use of polymorphism).

   return fgStreamMemberWise;
}

//______________________________________________________________________________
void TVirtualStreamerInfo::Optimize(Bool_t opt)
{
   //  This is a static function.
   //  Set optimization option.
   //  When this option is activated (default), consecutive data members
   //  of the same type are merged into an array (faster).
   //  Optimization must be off in TTree split mode.

   fgOptimize = opt;
}

//______________________________________________________________________________
TVirtualStreamerInfo *TVirtualStreamerInfo::Factory()
{
   // Static function returning a pointer to a new TVirtualStreamerInfo object.
   // If the Info factory does not exist, it is created via the plugin manager.
   // In reality the factory is an empty TStreamerInfo object.

   if (!fgInfoFactory) {
      TPluginHandler *h;
      if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualStreamerInfo","TStreamerInfo"))) {
         if (h->LoadPlugin() == -1) {
            ::Fatal("TVirtualStreamerInfo::Factory",
                    "The plugin handler for TVirtualStreamerInfo was found but failed to load!");
         } 
         fgInfoFactory = (TVirtualStreamerInfo*) h->ExecPlugin(0);
         if (fgInfoFactory == 0) {
            ::Fatal("TVirtualStreamerInfo::Factory",
                    "The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!");
         }
      } else {
         TString filename("$ROOTSYS/etc/plugins/TVirtualStreamerInfo");
         gSystem->ExpandPathName(filename);
         if (gSystem->AccessPathName(filename)) {            
            ::Fatal("TVirtualStreamerInfo::Factory",
                    "Cannot find the plugin handler for TVirtualStreamerInfo! "
                    "$ROOTSYS/etc/plugins/TVirtualStreamerInfo does not exist "
                    "or is inaccessible.");
         } else {
            ::Fatal("TVirtualStreamerInfo::Factory",
                    "Cannot find the plugin handler for TVirtualStreamerInfo! "
                    "However $ROOTSYS/etc/plugins/TVirtualStreamerInfo is accessible, "
                    "Check the content of this directory!");
         }
      }
   }

   return fgInfoFactory;
}

//______________________________________________________________________________
void TVirtualStreamerInfo::SetCanDelete(Bool_t opt)
{
   //  This is a static function.
   //  Set object delete option.
   //  When this option is activated (default), ReadBuffer automatically
   //  delete objects when a data member is a pointer to an object.
   //  If your constructor is not presetting pointers to 0, you must
   //  call this static function TStreamerInfo::SetCanDelete(kFALSE);

   fgCanDelete = opt;
}

//______________________________________________________________________________
void TVirtualStreamerInfo::SetFactory(TVirtualStreamerInfo *factory)
{
   //static function: Set the StreamerInfo factory
   fgInfoFactory = factory;
}

//______________________________________________________________________________
Bool_t TVirtualStreamerInfo::SetStreamMemberWise(Bool_t enable)
{
   // Set whether the TStreamerInfos will save the collections in
   // "member-wise" order whenever possible.  The default is to store member-wise.
   // kTRUE indicates member-wise storing
   // kFALSE inddicates object-wise storing
   // This function returns the previous value of fgStreamMemberWise.

   // A collection can be saved member wise when it contain is guaranteed to be
   // homogeneous.  For example std::vector<THit> can be stored member wise,
   // while std::vector<THit*> can not (possible use of polymorphism).

   Bool_t prev = fgStreamMemberWise;
   fgStreamMemberWise = enable;
   return prev;
}

//______________________________________________________________________________
void TVirtualStreamerInfo::Streamer(TBuffer &R__b)
{
   // Stream an object of class TVirtualStreamerInfo.

   TNamed::Streamer(R__b);
}
 TVirtualStreamerInfo.cxx:1
 TVirtualStreamerInfo.cxx:2
 TVirtualStreamerInfo.cxx:3
 TVirtualStreamerInfo.cxx:4
 TVirtualStreamerInfo.cxx:5
 TVirtualStreamerInfo.cxx:6
 TVirtualStreamerInfo.cxx:7
 TVirtualStreamerInfo.cxx:8
 TVirtualStreamerInfo.cxx:9
 TVirtualStreamerInfo.cxx:10
 TVirtualStreamerInfo.cxx:11
 TVirtualStreamerInfo.cxx:12
 TVirtualStreamerInfo.cxx:13
 TVirtualStreamerInfo.cxx:14
 TVirtualStreamerInfo.cxx:15
 TVirtualStreamerInfo.cxx:16
 TVirtualStreamerInfo.cxx:17
 TVirtualStreamerInfo.cxx:18
 TVirtualStreamerInfo.cxx:19
 TVirtualStreamerInfo.cxx:20
 TVirtualStreamerInfo.cxx:21
 TVirtualStreamerInfo.cxx:22
 TVirtualStreamerInfo.cxx:23
 TVirtualStreamerInfo.cxx:24
 TVirtualStreamerInfo.cxx:25
 TVirtualStreamerInfo.cxx:26
 TVirtualStreamerInfo.cxx:27
 TVirtualStreamerInfo.cxx:28
 TVirtualStreamerInfo.cxx:29
 TVirtualStreamerInfo.cxx:30
 TVirtualStreamerInfo.cxx:31
 TVirtualStreamerInfo.cxx:32
 TVirtualStreamerInfo.cxx:33
 TVirtualStreamerInfo.cxx:34
 TVirtualStreamerInfo.cxx:35
 TVirtualStreamerInfo.cxx:36
 TVirtualStreamerInfo.cxx:37
 TVirtualStreamerInfo.cxx:38
 TVirtualStreamerInfo.cxx:39
 TVirtualStreamerInfo.cxx:40
 TVirtualStreamerInfo.cxx:41
 TVirtualStreamerInfo.cxx:42
 TVirtualStreamerInfo.cxx:43
 TVirtualStreamerInfo.cxx:44
 TVirtualStreamerInfo.cxx:45
 TVirtualStreamerInfo.cxx:46
 TVirtualStreamerInfo.cxx:47
 TVirtualStreamerInfo.cxx:48
 TVirtualStreamerInfo.cxx:49
 TVirtualStreamerInfo.cxx:50
 TVirtualStreamerInfo.cxx:51
 TVirtualStreamerInfo.cxx:52
 TVirtualStreamerInfo.cxx:53
 TVirtualStreamerInfo.cxx:54
 TVirtualStreamerInfo.cxx:55
 TVirtualStreamerInfo.cxx:56
 TVirtualStreamerInfo.cxx:57
 TVirtualStreamerInfo.cxx:58
 TVirtualStreamerInfo.cxx:59
 TVirtualStreamerInfo.cxx:60
 TVirtualStreamerInfo.cxx:61
 TVirtualStreamerInfo.cxx:62
 TVirtualStreamerInfo.cxx:63
 TVirtualStreamerInfo.cxx:64
 TVirtualStreamerInfo.cxx:65
 TVirtualStreamerInfo.cxx:66
 TVirtualStreamerInfo.cxx:67
 TVirtualStreamerInfo.cxx:68
 TVirtualStreamerInfo.cxx:69
 TVirtualStreamerInfo.cxx:70
 TVirtualStreamerInfo.cxx:71
 TVirtualStreamerInfo.cxx:72
 TVirtualStreamerInfo.cxx:73
 TVirtualStreamerInfo.cxx:74
 TVirtualStreamerInfo.cxx:75
 TVirtualStreamerInfo.cxx:76
 TVirtualStreamerInfo.cxx:77
 TVirtualStreamerInfo.cxx:78
 TVirtualStreamerInfo.cxx:79
 TVirtualStreamerInfo.cxx:80
 TVirtualStreamerInfo.cxx:81
 TVirtualStreamerInfo.cxx:82
 TVirtualStreamerInfo.cxx:83
 TVirtualStreamerInfo.cxx:84
 TVirtualStreamerInfo.cxx:85
 TVirtualStreamerInfo.cxx:86
 TVirtualStreamerInfo.cxx:87
 TVirtualStreamerInfo.cxx:88
 TVirtualStreamerInfo.cxx:89
 TVirtualStreamerInfo.cxx:90
 TVirtualStreamerInfo.cxx:91
 TVirtualStreamerInfo.cxx:92
 TVirtualStreamerInfo.cxx:93
 TVirtualStreamerInfo.cxx:94
 TVirtualStreamerInfo.cxx:95
 TVirtualStreamerInfo.cxx:96
 TVirtualStreamerInfo.cxx:97
 TVirtualStreamerInfo.cxx:98
 TVirtualStreamerInfo.cxx:99
 TVirtualStreamerInfo.cxx:100
 TVirtualStreamerInfo.cxx:101
 TVirtualStreamerInfo.cxx:102
 TVirtualStreamerInfo.cxx:103
 TVirtualStreamerInfo.cxx:104
 TVirtualStreamerInfo.cxx:105
 TVirtualStreamerInfo.cxx:106
 TVirtualStreamerInfo.cxx:107
 TVirtualStreamerInfo.cxx:108
 TVirtualStreamerInfo.cxx:109
 TVirtualStreamerInfo.cxx:110
 TVirtualStreamerInfo.cxx:111
 TVirtualStreamerInfo.cxx:112
 TVirtualStreamerInfo.cxx:113
 TVirtualStreamerInfo.cxx:114
 TVirtualStreamerInfo.cxx:115
 TVirtualStreamerInfo.cxx:116
 TVirtualStreamerInfo.cxx:117
 TVirtualStreamerInfo.cxx:118
 TVirtualStreamerInfo.cxx:119
 TVirtualStreamerInfo.cxx:120
 TVirtualStreamerInfo.cxx:121
 TVirtualStreamerInfo.cxx:122
 TVirtualStreamerInfo.cxx:123
 TVirtualStreamerInfo.cxx:124
 TVirtualStreamerInfo.cxx:125
 TVirtualStreamerInfo.cxx:126
 TVirtualStreamerInfo.cxx:127
 TVirtualStreamerInfo.cxx:128
 TVirtualStreamerInfo.cxx:129
 TVirtualStreamerInfo.cxx:130
 TVirtualStreamerInfo.cxx:131
 TVirtualStreamerInfo.cxx:132
 TVirtualStreamerInfo.cxx:133
 TVirtualStreamerInfo.cxx:134
 TVirtualStreamerInfo.cxx:135
 TVirtualStreamerInfo.cxx:136
 TVirtualStreamerInfo.cxx:137
 TVirtualStreamerInfo.cxx:138
 TVirtualStreamerInfo.cxx:139
 TVirtualStreamerInfo.cxx:140
 TVirtualStreamerInfo.cxx:141
 TVirtualStreamerInfo.cxx:142
 TVirtualStreamerInfo.cxx:143
 TVirtualStreamerInfo.cxx:144
 TVirtualStreamerInfo.cxx:145
 TVirtualStreamerInfo.cxx:146
 TVirtualStreamerInfo.cxx:147
 TVirtualStreamerInfo.cxx:148
 TVirtualStreamerInfo.cxx:149
 TVirtualStreamerInfo.cxx:150
 TVirtualStreamerInfo.cxx:151
 TVirtualStreamerInfo.cxx:152
 TVirtualStreamerInfo.cxx:153
 TVirtualStreamerInfo.cxx:154
 TVirtualStreamerInfo.cxx:155
 TVirtualStreamerInfo.cxx:156
 TVirtualStreamerInfo.cxx:157
 TVirtualStreamerInfo.cxx:158
 TVirtualStreamerInfo.cxx:159
 TVirtualStreamerInfo.cxx:160
 TVirtualStreamerInfo.cxx:161
 TVirtualStreamerInfo.cxx:162
 TVirtualStreamerInfo.cxx:163
 TVirtualStreamerInfo.cxx:164
 TVirtualStreamerInfo.cxx:165
 TVirtualStreamerInfo.cxx:166
 TVirtualStreamerInfo.cxx:167
 TVirtualStreamerInfo.cxx:168
 TVirtualStreamerInfo.cxx:169
 TVirtualStreamerInfo.cxx:170
 TVirtualStreamerInfo.cxx:171
 TVirtualStreamerInfo.cxx:172
 TVirtualStreamerInfo.cxx:173
 TVirtualStreamerInfo.cxx:174
 TVirtualStreamerInfo.cxx:175
 TVirtualStreamerInfo.cxx:176
 TVirtualStreamerInfo.cxx:177
 TVirtualStreamerInfo.cxx:178
 TVirtualStreamerInfo.cxx:179
 TVirtualStreamerInfo.cxx:180
 TVirtualStreamerInfo.cxx:181
 TVirtualStreamerInfo.cxx:182
 TVirtualStreamerInfo.cxx:183
 TVirtualStreamerInfo.cxx:184
 TVirtualStreamerInfo.cxx:185
 TVirtualStreamerInfo.cxx:186
 TVirtualStreamerInfo.cxx:187
 TVirtualStreamerInfo.cxx:188
 TVirtualStreamerInfo.cxx:189
 TVirtualStreamerInfo.cxx:190
 TVirtualStreamerInfo.cxx:191
 TVirtualStreamerInfo.cxx:192
 TVirtualStreamerInfo.cxx:193
 TVirtualStreamerInfo.cxx:194
 TVirtualStreamerInfo.cxx:195
 TVirtualStreamerInfo.cxx:196
 TVirtualStreamerInfo.cxx:197
 TVirtualStreamerInfo.cxx:198
 TVirtualStreamerInfo.cxx:199
 TVirtualStreamerInfo.cxx:200
 TVirtualStreamerInfo.cxx:201
 TVirtualStreamerInfo.cxx:202
 TVirtualStreamerInfo.cxx:203
 TVirtualStreamerInfo.cxx:204
 TVirtualStreamerInfo.cxx:205
 TVirtualStreamerInfo.cxx:206
 TVirtualStreamerInfo.cxx:207
 TVirtualStreamerInfo.cxx:208
 TVirtualStreamerInfo.cxx:209
 TVirtualStreamerInfo.cxx:210
 TVirtualStreamerInfo.cxx:211
 TVirtualStreamerInfo.cxx:212
 TVirtualStreamerInfo.cxx:213
 TVirtualStreamerInfo.cxx:214
 TVirtualStreamerInfo.cxx:215
 TVirtualStreamerInfo.cxx:216
 TVirtualStreamerInfo.cxx:217
 TVirtualStreamerInfo.cxx:218
 TVirtualStreamerInfo.cxx:219
 TVirtualStreamerInfo.cxx:220
 TVirtualStreamerInfo.cxx:221
 TVirtualStreamerInfo.cxx:222
 TVirtualStreamerInfo.cxx:223
 TVirtualStreamerInfo.cxx:224
 TVirtualStreamerInfo.cxx:225
 TVirtualStreamerInfo.cxx:226
 TVirtualStreamerInfo.cxx:227
 TVirtualStreamerInfo.cxx:228
 TVirtualStreamerInfo.cxx:229
 TVirtualStreamerInfo.cxx:230
 TVirtualStreamerInfo.cxx:231
 TVirtualStreamerInfo.cxx:232
 TVirtualStreamerInfo.cxx:233