StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StRtsReaderMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StRtsReaderMaker.cxx,v 1.34 2013/02/19 20:10:19 fisyak Exp $
4  *
5  * Author: Valeri Fine, BNL Feb 2008
6  ***************************************************************************
7  *
8  * Description: Create the DAQ table from the RTS_READER
9  *
10  * Input: RTS_Reader
11  * Output: daq tables
12  *
13  ***************************************************************************
14  *
15  * $Log: StRtsReaderMaker.cxx,v $
16  * Revision 1.34 2013/02/19 20:10:19 fisyak
17  * Akio & Valery modification for meta data, bug #2452
18  *
19  * Revision 1.33 2012/09/13 20:01:49 fisyak
20  * Clean up, use Jeff's skip_then_get
21  *
22  * Revision 1.32 2010/12/14 15:27:04 genevb
23  * Use LOG_DEBUG only in maker's Debug modes
24  *
25  * Revision 1.31 2010/03/17 19:52:44 fine
26  * Comment out the redundant debug message
27  *
28  * Revision 1.30 2009/11/23 15:56:15 fisyak
29  * reduce print out
30  *
31  * Revision 1.29 2009/11/19 22:42:22 fine
32  * remove the token leak #1712
33  *
34  * Revision 1.28 2009/10/14 14:46:29 fine
35  * Initialize fDatReader to zero at class ctor. Issue #1665
36  *
37  * Revision 1.27 2009/10/13 19:42:28 fine
38  * remove the redundant assert
39  *
40  * Revision 1.26 2009/10/13 19:32:44 fine
41  * Re-Activate DAQ reader
42  *
43  * Revision 1.25 2009/10/13 15:51:48 fine
44  * Activate the new DAT file format
45  *
46  * Revision 1.24 2009/10/09 22:36:34 fine
47  * remove the redundant components
48  *
49  * Revision 1.23 2009/10/07 00:52:32 fine
50  * Move daqReader instantiation from StDAQMaker to StDAQReader to switch between input files properly
51  *
52  * Revision 1.22 2009/07/22 21:42:52 fine
53  * Add DAQ event header to pass
54  *
55  * Revision 1.21 2009/04/28 16:35:48 fine
56  * downgrade the message level from INFO to DEBUG
57  *
58  * Revision 1.20 2009/03/23 15:38:23 fine
59  * remove redundant messafes , reduce the level of others from INFO to DEBUG
60  *
61  * Revision 1.19 2009/02/20 23:32:43 fine
62  * avoid the fRtsTable double destruction. It causes the chain crash. Thanks Fisyak
63  *
64  * Revision 1.18 2008/12/29 23:57:40 fine
65  * restore the economic mode
66  *
67  * Revision 1.17 2008/12/29 21:16:47 fine
68  * Preserve / accumulate the copy the DAQ table to avoid the dead data access
69  *
70  * Revision 1.16 2008/12/22 19:39:35 fine
71  * improve the diagnostic
72  *
73  * Revision 1.15 2008/12/22 16:58:23 fine
74  * eliminate the redundant messages
75  *
76  * Revision 1.14 2008/12/17 02:04:59 fine
77  * improve the diagnostic messages
78  *
79  * Revision 1.13 2008/12/17 00:55:15 fine
80  * improve the diagnostic messages
81  *
82  * Revision 1.12 2008/12/16 22:33:00 fine
83  * Improve the diagnostic message
84  *
85  * Revision 1.11 2008/12/16 19:39:19 fine
86  * replace daq_dta_dict with get_size_t()
87  *
88  * Revision 1.10 2008/11/26 18:01:30 fine
89  * prepare StRtsReaderMaker for DAQ_READER transition
90  *
91  * Revision 1.9 2008/11/25 21:33:22 fine
92  * preparing DAQ maker for DAQ_READER
93  *
94  * Revision 1.8 2008/11/25 21:28:03 fine
95  * preprae DAQ maker for DAQ_READER
96  *
97  * Revision 1.7 2008/04/28 18:44:53 fine
98  * Add the third numeric parameter for get method
99  *
100  * Revision 1.6 2008/04/28 15:12:36 fine
101  * Fix the messages
102  *
103  * Revision 1.5 2008/04/10 16:23:34 fine
104  * Activate the generic RTS_READER interface
105  *
106  * Revision 1.4 2008/04/09 21:05:03 fine
107  * Add the generic way to treat the DAQ RTS structures
108  *
109  * Revision 1.3 2008/04/08 22:39:47 fine
110  * typo
111  *
112  * Revision 1.2 2008/04/08 22:19:56 fine
113  * Synch old and new EVP and RTS DAQ readers
114  *
115  * Revision 1.1 2008/04/08 20:03:52 fine
116  * add the maker to communicate with the new RTS_READER from RTS
117  *
118  * Revision 1.14 2008/02/01 01:20:14 fine
119  * Add the Slave mode
120  *
121  * Revision 1.13 2008/02/01 00:44:13 fine
122  * Add the TROOT header file
123  *
124  * Revision 1.12 2008/01/31 23:53:22 fine
125  * Do not call fRtsReader->Make() in Slave mode
126  *
127  * Revision 1.11 2008/01/30 20:05:22 fine
128  * add the simple datastruct
129  *
130  * Revision 1.10 2008/01/30 04:39:22 fine
131  * Add map for tof/raw query
132  *
133  * Revision 1.9 2008/01/29 18:29:54 fine
134  * Introdcue the slave mode for the rts_reader
135  *
136  * Revision 1.8 2008/01/12 00:37:53 fine
137  * Clean up
138  *
139  * Revision 1.7 2008/01/11 23:41:31 fine
140  * The first correctly working version
141  *
142  * Revision 1.6 2008/01/11 21:09:44 fine
143  * Fix the table size
144  *
145  * Revision 1.5 2008/01/11 19:08:33 fine
146  * Couple of bugs fixed. Move on
147  *
148  * Revision 1.4 2008/01/11 18:28:05 fine
149  * Remove the redundant data-member
150  *
151  * Revision 1.3 2008/01/11 18:09:35 fine
152  * Fix some typos
153  *
154  * Revision 1.2 2008/01/11 14:57:05 fine
155  * add DAQ system C-struct dictionary
156  *
157  * Revision 1.1 2008/01/11 01:16:54 fine
158  * The generic maker to steer the online RTS system
159  *
160  *
161  * StRtsReaderMaker - class to fill the STAR table DAQ event model
162  *
163  **************************************************************************/
164 #include "StRtsReaderMaker.h"
165 #include "StRtsTable.h"
166 #include "TROOT.h"
167 #include "StDAQMaker/StDAQReader.h"
168 
169 #include "TDataSetIter.h"
170 
171 # include "RTS/src/DAQ_READER/daq_det.h"
172 # include "RTS/src/DAQ_READER/daq_dta.h"
173 # include "RTS/src/DAQ_READER/daq_dta_structs.h"
174  typedef unsigned int UINT32;
175 # include "RTS/include/evp.h"
176 # include "RTS/src/DAQ_READER/cfgutil.h"
177 # include "RTS/src/DAQ_READER/daqReader.h"
178 
179 #include "StStreamFile.h"
180 
181 
182 ClassImp(StRtsReaderMaker);
183 
184 //_____________________________________________________________
185 StRtsReaderMaker::StRtsReaderMaker(const char *name):StMaker(name)
186  ,fRtsReader(0),fDatReader(0),fRtsTable(0),fBank(0)
187 {
188  // LOG_DEBUG << "StRtsReaderMaker::ctor" << endm;
189 }
190 
191 //_____________________________________________________________
192 StRtsReaderMaker::~StRtsReaderMaker()
193 {
194  delete fRtsReader;
195  fRtsReader = 0;
196  // fRtsTable will be deleted by the base StMaker dtor.
197  fRtsTable = 0;
198 }
199 //_____________________________________________________________
200 Int_t StRtsReaderMaker::Init() {
201  return StMaker::Init();
202 }
203 
204 //_____________________________________________________________
205 daqReader *StRtsReaderMaker::InitReader()
206 {
207  // Init EVP_READER
208  if (!fRtsReader && !fDatReader) {
209  StDAQReader *daqReader = 0;
210  // LOG_DEBUG << "StRtsReaderMaker::InitReader" << endm;
211  TDataSet *dr = GetDataSet("StDAQReader");
212  if(dr) daqReader = (StDAQReader *)(dr->GetObject());
213 
214  if(daqReader == NULL) {
215  LOG_INFO << "StRtsReaderMaker::InitReader No daqReader available..." << endm;
216  } else {
217  evpReader *daqEvp = daqReader->getFileReader();
218  if(daqEvp == NULL) {
219  LOG_INFO << "StRtsReaderMaker::InitReader No evpReader available..." << endm;
220  } else {
221  LOG_INFO << "StRtsReaderMaker::InitReader: evpReader was found: " << daqEvp << endm;
222  fRtsReader = daqEvp->rts();
223  if (!fRtsReader) {
224  LOG_ERROR << "StRtsReaderMaker::InitReader: no daqReader was found!" << endm;
225  }
226  }
227  }
228  }
229  return fRtsReader;
230 }
231 
232 //_____________________________________________________________
233 void StRtsReaderMaker::Clear(Option_t *option)
234 {
235  fRtsTable = 0;
236  fBank = 0;
237  fLastQuery = "";
238  // StMaker::Clear will delete fRtsTable
239  StMaker::Clear(option);
240 }
241 //_____________________________________________________________
242 void StRtsReaderMaker::SetDaqReader(daqReader *reader)
243 {
244  if (reader) {
245  assert(reader && !fDatReader && "Can not use two readers simultaneously");
246  }
247  fRtsReader = reader;
248 }
249 //_____________________________________________________________
250 void StRtsReaderMaker::SetDatReader(StStreamFile *reader)
251 {
252  if (reader) {
253  assert(reader && !fRtsReader && "Can not use two readers simultaneously");
254  }
255  fDatReader = reader;
256 }
257 
258 #if 0
259 //_____________________________________________________________
260 static const char*RtsDataTypeByBankName(const char *bankName)
261 {
262  //______________________________________________________
263  //
264  // Here we can do something more clever of course
265  // The idea l solution:
266  // the mapping should be provided by the class rts_reader
267  //______________________________________________________
268  //
269  // rts_reader::RtsDataTypeByBankName(const char *bankName)
270  //______________________________________________________
271 
272  TString bn = bankName;
273  if (bn == "cld" ) return "daq_cld";
274  if (bn == "raw" ) {
275  static const char *str = 0;
276  if (!str) {
277  gROOT->ProcessLine("struct intstruct { int a;}");
278  }
279  return "intstruct";
280  }
281  return 0;
282 }
283 #endif
284 
285 //_____________________________________________________________
286 StRtsTable *StRtsReaderMaker::InitTable(const char *detName,const char *bankName)
287 {
288  // Create the new instance of the StRtsTable
289  if (fRtsTable) {
290  // make sure there was no data anymore
291  if (fBank && !fBank->is_empty())
292  {
293  if (Debug()) {
294  LOG_DEBUG << " You are going to use \"" << detName << "/" << bankName << "\" RTS bank" << endm;
295  LOG_DEBUG << " even though you did not use all information from the previous RTS bank: \""
296  << fLastQuery << "\" yet" << endm;
297  }
298  }
299  delete fRtsTable;
300  fRtsTable = 0; // forget this table. It will be deleted by Clear method anyway
301  }
302  size_t dtBankSize = 0;
303  if (fBank) { dtBankSize = fBank->get_size_t(); }
304  else if (fDatReader) { dtBankSize = fDatReader->Length() ; }
305  if ( dtBankSize ) {
306  // we will reallocate it within FillTable() method
307  fRtsTable = new StRtsTable(dtBankSize,2);
308  if (Debug() > 3 ) fRtsTable->Print();
309  AddData(fRtsTable);
310  }
311  return fRtsTable;
312 }
313 //_____________________________________________________________
314 void StRtsReaderMaker::FillDaqHeader()
315 {
316  if (fRtsReader) {
317  fRtsTable->SetToken (fRtsReader->token );
318  fRtsTable->SetTrgcmd (fRtsReader->trgcmd );
319  fRtsTable->SetDaqcmd (fRtsReader->daqcmd );
320  fRtsTable->SetTrgword (fRtsReader->trgword);
321  fRtsTable->SetPhyword (fRtsReader->phyword);
322  fRtsTable->SetDaqbits (fRtsReader->daqbits);
323  fRtsTable->SetDaqbits_l1 (fRtsReader->daqbits_l1);
324  fRtsTable->SetDaqbits_l2 (fRtsReader->daqbits_l2);
325  fRtsTable->SetEvpgroups (fRtsReader->evpgroups);
326  fRtsTable->SetDetectors (fRtsReader->detectors);
327  }
328 }
329 
330 //_____________________________________________________________
331 TDataSet *StRtsReaderMaker::FillTable()
332 {
333  assert(fRtsTable);
334  if (fBank && fBank->iterate()) {
335  fRtsTable->SetAll( fBank->sec
336  , fBank->pad
337  , fBank->rdo
338  , fBank->row);
339  fRtsTable->SetMeta(fBank->meta);
340 
341  fRtsTable->SetNRows(0);
342  if (Debug()) {
343  LOG_DEBUG <<" StRtsReaderMaker::FillTable(): the bank size is "
344  << fBank->ncontent << " row" << ((fBank->ncontent>1)?"s ":" ")
345  << fRtsTable->GetRowSize() << " bytes each" << endm;
346  }
347  fRtsTable->AppendRows(fBank->Byte,fBank->ncontent);
348  fRtsTable->SetNRows(fBank->ncontent);
349  } else if (fDatReader) {
350  fRtsTable->SetAll(0,0,0,0);
351  fRtsTable->SetNRows(0);
352  fRtsTable->AppendRows(fDatReader->Record(),1);
353  fRtsTable->SetNRows(1);
354  } else {
355 #ifdef HARD_DEBUG
356  if (!fLastQuery.IsNull() && Debug()) {
357  LOG_DEBUG <<" StRtsReaderMaker::FillTable(): No data has been found for \""
358  << fLastQuery << "\" to fill the table"
359  << endm;
360  }
361 #endif
362  if (fRtsTable && Debug() > 3 ) fRtsTable->Print(0,5);
363  delete fRtsTable;
364  fRtsTable = 0; // forget this table. It will be deleted by Clear method anyway
365  fLastQuery = "";
366  }
367  return fRtsTable;
368 }
369 
370 //_____________________________________________________________________________
371 TDataSet *StRtsReaderMaker::FindDataSet (const char* logInput,const StMaker *uppMk,
372  const StMaker *dowMk) const
373 {
374  //--------------------------------------------------------------
375  // Input: Query: RTS/[detector[/rts_bank[ [bank_parameters] ]]]
376  // for example: RTS/tpx/cld[16] - to get the clusters for the
377  // 16th sector of tpx
378  // Special case: /RTS/trg/raw - the tge data can be provided by fDatReader too
379  // Return the RTS bank decorated as TGenericTable
380  //--------------------------------------------------------------
381 
382  // Do not process the empty request:
383  //LOG_INFO << " StRtsReaderMaker::FindDataSet: "
384  // << logInput << endm;
385  if ( !(logInput && logInput[0]) )
386  return StMaker::FindDataSet(logInput,uppMk,dowMk);
387 
388  TString rtsRequest = logInput;
389  Bool_t rtsSystem = false;
390  TDataSet *ds = 0;
391  StRtsReaderMaker *thisMaker = (StRtsReaderMaker *)this;
392 
393  if (fLastQuery == rtsRequest) {
394  rtsSystem = true;
395  } else if (fRtsReader || fDatReader) {
396  TObjArray *tokens = rtsRequest.Tokenize("/[],");
397  Int_t nItems = tokens->GetEntries();
398  if ( !strcmp(tokens->At(0)->GetName(),"RTS") ) {
399  // Pick the detector name
400  TString detName = tokens->At(1)->GetName();
401  // we found the detector
402  char *detNameBuf = new char[detName.Length()+1];
403  strncpy(detNameBuf,detName.Data(),detName.Length());
404  detNameBuf[detName.Length()]=0;
405  daq_det *rts_det = fRtsReader ? fRtsReader->det(detNameBuf) : 0;
406  delete [] detNameBuf;
407  if (rts_det) {
408  // Pick the rts bank
409  StRtsReaderMaker *thisMaker = (StRtsReaderMaker *)this;
410  switch (nItems-2) {
411  case 1:
412  thisMaker->fBank = rts_det->get( tokens->At(2)->GetName() );
413  break;
414  case 2:
415  thisMaker->fBank = rts_det->get( tokens->At(2)->GetName()
416  ,atoi(tokens->At(3)->GetName()));
417  if (Debug()) {
418  LOG_DEBUG <<" StRtsReaderMaker::FindDataSet det(\"" <<
419  detName << "\")->get(\""<<tokens->At(2)->GetName()
420  << "\"," << atoi(tokens->At(3)->GetName())
421  << ") "
422  << "fBank = "<< thisMaker->fBank << endm;
423  }
424  break;
425  case 3:
426  thisMaker->fBank = rts_det->get( tokens->At(2)->GetName()
427  ,atoi(tokens->At(3)->GetName())
428  ,atoi(tokens->At(4)->GetName()));
429  break;
430  case 4:
431  thisMaker->fBank = rts_det->get( tokens->At(2)->GetName()
432  ,atoi(tokens->At(3)->GetName())
433  ,atoi(tokens->At(4)->GetName())
434  ,atoi(tokens->At(5)->GetName()));
435  break;
436  default: thisMaker->fBank = 0; break;
437  };
438  if (fBank) {
439  thisMaker->InitTable(detName,tokens->At(2)->GetName());
440  rtsSystem = true;
441  thisMaker->fLastQuery = rtsRequest;
442  } else {
443  thisMaker->fLastQuery = "";
444  }
445  } else if (fDatReader && detName=="trg" && TString("raw") == tokens->At(2)->GetName()) {
446  thisMaker->InitTable(detName,tokens->At(2)->GetName());
447  thisMaker->fLastQuery = rtsRequest;
448  rtsSystem = fDatReader->Record();
449  if (Debug()) {
450  LOG_DEBUG << " StRtsReaderMaker::FindDataSet: DAT request was found: "
451  << fDatReader->Length() << (void *)fDatReader->Record() << endm;
452  }
453  }
454  }
455  delete tokens;
456  }
457 
458  if (rtsSystem) {
459  thisMaker->FillDaqHeader();
460  ds = thisMaker->FillTable();
461  } else {
462  ds = StMaker::FindDataSet(logInput,uppMk,dowMk);
463  }
464  return ds;
465 }
466 
467 //_____________________________________________________________
468 Int_t StRtsReaderMaker::InitRun(int run)
469 {
470  return StMaker::InitRun(run);
471 }
472 
473 //_____________________________________________________________
475 {
476  // Force RTS_READER to get the next event if it is not slave
477  int res = kStOk;
478  InitReader();
479  return res;
480 }
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1395
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
virtual Int_t Make()
virtual Long_t AppendRows(const void *row, UInt_t nRows)
Definition: TTable.cxx:1178
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
virtual void Clear(Option_t *option="")
User defined functions.
virtual Char_t * Print(Char_t *buf, Int_t n) const
Create IDL table defintion (to be used for XDF I/O)
Definition: TTable.cxx:1548
Definition: Stypes.h:41