JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
VQwSubsystem.cc
Go to the documentation of this file.
1/**
2 * VQwSubsystem.cc
3 *
4 * Base subsystem implementation providing map file loading, ROC/bank
5 * registration, detector map management, and parent/sibling access.
6 * Each analysis subsystem derives from this class. Documentation-only
7 * edits; runtime behavior unchanged.
8 */
9
10/*------------------------------------------------------------------------*//*!
11
12 \defgroup QwAnalysis QwAnalysis
13
14 \section myoverview Overview
15
16 Qweak Analysis Framework
17
18 Each subsystem will have a class derived from "VQwSubsystem", and
19 will be responsible for decoding of it's own data stream and any
20 special event processing required. QwSubsystemArray will handle
21 multiple "VQwSubsystem" objects and one call on the QwSubsystemArray
22 will handle all the calls to that method in each subsystem. Each
23 subsystem will also own the histograms and ntupling functions used
24 for its data.
25
26*//*-------------------------------------------------------------------------*/
27
28#include "VQwSubsystem.h"
29
30// Qweak headers
31#include "QwLog.h"
32#include "QwSubsystemArray.h"
33#include "QwParameterFile.h"
34
35
36Int_t ERROR = -1;
37
38
39// Load detector maps from a parameter file, dispatching to specific
40// loaders based on key-value pairs (map, param, eventcut, geom, cross, mask).
42{
43 Bool_t local_debug = false;
44
45 file.RewindToFileStart();
46
47 while (file.ReadNextLine()) {
48 // Trim comments and whitespace
49 file.TrimComment('!');
50 file.TrimComment('#');
51 file.TrimWhitespace();
52
53 // Find key-value pairs
54 std::string key, value;
55 if (file.HasVariablePair("=", key, value)) {
56 if ( value.size() > 0) {
57
58 // If-Ordering Optimization for parity
59 // Beamline 1423
60 // MainDetector 123
61 // Lumi 123
62 // Helicity 1
63 // Scanner 12
64 // Beammod 1
65 // 1(6),2(4),3(3),4(1)
66 // map, param, eventcut, geom
67
68 // Map file definition
69 if (key == "map" ) {
70 LoadChannelMap(value);
71 // fDetectorMapsNames.push_back(value);
72 }
73 // Parameter file definition
74 else if (key == "param" ) {
75 LoadInputParameters(value);
76 // fDetectorMapsNames.push_back(value);
77 }
78 // Event cut file definition
79 else if (key == "eventcut") {
80 LoadEventCuts(value);
81 // fDetectorMapsNames.push_back(value);
82 }
83 // Geometry file definition
84 else if (key == "geom" ) {
86 // fDetectorMapsNames.push_back(value);
87 }
88 // Crosstalk file definition
89 else if (key == "cross" ) {
91 // fDetectorMapsNames.push_back(value);
92 }
93 //Event type mask
94 else if (key == "mask") {
95 SetEventTypeMask(file.GetUInt(value));
96 }
97 }
98
99 } // end of HasVariablePair
100 } // end of while
101
102
103 //
104 // The above approach that fDetectorMapsNames.push_back(value) in VQwSubsystem doesn't work, because it reads the following...
105 //
106 // >>> VQwSubsystem::LoadDetectorMaps Subsystem Main Detector uses the following map files :
107 // ---> 1/3 : qweak_maindet.map
108 // ---> 2/3 : qweak_maindet_pedestal.map
109 // ---> 3/3 : qweak_maindet_eventcuts.in
110
111 //
112 // So, fDetectorMapsNams.push_back will be called LoadChannelMap(), LoadInputParameter(), LoadEventCuts(),
113 // and LoadGeometryDefinition() in each subsystem.
114 //
115 // >>> VQwSubsystem::LoadDetectorMaps Subsystem Main Detector uses the following map files :
116 // ---> 1/3 : /home/jhlee/QwAnalysis/trunk/Parity/prminput/qweak_maindet.10213-.map
117 // ---> 2/3 : /home/jhlee/QwAnalysis/trunk/Parity/prminput/qweak_maindet_pedestal.10229-.map
118 // ---> 3/3 : /home/jhlee/QwAnalysis/trunk/Parity/prminput/qweak_maindet_eventcuts.in
119 //
120 // Friday, March 18 15:32:09 EDT 2011, jhlee
121
122 PrintDetectorMaps(local_debug);
123
124 return 0;
125}
126
127// Get a sibling subsystem by name from the parent array.
128// Parameters and return value are documented in the header.
129VQwSubsystem* VQwSubsystem::GetSibling(const std::string& name) const
130{
131 // Get the parent and check for existence
132 QwSubsystemArray* parent = GetParent();
133 if (parent != 0)
134 // Return the subsystem with name in the parent
135 return parent->GetSubsystemByName(name);
136 else
137 return 0; // GetParent() prints error already
138}
139
140
141
142// Clear all ROC and bank registrations and reset current IDs.
150
151// Compute the flat subbank index from ROC and bank IDs.
152Int_t VQwSubsystem::GetSubbankIndex(const ROCID_t roc_id, const BankID_t bank_id) const
153{
154 // Bool_t lDEBUG=kTRUE;
155 Int_t index = -1;
156 Int_t roc_index = FindIndex(fROC_IDs, roc_id);//will return the vector index for the Roc from the vector fROC_IDs.
157 // std::cout << "------------- roc_index" << roc_index <<std::endl;
158 if (roc_index>=0){
159 index = FindIndex(fBank_IDs[roc_index],bank_id);
160 // std::cout << " Find Index " << index
161 // << " roc index " << roc_index
162 // << " index " << index <<std::endl;
163
164 if (index>=0){
165 for (Int_t i=0; i<roc_index; i++){
166 index += (fBank_IDs[i].size());
167 // std::cout << " i " << i
168 // << " fBank_IDs[i].size() " << fBank_IDs[i].size()
169 // << " index " << index
170 // << std::endl;
171 }
172 }
173 }
174 // std::cout << "return:index " << index << std::endl;
175 return index;
176}
177
178// Register a ROC and bank ID pair, creating entries if new.
179Int_t VQwSubsystem::RegisterROCNumber(const ROCID_t roc_id, const BankID_t bank_id)
180{
181 Int_t stat = 0;
182 Int_t roc_index = 0;
183 roc_index = FindIndex(fROC_IDs, roc_id);
184
185 //will return the vector index for this roc_id on the vector fROC_IDs
186 if (roc_index==-1){
187 fROC_IDs.push_back(roc_id); // new ROC number is added.
188 roc_index = (fROC_IDs.size() - 1);
189 std::vector<BankID_t> tmpvec(1,bank_id);
190 fBank_IDs.push_back(tmpvec);
191 fMarkerWords.resize(fROC_IDs.size());
192 fMarkerWords.at(roc_index).resize(1);
193 } else {
194 Int_t bank_index = FindIndex(fBank_IDs[roc_index],bank_id);
195 if (bank_index==-1) { // if the bank_id is not registered then register it.
196 fBank_IDs[roc_index].push_back(bank_id);
197 fMarkerWords.at(roc_index).resize(fBank_IDs.at(roc_index).size());
198 } else {
199 // This subbank in this ROC has already been registered!
200 QwError << std::hex << "VQwSubsystem::RegisterROCNumber: "
201 << "This subbank (0x" << bank_id << ") "
202 << "in this ROC (0x" << roc_id << ") "
203 << "has already been registered!"
204 << std::dec << QwLog::endl;
205 stat = ERROR;
206 }
207 }
208 if (stat!=-1){
209 fCurrentROC_ID = roc_id;
210 fCurrentBank_ID = bank_id;
211 } else {
214 }
215 return stat;
216}
217
218// Register a subbank under the current ROC.
220{
221 Int_t stat = 0;
223 stat = RegisterROCNumber(fCurrentROC_ID, bank_id);
224 fCurrentBank_ID = bank_id;
225 } else {
226 // There is not a ROC registered yet!
227 QwError << std::hex << "VQwSubsystem::RegisterSubbank: "
228 << "This subbank (" << bank_id << ") "
229 << "does not have an associated ROC! "
230 << "Add a 'ROC=#' line to the map file."
231 << std::dec << QwLog::endl;
232 stat = ERROR;
235 }
236 return stat;
237}
238
239
240// Register a marker word within the current ROC/bank context.
241Int_t VQwSubsystem::RegisterMarkerWord(const UInt_t markerword)
242{
243 static BankID_t bankIDmask = 0xffffffff;
244 Int_t stat = 0;
246 Int_t roc_index = FindIndex(fROC_IDs, fCurrentROC_ID);
247 Int_t bank_index = FindIndex(fBank_IDs[roc_index],(fCurrentBank_ID&bankIDmask));
248 fMarkerWords.at(roc_index).at(bank_index).push_back(markerword);
249 BankID_t tmpbank = markerword;
250 tmpbank = ((tmpbank)<<32) + (fCurrentBank_ID&bankIDmask);
251 RegisterSubbank(tmpbank);
252 } else {
253 // There is not a ROC registered yet!
254 QwError << std::hex << "VQwSubsystem::RegisterSubbank: "
255 << "This Marker word (" << markerword << ") "
256 << "does not have an associated ROC! "
257 << "Add a 'ROC=#' line to the map file."
258 << std::dec << QwLog::endl;
259 stat = ERROR;
262 }
263 return stat;
264}
265
266// Parse and register ROC, bank, and marker word entries from a map file.
268 UInt_t value = 0;
269 if (mapstr.PopValue("roc",value)) {
270 RegisterROCNumber(value,0);
271 }
272 if (mapstr.PopValue("bank",value)) {
273 RegisterSubbank(value);
274 }
275 if (mapstr.PopValue("markerword",value)) {
276 RegisterMarkerWord(value);
277 }
278}
279
280// Print subsystem name, registered ROCs/banks, and parent information.
282{
283 std::cout << "Name of this subsystem: " << fSystemName << std::endl;
284 for (size_t roc_index = 0; roc_index < fROC_IDs.size(); roc_index++) {
285 std::cout << "ROC" << std::dec << fROC_IDs[roc_index] << ": ";
286 for (size_t bank_index = 0; bank_index < fBank_IDs[roc_index].size(); bank_index++)
287 std::cout << std::hex << "0x" << fBank_IDs[roc_index][bank_index] << " ";
288 std::cout << std::dec << std::endl;
289 }
290 std::cout << "in array " << std::hex << GetParent() << std::dec << std::endl;
291}
292
293
294// Assignment operator: copy data-loaded status.
296{
297 this->fIsDataLoaded = value->fIsDataLoaded;
298 return *this;
299}
300
301
302
304{
305 return fDetectorMapsNames;
306}
307
308
309
310// Return the map of detector map file names to contents.
311std::map<TString, TString> VQwSubsystem::GetDetectorMaps()
312{
313 return fDetectorMaps;
314}
315
316
317
318// Print loaded detector map file names for debugging.
319void VQwSubsystem::PrintDetectorMaps(Bool_t status) const
320{
321 Bool_t local_debug = false;
322 if (status) {
323 QwMessage << " >>> VQwSubsystem::LoadDetectorMaps Subsystem " << fSystemName
324 << " uses the following map files:" << QwLog::endl;
325
326 Int_t index = 0;
327 size_t total = fDetectorMaps.size();
328
329 if (total != 0) {
330
331 for (std::map<TString,TString>::const_iterator ii = fDetectorMaps.begin();
332 ii != fDetectorMaps.end(); ++ii) {
333
334 index++;
335 TString name = (*ii).first;
336 TString all = (*ii).second;
337 QwMessage << " ---> " << index << "/" << total << ": " << name << QwLog::endl;
338 if (local_debug)
339 QwMessage << " " << all << QwLog::endl;
340
341 }
342
343 } else {
344 QwMessage << " ---> No map files" << QwLog::endl;
345 }
346 }
347}
Definition of the pure virtual base class of all subsystems.
A logfile class, based on an identical class in the Hermes analyzer.
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
Array container for managing multiple subsystems.
Parameter file parsing and management.
ULong64_t BankID_t
Definition QwTypes.h:21
static const BankID_t kNullBankID
Definition QwTypes.h:23
static const ROCID_t kNullROCID
Bank ID will combine both bank and marker words.
Definition QwTypes.h:22
UInt_t ROCID_t
Definition QwTypes.h:20
Int_t ERROR
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Configuration file parser with flexible tokenization and search capabilities.
Bool_t PopValue(const std::string keyname, T &retvalue)
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
void TrimComment(const char commentchar)
static UInt_t GetUInt(const TString &varvalue)
Container for managing multiple subsystems with common operations.
virtual VQwSubsystem * GetSubsystemByName(const TString &name)
Get the subsystem with the specified name.
virtual Int_t RegisterROCNumber(const ROCID_t roc_id, const BankID_t bank_id=0)
Tell the object that it will decode data from this ROC and sub-bank.
std::vector< ROCID_t > fROC_IDs
Vector of ROC IDs associated with this subsystem.
virtual Int_t LoadChannelMap(TString mapfile)=0
Mandatory map file definition.
BankID_t fCurrentBank_ID
Bank ID (and Marker word) that is currently being processed;.
virtual std::map< TString, TString > GetDetectorMaps()
TString fSystemName
Name of this subsystem.
Int_t GetSubbankIndex() const
std::vector< TString > fDetectorMapsNames
Names of loaded detector map files.
std::vector< std::vector< BankID_t > > fBank_IDs
Vector of Bank IDs per ROC ID associated with this subsystem.
void SetEventTypeMask(const UInt_t mask)
Set event type mask.
virtual VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
virtual void PrintInfo() const
Print some information about the subsystem.
void RegisterRocBankMarker(QwParameterFile &mapstr)
virtual Int_t LoadEventCuts(TString)
Optional event cut file.
virtual Int_t LoadGeometryDefinition(TString)
Optional geometry definition.
Bool_t fIsDataLoaded
Has this subsystem gotten data to be processed?
virtual Int_t LoadDetectorMaps(QwParameterFile &file)
Parse parameter file to find the map files.
Int_t FindIndex(const std::vector< T > &myvec, const T value) const
Int_t RegisterMarkerWord(const UInt_t markerword)
virtual std::vector< TString > GetParamFileNameList()
std::map< TString, TString > fDetectorMaps
Map of file name to full path or content.
void ClearAllBankRegistrations()
Clear all registration of ROC and Bank IDs for this subsystem.
virtual Int_t LoadInputParameters(TString mapfile)=0
Mandatory parameter file definition.
virtual void PrintDetectorMaps(Bool_t status) const
VQwSubsystem(const TString &name)
Constructor with name.
Int_t RegisterSubbank(const BankID_t bank_id)
Tell the object that it will decode data from this sub-bank in the ROC currently open for registratio...
virtual Int_t LoadCrosstalkDefinition(TString)
Optional crosstalk definition.
ROCID_t fCurrentROC_ID
ROC ID that is currently being processed.
std::vector< std::vector< std::vector< UInt_t > > > fMarkerWords
Vector of marker words per ROC & subbank associated with this subsystem.
VQwSubsystem * GetSibling(const std::string &name) const
Get the sibling with specified name.