00001
00002
00003 #ifndef XAODROOTACCESS_TAUXSTORE_H
00004 #define XAODROOTACCESS_TAUXSTORE_H
00005
00006
00007 #include <vector>
00008 #include <string>
00009
00010
00011 #include "AthContainersInterfaces/IAuxStore.h"
00012 #include "AthContainersInterfaces/IAuxStoreIO.h"
00013 #include "AthContainers/tools/threading.h"
00014 #include "xAODCore/AuxSelection.h"
00015
00016
00017 #include "xAODRootAccess/tools/TReturnCode.h"
00018
00019
00020 class TTree;
00021 class TBranch;
00022 namespace SG {
00023 class IAuxTypeVector;
00024 class AuxStoreInternal;
00025 }
00026
00027 namespace xAOD {
00028
00029
00030 class TEvent;
00031
00044 class TAuxStore : public SG::IAuxStore,
00045 public SG::IAuxStoreIO {
00046
00048 friend class TEvent;
00049
00050 public:
00052 enum EStructMode {
00053 kUndefinedStore = 0,
00054 kContainerStore = 1,
00055 kObjectStore = 2
00056 };
00058 typedef SG::auxid_t auxid_t;
00060 typedef SG::auxid_set_t auxid_set_t;
00061
00063 TAuxStore( const char* prefix = "", Bool_t topStore = kTRUE,
00064 EStructMode mode = kUndefinedStore,
00065 Int_t basketSize = 2048, Int_t splitLevel = 0 );
00067 ~TAuxStore();
00068
00070 EStructMode structMode() const;
00072 TReturnCode setStructMode( EStructMode mode );
00073
00075 const char* prefix() const;
00077 void setPrefix( const char* prefix );
00078
00080 Bool_t isTopStore() const;
00082 void setTopStore( Bool_t value = kTRUE );
00083
00085 Int_t basketSize() const;
00087 void setBasketSize( Int_t value );
00088
00090 Int_t splitLevel() const;
00092 void setSplitLevel( Int_t value );
00093
00095 TReturnCode readFrom( ::TTree* tree, ::Bool_t printWarnings = kTRUE );
00097 TReturnCode writeTo( ::TTree* tree );
00098
00100 Int_t getEntry( Long64_t entry, Int_t getall = 0 );
00101
00103 void reset();
00104
00107
00109 virtual const void* getData( auxid_t auxid ) const;
00110
00112 virtual const auxid_set_t& getAuxIDs() const;
00113
00115 virtual void* getDecoration( auxid_t auxid, size_t size,
00116 size_t capacity );
00117
00119 virtual void lock();
00122 virtual void clearDecorations();
00123
00125 virtual size_t size() const;
00126
00128
00131
00133 virtual void* getData( auxid_t auxid, size_t size,
00134 size_t capacity );
00135
00137 virtual const auxid_set_t& getWritableAuxIDs() const;
00138
00140 virtual void resize( size_t size );
00142 virtual void reserve( size_t size );
00144 virtual void shift( size_t pos, ptrdiff_t offs );
00145
00147
00150
00152 virtual const void* getIOData( auxid_t auxid ) const;
00153
00155 virtual const std::type_info* getIOType( auxid_t auxid ) const;
00156
00158 virtual const auxid_set_t& getDynamicAuxIDs() const;
00159
00161 virtual void selectAux( const std::set< std::string >& attributes );
00162
00164 virtual const auxid_set_t& getSelectedAuxIDs() const;
00165
00167
00168 private:
00170 TReturnCode initStats( ::TTree* tree );
00172 TReturnCode setupInputData( auxid_t auxid ) const;
00174 TReturnCode setupOutputData( auxid_t auxid ) const;
00176 TReturnCode scanInputTree();
00178 TReturnCode setupAuxBranch( ::TBranch* br, const char* auxName,
00179 ::Bool_t staticBranch );
00181 ::Bool_t isAuxIDSelected( auxid_t auxid ) const;
00183 static ::Bool_t isPrimitiveBranch( TBranch* br );
00185 static ::Bool_t isContainerBranch( TBranch* br, auxid_t auxid );
00187 static ::Bool_t isRegisteredType( auxid_t auxid );
00188
00190 std::string m_prefix;
00192 std::string m_dynPrefix;
00193
00195 ::Bool_t m_topStore;
00196
00198 mutable EStructMode m_structMode;
00200 ::Int_t m_basketSize;
00202 ::Int_t m_splitLevel;
00203
00205 ::Long64_t m_entry;
00206
00208 ::TTree* m_inTree;
00210 ::TTree* m_outTree;
00211
00213 ::Bool_t m_inputScanned;
00214
00216 AuxSelection m_selection;
00218 SG::AuxStoreInternal* m_transientStore;
00219
00221 mutable auxid_set_t m_auxIDs;
00223 mutable std::vector< SG::IAuxTypeVector* > m_vecs;
00225 mutable std::size_t m_size;
00226
00228 ::Bool_t m_locked;
00230 mutable std::vector< ::Bool_t > m_isDecoration;
00231
00233 mutable size_t m_tick;
00234
00236 typedef AthContainers_detail::mutex mutex_t;
00238 typedef AthContainers_detail::lock_guard< mutex_t > guard_t;
00240 mutable mutex_t m_mutex1, m_mutex2;
00241
00243 struct TSAuxidSet {
00244 size_t m_tick;
00245 auxid_set_t m_set;
00246
00247 TSAuxidSet( size_t tick, const auxid_set_t& set )
00248 : m_tick( tick ), m_set( set ) {}
00249 };
00250
00252 mutable AthContainers_detail::thread_specific_ptr< TSAuxidSet >
00253 m_tsAuxids;
00254
00260 class TBranchHandle {
00261
00262 public:
00264 TBranchHandle( ::Bool_t staticBranch, ::Bool_t primitiveBranch,
00265 const std::type_info* ti, void* obj,
00266 SG::auxid_t auxid, const std::string* prefix );
00267
00269 ::Int_t getEntry( ::Long64_t entry );
00271 ::TBranch** branchPtr();
00273 void* objectPtr();
00275 void* inputObjectPtr();
00277 void* outputObjectPtr();
00279 const std::type_info* typeInfo() const;
00281 void reset();
00282
00283 private:
00285 ::TBranch* m_branch;
00287 void* m_object;
00289 ::Bool_t m_static;
00291 ::Bool_t m_primitive;
00293 const std::type_info* m_typeInfo;
00295 ::Bool_t m_needsRead;
00297 SG::auxid_t m_auxid;
00299 const std::string* m_prefix;
00300
00301 };
00302
00304 mutable std::vector< TBranchHandle* > m_branches;
00306 mutable std::vector< bool > m_branchesWritten;
00309 mutable std::vector< bool > m_missingBranches;
00310
00311 };
00312
00313 }
00314
00315 #endif // XAODROOTACCESS_TAUXSTORE_H