Project
Loading...
Searching...
No Matches
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
24class FairEventHeader;
25
31
32class FairSource : public TObject
33{
34 public:
35 FairSource();
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; }
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:
63};
64
65namespace {
66
67template<typename S>
68bool 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
Source_Type
Definition FairSource.h:27
@ kONLINE
Definition FairSource.h:28
@ kFILE
Definition FairSource.h:29
virtual Int_t CheckMaxEventNo(Int_t=0)
Definition FairSource.h:50
virtual void ReadBranchEvent(const char *, Int_t)
Definition FairSource.h:53
Int_t GetRunId() const
Definition FairSource.h:56
virtual Source_Type GetSourceType()=0
virtual ~FairSource()
virtual Bool_t SpecifyRunId()=0
virtual Int_t ReadEvent(UInt_t=0)=0
virtual void Reset()=0
virtual Bool_t Init()=0
virtual void ReadBranchEvent(const char *)
Definition FairSource.h:52
Int_t fRunId
Definition FairSource.h:59
virtual void Close()=0
virtual Bool_t ReInitUnpackers()=0
virtual Bool_t ActivateObjectAny(void **, const std::type_info &, const char *)
Definition FairSource.h:44
virtual void SetParUnpackers()=0
ClassDef(FairSource, 2)
virtual void FillEventHeader(FairEventHeader *feh)
virtual Bool_t ActivateObject(TObject **, const char *)
Definition FairSource.h:43
virtual Bool_t InitUnpackers()=0
void SetRunId(Int_t runId)
Definition FairSource.h:55
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"