BmnRoot
Loading...
Searching...
No Matches
BmnFunctionAna.cxx
Go to the documentation of this file.
1#include "BmnFunctionAna.h"
2#include "DstRunHeader.h"
3#include "BmnNewFieldMap.h"
4#include "BmnFieldMapSym3.h"
5
6#include "FairLogger.h"
7
8#include "TSystem.h"
9#include "TFile.h"
10
11#include <iostream>
12using namespace std;
13
14// get magnetic field from a specified DST file
15// fileName: DST file path [in]
16// fieldScale: magnetic field scale [out]; fieldType: magnetic field type [out]
17// returns magnetic field, nullptr - if some errors occured
18FairField* BmnFunctionAna::GetDSTField(TString dstFileName, Double_t& fieldScale, Int_t& fieldType)
19{
20 gSystem->ExpandPathName(dstFileName);
21 if (gSystem->AccessPathName(dstFileName.Data()) == true)
22 {
23 LOG(error)<<"GetDSTField: no specified file: "<<dstFileName;
24 return nullptr;
25 }
26
27 TFile* dst_file = TFile::Open(dstFileName.Data());
28 if (dst_file->IsZombie())
29 {
30 LOG(error)<<"GetDSTField: opening the input file failed: "<<dstFileName;
31 return nullptr;
32 }
33
34 // Get a pointer to "DstRunHeader"
35 DstRunHeader* pRunHeader = dynamic_cast<DstRunHeader*>(dst_file->Get("DstRunHeader"));
36 if (!pRunHeader)
37 {
38 LOG(error)<<"GetDSTField: No 'DstRunHeader' branch found in the input file"<<dstFileName;
39 dst_file->Close();
40 return nullptr;
41 }
42
43 // get field type and scale from the 'DstRunHeader' object
44 fieldType = pRunHeader->GetFieldType();
45 fieldScale = pRunHeader->GetFieldScale();
46 TString fieldName = pRunHeader->GetFieldName();
47 FairField* magField = nullptr;
48 switch (fieldType)
49 {
50 case 1:
51 {
52 magField = new BmnNewFieldMap(fieldName.Data());
53 (dynamic_cast<BmnNewFieldMap*>(magField))->SetScale(fieldScale);
54 magField->Init();
55 break;
56 }
57 case 3:
58 {
59 magField = new BmnFieldMapSym3(fieldName.Data());
60 (dynamic_cast<BmnFieldMapSym3*>(magField))->SetScale(fieldScale);
61 magField->Init();
62 break;
63 }
64 default:
65 LOG(error)<<"GetDSTField: This type of the magnetic field is not supported: "<<fieldType;
66 }
67
68 dst_file->Close();
69 return magField;
70}
static FairField * GetDSTField(TString fileName, Double_t &fieldScale, Int_t &fieldType)
TString GetFieldName()
Double_t GetFieldScale()
Int_t GetFieldType()
STL namespace.