KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
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 "KVDataRepository.h"
9
11
12
13// BEGIN_HTML <!--
14/* -->
15<h2>KVFzDataReader</h2>
16<h4>Read FAZIA DAQ files</h4>
17<!-- */
18// --> END_HTML
20
21DAQ::FzEventSet fFzEvSet;
22
23
25
27{
28 google::protobuf::io::CodedInputStream codedIStream((const uint8_t*)(fBuffer + fEvOffset), fEvSize);
29 if (!fFzEvSet.ParseFromCodedStream(&codedIStream)) {
30 Error("parse_event_from_message", "problem parsing event set");
31 return false;
32 }
33 if (fFzEvSet.ev_size() > 1) {
34 Error("parse_event_from_message", "FzEventSet with %d events", fFzEvSet.ev_size());
35 return false;
36 }
37 return true;
38}
39
40
41
44
46{
47 // if previous read reached the end of a file, we try to open the next file in the list
48
50 TObject* o = fFileListIterator->operator()();
51 if (!o) return false; // no more files to read
52 // open next file
53 KVString url = fFullFilePath + o->GetName();
54 open_file(url);
55 }
57}
58
59
60
65
67 : KVProtobufDataReader(bufSiz), fListOfFiles(nullptr), fFileListIterator(nullptr)
68{
69 // Open set of FAZIA DAQ files for reading. Filepath URL will be passed to TFile::Open
70 // therefore can use same plugins eg. "root://" etc.
71 // Note: buffer size given as Int_t, as this is argument type required by TFile::ReadBuffer
72
73 fFullFilePath = filepath;
74 fFullFilePath += "/";
75#if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
76 fListOfFiles.reset(gDataRepository->GetDirectoryListing(gDataSet, "raw", gSystem->BaseName(filepath)));
77#else
79 fListOfFiles = gDataRepository->GetDirectoryListing(gDataSet, "raw", gSystem->BaseName(filepath));
80#endif
81 run_number = gDataSet->GetAvailableRunsFile("raw")->IsRunFileName(gSystem->BaseName(filepath));
82
83 // each run has a set of files with names like
84 // FzEventSet-1490951242-9758.pb
85 // FzEventSet-1490951250-9759.pb
86 // FzEventSet-1490951257-9760.pb
87 // they should be read in sequential (chronological) order. the directory listing given above
88 // may not automatically be in the right order, therefore we sort the file list according to
89 // the final number (i.e. 9758, 9759, 9760 in the example above)
90
91 std::map<int, std::string> filelist;
92#if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
93 fFileListIterator.reset(new TIter(fListOfFiles.get()));
94#else
97#endif
98 KVBase* b;
99 while ((b = (KVBase*)fFileListIterator->operator()())) {
100 KVString bb(b->GetName());
101 bb.Begin("-.");
102 for (int i = 0; i < 2; ++i) bb.Next();
103 filelist[bb.Next().Atoi()] = b->GetName();
104 }
105 fListOfFiles->Clear();
106 for (std::map<int, std::string>::iterator mapit = filelist.begin(); mapit != filelist.end(); ++mapit) {
107 fListOfFiles->Add(new KVBase((*mapit).second.c_str()));
108 }
109 fListOfFiles->ls();
110 fFileListIterator->Reset();
111 // open first file
112 KVString url = fFullFilePath + fFileListIterator->operator()()->GetName();
113 open_file(url);
114}
115
116
117
119
120const DAQ::FzEvent& KVFzDataReader::get_fazia_event() const
121{
122 return fFzEvSet.ev(0);
123}
124
125
126
128
130{
131 return new KVFzDataReader(filename);
132}
133
134
135//____________________________________________________________________________//
136
137
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
R__EXTERN TSystem * gSystem
Int_t IsRunFileName(const Char_t *filename)
Base class for KaliVeda framework.
Definition KVBase.h:142
KVBase()
Default constructor.
Definition KVBase.cpp:317
virtual KVUniqueNameList * GetDirectoryListing(const KVDataSet *dataset, const Char_t *datatype="", const Char_t *subdir="")
KVAvailableRunsFile * GetAvailableRunsFile(const Char_t *type) const
Definition KVDataSet.cpp:50
Handle FAZIA protobuf-format raw data files.
KVString fFullFilePath
full path to files including "root:" etc. and "/run000000/"
std::unique_ptr< 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="")
std::unique_ptr< TIter > fFileListIterator
iterator for file list
bool read_buffer()
if previous read reached the end of a file, we try to open the next file in the list
bool parse_event_from_message()
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
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
const char * GetName() const override
virtual const char * GetName() const
virtual void Error(const char *method, const char *msgfmt,...) const
Int_t Atoi() const
virtual const char * BaseName(const char *pathname)
ClassImp(TPyArg)