KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVFzDataReader.cpp
Go to the documentation of this file.
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 // BEGIN_HTML <!--
14 /* -->
15 <h2>KVFzDataReader</h2>
16 <h4>Read FAZIA DAQ files</h4>
17 <!-- */
18 // --> END_HTML
20 
21 DAQ::FzEventSet fFzEvSet;
22 
23 
25 
26 bool KVFzDataReader::parse_event_from_message()
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 
49  if (fReachedEndOfFile) {
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)
77 #else
80 #endif
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 
120 const 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
uint8_t
std::string fBuffer
KVDataRepository * gDataRepository
KVDataSet * gDataSet
Definition: KVDataSet.cpp:30
DAQ::FzEventSet fFzEvSet
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define SafeDelete(p)
#define b(i)
char Char_t
const char Option_t
R__EXTERN TSystem * gSystem
Int_t IsRunFileName(const Char_t *filename)
Base class for KaliVeda framework.
Definition: KVBase.h:135
KVBase()
Default constructor.
Definition: KVBase.cpp:320
virtual KVUniqueNameList * GetDirectoryListing(const KVDataSet *dataset, const Char_t *datatype="", const Char_t *subdir="")
KVAvailableRunsFile * GetAvailableRunsFile(const Char_t *type) const
Definition: KVDataSet.cpp:49
Handle FAZIA protobuf-format raw data files.
KVString fFullFilePath
full path to files including "root:" etc. and "/run000000/"
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()
if previous read reached the end of a file, we try to open the next file in the list
unique_ptr< KVUniqueNameList > fListOfFiles
list of files for run
unique_ptr< TIter > fFileListIterator
iterator for file list
Read Google Protobuf DAQ files.
void open_file(const Char_t *filepath)
virtual bool read_buffer()
read a buffer from the file
bool fReachedEndOfFile
true when we have read all bytes from file
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
void Begin(TString delim) const
Definition: KVString.cpp:562
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:675
virtual const char * GetName() const
virtual const char * GetName() const
Int_t Atoi() const
virtual const char * BaseName(const char *pathname)
void Error(const char *location, const char *va_(fmt),...)