ATLAS Offline Software
Loading...
Searching...
No Matches
AthToolSupport/AsgDataHandles/AsgDataHandles/WriteHandle.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5*/
6
13
14
15#ifndef ASG_DATA_HANDLES_WRITE_HANDLE_H
16#define ASG_DATA_HANDLES_WRITE_HANDLE_H
17
18#ifndef XAOD_STANDALONE
20#else
21
24#include <string>
25#include <memory> /*unique_ptr*/
26
27
28namespace SG {
29
30
43template <class T>
44class WriteHandle
45 : public SG::VarHandleBase
46{
47public:
48 typedef T* pointer_type; // FIXME: better handling of
49 typedef const T* const_pointer_type; // qualified T type ?
50 typedef T& reference_type;
51 typedef const T& const_reference_type;
52
53
54 //************************************************************************
55 // Constructors, etc.
56 //
57
58
59 // /**
60 // * @brief Default constructor.
61 // *
62 // * The handle will not be usable until a non-blank key is assigned.
63 // */
64 // WriteHandle();
65
66
71 explicit WriteHandle(const std::string& sgkey);
72
73
83 explicit WriteHandle(const std::string& sgkey, const EventContext& ctx);
84
85
93 explicit WriteHandle (const WriteHandleKey<T>& key);
94
95
107 explicit WriteHandle (const WriteHandleKey<T>& key, const EventContext& ctx);
108
109
113 WriteHandle( const WriteHandle& rhs );
114
115
119 WriteHandle( WriteHandle&& rhs );
120
121
125 WriteHandle& operator=( const WriteHandle& rhs );
126
127
132
133
139 ~WriteHandle();
140
141
142 //************************************************************************
143 // Deference. These all return only the cached pointer.
144 //
145
146
147 // /**
148 // * @brief Dereference the pointer.
149 // * Returns the cached pointer. Throws ExcNullWriteHandle if null.
150 // */
151 // pointer_type operator->();
152
153
159
160
161 // /**
162 // * @brief Dereference the pointer.
163 // * Returns the cached pointer.
164 // */
165 // const_pointer_type cptr() const;
166
167
168 // /**
169 // * @brief Dereference the pointer.
170 // * Returns the cached pointer.
171 // */
172 // pointer_type ptr();
173
174
175 // /**
176 // * @brief Return the cached pointer directly; no lookup.
177 // */
178 // pointer_type cachedPtr();
179
180
184 bool isValid();
185
186
187 //************************************************************************
188 // Record.
189 //
190
191
196 StatusCode record (std::unique_ptr<T> data);
197
198
203 StatusCode recordNonConst (std::unique_ptr<T> data);
204
205
211 template <class AUXSTORE>
212 StatusCode record (std::unique_ptr<T> data,
213 std::unique_ptr<AUXSTORE> store);
214
215
221 template <class AUXSTORE>
222 StatusCode recordNonConst (std::unique_ptr<T> data,
223 std::unique_ptr<AUXSTORE> store);
224
225
226 // /**
227 // * @brief Record a const shared DataObject to the store.
228 // * @param data The object to record.
229 // *
230 // * The event store takes shared ownership of the object.
231 // */
232 // StatusCode record (SG::DataObjectSharedPtr<T> data);
233
234
235 // /**
236 // * @brief Record a non-const shared DataObject to the store.
237 // * @param data The object to record.
238 // *
239 // * The event store takes shared ownership of the object.
240 // */
241 // StatusCode recordNonConst (SG::DataObjectSharedPtr<T> data);
242
243
258 const_pointer_type put (std::unique_ptr<T> data/*,
259 bool returnExisting = false*/) const;
260
261
262 // /**
263 // * @brief Record an object to the store.
264 // * @param data The object to record.
265 // * @param returnExisting Allow an existing object?
266 // *
267 // * Unlike record(), this does not change the handle object.
268 // * That means that one will not be able to get the object back
269 // * by dereferencing the handle.
270 // * Returns the object placed in the store, or nullptr if there
271 // * was an error.
272 // * If there was already an object in the store with the given key,
273 // * then return null, unless @c returnExisting is true, in which case
274 // * return success. In either case, @c data is destroyed.
275 // */
276 // const_pointer_type put (std::unique_ptr<const T> data,
277 // bool returnExisting = false) const;
278
279
280 // /**
281 // * @brief Record an object to the store.
282 // * @param data The object to record.
283 // * @param returnExisting Allow an existing object?
284 // *
285 // * Unlike record(), this does not change the handle object.
286 // * That means that one will not be able to get the object back
287 // * by dereferencing the handle.
288 // * Returns the object placed in the store, or nullptr if there
289 // * was an error.
290 // * If there was already an object in the store with the given key,
291 // * then return null, unless @c returnExisting is true, in which case
292 // * return success. In either case, @c data is destroyed.
293 // */
294 // const_pointer_type put (std::unique_ptr<const ConstDataVector<T> > data,
295 // bool returnExisting = false) const;
296
297
298 // /**
299 // * @brief Record an object to the store.
300 // * @param ctx The event context to use.
301 // * @param data The object to record.
302 // * @param returnExisting Allow an existing object?
303 // *
304 // * Unlike record(), this does not change the handle object.
305 // * That means that one will not be able to get the object back
306 // * by dereferencing the handle.
307 // * Returns the object placed in the store, or nullptr if there
308 // * was an error.
309 // * If there was already an object in the store with the given key,
310 // * then return null, unless @c returnExisting is true, in which case
311 // * return success. In either case, @c data is destroyed.
312 // */
313 // const_pointer_type put (const EventContext& ctx,
314 // std::unique_ptr<const ConstDataVector<T> > data,
315 // bool returnExisting = false) const;
316
317
318 // /**
319 // * @brief Record an object to the store.
320 // * @param ctx The event context to use.
321 // * @param data The object to record.
322 // * @param returnExisting Allow an existing object?
323 // *
324 // * Unlike record(), this does not change the handle object.
325 // * That means that one will not be able to get the object back
326 // * by dereferencing the handle.
327 // * Returns the object placed in the store, or nullptr if there
328 // * was an error.
329 // * If there was already an object in the store with the given key,
330 // * then return null, unless @c returnExisting is true, in which case
331 // * return success. In either case, @c data is destroyed.
332 // */
333 // const_pointer_type put (const EventContext& ctx,
334 // std::unique_ptr<T> data,
335 // bool returnExisting = false) const;
336
337
338 // /**
339 // * @brief Record an object to the store.
340 // * @param ctx The event context to use.
341 // * @param data The object to record.
342 // * @param returnExisting Allow an existing object?
343 // *
344 // * Unlike record(), this does not change the handle object.
345 // * That means that one will not be able to get the object back
346 // * by dereferencing the handle.
347 // * Returns the object placed in the store, or nullptr if there
348 // * was an error.
349 // * If there was already an object in the store with the given key,
350 // * then return null, unless @c returnExisting is true, in which case
351 // * return success. In either case, @c data is destroyed.
352 // */
353 // const_pointer_type put (const EventContext& ctx,
354 // std::unique_ptr<const T> data,
355 // bool returnExisting = false) const;
356
357
358 // /**
359 // * @brief Record an object to the store.
360 // * @param data The object to record.
361 // *
362 // * Unlike record(), this does not change the handle object.
363 // * That means that one will not be able to get the object back
364 // * by dereferencing the handle.
365 // * Returns the object placed in the store, or nullptr if there
366 // * was an error.
367 // *
368 // * The event store takes shared ownership of the object.
369 // */
370 // const_pointer_type put (SG::DataObjectSharedPtr<T> data) const;
371
372
373 // /**
374 // * @brief Record an object to the store.
375 // * @param ctx The event context to use.
376 // * @param data The object to record.
377 // *
378 // * Unlike record(), this does not change the handle object.
379 // * That means that one will not be able to get the object back
380 // * by dereferencing the handle.
381 // * Returns the object placed in the store, or nullptr if there
382 // * was an error.
383 // *
384 // * The event store takes shared ownership of the object.
385 // */
386 // const_pointer_type put (const EventContext& ctx,
387 // SG::DataObjectSharedPtr<T> data) const;
388
389
390 // /**
391 // * @brief Record an object and its auxiliary store to the store.
392 // * @param data The object to record.
393 // * @param auxstore Auxiliary store object.
394 // *
395 // * Unlike record(), this does not change the handle object.
396 // * That means that one will not be able to get the object back
397 // * by dereferencing the handle.
398 // * Returns the object placed in the store, or nullptr if there
399 // * was an error.
400 // * If there was already an object in the store with the given key,
401 // * then return null, and the objects passed in are destroyed.
402 // */
403 // template <class AUXSTORE>
404 // const_pointer_type
405 // put (std::unique_ptr<T> data,
406 // std::unique_ptr<AUXSTORE> auxstore) const;
407
408
409 // /**
410 // * @brief Record an object and its auxiliary store to the store.
411 // * @param data The object to record.
412 // * @param auxstore Auxiliary store object.
413 // *
414 // * Unlike record(), this does not change the handle object.
415 // * That means that one will not be able to get the object back
416 // * by dereferencing the handle.
417 // * Returns the object placed in the store, or nullptr if there
418 // * was an error.
419 // * If there was already an object in the store with the given key,
420 // * then return null, and the objects passed in are destroyed.
421 // *
422 // * Unlike the version taking unique_ptr<T>, this does not alter the
423 // * store pointer of @c data.
424 // */
425 // template <class AUXSTORE>
426 // const_pointer_type
427 // put (std::unique_ptr<const T> data,
428 // std::unique_ptr<const AUXSTORE> auxstore) const;
429
430
431 // /**
432 // * @brief Record an object and its auxiliary store to the store.
433 // * @param ctx The event context to use.
434 // * @param data The object to record.
435 // * @param auxstore Auxiliary store object.
436 // *
437 // * Unlike record(), this does not change the handle object.
438 // * That means that one will not be able to get the object back
439 // * by dereferencing the handle.
440 // * Returns the object placed in the store, or nullptr if there
441 // * was an error.
442 // * If there was already an object in the store with the given key,
443 // * then return null, and the objects passed in are destroyed.
444 // */
445 // template <class AUXSTORE>
446 // const_pointer_type
447 // put (const EventContext& ctx,
448 // std::unique_ptr<T> data,
449 // std::unique_ptr<AUXSTORE> auxstore) const;
450
451
452 // /**
453 // * @brief Record an object and its auxiliary store to the store.
454 // * @param ctx The event context to use.
455 // * @param data The object to record.
456 // * @param auxstore Auxiliary store object.
457 // *
458 // * Unlike record(), this does not change the handle object.
459 // * That means that one will not be able to get the object back
460 // * by dereferencing the handle.
461 // * Returns the object placed in the store, or nullptr if there
462 // * was an error.
463 // * If there was already an object in the store with the given key,
464 // * then return null, and the objects passed in are destroyed.
465 // *
466 // * Unlike the version taking unique_ptr<T>, this does not alter the
467 // * store pointer of @c data.
468 // */
469 // template <class AUXSTORE>
470 // const_pointer_type
471 // put (const EventContext& ctx,
472 // std::unique_ptr<const T> data,
473 // std::unique_ptr<const AUXSTORE> auxstore) const;
474
475
482 WriteHandle& operator=( std::unique_ptr<T> data );
483
484
485 // /**
486 // * @brief Make an alias.
487 // * @param key Alternate key by which the referenced object should be known.
488 // *
489 // * The current handle should be valid and referencing an object
490 // * (i.e., @c record should have been called on it).
491 // *
492 // * The object will also be known by the name given in @c key.
493 // */
494 // StatusCode alias (const WriteHandleKey<T>& key);
495
496
497 // /**
498 // * @brief Make an explicit link.
499 // * @param key Alternate clid by which the referenced object
500 // * should be known. The SG key must match the key of the
501 // * current handle.
502 // *
503 // * You should generally not be using this!
504 // *
505 // * The current handle should be valid and referencing an object
506 // * (i.e., @c record should have been called on it).
507 // *
508 // * This makes a symlink: the object will be retrievable
509 // * as a different type.
510 // *
511 // * Note that if @c T and @c @U are related via @c SG_BASE and/or
512 // * @c DATAVECTOR_BASE, then you shouldn't need to explicitly make a symlink;
513 // * that should happen automatically.
514 // *
515 // * If a @c U* is not convertable to a @c T* via C++ rules, then you likely
516 // * will be, at best, relying on undefined behavior. You will probably
517 // * get warnings from the undefined behavior sanitizer when if you try
518 // * to dereference the @c U*.
519 // *
520 // * This usage is here mainly to assist in migrating some existing
521 // * patterns to MT. You should think several times before using
522 // * in new code.
523 // */
524 // template <class U>
525 // StatusCode symLink (const WriteHandleKey<U>& key);
526
527
528private:
529 // /**
530 // * @brief Return the cached pointer directly.
531 // *
532 // * If it is null, throw ExcNullWriteHandle.
533 // */
534 // pointer_type checkedCachedPtr();
535
536
537 // /**
538 // * @brief Helper for record.
539 // * @param data The object to record.
540 // * @param isConst If true, record the object as const.
541 // * @param returnExisting Allow an existing object.
542 // */
543 // template <class U>
544 // StatusCode doRecord (U data,
545 // bool isConst,
546 // bool returnExisting);
547
548
549 // /**
550 // * @brief Helper for put.
551 // * @param ctx The event context, or nullptr to use the current context.
552 // * @param data The object to record.
553 // * @param returnExisting Allow an existing object.
554 // * @param[out] store The store being used.
555 // *
556 // * Unlike record(), this does not change the handle object.
557 // * That means that one will not be able to get the object back
558 // * by dereferencing the handle.
559 // * Returns the object placed in the store, or nullptr if there
560 // * was an error.
561 // * If there was already an object in the store with the given key,
562 // * then return null, unless @c returnExisting is true, in which case
563 // * return success. In either case, @c data is destroyed.
564 // */
565 // template <class U>
566 // const_pointer_type doPut (const EventContext* ctx,
567 // U data,
568 // bool returnExisting,
569 // IProxyDict* & store) const;
570
571
572 // /**
573 // * @brief Helper for recording an object and its auxiliary store to the store.
574 // * @param ctx The event context, or nullptr to use the current context.
575 // * @param data The object to record.
576 // * @param auxstore Auxiliary store object.
577 // *
578 // * Unlike record(), this does not change the handle object.
579 // * That means that one will not be able to get the object back
580 // * by dereferencing the handle.
581 // * Returns the object placed in the store, or nullptr if there
582 // * was an error.
583 // * If there was already an object in the store with the given key,
584 // * then return null, and the objects passed in are destroyed.
585 // */
586 // template <class AUXSTORE>
587 // typename WriteHandle<T>::const_pointer_type
588 // doPut (const EventContext* ctx,
589 // std::unique_ptr<T> data,
590 // std::unique_ptr<AUXSTORE> auxstore) const;
591
592
593 // /**
594 // * @brief Helper for recording an object and its auxiliary store to the store.
595 // * @param ctx The event context, or nullptr to use the current context.
596 // * @param data The object to record.
597 // * @param auxstore Auxiliary store object.
598 // *
599 // * Unlike record(), this does not change the handle object.
600 // * That means that one will not be able to get the object back
601 // * by dereferencing the handle.
602 // * Returns the object placed in the store, or nullptr if there
603 // * was an error.
604 // * If there was already an object in the store with the given key,
605 // * then return null, and the objects passed in are destroyed.
606 // */
607 // template <class AUXSTORE>
608 // typename WriteHandle<T>::const_pointer_type
609 // doPut (const EventContext* ctx,
610 // std::unique_ptr<const T> data,
611 // std::unique_ptr<const AUXSTORE> auxstore) const;
612
613
614 // /**
615 // * @brief Record an object and its auxiliary store to the store.
616 // * @param data The object to record.
617 // * @param auxstore Auxiliary store object.
618 // * @param isConst If true, record the objects as const.
619 // */
620 // template <class AUXSTORE>
621 // StatusCode
622 // record (std::unique_ptr<T> data,
623 // std::unique_ptr<AUXSTORE> auxstore,
624 // bool isConst);
625
626
627private:
628 // /// If non-null, then we need to lock the associated aux store object
629 // /// when we're deleted.
630 // ///
631 // /// This is set when we record an object along with the associated aux const
632 // /// with the const flag set (the default). Recall that for a const record,
633 // /// we want to support the semantics that you can get a non-const pointer
634 // /// back from the handle as long as it exists, to finish initialization
635 // /// of the object. For an aux store, though, just getting back a non-const
636 // /// pointer is not sufficient, since the store will have been locked
637 // /// at the time of the record, preventing changes to the store.
638 // ///
639 // /// So if we're meant to record a const aux store object, we don't actually
640 // /// set it const on the record, but instead set this and do the
641 // /// setConst in the destructor.
642 // SG::DataProxy* m_lockAuxPending = nullptr;
643
645 T *m_ptr {nullptr};
646};
647
648
656template <class T>
658
659
671template <class T>
673 const EventContext& ctx);
674
675
676} /* namespace SG */
677
678
680
681
682// #ifndef NO_LEGACY_HANDLES
683// namespace SG {
684// template <class T>
685// using WVar = WriteHandle<T>;
686// }
687// #endif
688
689#endif
690
691#endif
Base class for VarHandle classes.
Property holding a SG store/key/clid from which a WriteHandle is made.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Handle class for recording to StoreGate.
virtual const std::string & key() const =0
void * m_ptr
The object to which we are bound.
std::string store() const
Return the name of the store holding the object we are proxying.
Property holding a SG store/key/clid from which a WriteHandle is made.
WriteHandle()
Default constructor.
WriteHandle & operator=(const WriteHandle &rhs)
Assignment operator.
~WriteHandle()
Destructor.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
const_pointer_type put(std::unique_ptr< T > data, bool returnExisting=false) const
Record an object to the store.
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
reference_type operator*()
Dereference the pointer.
::StatusCode StatusCode
StatusCode definition for legacy code.
Forward declaration.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
unsigned long long T