Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
DAQconfig.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 28/08/22
2
4//
5// DAQconfig, DAQInfoExtra
6//
7// Helper classes to support DAQ configuration info.
8//
9// Used in CodaDecoder and THaRunBase.
10// Filled in CodaDecoder::daqConfigDecode.
11//
13
14#include "DAQconfig.h"
15#include "Textvars.h" // for Podd::vsplit
16#include "TList.h"
17#include <sstream>
18
19using namespace std;
20
21//_____________________________________________________________________________
23 : fMinScan(50)
24{}
25
26//_____________________________________________________________________________
27size_t DAQconfig::parse( size_t i )
28{
29 // Parse string with index 'i' into key/value pairs stored in 'keyval' map.
30 // The key is the first field of a non-comment line. The value is the rest of
31 // the line. Whitespace between value fields is collapsed into single spaces.
32
33 if( i >= strings.size() )
34 return 0;
35 istringstream istr(strings[i]);
36 string line;
37 while( getline(istr, line) ) {
38 auto pos = line.find('#');
39 if( pos != string::npos )
40 line.erase(pos);
41 if( line.find_first_not_of(" \t") == string::npos )
42 continue;
43 auto items = Podd::vsplit(line);
44 if( !items.empty() ) {
45 string& key = items[0];
46 string val;
47 val.reserve(line.size());
48 for( size_t j = 1, e = items.size(); j < e; ++j ) {
49 val.append(items[j]);
50 if( j + 1 != e )
51 val.append(" ");
52 }
53 if( val != "end" )
54 keyval.emplace(std::move(key), std::move(val));
55 }
56 }
57 return keyval.size();
58}
59
60//_____________________________________________________________________________
62{
63 // Add a DAQInfoExtra 'obj' to 'p', which is typically some class's fExtra
64 // variable. If p is non-NULL and an object, convert it to a TList
65 // which owns its objects and contains the existing object and the new
66 // DAQInfoExtra. If it already is a TList, add the DAQInfoExtra object to it.
67
68 auto* ifo = obj ? obj : new DAQInfoExtra;
69 if( !p )
70 p = ifo;
71 else {
72 auto* lst = dynamic_cast<TList*>(p);
73 if( !lst ) {
74 auto* q = p;
75 p = lst = new TList;
76 lst->SetOwner();
77 lst->Add(q);
78 }
79 lst->Add(ifo);
80 }
81}
82
83//_____________________________________________________________________________
85{
86 auto* ifo = dynamic_cast<DAQInfoExtra*>(p);
87 if( !ifo ) {
88 auto* lst = dynamic_cast<TList*>(p);
89 if( lst ) {
90 for( auto* obj: *lst ) {
91 ifo = dynamic_cast<DAQInfoExtra*>(obj);
92 if( ifo )
93 break;
94 }
95 }
96 }
97 return ifo;
98}
99
100//_____________________________________________________________________________
102{
103 // Get DAQconnfig object from p, which can either be the object or a TList*.
104
105 auto* ifo = GetExtraInfo(p);
106 return ifo ? &ifo->fDAQconfig : nullptr;
107}
108
109//_____________________________________________________________________________
#define e(i)
winID h TVirtualViewer3D TVirtualGLPainter p
float * q
static DAQconfig * GetFrom(TObject *p)
static void AddTo(TObject *&p, TObject *obj=nullptr)
Definition DAQconfig.cxx:61
static DAQInfoExtra * GetExtraInfo(TObject *p)
Definition DAQconfig.cxx:84
virtual void SetOwner(Bool_t enable=kTRUE)
TLine * line
STL namespace.
size_t parse(size_t i)
Definition DAQconfig.cxx:27
std::vector< std::string > strings
Definition DAQconfig.h:18
std::map< std::string, std::string > keyval
Definition DAQconfig.h:19
ClassImp(TPyArg)