QwAnalysis
VQwSubsystemTracking.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: VQwSubsystemTracking.cc *
3 * *
4 * Author: *
5 * Time-stamp: *
6 \**********************************************************/
7 
8 #include "VQwSubsystemTracking.h"
9 
10 // Qweak headers
11 #include "QwParameterFile.h"
12 
14 {
15  // Open parameter file
16  QwParameterFile* map = new QwParameterFile(filename.Data());
17 
18  // Add detector map name to file
20 
21  // Clear current set of detectors before reading geometry file
22  fDetectorInfo.clear();
23 
24  // Read preamble
25  QwParameterFile* preamble = map->ReadSectionPreamble();
26  preamble->TrimComment("!#"); // Remove everything after a '!' or '#' character
27  preamble->TrimWhitespace(); // Get rid of leading and trailing spaces
28 
29  // Read detector sections
30  QwParameterFile* section;
31  std::string section_name;
32  while ((section = map->ReadNextSection(section_name))) {
33 
34  // Create new detector info object
35  QwDetectorInfo* detector = new QwDetectorInfo(section_name);
36 
37  // Load preamble parameters
38  detector->LoadGeometryDefinition(preamble);
39 
40  // Load section parameters
41  detector->LoadGeometryDefinition(section);
42 
43  // Construct "R2-octant" to request the requested octant
44  std::stringstream octant_option;
45  EQwRegionID region = detector->GetRegion();
46  if (region == kRegionIDTrig) region = kRegionID3;
47  octant_option << "R" << region << "-octant";
48 
49  // Obtain the current octant number from the command line options
50  if (gQwOptions.HasValue(octant_option.str())) {
51  // The octant specified on the command line is for package 2...
52  detector->SetOctant(gQwOptions.GetValue<Int_t>(octant_option.str()));
53  // So if we want package 1 we need to change the octant number
54  if (detector->GetPackage() == kPackage1)
55  detector->SetOctant((detector->GetOctant() + 3) % 8 + 1);
56  } else // no octant explicitly specified
57  detector->SetOctant(0);
58 
59  // Construct "R-octant = " tag to construct the correct module header
60  std::stringstream octant_match;
61  octant_match << octant_option.str() << " = " << detector->GetOctant();
62 
63  // Find modules matching the current octant
64  QwParameterFile* module;
65  std::string module_name;
66  section->RewindToFileStart();
67  while ((module = section->ReadNextModule(module_name))) {
68  // Find matching module
69  if (module_name == octant_match.str()) {
70  // Load section parameters
71  detector->LoadGeometryDefinition(module);
72  }
73 
74  // Delete object created by ReadNextModule
75  delete module;
76  }
77 
78  // Add detector to the list
79  QwMessage << *detector << QwLog::endl;
80  fDetectorInfo.push_back(detector);
81 
82  // Delete object created by ReadNextSection
83  delete section;
84  }
85 
86  // Delete object created by ReadNextSection
87  delete preamble;
88 
89  // Delete QwParameterFile object
90  delete map;
91 
92  return 0; // \todo why?
93 }
94 
95 
97 {
98  // Open parameter file
99  QwParameterFile* map = new QwParameterFile(filename.Data());
100 
101  // Add detector map name to file
103 
104  // Read preamble
105  QwParameterFile* preamble = map->ReadSectionPreamble();
106  preamble->TrimComment("!#"); // Remove everything after a '!' or '#' character
107  preamble->TrimWhitespace(); // Get rid of leading and trailing spaces
108 
109  // Read detector sections
110  QwParameterFile* section;
111  std::string section_name;
112  while ((section = map->ReadNextSection(section_name))) {
113 
114  // Find detector info object for this detector
115  QwGeometry detectors = fDetectorInfo.name(section_name);
116  if (detectors.size() != 1) {
117  QwWarning << "Warning: LoadCrosstalkDefinition detector name " << section_name
118  << " has " << detectors.size() << " matching detectors." << QwLog::endl;
119  QwMessage << "Options are:" << QwLog::endl;
121  exit(-1);
122  }
123  // Get the first (and only) match
124  QwDetectorInfo* detector = detectors[0];
125 
126  // Load preamble parameters
127  detector->LoadCrosstalkDefinition(preamble);
128 
129  // Load section parameters
130  detector->LoadCrosstalkDefinition(section);
131 
132  // Delete object created by ReadNextSection
133  delete section;
134  }
135 
136  // Delete object created by ReadNextSection
137  delete preamble;
138 
139  // Delete QwParameterFile object
140  delete map;
141 
142  return 0; // \todo why?
143 }
144 
145 
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
std::map< TString, TString > fDetectorMaps
Definition: VQwSubsystem.h:322
void push_back(QwDetectorInfo &detector)
Add single detector object.
Definition: QwGeometry.h:55
EQwDetectorPackage GetPackage() const
bool HasValue(const std::string &key)
Has this key been defined.
Definition: QwOptions.h:233
Int_t LoadGeometryDefinition(TString mapfile)
Load geometry definition for tracking subsystems.
void TrimComment(const char commentchar)
EQwRegionID GetRegion() const
QwOptions gQwOptions
Definition: QwOptions.cc:27
void SetOctant(const int octant)
const std::pair< TString, TString > GetParamFileNameContents()
QwParameterFile * ReadNextSection(std::string &secname, const bool keep_header=false)
const QwGeometry name(const std::string &name)
Get detectors by name.
Definition: QwGeometry.h:83
T GetValue(const std::string &key)
Get a templated value.
Definition: QwOptions.h:240
QwParameterFile * ReadNextModule(std::string &secname, bool keep_header=false)
EQwRegionID
Definition: QwTypes.h:16
QwGeometry fDetectorInfo
Geometry information of this subsystem.
void LoadGeometryDefinition(QwParameterFile *map)
QwParameterFile * ReadSectionPreamble()
Rewinds to the start and read until it finds next section header.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Collection of QwDetectorInfo pointers that specifies an experimental geometry.
Definition: QwGeometry.h:27
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
Int_t LoadCrosstalkDefinition(TString mapfile)
Load crosstalk definition for tracking subsystems.
int GetOctant() const
void LoadCrosstalkDefinition(QwParameterFile *map)