JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwScanData.cc
Go to the documentation of this file.
1#include "QwScanData.h"
2#include "QwRootFile.h"
3#include <algorithm>
4
5char const* const QwScanData::CleanDataIndex::fCleanWordName = "cleandata";
6QwScanData::QwScanData(TString const& name)
7: VQwSubsystem(name)
8, VQwSubsystemParity(name) {}
9
17
18Int_t QwScanData::LoadChannelMap(TString mapfile)
19{
20 // Open the Param file
21 QwParameterFile mapstr(mapfile.Data());
22 mapstr.EnableGreediness();
23 mapstr.SetCommentChars("!");
24
26
27 while (mapstr.ReadNextLine()) {
28 // This sets fCurrentROC_ID and fCurrentBank_ID
30 mapstr.TrimComment(); // Remove everything after a comment character.
31 mapstr.TrimWhitespace(); // Get rid of leading and trailing whitespace
32 if (mapstr.LineIsEmpty()) continue;
33
34 // Break this line into tokens to process it.
35 TString modtype = mapstr.GetTypedNextToken<TString>();
36 UInt_t modnum = mapstr.GetTypedNextToken<UInt_t>();
37 UInt_t channum = mapstr.GetTypedNextToken<UInt_t>();
38 TString name = mapstr.GetTypedNextToken<TString>();
39 modtype.ToUpper();
40
41 if(modtype != "WORD") {
42 QwError << "Unrecognized module type " << modtype << QwLog::endl;
43 continue;
44 }
45 // Register data channel type
46 Int_t subbank = GetSubbankIndex();
47 QwVerbose << "Registering " << modtype << " " << name
48 << std::hex
49 << " in ROC 0x" << fCurrentROC_ID << ", bank 0x" << fCurrentBank_ID
50 << std::dec
51 << " at mod " << modnum << ", chan " << channum
52 << QwLog::endl;
53 fWords.emplace_back( QwWord{subbank, 0, modtype, name, "", -1} );
55 SetCleanDataIndex(fWords.size()-1);
56 }
57 }
58 if(CheckCleanDataIndex() == false) {
59 QwError << "fCleanDataIndex is not set inside QwScanData Subsystem" << QwLog::endl;
60 }
61 return 0;
62}
63
65{
66 if(Compare(value))
67 {
69 QwScanData* input = dynamic_cast<QwScanData*>(value);
70 fWords = input->fWords;
71 }
72 return *this;
73}
74
75// Goal: If any of the scan data values changed during a pattern,
76// mark the whole pattern as not clean
78{
79 if(Compare(value)){
80 QwScanData* input = dynamic_cast<QwScanData*>(value);
81 if( !std::equal(
82 fWords.cbegin(),
83 fWords.cend(),
84 input->fWords.cbegin(),
85 input->fWords.cend(),
86 [](QwWord const& q1, QwWord const& q2){
87 return q1.fValue == q2.fValue;
88 })) {
90 }
91 }
92 return *this;
93}
94
95// Goal: If any of the scan data values changed during a pattern,
96// mark the whole pattern as not clean
98{
99 if(Compare(value)){
100 QwScanData* input = dynamic_cast<QwScanData*>(value);
101 if( !std::equal(
102 fWords.cbegin(),
103 fWords.cend(),
104 input->fWords.cbegin(),
105 input->fWords.cend(),
106 [](QwWord const& q1, QwWord const& q2){
107 return q1.fValue == q2.fValue;
108 })) {
110 }
111 }
112 return *this;
113}
114
115
117{
118 for(auto & word : fWords) word.ClearEventData();
119}
120
121Int_t QwScanData::ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
122{
123 UInt_t words_read = 0;
124
125 // Get the subbank index (or -1 when no match)
126 Int_t subbank = GetSubbankIndex(roc_id, bank_id);
127 if (subbank >= 0 && num_words > 0) {
128 words_read++;
129 for(std::size_t i = 0; i < fWords.size(); i++)
130 fWords[i].fValue = buffer[i];
131 words_read = num_words;
132 }
133
134 return words_read;
135}
136
138{
139 // Do post-processing here
140 // By Default, we have none
141 return;
142}
143
145{
146 // Apply cuts here
147 // By Default, we have none
148 return true;
149}
150
152{
153 // Return errors here
154 // By default, we have none
155 return 0;
156}
157void QwScanData::AccumulateRunningSum(VQwSubsystem* value, Int_t count, Int_t ErrorMask)
158{
159 // No-op
160 return;
161}
163{
164 // Check for Burb failure
165 // By default, we succeed
166 return kFALSE;
167}
168
170{
171 // No-op
172 return;
173}
174
176{
177 // No-op
178 return;
179}
180void QwScanData::Scale(Double_t factor)
181{
182 // No-op
183 return;
184}
185
187{
188 // No-op
189 return;
190}
191
193{
194 // No-op
195 return;
196}
197
199{
200 // No-op
201 return;
202}
203
205{
206 // No-op
207 return;
208}
209
210void QwScanData::SetSaveType(TString const& prefix)
211{
212 Ssiz_t len;
213 if (TRegexp("diff_").Index(prefix,&len) == 0
214 || TRegexp("asym[1-9]+_").Index(prefix,&len) == 0
215 || TRegexp("yield_").Index(prefix,&len) == 0)
217 else if (TRegexp("asym").Index(prefix,&len) == 0)
219 else
221}
222void QwScanData::ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
223{
224 SetSaveType(prefix);
226 fTreeArrayIndex = values.size();
227 for (size_t i=0; i<fWords.size(); i++) {
228 TString basename = fWords[i].fWordName;
229 values.push_back(basename.Data(), 'I');
230 tree->Branch(basename, &(values[fTreeArrayIndex + i]), values.LeafList(fTreeArrayIndex + i).c_str());
231 }
232 }
233}
234
236{
237
239 int index = fTreeArrayIndex;
240 for (auto& word : fWords){
241 values.SetValue(index++, word.fValue);
242 }
243 }
244}
245
246#ifdef HAS_RNTUPLE_SUPPORT
247void QwScanData::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
248{
249 SetSaveType(prefix);
251 fTreeArrayIndex = values.size();
252 for (auto const& word : fWords) {
253 TString basename = word.fWordName;
254 values.push_back(0.0);
255 fieldPtrs.push_back(model->MakeField<Double_t>(basename.Data()));
256 }
257 }
258}
259
260void QwScanData::FillNTupleVector(std::vector<Double_t>& values) const
261{
263 int index = fTreeArrayIndex;
264 for (auto& word : fWords){
265 values[index++] = word.fValue;
266 }
267 }
268}
269#endif // HAS_RNTUPLE_SUPPORT
270
272{
273 return fIndex == other.fIndex;
274}
275
276/* \brief Sets Clean data word index
277 * \param index -- index to set
278 *
279 * Sets the CleanData index. Will return if already set and print an error
280 */
282{
283 if(CheckCleanDataIndex() == false) {
284 fCleanDataIndex.fIndex= fWords.size()-1;
285 } else {
286 QwWarning << "ScanData Word already Set! " << '\n';
287 QwWarning << "\tCurrent: " << fCleanDataIndex.fIndex << '\n';
288 QwWarning << "\tFound: " << index << QwLog::endl;
289 }
290
291}
292/*
293 * \brief Checks to see if CleanDataIndex is set
294 *
295 * Returns true if set, false otherwise
296 */
298{
299 return !(fCleanDataIndex == CleanDataIndex{});
300}
301
302/* \brief Sets Clean data word value
303 * \param clean_flag -- clean data enum value {0, 1}
304 *
305 * Sets the CleanData value and returns true if CleanDataIndex is set.
306 * Will return false if CleanDataIndex is not set
307 */
309{
310 bool status = false;
311 if(CheckCleanDataIndex()) {
312 fWords[fCleanDataIndex.fIndex].fValue = static_cast<int>(clean_flag);
313 status = true;
314 }
315 return status;
316}
ULong64_t BankID_t
Definition QwTypes.h:21
UInt_t ROCID_t
Definition QwTypes.h:20
ROOT file and tree management wrapper classes.
#define QwVerbose
Predefined log drain for verbose messages.
Definition QwLog.h:54
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
#define QwWarning
Predefined log drain for warnings.
Definition QwLog.h:44
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Configuration file parser with flexible tokenization and search capabilities.
T GetTypedNextToken()
Get next token into specific type.
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
void SetCommentChars(const std::string value)
Set various sets of special characters.
void TrimComment(const char commentchar)
const std::pair< TString, TString > GetParamFileNameContents()
A helper class to manage a vector of branch entries for ROOT trees.
Definition QwRootFile.h:55
size_type size() const noexcept
Definition QwRootFile.h:83
std::string LeafList(size_type start_index=0) const
Definition QwRootFile.h:230
void push_back(const std::string &name, const char type='D')
Definition QwRootFile.h:197
void SetValue(size_type index, Double_t val)
Definition QwRootFile.h:110
Word-level data manipulation and bit operations.
Definition QwWord.h:31
BankID_t fCurrentBank_ID
Bank ID (and Marker word) that is currently being processed;.
Int_t GetSubbankIndex() const
Bool_t Compare(VQwSubsystem *source)
virtual VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
void RegisterRocBankMarker(QwParameterFile &mapstr)
virtual void ClearEventData()=0
std::map< TString, TString > fDetectorMaps
Map of file name to full path or content.
VQwSubsystem(const TString &name)
Constructor with name.
ROCID_t fCurrentROC_ID
ROC ID that is currently being processed.
RootSaveType fSaveType
Definition QwScanData.h:66
void PrintErrorCounters() const override
void ProcessEvent() override
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override
void IncrementErrorCounters() override
Increment the error counters.
VQwSubsystem & operator+=(VQwSubsystem *value) override
Definition QwScanData.cc:77
void Scale(Double_t factor) override
void CalculateRunningAverage() override
Calculate the average for all good events.
void SetSaveType(TString const &prefix)
Int_t fTreeArrayIndex
Definition QwScanData.h:25
VQwSubsystem & operator=(VQwSubsystem *value) override
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
Definition QwScanData.cc:64
UInt_t GetEventcutErrorFlag() override
Return the error flag to the top level routines related to stability checks and ErrorFlag updates.
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Construct the branch and tree vector.
Int_t LoadChannelMap(TString mapfile) override
Mandatory map file definition.
Definition QwScanData.cc:18
Bool_t ApplySingleEventCuts() override
Apply the single event cuts.
void FillTreeVector(QwRootTreeBranchVector &values) const override
Fill the tree vector.
void AccumulateRunningSum(VQwSubsystem *value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
Update the running sums for devices.
std::vector< QwWord > fWords
Definition QwScanData.h:23
void SetCleanDataIndex(Int_t index)
CleanDataIndex fCleanDataIndex
Definition QwScanData.h:24
bool SetCleanData(CleanDataVal clean_flag)
void DeaccumulateRunningSum(VQwSubsystem *value, Int_t ErrorMask=0xFFFFFFF) override
remove one entry from the running sums for devices
Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
TODO: The non-event-type-aware ProcessEvBuffer routine should be replaced with the event-type-aware v...
void ClearEventData() override
bool CheckCleanDataIndex() const
VQwSubsystem & operator-=(VQwSubsystem *value) override
Definition QwScanData.cc:97
Bool_t CheckForBurpFail(const VQwSubsystem *subsys) override
Report the number of events failed due to HW and event cut failures.
QwScanData(TString const &name)
Definition QwScanData.cc:6
static char const *const fCleanWordName
Definition QwScanData.h:19
bool operator==(CleanDataIndex const &other) const
VQwSubsystemParity()
Private default constructor (not implemented, will throw linker error on use)
virtual UInt_t UpdateErrorFlag()
Uses the error flags of contained data elements to update Returns the error flag to the top level rou...