TStreamerInfoActions.h

Go to the documentation of this file.
00001 // @(#)root/io:$Id: TStreamerInfoActions.h 36169 2010-10-07 16:06:18Z pcanal $
00002 // Author: Philippe Canal 05/2010
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TStreamerInfoActions
00013 #define ROOT_TStreamerInfoActions
00014 
00015 #include <vector>
00016 
00017 #include "TStreamerInfo.h"
00018 
00019 namespace TStreamerInfoActions {
00020 
00021    class TConfiguration {
00022       // Base class of the Configurations.
00023    protected:
00024    public:
00025       TVirtualStreamerInfo *fInfo;    // TStreamerInfo form which the action is derived
00026       UInt_t                fElemId;  // Identifier of the TStreamerElement
00027       Int_t                 fOffset;  // Offset within the object
00028       UInt_t                fLength;  // Number of element in a fixed length array.
00029    public:
00030       TConfiguration(TVirtualStreamerInfo *info, UInt_t id, Int_t offset) : fInfo(info), fElemId(id), fOffset(offset),fLength(1) {};
00031       TConfiguration(TVirtualStreamerInfo *info, UInt_t id, Int_t offset, UInt_t length) : fInfo(info), fElemId(id), fOffset(offset),fLength(length) {};
00032       virtual ~TConfiguration() {};
00033       
00034       virtual void AddToOffset(Int_t delta);
00035 
00036       virtual TConfiguration *Copy() { return new TConfiguration(*this); }
00037 
00038       virtual void Print() const;
00039       virtual void PrintDebug(TBuffer &buffer, void *object) const;
00040    };
00041 
00042    class TLoopConfiguration {
00043       // Base class of the Configurations for the member wise looping routines.
00044    public:
00045       TLoopConfiguration() {};
00046       // virtual void PrintDebug(TBuffer &buffer, void *object) const;
00047       virtual ~TLoopConfiguration() {};
00048       virtual void Print() const;
00049       virtual void *GetFirstAddress(void *start, const void *end) const = 0;
00050       virtual TLoopConfiguration* Copy() = 0; // { return new TLoopConfiguration(*this); }
00051    };
00052       
00053    typedef TVirtualCollectionProxy::Next_t Next_t;
00054 
00055    typedef Int_t (*TStreamerInfoAction_t)(TBuffer &buf, void *obj, const TConfiguration *conf);
00056    typedef Int_t (*TStreamerInfoVecPtrLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TConfiguration *conf);
00057    typedef Int_t (*TStreamerInfoLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TLoopConfiguration *loopconf, const TConfiguration *conf);
00058    
00059    class TConfiguredAction : public TObject {
00060    public:
00061       union {
00062          TStreamerInfoAction_t           fAction;
00063          TStreamerInfoVecPtrLoopAction_t fVecPtrLoopAction;
00064          TStreamerInfoLoopAction_t       fLoopAction;
00065       };
00066       TConfiguration              *fConfiguration;
00067    public:
00068       TConfiguredAction() : fAction(0), fConfiguration(0) {}
00069       TConfiguredAction(const TConfiguredAction &rval) : TObject(rval), fAction(rval.fAction), fConfiguration(rval.fConfiguration)
00070       {
00071          // Technically this is a move constructor ...
00072          const_cast<TConfiguredAction&>(rval).fConfiguration = 0;
00073       }
00074       TConfiguredAction(TStreamerInfoAction_t action, TConfiguration *conf) : fAction(action), fConfiguration(conf)
00075       {
00076          // Usual constructor.
00077       }
00078       TConfiguredAction(TStreamerInfoVecPtrLoopAction_t action, TConfiguration *conf) : fVecPtrLoopAction(action), fConfiguration(conf)
00079       {
00080          // Usual constructor.
00081       }
00082       TConfiguredAction(TStreamerInfoLoopAction_t action, TConfiguration *conf) : fLoopAction(action), fConfiguration(conf)
00083       {
00084          // Usual constructor.
00085       }
00086       ~TConfiguredAction() {
00087          // Usual destructor.
00088          // Idea: the configuration ownership might be moved to a single list so that
00089          // we can shared them between the optimized and non-optimized list of actions.
00090          delete fConfiguration; 
00091       }
00092       void PrintDebug(TBuffer &buffer, void *object) const;
00093                       
00094       inline Int_t operator()(TBuffer &buffer, void *object) const {
00095          return fAction(buffer, object, fConfiguration);
00096       }
00097 
00098       inline Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection) const {
00099          return fVecPtrLoopAction(buffer, start_collection, end_collection, fConfiguration);
00100       }
00101       
00102       inline Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection, const TLoopConfiguration *loopconf) const {
00103          return fLoopAction(buffer, start_collection, end_collection, loopconf, fConfiguration);
00104       }
00105       
00106       ClassDef(TConfiguredAction,0); // A configured action
00107    };
00108    
00109    typedef std::vector<TConfiguredAction> ActionContainer_t;
00110    class TActionSequence : public TObject {
00111       TActionSequence() {};
00112    public:
00113       TActionSequence(TVirtualStreamerInfo *info, UInt_t maxdata) : fStreamerInfo(info), fLoopConfig(0) { fActions.reserve(maxdata); };
00114       ~TActionSequence() { 
00115          delete fLoopConfig; 
00116       }
00117 
00118       template <typename action_t> 
00119       void AddAction( action_t action, TConfiguration *conf ) {
00120          fActions.push_back( TConfiguredAction(action, conf) );
00121       }
00122       void AddAction(const TConfiguredAction &action ) {
00123          fActions.push_back( action );
00124       }
00125       
00126       TVirtualStreamerInfo *fStreamerInfo; // StreamerInfo used to derive these actions.
00127       TLoopConfiguration   *fLoopConfig;   // If this is a bundle of memberwise streaming action, this configures the looping
00128       ActionContainer_t     fActions;
00129 
00130       void AddToOffset(Int_t delta);
00131       
00132       TActionSequence *CreateCopy();      
00133       static TActionSequence *CreateReadMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy);
00134       TActionSequence *CreateSubSequence(const std::vector<Int_t> &element_ids, size_t offset);      
00135       
00136       void Print(Option_t * = "") const;
00137 
00138       ClassDef(TActionSequence,0);
00139    };
00140 
00141 }
00142 
00143 #endif // ROOT_TStreamerInfoActions
00144 
00145 

Generated on Tue Jul 5 14:28:14 2011 for ROOT_528-00b_version by  doxygen 1.5.1