FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairSource.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -----------------------------------------------------------------------------
9 // ----- -----
10 // ----- FairSource -----
11 // ----- Created 01.11.2013 by F. Uhlig -----
12 // ----- -----
13 // -----------------------------------------------------------------------------
14 
15 #ifndef FAIRSOURCE_H
16 #define FAIRSOURCE_H
17 
18 #include "FairLogger.h"
19 #include "TClass.h"
20 
21 #include <Rtypes.h>
22 #include <TObject.h>
23 
24 class FairEventHeader;
25 
27 {
30 };
31 
32 class FairSource : public TObject
33 {
34  public:
35  FairSource();
36  FairSource(const FairSource& source);
37  virtual ~FairSource();
38  virtual Bool_t Init() = 0;
39  virtual Int_t ReadEvent(UInt_t = 0) = 0;
40  virtual Bool_t SpecifyRunId() = 0;
41  virtual void Close() = 0;
42  virtual void Reset() = 0;
43  virtual Bool_t ActivateObject(TObject**, const char*) { return kFALSE; }
44  virtual Bool_t ActivateObjectAny(void**, const std::type_info&, const char*) { return kFALSE; }
45  virtual Source_Type GetSourceType() = 0;
46  virtual void SetParUnpackers() = 0;
47  virtual Bool_t InitUnpackers() = 0;
48  virtual Bool_t ReInitUnpackers() = 0;
50  virtual Int_t CheckMaxEventNo(Int_t = 0) { return -1; }
52  virtual void ReadBranchEvent(const char*) { return; }
53  virtual void ReadBranchEvent(const char*, Int_t) { return; }
54  virtual void FillEventHeader(FairEventHeader* feh);
55  void SetRunId(Int_t runId) { fRunId = runId; }
56  Int_t GetRunId() const { return fRunId; }
57 
58  protected:
59  Int_t fRunId;
60 
61  public:
62  ClassDef(FairSource, 2);
63 };
64 
65 namespace {
66 
67 template<typename S>
68 bool ActivateObjectAnyImpl(S* source, void** obj, const std::type_info& info, const char* brname)
69 {
70  // we check if the types match at all
71  auto br = source->GetBranch(brname);
72  if (!br) {
73  // branch not found in source
74  return false;
75  }
76 
77  // look up the TClass and resulting typeid stored in this branch
78  auto cl = TClass::GetClass(br->GetClassName());
79  if (!cl) {
80  // class not found
81  return false;
82  }
83 
84  auto storedtype = cl->GetTypeInfo();
85 
86  // check consistency of types
87  if (info.hash_code() != storedtype->hash_code()) {
88  LOG(info) << "Trying to read from branch " << brname << " with wrong type " << info.name()
89  << " (expected: " << storedtype->name() << ")\n";
90  return false;
91  }
92  source->SetBranchStatus(brname, 1);
93  // force to use the (void*) interface which is non-checking
94  source->SetBranchAddress(brname, (void*)obj);
95  return true;
96 }
97 
98 } // namespace
99 
100 #endif
virtual void SetParUnpackers()=0
virtual Bool_t ActivateObjectAny(void **, const std::type_info &, const char *)
Definition: FairSource.h:44
ClassDef(FairSource, 2)
virtual Int_t ReadEvent(UInt_t=0)=0
virtual Source_Type GetSourceType()=0
virtual void FillEventHeader(FairEventHeader *feh)
Definition: FairSource.cxx:31
virtual void ReadBranchEvent(const char *)
Definition: FairSource.h:52
virtual void ReadBranchEvent(const char *, Int_t)
Definition: FairSource.h:53
void SetRunId(Int_t runId)
Definition: FairSource.h:55
Int_t fRunId
Definition: FairSource.h:59
virtual Bool_t InitUnpackers()=0
Source_Type
Definition: FairSource.h:26
virtual Bool_t SpecifyRunId()=0
virtual void Close()=0
virtual Bool_t Init()=0
virtual Int_t CheckMaxEventNo(Int_t=0)
Definition: FairSource.h:50
Int_t GetRunId() const
Definition: FairSource.h:56
virtual Bool_t ReInitUnpackers()=0
virtual ~FairSource()
Definition: FairSource.cxx:29
virtual void Reset()=0
virtual Bool_t ActivateObject(TObject **, const char *)
Definition: FairSource.h:43