FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairLmdSource.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -----------------------------------------------------------------------------
9 // ----- -----
10 // ----- FairLmdSource -----
11 // ----- Created 12.04.2013 by D.Kresan -----
12 // -----------------------------------------------------------------------------
13 
14 #include "FairLmdSource.h"
15 
16 #include "FairLogger.h"
17 
18 #include <TIterator.h>
19 #include <TList.h>
20 #include <TObjString.h>
21 #include <TRegexp.h>
22 #include <TSystem.h>
23 #include <TSystemDirectory.h>
24 #include <TSystemFile.h>
25 
27  : FairMbsSource()
28  , fCurrentFile(0)
29  , fNEvent(0)
30  , fCurrentEvent(0)
31  , fFileNames(new TList())
32  , fxInputChannel(nullptr)
33  , fxEvent(nullptr)
34  , fxBuffer(nullptr)
35  , fxEventData(nullptr)
36  , fxSubEvent(nullptr)
37  , fxInfoHeader(nullptr)
38 {}
39 
41  : FairMbsSource(source)
42  , fCurrentFile(source.GetCurrentFile())
43  , fNEvent(0)
44  , fCurrentEvent(0)
45  , fFileNames(new TList())
46  , fxInputChannel(nullptr)
47  , fxEvent(nullptr)
48  , fxBuffer(nullptr)
49  , fxEventData(nullptr)
50  , fxSubEvent(nullptr)
51  , fxInfoHeader(nullptr)
52 {}
53 
55 {
56  fFileNames->Delete();
57  delete fFileNames;
58 }
59 
60 void FairLmdSource::AddFile(TString fileName)
61 {
62  FileStat_t buf;
63  if (1 == gSystem->GetPathInfo(fileName.Data(), buf)) {
64  LOG(warn) << "FairLmdSource: not found: " << fileName;
65  return;
66  }
67 
68  TObjString* str = new TObjString(fileName);
69  fFileNames->Add(str);
70 }
71 
72 void FairLmdSource::AddPath(TString dir, TString wildCard)
73 {
74  FileStat_t buf;
75  if (1 == gSystem->GetPathInfo(dir.Data(), buf)) {
76  LOG(warn) << "FairLmdSource: not found: " << dir;
77  return;
78  }
79 
80  TRegexp* re = new TRegexp(wildCard.Data(), kTRUE);
81  TSystemDirectory* sdir = new TSystemDirectory("dir", dir.Data());
82  TString dname(dir);
83  if (!dname.EndsWith("/")) {
84  dname += "/";
85  }
86  TList* list = sdir->GetListOfFiles();
87 
88  TIterator* iter = list->MakeIterator();
89  TSystemFile* file;
90  TString name;
91  while (nullptr != (file = static_cast<TSystemFile*>(iter->Next()))) {
92  name = file->GetName();
93  if (name.Contains(*re)) {
94  name = dname + name;
95  AddFile(name);
96  }
97  }
98 
99  list->Delete();
100 }
101 
103 {
104  if (fFileNames->GetSize() == 0) {
105  return kFALSE;
106  }
107 
108  TString name = (static_cast<TObjString*>(fFileNames->At(fCurrentFile)))->GetString();
109  if (!OpenNextFile(name)) {
110  return kFALSE;
111  }
112 
113  fCurrentFile += 1;
114 
115  // Init Counters
116  fNEvent = fCurrentEvent = 0;
117 
118  return kTRUE;
119 }
120 
121 Bool_t FairLmdSource::OpenNextFile(TString fileName)
122 {
123  Int_t inputMode = GETEVT__FILE;
125  void* headptr = &fxInfoHeader;
126  INTS4 status;
127 
128  LOG(info) << "File " << fileName << " will be opened.";
129 
130  status = f_evt_get_open(
131  inputMode, const_cast<char*>(fileName.Data()), fxInputChannel, static_cast<Char_t**>(headptr), 1, 1);
132 
133  if (status) {
134  LOG(error) << "File " << fileName << " opening failed.";
135  return kFALSE;
136  }
137 
138  LOG(info) << "File " << fileName << " opened.";
139 
140  // Decode File Header
141  // Bool_t result = Unpack((Int_t*)fxInfoHeader, sizeof(s_filhe), -4, -4, -4, -4, -4);
142  Unpack(reinterpret_cast<Int_t*>(fxInfoHeader), sizeof(s_filhe), -4, -4, -4, -4, -4);
143 
144  return kTRUE;
145 }
146 
148 {
149  void* evtptr = &fxEvent;
150  void* buffptr = &fxBuffer;
151 
152  Int_t status = f_evt_get_event(fxInputChannel, static_cast<INTS4**>(evtptr), static_cast<INTS4**>(buffptr));
153  // Int_t fuEventCounter = fxEvent->l_count;
154  // Int_t fCurrentMbsEventNo = fuEventCounter;
155 
156  if (GETEVT__SUCCESS != status) {
157 
158  LOG(info) << "FairMbsStreamSource::ReadEvent()";
159 
160  CHARS* sErrorString = nullptr;
161  f_evt_error(status, sErrorString, 0);
162 
163  if (fCurrentFile >= fFileNames->GetSize()) {
164  return 1;
165  }
166 
167  if (GETEVT__NOMORE == status) {
168  Close();
169  }
170 
171  TString name = (static_cast<TObjString*>(fFileNames->At(fCurrentFile)))->GetString();
172  if (!OpenNextFile(name)) {
173  return 1;
174  } else {
175  fCurrentFile += 1;
176  return ReadEvent();
177  }
178  }
179 
180  // Store Start Times
181  if (fCurrentEvent == 0)
182  Unpack(reinterpret_cast<Int_t*>(fxBuffer), sizeof(s_bufhe), -4, -4, -4, -4, -4);
183 
184  // Decode event header
185  Bool_t result = kFALSE;
186  /*Bool_t result = */ Unpack(reinterpret_cast<Int_t*>(fxEvent), sizeof(s_ve10_1), -2, -2, -2, -2, -2);
187 
188  Int_t nrSubEvts = f_evt_get_subevent(fxEvent, 0, nullptr, nullptr, nullptr);
189  Int_t sebuflength;
190  Short_t setype;
191  Short_t sesubtype;
192  Short_t seprocid;
193  Short_t sesubcrate;
194  Short_t secontrol;
195 
196  LOG(debug2) << "FairLmdSource::ReadEvent => Found " << nrSubEvts << " Sub-event ";
197  // if (fCurrentEvent%10000==0)
198  // cout << " -I- LMD_ANA: evt# " << fCurrentEvent << " n_subevt# " << nrSubEvts << " evt processed# " << fNEvent
199  // << " : " << fxEvent->l_count << endl;
200 
201  // Int_t* SubEventDataPtr = new Int_t;
202  for (Int_t i = 1; i <= nrSubEvts; i++) {
203  void* SubEvtptr = &fxSubEvent;
204  void* EvtDataptr = &fxEventData;
205  Int_t nrlongwords;
206  status = f_evt_get_subevent(
207  fxEvent, i, static_cast<Int_t**>(SubEvtptr), static_cast<Int_t**>(EvtDataptr), &nrlongwords);
208  if (status) {
209  return 1;
210  }
211  sebuflength = nrlongwords;
212  setype = fxSubEvent->i_type;
213  sesubtype = fxSubEvent->i_subtype;
214  seprocid = fxSubEvent->i_procid;
215  sesubcrate = fxSubEvent->h_subcrate;
216  secontrol = fxSubEvent->h_control;
217 
218  // cout << setype << " " << sesubtype << " " << seprocid << " " << sesubcrate << " " << secontrol << endl;
219 
220  if (Unpack(fxEventData, sebuflength, setype, sesubtype, seprocid, sesubcrate, secontrol)) {
221  result = kTRUE;
222  }
223  }
224 
225  // Increment evt counters.
226  fNEvent++;
227  fCurrentEvent++;
228 
229  if (!result) {
230  return 2;
231  }
232 
233  return 0;
234 }
235 
237 {
239  Unpack(reinterpret_cast<Int_t*>(fxBuffer), sizeof(s_bufhe), -4, -4, -4, -4, -4);
240  fCurrentEvent = 0;
241 }
242 
s_filhe * fxInfoHeader
Definition: FairLmdSource.h:64
#define GETEVT__SUCCESS
Definition: f_evt.h:130
INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d, INTS4 *pl_lwords)
Definition: f_evt.c:228
s_ve10_1 * fxEvent
Definition: FairLmdSource.h:60
INTS4 f_evt_get_close(s_evt_channel *ps_chan)
Definition: f_evt.c:1189
CHARS h_subcrate
Definition: s_ves10_1.h:35
INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan, CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
Definition: f_evt.c:555
Bool_t Unpack(Int_t *data, Int_t size, Short_t type, Short_t subType, Short_t procId, Short_t subCrate, Short_t control)
Int_t fCurrentEvent
Definition: FairLmdSource.h:57
TList * fFileNames
Definition: FairLmdSource.h:58
INTS2 i_procid
Definition: s_ves10_1.h:34
INTS4 f_evt_error(INTS4 l_error, CHARS *pc_dest, INTS4 l_out)
Definition: f_evt.c:1756
#define GETEVT__NOMORE
Definition: f_evt.h:133
ClassImp(FairEventBuilder)
virtual ~FairLmdSource()
void AddFile(TString fileName)
int INTS4
Definition: typedefs.h:21
Int_t * fxEventData
Definition: FairLmdSource.h:62
Bool_t OpenNextFile(TString fileName)
virtual Int_t ReadEvent(UInt_t=0)
void AddPath(TString dir, TString wildCard)
INTS2 i_type
Definition: s_ves10_1.h:32
virtual Bool_t Init()
s_ves10_1 * fxSubEvent
Definition: FairLmdSource.h:63
char CHARS
Definition: typedefs.h:15
INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
Definition: f_evt.c:987
Int_t fCurrentFile
Definition: FairLmdSource.h:55
#define GETEVT__FILE
Definition: f_evt.h:119
s_bufhe * fxBuffer
Definition: FairLmdSource.h:61
INTS2 i_subtype
Definition: s_ves10_1.h:33
s_evt_channel * fxInputChannel
Definition: FairLmdSource.h:59
virtual void Close()
CHARS h_control
Definition: s_ves10_1.h:36