KaliVeda
Toolkit for HIC analysis
KVFzDataReader.cpp
1 //Created by KVClassFactory on Mon Jan 14 12:10:22 2019
2 //Author: John Frankland,,,
3 
4 #include "KVFzDataReader.h"
5 
6 #include <google/protobuf/io/coded_stream.h>
7 #include "FzEventSet.pb.h"
8 #include "KVDataSetRepository.h"
9 #include "KVDataSet.h"
10 #include "KVAvailableRunsFile.h"
11 
13 
14 // BEGIN_HTML <!--
16 /* -->
17 <h2>KVFzDataReader</h2>
18 <h4>Read FAZIA DAQ files</h4>
19 <!-- */
20 // --> END_HTML
22 
23 DAQ::FzEventSet fFzEvSet;
24 
25 
27 
29 {
30  google::protobuf::io::CodedInputStream codedIStream((const uint8_t*)(fBuffer + fEvOffset), fEvSize);
31  if (!fFzEvSet.ParseFromCodedStream(&codedIStream)) {
32  Error("parse_event_from_message", "problem parsing event set");
33  return false;
34  }
35  if (fFzEvSet.ev_size() > 1) {
36  Error("parse_event_from_message", "FzEventSet with %d events", fFzEvSet.ev_size());
37  return false;
38  }
39  return true;
40 }
41 
42 
43 
46 
48 {
49  // if previous read reached the end of a file, we try to open the next file in the list
50 
51  if (fReachedEndOfFile) {
52  TObject* o = fFileListIterator->operator()();
53  if (!o) return false; // no more files to read
54  // open next file
55  KVString url = fFullFilePath + o->GetName();
56  open_file(url);
57  }
59 }
60 
61 
62 
67 
69  : KVProtobufDataReader(bufSiz), fFileListIterator{}
70 {
71  // Open set of FAZIA DAQ files for reading. Filepath URL will be passed to TFile::Open
72  // therefore can use same plugins eg. "root://" etc.
73  // Note: buffer size given as Int_t, as this is argument type required by TFile::ReadBuffer
74 
75  fFullFilePath = filepath;
76  fFullFilePath += "/";
77  fListOfFiles = dynamic_cast<KVDataSetRepository*>(gDataRepository)->GetDirectoryListing(gDataSet, "raw", gSystem->BaseName(filepath));
78  run_number = gDataSet->GetAvailableRunsFile("raw")->IsRunFileName(gSystem->BaseName(filepath)).value().first;
79 
80  // each run has a set of files with names like
81  // FzEventSet-1490951242-9758.pb
82  // FzEventSet-1490951250-9759.pb
83  // FzEventSet-1490951257-9760.pb
84  // they should be read in sequential (chronological) order. the directory listing given above
85  // may not automatically be in the right order, therefore we sort the file list according to
86  // the final number (i.e. 9758, 9759, 9760 in the example above)
87 
88  std::map<int, std::string> filelist;
89 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
91 #else
94 #endif
95  KVBase* b;
96  while ((b = (KVBase*)fFileListIterator->operator()())) {
97  KVString bb(b->GetName());
98  bb.Begin("-.");
99  for (int i = 0; i < 2; ++i) bb.Next();
100  filelist[bb.Next().Atoi()] = b->GetName();
101  }
103  for (std::map<int, std::string>::iterator mapit = filelist.begin(); mapit != filelist.end(); ++mapit) {
104  fListOfFiles.Add(new KVBase((*mapit).second.c_str()));
105  }
106  fListOfFiles.ls();
107  fFileListIterator->Reset();
108  // open first file
109  KVString url = fFullFilePath + fFileListIterator->operator()()->GetName();
110  open_file(url);
111 }
112 
113 
114 
116 
117 const DAQ::FzEvent& KVFzDataReader::get_fazia_event() const
118 {
119  return fFzEvSet.ev(0);
120 }
121 
122 
123 
125 
127 {
128  return new KVFzDataReader(filename);
129 }
130 
131 
132 //____________________________________________________________________________//
133 
134 
int Int_t
#define SafeDelete(p)
char Char_t
const char Option_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
R__EXTERN TSystem * gSystem
std::optional< run_index_t > IsRunFileName(const Char_t *filename)
Base class for KaliVeda framework.
Definition: KVBase.h:140
void Error(const char *method, const char *msgfmt,...) const override
colourised errors (red) !
Definition: KVBase.cpp:1686
KVBase()
Default constructor.
Definition: KVBase.cpp:329
A repository for experimental datasets.
KVAvailableRunsFile * GetAvailableRunsFile(const TString &type) const
Definition: KVDataSet.cpp:49
Handle FAZIA protobuf-format raw data files.
KVString fFullFilePath
full path to files including "root:" etc. and "/run000000/"
KVUniqueNameList fListOfFiles
list of files for run
const DAQ::FzEvent & get_fazia_event() const
int run_number
run number deduced from filename
static KVFzDataReader * Open(const Char_t *filename, Option_t *opt="")
bool read_buffer() override
if previous read reached the end of a file, we try to open the next file in the list
std::unique_ptr< TIter > fFileListIterator
iterator for file list
bool parse_event_from_message() override
Read Google Protobuf DAQ files.
void open_file(const Char_t *filepath)
UInt_t fEvSize
size of next event in buffer
virtual bool read_buffer()
read a buffer from the file
bool fReachedEndOfFile
true when we have read all bytes from file
char * fBuffer
current buffer
ptrdiff_t fEvOffset
next position to read in buffer
void Clear(Option_t *option="") override
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
void Add(TObject *obj) override
void ls(Option_t *option="") const override
const char * GetName() const override
virtual const char * GetName() const
Int_t Atoi() const
virtual const char * BaseName(const char *pathname)
ClassImp(TPyArg)