FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairOnlineSink.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
16 #ifndef FAIRONLINESINK_H_
17 #define FAIRONLINESINK_H_
18 
19 #include "FairSink.h"
20 
21 #include <Rtypes.h>
22 #include <string>
23 #include <typeinfo>
24 
25 class FairEventHeader;
26 class FairMQRunDevice;
27 class TObject;
28 class TTree;
29 
30 class FairOnlineSink : public FairSink
31 {
32  public:
34  virtual ~FairOnlineSink() {}
35 
36  virtual Bool_t InitSink() { return kTRUE; }
37  virtual void Close() {}
38  virtual void Reset() {}
39 
40  virtual Sink_Type GetSinkType() { return kONLINESINK; }
41 
42  virtual void FillEventHeader(FairEventHeader* /* feh */) {}
43 
44  virtual void SetOutTree(TTree* /* fTree */) { return; }
45 
46  virtual void Fill();
47 
48  virtual Int_t Write(const char* /* name=0 */, Int_t /* option=0 */, Int_t /* bufsize=0 */) { return -1; }
49 
50  virtual void RegisterImpl(const char*, const char*, void*);
51  virtual void RegisterAny(const char* brname, const std::type_info& oi, const std::type_info& pi, void* obj);
52 
53  virtual void WriteFolder() {}
54  virtual bool CreatePersistentBranchesAny() { return false; }
55 
56  virtual void WriteObject(TObject* /* f */, const char*, Int_t /* option = 0 */) {}
57  virtual void WriteGeometry() {}
58 
59  virtual void SetMQRunDevice(FairMQRunDevice* mrs) { fMQRunDevice = mrs; }
60  virtual FairMQRunDevice* GetMQRunDevice() { return fMQRunDevice; }
61 
62  virtual FairSink* CloneSink();
63 
64  bool IsPersistentBranchAny(const char* name);
65 
66  /* /// Returns a default object for a branch or looks it up when it exists already. */
67  /* /// Returns nullptr when the branch does not exist or looking up with wrong type. */
68  /* /// The returned default object will be filled with data by the framework. */
69  template<typename T>
70  T GetPersistentBranchAny(const char* name) const;
71 
72  private:
73  FairMQRunDevice* fMQRunDevice;
74 
75  // private helper function to emit a warning
76  void EmitPersistentBranchWrongTypeWarning(const char* brname, const char* typen1, const char* typen2) const;
77 
79  FairOnlineSink& operator=(const FairOnlineSink&);
80 };
81 
82 // try to retrieve an object address from the registered branches/names
83 template<typename T>
84 T FairOnlineSink::GetPersistentBranchAny(const char* brname) const
85 {
86  static_assert(std::is_pointer<T>::value, "Return type of GetPersistentBranchAny has to be a pointer");
87  using P = typename std::remove_pointer<T>::type;
88  auto iter = fPersistentBranchesMap.find(brname);
89  if (iter != fPersistentBranchesMap.end()) {
90  // verify type consistency
91  if (typeid(P).hash_code() != iter->second->origtypeinfo.hash_code()) {
92  EmitPersistentBranchWrongTypeWarning(brname, typeid(P).name(), iter->second->origtypeinfo.name());
93  return nullptr;
94  }
95  return static_cast<T>(iter->second->ptraddr);
96  }
97  return nullptr;
98 }
99 
100 #endif /* FAIRONLINESIK_H_ */
Sink_Type
Definition: FairSink.h:29
virtual void WriteObject(TObject *, const char *, Int_t)
virtual void WriteFolder()
virtual Bool_t InitSink()
virtual bool CreatePersistentBranchesAny()
virtual ~FairOnlineSink()
T GetPersistentBranchAny(const char *name) const
virtual Int_t Write(const char *, Int_t, Int_t)
virtual FairMQRunDevice * GetMQRunDevice()
virtual void RegisterImpl(const char *, const char *, void *)
virtual void SetOutTree(TTree *)
virtual void RegisterAny(const char *brname, const std::type_info &oi, const std::type_info &pi, void *obj)
virtual void Reset()
virtual void Close()
virtual void SetMQRunDevice(FairMQRunDevice *mrs)
virtual void WriteGeometry()
virtual void FillEventHeader(FairEventHeader *)
virtual void Fill()
bool IsPersistentBranchAny(const char *name)
std::map< std::string, std::unique_ptr< TypeAddressPair const > > fPersistentBranchesMap
Definition: FairSink.h:89
virtual FairSink * CloneSink()
virtual Sink_Type GetSinkType()