ATLAS Offline Software
Loading...
Searching...
No Matches
AthToolSupport/AsgDataHandles/AsgDataHandles/WriteHandle.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5/**
6 * @file AsgDataHandles/WriteHandle.icc
7 * @author Nils Krumnack <Nils.Erik.Krumnack@cern.h>
8 * @author S. Binet, P. Calafiura, scott snyder <snyder@bnl.gov> (for original version)
9 * @brief Handle class for recording to StoreGate.
10 */
11
12#include "xAODRootAccess/TActiveStore.h"
13#include "xAODRootAccess/TStore.h"
14#include <stdexcept>
15
16
17namespace SG {
18
19
20//************************************************************************
21// Constructors, etc.
22//
23
24
25// /**
26// * @brief Default constructor.
27// *
28// * The handle will not be usable until a non-blank key is assigned.
29// */
30// template <class T>
31// inline
32// WriteHandle<T>::WriteHandle()
33// : VarHandleBase(ClassID_traits<T>::ID(), Gaudi::DataHandle::Writer)
34// {
35// }
36
37
38/**
39 * @brief Constructor with full arguments.
40 * @param sgkey StoreGate key of the referenced object.
41 */
42template <class T>
43inline
44WriteHandle<T>::WriteHandle (const std::string& sgkey)
45 : VarHandleBase (sgkey)
46{
47}
48
49
50/**
51 * @brief Constructor specifying the key as a string, with context.
52 * @param sgkey StoreGate key of the referenced object.
53 * @param ctx The event context.
54 *
55 * In the standalone implementation the store is always taken from
56 * @c xAOD::TActiveStore, so the context is currently ignored.
57 */
58template <class T>
59inline
60WriteHandle<T>::WriteHandle (const std::string& sgkey,
61 const EventContext& /*ctx*/)
62 : VarHandleBase (sgkey)
63{
64}
65
66
67/**
68 * @brief Constructor from a WriteHandleKey.
69 * @param key The key object holding the clid/key/store.
70 *
71 * This will raise an exception if the StoreGate key is blank,
72 * or if the event store cannot be found.
73 */
74template <class T>
75inline
76WriteHandle<T>::WriteHandle (const WriteHandleKey<T>& key)
77 : VarHandleBase (key, nullptr)
78{
79}
80
81
82/**
83 * @brief Constructor from a WriteHandleKey and an explicit event context.
84 * @param key The key object holding the clid/key.
85 * @param ctx The event context.
86 *
87 * This will raise an exception if the StoreGate key is blank,
88 * or if the event store cannot be found.
89 *
90 * If the default event store has been requested, then the thread-specific
91 * store from the event context will be used.
92 */
93template <class T>
94inline
95WriteHandle<T>::WriteHandle (const WriteHandleKey<T>& key,
96 const EventContext& ctx)
97 : VarHandleBase (key, &ctx)
98{
99}
100
101
102/**
103 * @brief Copy constructor.
104 */
105template <class T>
106inline
107WriteHandle<T>::WriteHandle(const WriteHandle& h)
108 : VarHandleBase(h)
109{
110}
111
112
113/**
114 * @brief Move constructor.
115 */
116template <class T>
117WriteHandle<T>::WriteHandle(WriteHandle&& h)
118 : VarHandleBase(std::move(h))
119{
120 // m_lockAuxPending = h.m_lockAuxPending;
121 // h.m_lockAuxPending = nullptr;
122}
123
124
125/**
126 * @brief Assignment operator.
127 */
128template <class T>
129inline
130WriteHandle<T>&
131WriteHandle<T>::operator= (const WriteHandle& h)
132{
133 if (this != &h)
134 this->VarHandleBase::operator=(h);
135 return *this;
136}
137
138
139/**
140 * @brief Move operator.
141 */
142template <class T>
143inline
144WriteHandle<T>&
145WriteHandle<T>::operator= (WriteHandle&& h)
146{
147 if (this != &h) {
148 this->VarHandleBase::operator=(std::move(h));
149 // m_lockAuxPending = h.m_lockAuxPending;
150 // h.m_lockAuxPending = nullptr;
151 }
152 return *this;
153}
154
155
156/**
157 * @brief Destructor.
158 *
159 * Lock an aux object if m_lockAuxPending is true.
160 */
161template <class T>
162WriteHandle<T>::~WriteHandle()
163{
164 // if (m_lockAuxPending) {
165 // m_lockAuxPending->setConst();
166 // }
167}
168
169
170//************************************************************************
171// Deference. These all return only the cached pointer.
172//
173
174
175// /**
176// * @brief Dereference the pointer.
177// * Returns the cached pointer. Throws ExcNullWriteHandle if null.
178// */
179// template <class T>
180// inline
181// typename WriteHandle<T>::pointer_type
182// WriteHandle<T>::operator->()
183// {
184// return WriteHandle<T>::checkedCachedPtr();
185// }
186
187
188/**
189 * @brief Dereference the pointer.
190 * Returns the cached pointer. Throws ExcNullWriteHandle if null.
191 */
192template <class T>
193inline
194typename WriteHandle<T>::reference_type
195WriteHandle<T>::operator*()
196{
197 if (m_ptr == nullptr)
198 throw std::runtime_error ("dereferenced handle is null: " + key());
199 return *m_ptr;
200}
201
202
203// /**
204// * @brief Dereference the pointer.
205// * Returns the cached pointer.
206// */
207// template <class T>
208// inline
209// typename WriteHandle<T>::const_pointer_type
210// WriteHandle<T>::cptr() const
211// {
212// return reinterpret_cast<pointer_type>(this->m_ptr);
213// }
214
215
216// /**
217// * @brief Dereference the pointer.
218// * Returns the cached pointer.
219// */
220// template <class T>
221// inline
222// typename WriteHandle<T>::pointer_type
223// WriteHandle<T>::ptr()
224// {
225// return cachedPtr();
226// }
227
228
229// /**
230// * @brief Return the cached pointer directly; no lookup.
231// */
232// template <class T>
233// inline
234// typename WriteHandle<T>::pointer_type
235// WriteHandle<T>::cachedPtr()
236// {
237// return reinterpret_cast<pointer_type>(this->m_ptr);
238// }
239
240
241/**
242 * @brief Can the handle be successfully dereferenced?
243 */
244template <class T>
245inline
246bool WriteHandle<T>::isValid()
247{
248 return this->m_ptr != nullptr;
249}
250
251
252//************************************************************************
253// Record.
254
255
256/**
257 * @brief Record a const object to the store.
258 * @param data The object to record.
259 */
260template <class T>
261inline
262StatusCode
263WriteHandle<T>::WriteHandle::record (std::unique_ptr<T> data)
264{
265 m_ptr = data.get();
266 if (xAOD::TActiveStore::store()->record (std::move (data), key()).isFailure())
267 return StatusCode::FAILURE;
268 return StatusCode::SUCCESS;
269}
270
271
272/**
273 * @brief Record a non-const object to the store.
274 * @param data The object to record.
275 */
276template <class T>
277inline
278StatusCode
279WriteHandle<T>::WriteHandle::recordNonConst (std::unique_ptr<T> data)
280{
281 // In standalone there is no const/non-const distinction for the store, so
282 // this simply forwards to @ref record.
283 return record (std::move (data));
284}
285
286
287/**
288 * @brief Record a const object and its auxiliary store to the store.
289 * @param data The object to record.
290 * @param auxstore Auxiliary store object.
291 */
292template <class T>
293template <class AUXSTORE>
294inline
295StatusCode
296WriteHandle<T>::WriteHandle::record (std::unique_ptr<T> data,
297 std::unique_ptr<AUXSTORE> auxstore)
298{
299 // If there's no store association, do it now.
300 if (data->getStore() == nullptr)
301 data->setStore (auxstore.get());
302
303 m_ptr = data.get();
304 if (xAOD::TActiveStore::store()->record (std::move (auxstore), key() + "Aux.").isFailure())
305 return StatusCode::FAILURE;
306 if (xAOD::TActiveStore::store()->record (std::move (data), key()).isFailure())
307 return StatusCode::FAILURE;
308 return StatusCode::SUCCESS;
309}
310
311
312/**
313 * @brief Record a non-const object and its auxiliary store to the store.
314 * @param data The object to record.
315 * @param auxstore Auxiliary store object.
316 */
317template <class T>
318template <class AUXSTORE>
319inline
320StatusCode
321WriteHandle<T>::WriteHandle::recordNonConst (std::unique_ptr<T> data,
322 std::unique_ptr<AUXSTORE> auxstore)
323{
324 // In standalone there is no const/non-const distinction for the store, so
325 // this simply forwards to @ref record.
326 return record (std::move (data), std::move (auxstore));
327}
328
329
330// /**
331// * @brief Record a const shared DataObject to the store.
332// * @param data The object to record.
333// *
334// * The event store takes shared ownership of the object.
335// */
336// template <class T>
337// inline
338// StatusCode
339// WriteHandle<T>::record (SG::DataObjectSharedPtr<T> data)
340// {
341// return this->doRecord (std::move(data), true, false);
342// }
343
344
345// /**
346// * @brief Record a non-const shared DataObject to the store.
347// * @param data The object to record.
348// *
349// * The event store takes shared ownership of the object.
350// */
351// template <class T>
352// inline
353// StatusCode
354// WriteHandle<T>::recordNonConst (SG::DataObjectSharedPtr<T> data)
355// {
356// return this->doRecord (std::move(data), false, false);
357// }
358
359
360/**
361 * @brief Record an object to the store.
362 * @param data The object to record.
363 * @param returnExisting Allow an existing object?
364 *
365 * Unlike record(), this does not change the handle object.
366 * That means that one will not be able to get the object back
367 * by dereferencing the handle.
368 * Returns the object placed in the store, or nullptr if there
369 * was an error.
370 * If there was already an object in the store with the given key,
371 * then return null, unless @c returnExisting is true, in which case
372 * return success. In either case, @c data is destroyed.
373 */
374template <class T>
375inline
376typename WriteHandle<T>::const_pointer_type
377WriteHandle<T>::put (std::unique_ptr<T> data/*,
378 bool returnExisting / *= false*/) const
379{
380 const_pointer_type result = data.get();
381 if (xAOD::TActiveStore::store()->record (std::move (data), key()).isFailure())
382 throw std::runtime_error ("failed to record object: " + key());
383 return result;
384}
385
386
387// /**
388// * @brief Record an object to the store.
389// * @param data The object to record.
390// * @param returnExisting Allow an existing object?
391// *
392// * Unlike record(), this does not change the handle object.
393// * That means that one will not be able to get the object back
394// * by dereferencing the handle.
395// * Returns the object placed in the store, or nullptr if there
396// * was an error.
397// * If there was already an object in the store with the given key,
398// * then return null, unless @c returnExisting is true, in which case
399// * return success. In either case, @c data is destroyed.
400// */
401// template <class T>
402// inline
403// typename WriteHandle<T>::const_pointer_type
404// WriteHandle<T>::put (std::unique_ptr<const T> data,
405// bool returnExisting /*= false*/) const
406// {
407// IProxyDict* store = nullptr;
408// return doPut (nullptr, std::move(data), returnExisting, store);
409// }
410
411
412// /**
413// * @brief Record an object to the store.
414// * @param data The object to record.
415// * @param returnExisting Allow an existing object?
416// *
417// * Unlike record(), this does not change the handle object.
418// * That means that one will not be able to get the object back
419// * by dereferencing the handle.
420// * Returns the object placed in the store, or nullptr if there
421// * was an error.
422// * If there was already an object in the store with the given key,
423// * then return null, unless @c returnExisting is true, in which case
424// * return success. In either case, @c data is destroyed.
425// */
426// template <class T>
427// inline
428// typename WriteHandle<T>::const_pointer_type
429// WriteHandle<T>::put (std::unique_ptr<const ConstDataVector<T> > data,
430// bool returnExisting /*= false*/) const
431// {
432// IProxyDict* store = nullptr;
433// std::unique_ptr<const T> coll (data.release()->asDataVector());
434// return doPut (nullptr, std::move(coll), returnExisting, store);
435// }
436
437
438// /**
439// * @brief Record an object to the store.
440// * @param ctx The event context to use.
441// * @param data The object to record.
442// * @param returnExisting Allow an existing object?
443// *
444// * Unlike record(), this does not change the handle object.
445// * That means that one will not be able to get the object back
446// * by dereferencing the handle.
447// * Returns the object placed in the store, or nullptr if there
448// * was an error.
449// * If there was already an object in the store with the given key,
450// * then return null, unless @c returnExisting is true, in which case
451// * return success. In either case, @c data is destroyed.
452// */
453// template <class T>
454// inline
455// typename WriteHandle<T>::const_pointer_type
456// WriteHandle<T>::put (const EventContext& ctx,
457// std::unique_ptr<const ConstDataVector<T> > data,
458// bool returnExisting /*= false*/) const
459// {
460// IProxyDict* store = nullptr;
461// std::unique_ptr<const T> coll (data.release()->asDataVector());
462// return doPut (&ctx, std::move(coll), returnExisting, store);
463// }
464
465
466// /**
467// * @brief Record an object to the store.
468// * @param ctx The event context to use.
469// * @param data The object to record.
470// * @param returnExisting Allow an existing object?
471// *
472// * Unlike record(), this does not change the handle object.
473// * That means that one will not be able to get the object back
474// * by dereferencing the handle.
475// * Returns the object placed in the store, or nullptr if there
476// * was an error.
477// * If there was already an object in the store with the given key,
478// * then return null, unless @c returnExisting is true, in which case
479// * return success. In either case, @c data is destroyed.
480// */
481// template <class T>
482// inline
483// typename WriteHandle<T>::const_pointer_type
484// WriteHandle<T>::put (const EventContext& ctx,
485// std::unique_ptr<T> data,
486// bool returnExisting /*= false*/) const
487// {
488// IProxyDict* store = nullptr;
489// return doPut (&ctx, std::move(data), returnExisting, store);
490// }
491
492
493// /**
494// * @brief Record an object to the store.
495// * @param ctx The event context to use.
496// * @param data The object to record.
497// * @param returnExisting Allow an existing object?
498// *
499// * Unlike record(), this does not change the handle object.
500// * That means that one will not be able to get the object back
501// * by dereferencing the handle.
502// * Returns the object placed in the store, or nullptr if there
503// * was an error.
504// * If there was already an object in the store with the given key,
505// * then return null, unless @c returnExisting is true, in which case
506// * return success. In either case, @c data is destroyed.
507// */
508// template <class T>
509// inline
510// typename WriteHandle<T>::const_pointer_type
511// WriteHandle<T>::put (const EventContext& ctx,
512// std::unique_ptr<const T> data,
513// bool returnExisting /*= false*/) const
514// {
515// IProxyDict* store = nullptr;
516// return doPut (&ctx, std::move(data), returnExisting, store);
517// }
518
519
520// /**
521// * @brief Record an object to the store.
522// * @param data The object to record.
523// *
524// * Unlike record(), this does not change the handle object.
525// * That means that one will not be able to get the object back
526// * by dereferencing the handle.
527// * Returns the object placed in the store, or nullptr if there
528// * was an error.
529// *
530// * The event store takes shared ownership of the object.
531// */
532// template <class T>
533// inline
534// typename WriteHandle<T>::const_pointer_type
535// WriteHandle<T>::put (SG::DataObjectSharedPtr<T> data) const
536// {
537// IProxyDict* store = nullptr;
538// return doPut (nullptr, std::move(data), false, store);
539// }
540
541
542// /**
543// * @brief Record an object to the store.
544// * @param ctx The event context to use.
545// * @param data The object to record.
546// *
547// * Unlike record(), this does not change the handle object.
548// * That means that one will not be able to get the object back
549// * by dereferencing the handle.
550// * Returns the object placed in the store, or nullptr if there
551// * was an error.
552// *
553// * The event store takes shared ownership of the object.
554// */
555// template <class T>
556// inline
557// typename WriteHandle<T>::const_pointer_type
558// WriteHandle<T>::put (const EventContext& ctx,
559// SG::DataObjectSharedPtr<T> data) const
560// {
561// IProxyDict* store = nullptr;
562// return doPut (&ctx, std::move(data), false, store);
563// }
564
565
566// /**
567// * @brief Record an object and its auxiliary store to the store.
568// * @param data The object to record.
569// * @param auxstore Auxiliary store object.
570// *
571// * Unlike record(), this does not change the handle object.
572// * That means that one will not be able to get the object back
573// * by dereferencing the handle.
574// * Returns the object placed in the store, or nullptr if there
575// * was an error.
576// * If there was already an object in the store with the given key,
577// * then return null, and the objects passed in are destroyed.
578// */
579// template <class T>
580// template <class AUXSTORE>
581// typename WriteHandle<T>::const_pointer_type
582// WriteHandle<T>::put (std::unique_ptr<T> data,
583// std::unique_ptr<AUXSTORE> auxstore) const
584// {
585// return doPut (nullptr, std::move(data), std::move(auxstore));
586// }
587
588
589
590// /**
591// * @brief Record an object and its auxiliary store to the store.
592// * @param data The object to record.
593// * @param auxstore Auxiliary store object.
594// *
595// * Unlike record(), this does not change the handle object.
596// * That means that one will not be able to get the object back
597// * by dereferencing the handle.
598// * Returns the object placed in the store, or nullptr if there
599// * was an error.
600// * If there was already an object in the store with the given key,
601// * then return null, and the objects passed in are destroyed.
602// *
603// * Unlike the version taking unique_ptr<T>, this does not alter the
604// * store pointer of @c data.
605// */
606// template <class T>
607// template <class AUXSTORE>
608// typename WriteHandle<T>::const_pointer_type
609// WriteHandle<T>::put (std::unique_ptr<const T> data,
610// std::unique_ptr<const AUXSTORE> auxstore) const
611// {
612// return doPut (nullptr, std::move(data), std::move(auxstore));
613// }
614
615
616// /**
617// * @brief Record an object and its auxiliary store to the store.
618// * @param ctx The event context to use.
619// * @param data The object to record.
620// * @param auxstore Auxiliary store object.
621// *
622// * Unlike record(), this does not change the handle object.
623// * That means that one will not be able to get the object back
624// * by dereferencing the handle.
625// * Returns the object placed in the store, or nullptr if there
626// * was an error.
627// * If there was already an object in the store with the given key,
628// * then return null, and the objects passed in are destroyed.
629// */
630// template <class T>
631// template <class AUXSTORE>
632// typename WriteHandle<T>::const_pointer_type
633// WriteHandle<T>::put (const EventContext& ctx,
634// std::unique_ptr<T> data,
635// std::unique_ptr<AUXSTORE> auxstore) const
636// {
637// return doPut (&ctx, std::move(data), std::move(auxstore));
638// }
639
640
641// /**
642// * @brief Record an object and its auxiliary store to the store.
643// * @param ctx The event context to use.
644// * @param data The object to record.
645// * @param auxstore Auxiliary store object.
646// *
647// * Unlike record(), this does not change the handle object.
648// * That means that one will not be able to get the object back
649// * by dereferencing the handle.
650// * Returns the object placed in the store, or nullptr if there
651// * was an error.
652// * If there was already an object in the store with the given key,
653// * then return null, and the objects passed in are destroyed.
654// *
655// * Unlike the version taking unique_ptr<T>, this does not alter the
656// * store pointer of @c data.
657// */
658// template <class T>
659// template <class AUXSTORE>
660// typename WriteHandle<T>::const_pointer_type
661// WriteHandle<T>::put (const EventContext& ctx,
662// std::unique_ptr<const T> data,
663// std::unique_ptr<const AUXSTORE> auxstore) const
664// {
665// return doPut (&ctx, std::move(data), std::move(auxstore));
666// }
667
668
669/**
670 * @brief Alternate notation for record. Records a non-const object.
671 * @param data Object to record.
672 *
673 * Throws an exception on failure.
674 */
675template <class T>
676WriteHandle<T>&
677WriteHandle<T>::operator= (std::unique_ptr<T> data)
678{
679 if (recordNonConst (std::move(data)).isFailure()) {
680 throw std::runtime_error ("WriteHandle<T>::operator=(unique_ptr) Record failed.");
681 }
682 return *this;
683}
684
685
686// /**
687// * @brief Make an alias.
688// * @param key Alternate key by which the referenced object should be known.
689// *
690// * The current handle should be valid and referencing an object
691// * (i.e., @c record should have been called on it).
692// *
693// * The object will also be known by the name given in @c key.
694// */
695// template <class T>
696// StatusCode WriteHandle<T>::alias (const WriteHandleKey<T>& key)
697// {
698// return symLink_impl (this->clid(), key.key());
699// }
700
701
702// /**
703// * @brief Make an explicit link.
704// * @param key Alternate clid by which the referenced object
705// * should be known. The SG key must match the key of the
706// * current handle.
707// *
708// * You should generally not be using this!
709// *
710// * The current handle should be valid and referencing an object
711// * (i.e., @c record should have been called on it).
712// *
713// * This makes a symlink: the object will be retrievable
714// * as a different type.
715// *
716// * Note that if @c T and @c @U are related via @c SG_BASE and/or
717// * @c DATAVECTOR_BASE, then you shouldn't need to explicitly make a symlink;
718// * that should happen automatically.
719// *
720// * If a @c U* is not convertable to a @c T* via C++ rules, then you likely
721// * will be, at best, relying on undefined behavior. You will probably
722// * get warnings from the undefined behavior sanitizer when if you try
723// * to dereference the @c U*.
724// *
725// * This usage is here mainly to assist in migrating some existing
726// * patterns to MT. You should think several times before using
727// * in new code.
728// */
729// template <class T>
730// template <class U>
731// StatusCode WriteHandle<T>::symLink (const WriteHandleKey<U>& other)
732// {
733// if (this->key() != other.key()) {
734// REPORT_ERROR (StatusCode::FAILURE)
735// << "symLink: SG keys do not match: " << other.key() << " vs "
736// << this->key();
737// return StatusCode::FAILURE;
738// }
739// return symLink_impl (other.clid(), other.key());
740// }
741
742
743// /**
744// * @brief Return the cached pointer directly.
745// *
746// * If it is null, throw ExcNullWriteHandle.
747// */
748// template <class T>
749// typename WriteHandle<T>::pointer_type
750// WriteHandle<T>::checkedCachedPtr()
751// {
752// if (!m_ptr)
753// throwExcNullWriteHandle (clid(), key(), store());
754// return cachedPtr();
755// }
756
757
758// /**
759// * @brief Helper for record.
760// * @param data The object to record.
761// * @param isConst If true, record the object as const.
762// * @param returnExisting Allow an existing object.
763// */
764// template <class T>
765// template <class U>
766// StatusCode WriteHandle<T>::doRecord (U data,
767// bool isConst,
768// bool returnExisting)
769// {
770// typedef typename U::element_type elt_t;
771
772// // make sure the BaseInfo(Base) structure is initialized
773// SG::BaseInfo<elt_t>::baseinfo();
774
775// // If s_isConst is set for this type, then we want to automatically
776// // make it const when recorded.
777// bool allowMods = !isConst;
778// if (ClassID_traits<elt_t>::s_isConst)
779// allowMods = false;
780
781// void* dataPtr(data.get());
782// std::unique_ptr<DataObject> dobj (SG::asStorable (std::move (data)));
783// return this->record_impl (std::move(dobj), dataPtr, allowMods, returnExisting);
784// }
785
786
787// /**
788// * @brief Helper for put.
789// * @param ctx The event context, or nullptr to use the current context.
790// * @param data The object to record.
791// * @param returnExisting Allow an existing object.
792// * @param[out] store The store being used.
793// *
794// * Unlike record(), this does not change the handle object.
795// * That means that will not be able to get the object back
796// * by dereferencing the handle.
797// * Returns the object placed in the store, or nullptr if there
798// * was an error.
799// * If there was already an object in the store with the given key,
800// * then return null, unless @c returnExisting is true, in which case
801// * return success. In either case, @c data is destroyed.
802// */
803// template <class T>
804// template <class U>
805// typename WriteHandle<T>::const_pointer_type
806// WriteHandle<T>::doPut (const EventContext* ctx,
807// U data,
808// bool returnExisting,
809// IProxyDict* & store) const
810// {
811// //typedef typename U::element_type elt_t;
812// typedef T elt_t;
813
814// // make sure the BaseInfo(Base) structure is initialized
815// SG::BaseInfo<elt_t>::baseinfo();
816
817// const void* dataPtr = data.get();
818// std::unique_ptr<DataObject> dobj (SG::asStorable (std::move (data)));
819// return reinterpret_cast<const T*>
820// (this->put_impl (ctx, std::move(dobj), dataPtr, false, returnExisting, store));
821// }
822
823
824// /**
825// * @brief Helper for recording an object and its auxiliary store to the store.
826// * @param ctx The event context, or nullptr to use the current context.
827// * @param data The object to record.
828// * @param auxstore Auxiliary store object.
829// *
830// * Unlike record(), this does not change the handle object.
831// * That means that will not be able to get the object back
832// * by dereferencing the handle.
833// * Returns the object placed in the store, or nullptr if there
834// * was an error.
835// * If there was already an object in the store with the given key,
836// * then return null, and the objects passed in are destroyed.
837// */
838// template <class T>
839// template <class AUXSTORE>
840// typename WriteHandle<T>::const_pointer_type
841// WriteHandle<T>::doPut (const EventContext* ctx,
842// std::unique_ptr<T> data,
843// std::unique_ptr<AUXSTORE> auxstore) const
844// {
845// T& dref = *data;
846
847// // If there's no store association, do it now.
848// if (data->getStore() == nullptr)
849// data->setStore (auxstore.get());
850
851// IProxyDict* store = nullptr;
852// const T* ptr = this->doPut (ctx, std::move(data), false, store);
853// if (!ptr) return nullptr;
854
855// SG::DataObjectSharedPtr<DataObject> dobj
856// (SG::asStorable (std::move (auxstore)));
857// SG::DataProxy* proxy = store->recordObject (std::move(dobj),
858// this->name() + "Aux.",
859// false,
860// false);
861// if (!proxy) {
862// REPORT_ERROR (StatusCode::FAILURE)
863// << "recordObject of aux store failed";
864
865// // If we've failed here, then the aux store object has been deleted,
866// // but not the primary object. Null out the store pointer to prevent
867// // having a dangling pointer to a deleted object.
868// dref.setStore (static_cast<SG::IConstAuxStore*>(nullptr));
869// return nullptr;
870// }
871
872// return ptr;
873// }
874
875
876// /**
877// * @brief Helper for recording an object and its auxiliary store to the store.
878// * @param ctx The event context, or nullptr to use the current context.
879// * @param data The object to record.
880// * @param auxstore Auxiliary store object.
881// *
882// * Unlike record(), this does not change the handle object.
883// * That means that will not be able to get the object back
884// * by dereferencing the handle.
885// * Returns the object placed in the store, or nullptr if there
886// * was an error.
887// * If there was already an object in the store with the given key,
888// * then return null, and the objects passed in are destroyed.
889// */
890// template <class T>
891// template <class AUXSTORE>
892// typename WriteHandle<T>::const_pointer_type
893// WriteHandle<T>::doPut (const EventContext* ctx,
894// std::unique_ptr<const T> data,
895// std::unique_ptr<const AUXSTORE> auxstore) const
896// {
897// IProxyDict* store = nullptr;
898// const T* ptr = this->doPut (ctx, std::move(data), false, store);
899// if (!ptr) return nullptr;
900
901// SG::DataObjectSharedPtr<DataObject> dobj
902// (SG::asStorable (std::move (auxstore)));
903// SG::DataProxy* proxy = store->recordObject (std::move(dobj),
904// this->name() + "Aux.",
905// false,
906// false);
907// if (!proxy) {
908// REPORT_ERROR (StatusCode::FAILURE)
909// << "recordObject of aux store failed";
910// return nullptr;
911// }
912
913// return ptr;
914// }
915
916
917// /**
918// * @brief Record an object and its auxiliary store to the store.
919// * @param data The object to record.
920// * @param auxstore Auxiliary store object.
921// * @param isConst If true, record the objects as const.
922// */
923// template <class T>
924// template <class AUXSTORE>
925// StatusCode
926// WriteHandle<T>::record (std::unique_ptr<T> data,
927// std::unique_ptr<AUXSTORE> auxstore,
928// bool isConst)
929// {
930// T& dref = *data;
931
932// // If there's no store association, do it now.
933// if (data->getStore() == nullptr)
934// data->setStore (auxstore.get());
935
936// if (isConst) {
937// // Temporarily clear the store association, in order to prevent
938// // the aux store from being locked at this point.
939// IAuxStore* store = dref.getStore();
940// if (store)
941// dref.setStore (static_cast<SG::IAuxStore*>(nullptr));
942// CHECK (this->record(std::move(data)));
943// // Deliberately not using RAII here. If there is an error,
944// // then the object referenced by data will be deleted.
945// dref.setStore (store);
946// }
947// else
948// CHECK (this->recordNonConst(std::move(data)));
949
950// // Store and proxy must be valid if we get to this point.
951
952// SG::DataObjectSharedPtr<DataObject> dobj
953// (SG::asStorable (std::move (auxstore)));
954// SG::DataProxy* proxy = m_store->recordObject (std::move(dobj),
955// this->name() + "Aux.",
956// true,
957// false);
958// if (!proxy) {
959// REPORT_ERROR (StatusCode::FAILURE)
960// << "recordObject of aux store failed";
961
962// // If we've failed here, then the aux store object has been deleted,
963// // but not the primary object. Null out the store pointer to prevent
964// // having a dangling pointer to a deleted object.
965// dref.setStore (static_cast<SG::IConstAuxStore*>(nullptr));
966// return StatusCode::FAILURE;
967// }
968
969// if (m_proxy->isConst())
970// m_lockAuxPending = proxy;
971
972// return StatusCode::SUCCESS;
973// }
974
975
976/**
977 * @brief Return a @c WriteHandle referencing @c key.
978 * @param key The key object holding the clid/key/store.
979 *
980 * This will raise an exception if the StoreGate key is blank,
981 * or if the event store cannot be found.
982 */
983template <class T>
984WriteHandle<T> makeHandle (const WriteHandleKey<T>& key)
985{
986 return WriteHandle<T> (key);
987}
988
989
990/**
991 * @brief Return a @c WriteHandle referencing @c key for an explicit context.
992 * @param key The key object holding the clid/key/store.
993 * @param ctx The event context.
994 *
995 * This will raise an exception if the StoreGate key is blank,
996 * or if the event store cannot be found.
997 *
998 * If the default event store has been requested, then the thread-specific
999 * store from the event context will be used.
1000 */
1001template <class T>
1002WriteHandle<T> makeHandle (const WriteHandleKey<T>& key,
1003 const EventContext& ctx)
1004{
1005 return WriteHandle<T> (key, ctx);
1006}
1007
1008
1009} /* namespace SG */