KaliVeda
Toolkit for HIC analysis
KVMFMDataFileReader.cpp
1 //Created by KVClassFactory on Fri Apr 6 16:33:15 2018
2 //Author: John Frankland,,,
3 
4 #include "KVMFMDataFileReader.h"
5 #include "TSystem.h"
6 #include "TError.h"
7 #include "MFMXmlFileHeaderFrame.h"
8 
10 
11 
12 
27  : KVRawDataReader(), MFMFileReader(filepath, bufsize * 1024 * 1024)
28 {
29  // Open the datafile with given path
30  //
31  // bufsize = buffer size [MB] - default = 512
32  //
33  // Read the first frame in the file (should be a MFMXmlFileHeaderFrame) and extract informations
34  //
35  // If the variable
36  // KVMFMDataFileReader.ActionsDirectory
37  // has been set, it will be used to search for EBYEDAT actions files in order to
38  // decode any EBYEDAT data in the file
39  //
40  // If the file is not opened successfully, this object will be made a zombie (check IsZombie())
41 
42  if(!IsReady())
43  {
44  MakeZombie();
45  return;
46  }
47  std::string actions_dir = gEnv->GetValue("KVMFMDataFileReader.ActionsDirectory", "");
48  if (actions_dir != "") SetActionsDirectory(actions_dir);
49  std::string actions_expname = gEnv->GetValue("KVMFMDataFileReader.ActionsExpName", "");
50  if (actions_expname != "") SetActionsExpName(actions_expname);
51  if (!ReadNextFrame()) {
52  Error("KVMFMDataFileReader", "Cannot read file %s", filepath);
53  MakeZombie();
54  return;
55  }
56  if (GetFrameReadType() != MFM_XML_FILE_HEADER_FRAME_TYPE) {
57  Warning("KVMFMDataFileReader", "First frame in file is not MFM_XML_FILE_HEADER_FRAME_TYPE: type is %s",
58  GetFrameReadTypeSymbol().c_str());
59  }
60  else {
61  GetFrameRead().Print();
62  fRunInfos.SetValue("ExperimentName", GetFrameRead<MFMXmlFileHeaderFrame>().GetExperimentName());
63  fRunInfos.SetValue("FileName", GetFrameRead<MFMXmlFileHeaderFrame>().GetFileName());
64  fRunInfos.SetValue("FileCreationTime", GetFrameRead<MFMXmlFileHeaderFrame>().GetFileCreationTime());
65  fRunInfos.SetValue("RunNumber", GetFrameRead<MFMXmlFileHeaderFrame>().GetRunNumber());
66  fRunInfos.SetValue("RunIndex", GetFrameRead<MFMXmlFileHeaderFrame>().GetRunIndex());
67  fRunInfos.SetValue("RunStartTime", GetFrameRead<MFMXmlFileHeaderFrame>().GetRunStartTime());
68  }
69 }
70 
71 
72 
74 
76 {
77  TString fp(filepath);
78  if (fp.Contains('$')) gSystem->ExpandPathName(fp);
79  ::Info("KVMFMDataFileReader::Open", "Opening file %s...", fp.Data());
80  auto f = new KVMFMDataFileReader(fp);
81  if(f->IsZombie())
82  {
83  ::Warning("KVMFMDataFileReader::Open", "Failed to open file %s...", fp.Data());
84  delete f;
85  f=nullptr;
86  }
87  return f;
88 }
89 
90 
91 
95 
97 {
98  // Set directory in which to look for Ebyedat ACTIONS_* files
99  // Defaults to data directory
100  GetFrameLibrary().SetEbyedatActionsDirectory(d);
101 }
102 
103 
104 
110 
112 {
113  // Set experiment name for Ebyedat ACTIONS_* files.
114  //
115  // Setting this means that a single ACTIONS file will be looked for in the actions directory
116  // (set with SetActionsDirectory).
117  GetFrameLibrary().SetEbyedatExpName(e);
118 }
119 
120 
121 
125 
127 {
128  // Return run number of file currently being read.
129  // Only call once file has been successfully opened.
130 
131  return fRunInfos.GetIntValue("RunNumber");
132 }
133 
134 
135 
138 
140 {
141  // Returns full path to last ACTIONS file used to decode Ebyedat parameters
142  return GetFrameLibrary().GetLastEbyedatActionsFile().c_str();
143 }
144 
145 
146 #ifdef WITH_MESYTEC
147 
151 
152 void KVMFMDataFileReader::InitialiseMesytecConfig(const std::string& crate, const std::string& channels)
153 {
154  // Read the two files whose full paths are given as argument in order to set up the
155  // Mesytec crate config and module-channel-detector correspondence
156 
157 #ifndef MESYTEC_DATA_BUFFER_READER_NO_DEFINE_SETUP
158  mesytec::experimental_setup exp;
159  exp.read_crate_map(crate);
160  exp.read_detector_correspondence(channels);
161  MTEC_bufrdr.define_setup(exp);
162 #else
163  MTEC_bufrdr.read_crate_map(crate);
164  MTEC_bufrdr.read_detector_correspondence(channels);
165 #endif
166 }
167 
168 #endif
169 
int Int_t
#define d(i)
#define f(i)
#define e(i)
char Char_t
const char Option_t
R__EXTERN TEnv * gEnv
R__EXTERN TSystem * gSystem
void Warning(const char *method, const char *msgfmt,...) const override
Definition: KVBase.cpp:1696
Read MFM format acquisition data.
KVMFMDataFileReader(const Char_t *filepath, ULong64_t bufsize=512)
void SetActionsExpName(const string &)
void SetActionsDirectory(const string &)
TString GetPathToLastEbyedatActionsFile()
Returns full path to last ACTIONS file used to decode Ebyedat parameters.
Int_t GetRunNumberReadFromFile() const override
void InitialiseMesytecConfig(const std::string &crate, const std::string &channels)
static KVMFMDataFileReader * Open(const Char_t *filepath, Option_t *="")
mesytec::buffer_reader MTEC_bufrdr
Int_t GetIntValue(const Char_t *name) const
Abstract base class for reading raw (DAQ) data.
KVNameValueList fRunInfos
informations on run extracted from file
virtual const char * GetValue(const char *name, const char *dflt) const
virtual void Info(const char *method, const char *msgfmt,...) const
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual char * ExpandPathName(const char *path)
unsigned long long ULong64_t
RVec< PromoteType< T > > exp(const RVec< T > &v)
void Error(const char *location, const char *fmt,...)
std::string GetFileName(const clang::Decl &decl, const cling::Interpreter &interp)
void Warning(const char *location, const char *fmt,...)
ClassImp(TPyArg)