Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaDecData.cxx
Go to the documentation of this file.
1//*-- Author: Ole Hansen, July 2018
2
4//
5// THaDecData
6//
7// Hall A version of Podd::DecData with support for reading the Hall A
8// legacy database file format and for decoding trigger bits.
9//
10// In addition to the channel contents that Podd::DecData supports
11// (see comments in DecData.cxx), this class adds support for
12// "bitNN" variables, where NN is a number 0-31. They
13// report the value of a trigger bit read via a multihit TDC.
14// Database entries for such variables would be as follows:
15//
16// D.bit =
17// # trigger bit crate slot channel cutlo cuthi
18// bit1 4 11 64 0 2000
19// bit2 4 11 65 0 2000
20// etc.
21// Ask the DAQ expert for more information.
22//
24
25// If defined, add support for reading legacy database format
26#define DECDATA_LEGACY_DB
27
28#include "THaDecData.h"
29#include "TDatime.h"
30#include "TClass.h"
31#include "BdataLoc.h"
32#include "TrigBitLoc.h"
33
34#include <cstdio>
35
36#ifdef DECDATA_LEGACY_DB
37# include "TObjArray.h"
38# include "TObjString.h"
39# include <memory> // for unique_ptr
40#endif
41
42using namespace std;
43using namespace Podd;
44
45//_____________________________________________________________________________
46THaDecData::THaDecData( const char* name, const char* descript )
47 : Podd::DecData(name,descript)
48{
49}
50
51//_____________________________________________________________________________
52FILE* THaDecData::OpenFile( const TDatime& date )
53{
54 // Open THaDecData database file. First look for standard file name,
55 // e.g. "db_D.dat". If not found and if legacy file format support is
56 // configured, look for legacy file name "decdata.map"
57
58 FILE* fi = THaApparatus::OpenFile( date );
59#ifdef DECDATA_LEGACY_DB
60 if( fi )
61 return fi;
62 fi = OpenDBFile("decdata.dat", date,
63 Here("OpenDBFile()"), "r", fDebug);
64#endif
65 return fi;
66}
67
68//_____________________________________________________________________________
69#ifdef DECDATA_LEGACY_DB
70
71inline
72static TString& GetString( const TObjArray* params, Int_t pos )
73{
74 return GetObjArrayString(params,pos);
75}
76
77//_____________________________________________________________________________
78static Int_t ReadOldFormatDB( FILE* file, map<TString,TString>& configstr_map )
79{
80 // Read old-style THaDecData database file and put results into a map from
81 // database key to value (simulating the new-style key/value database info).
82 // Old-style "crate" objects are all assumed to be multihit channels, even
83 // though they usually are not.
84
85 const Int_t bufsiz = 256;
86 char* buf = new char[bufsiz];
87 string dbline;
88 const int nkeys = 3;
89 TString confkey[nkeys] = { "multi", "word", "bit" };
90 TString confval[nkeys];
91 // Read all non-comment lines
92 rewind(file);
93 while( ReadDBline(file, buf, bufsiz, dbline) != EOF ) {
94 if( dbline.empty() ) continue;
95 // Tokenize each line read
96 TString line( dbline.c_str() );
97 unique_ptr<TObjArray> tokens( line.Tokenize(" \t") );
98 TObjArray* params = tokens.get();
99 if( params->IsEmpty() || params->GetLast() < 4 ) continue;
100 // Determine data type
101 bool is_slot = ( GetString(params,1) == "crate" );
102 int idx = is_slot ? 0 : 1;
103 TString name = GetString(params,0);
104 // TrigBits are crate types with special names
105 bool is_bit = ( is_slot && name.BeginsWith("bit") && name.Length() > 3 );
106 if( is_bit ) {
107 TString name2 = name(3,name.Length());
108 if( name2.IsDigit() && name2.Atoi() < 32 )
109 idx = 2;
110 }
111 confval[idx] += name;
112 confval[idx] += " ";
113 for( int i = 2; i < 5; ++ i ) {
114 confval[idx] += GetString(params,i).Data();
115 confval[idx] += " ";
116 }
117 if( is_bit ) {
118 // Simulate the hardcoded cut range for event type bit TDC channels
119 // from the old THaDecData
120 confval[idx] += "0 2000 ";
121 }
122 }
123 delete [] buf;
124 // Put the retrieved strings into the key/value map
125 for( int i = 0; i < nkeys; ++ i ) {
126 if( !confval[i].IsNull() )
127 configstr_map[confkey[i]] = confval[i];
128 }
129 return 0;
130}
131#endif
132
133//_____________________________________________________________________________
135{
136 // If configured, check database format and, if detected, read legacy
137 // format database. Otherwise do what the base class does.
138#ifdef DECDATA_LEGACY_DB
139 fConfigstrMap.clear();
140 if( db_version == 1 )
142 else
143#endif
144 return Podd::DecData::SetupDBVersion(file,db_version);
145}
146
147//_____________________________________________________________________________
149 Int_t db_version,
150 const BdataLoc::BdataLocType& loctype,
151 TString& configstr )
152{
153#ifdef DECDATA_LEGACY_DB
154 // Retrieve old-format database parameters read above for this type
155 if( db_version == 1 ) {
156 auto found = fConfigstrMap.find(loctype.fDBkey);
157 if( found == fConfigstrMap.end() )
158 return -1;
159 configstr = found->second;
160 return 0;
161 } else
162#endif
163 return Podd::DecData::GetConfigstr(file,date,db_version,loctype,configstr);
164}
165
166//_____________________________________________________________________________
168{
169 // Read THaDecData database
170
172#ifdef DECDATA_LEGACY_DB
173 fConfigstrMap.clear();
174#endif
175 if( err )
176 return err;
177
178 // Configure the trigger bits with a pointer to our evtypebits
179 TIter next( &fBdataLoc );
180 while( auto* dataloc = static_cast<BdataLoc*>( next() ) ) {
181 if( dataloc->IsA() == TrigBitLoc::Class() )
182 dataloc->OptionPtr( &evtypebits );
183 }
184
185 fIsInit = true;
186 return kOK;
187}
188
189
191
int Int_t
char name[80]
static Int_t ReadOldFormatDB(FILE *file, map< TString, TString > &configstr_map)
static TString & GetString(const TObjArray *params, Int_t pos)
const char * fDBkey
Definition BdataLoc.h:34
virtual Int_t ReadDatabase(const TDatime &date)
Definition DecData.cxx:309
virtual Int_t GetConfigstr(FILE *file, const TDatime &date, Int_t db_version, const BdataLoc::BdataLocType &loctype, TString &configstr)
Definition DecData.cxx:298
virtual Int_t SetupDBVersion(FILE *file, Int_t db_version)
Definition DecData.cxx:288
THashList fBdataLoc
Definition DecData.h:38
UInt_t evtypebits
Definition DecData.h:37
virtual const char * Here(const char *) const
virtual FILE * OpenFile(const TDatime &date)
virtual Int_t SetupDBVersion(FILE *file, Int_t db_version)
std::map< TString, TString > fConfigstrMap
Definition THaDecData.h:33
virtual FILE * OpenFile(const TDatime &date)
THaDecData(const char *name="D", const char *description="Raw Hall A decoder data")
virtual Int_t ReadDatabase(const TDatime &date)
virtual Int_t GetConfigstr(FILE *file, const TDatime &date, Int_t db_version, const BdataLoc::BdataLocType &loctype, TString &configstr)
static TClass * Class()
Bool_t IsEmpty() const override
Int_t GetLast() const override
Int_t Atoi() const
const char * Data() const
Bool_t IsDigit() const
TLine * line
STL namespace.
ClassImp(TPyArg)