46 static const int WILDCARD = -1;
48 static const std::string reset_t =
"reset";
49 static const std::string set_t =
"set";
50 static const std::string setx_t =
"setx";
51 static const std::string sety_t =
"sety";
52 static const std::string setz_t =
"setz";
53 static const std::string addx_t =
"addx";
54 static const std::string addy_t =
"addy";
55 static const std::string addz_t =
"addz";
56 static const std::string subx_t =
"subx";
57 static const std::string suby_t =
"suby";
58 static const std::string subz_t =
"subz";
59 static const std::string add_t =
"add";
60 static const std::string sub_t =
"sub";
61 static const std::string rot_t =
"rot";
62 static const std::string lower_t =
"lower";
63 static const std::string upper_t =
"upper";
64 static const std::string mul_t =
"mul";
65 static const std::string div_t =
"div";
66 static const std::string tilt_t =
"tilt";
67 static const std::string swap_t =
"swap";
69 static const std::string assign_t =
"assign";
70 static const std::string locate_t =
"locate";
71 static const std::string
string_t =
"string";
73 static const std::string rand_t =
"rand";
74 static const std::string randset_t = rand_t + set_t;
75 static const std::string randadd_t = rand_t + add_t;
76 static const std::string randsub_t = rand_t + sub_t;
77 static const std::string randrot_t = rand_t + rot_t;
78 static const std::string randmul_t = rand_t + mul_t;
79 static const std::string randdiv_t = rand_t + div_t;
80 static const std::string randtilt_t = rand_t + tilt_t;
82 static const std::string RESET_t =
"RESET";
83 static const std::string SET_t =
"SET";
84 static const std::string ADD_t =
"ADD";
85 static const std::string SUB_t =
"SUB";
86 static const std::string ROT_t =
"ROT";
96 inline bool apply(
JModule& module,
const std::string& action)
98 if (action == reset_t) {
102 module.setCalibration(JCalibration());
103 module.setStatus(JStatus());
104 module.setQuaternion(JQuaternion3D());
105 module.set(getModule<JKM3NeT_t>(1).getPosition());
107 for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
112 }
else if (action == RESET_t) {
114 module.setCalibration(JCalibration());
115 module.setQuaternion(JQuaternion3D());
116 module.setCalibration(getAverage(make_array(module.begin(), module.end(), &JPMT::getT0), 0.0));
135 inline bool apply(
JModule& module,
const std::string& action,
const double value)
137 if (action == set_t) {
141 }
else if (action == setx_t) {
143 module.set(JVector3D(value, module.getY(), module.getZ()));
145 }
else if (action == addx_t) {
147 module.add(JVector3D(value, 0.0, 0.0));
149 }
else if (action == subx_t) {
151 module.sub(JVector3D(value, 0.0, 0.0));
153 }
else if (action == sety_t) {
155 module.set(JVector3D(module.getX(), value, module.getZ()));
157 }
else if (action == addy_t) {
159 module.add(JVector3D(0.0, value, 0.0));
161 }
else if (action == suby_t) {
163 module.sub(JVector3D(0.0, value, 0.0));
165 }
else if (action == setz_t) {
167 module.set(JVector3D(module.getX(), module.getY(), value));
169 }
else if (action == addz_t) {
171 module.add(JVector3D(0.0, 0.0, value));
173 }
else if (action == subz_t) {
175 module.sub(JVector3D(0.0, 0.0, value));
177 }
else if (action == add_t) {
181 }
else if (action == sub_t) {
185 }
else if (action == rot_t) {
187 const JVector3D center =
module.getPosition();
191 module.rotate(JRotation3Z(value));
195 }
else if (action == lower_t ||
198 const JVector3D center =
module.getPosition();
204 for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
205 if ((action == upper_t && pmt->getDZ() > 0.0) ||
206 (action == lower_t && pmt->getDZ() < 0.0)) {
213 }
else if (action == mul_t) {
228 }
else if (action == div_t) {
243 }
else if (action == SET_t) {
245 module.getCalibration().setT0(value);
247 }
else if (action == ADD_t) {
249 module.getCalibration().addT0(value);
251 }
else if (action == SUB_t) {
253 module.getCalibration().subT0(value);
255 }
else if (action == ROT_t) {
257 module.setQuaternion(JQuaternion3Z(value) * module.getQuaternion());
259 }
else if (action == randadd_t) {
261 module.add(gRandom->Gaus(0.0, value));
263 }
else if (action == randsub_t) {
265 module.sub(gRandom->Gaus(0.0, value));
267 }
else if (action == randrot_t){
269 const JVector3D center =
module.getPosition();
273 module.rotate(JRotation3Z(gRandom->Gaus(0.0, value)));
277 }
else if (action == randmul_t) {
285 }
else if (action == randdiv_t) {
293 }
else if (action == assign_t) {
295 module.setID((int) value);
299 module.setLocation(JLocation((int) value, module.getFloor()));
319 inline bool apply(
JModule& module,
const std::string& action,
const double first,
const double second)
321 if (action == tilt_t) {
323 const double Tx = first;
324 const double Ty = second;
325 const double Tz = sqrt(1.0 - Tx*Tx - Ty*Ty);
327 const double x = Tx * module.
getZ() +
module.getX();
328 const double y = Ty * module.
getZ() +
module.getY();
329 const double z = Tz * module.
getZ();
331 module.set(JPosition3D(x,y,z));
333 }
else if (action == locate_t) {
335 module.setLocation(JLocation((int) first, (int) second));
337 }
else if (action == swap_t) {
339 std::swap(module[(
int) first], module[(
int) second]);
358 inline bool apply(
JModule& module,
const std::string& action,
const JVector3D& pos)
361 gRandom->Gaus(0.0, pos.
getY()),
362 gRandom->Gaus(0.0, pos.
getZ()));
366 else if (action == add_t)
368 else if (action == sub_t)
370 else if (action == randset_t)
372 else if (action == randadd_t)
374 else if (action == randsub_t)
394 module.setQuaternion(Q);
395 else if (action == ADD_t)
396 module.setQuaternion(Q * module.getQuaternion());
397 else if (action == SUB_t)
398 module.setQuaternion(Q.getConjugate() * module.getQuaternion());
402 module.getQuaternion().normalise();
416 inline bool apply(
JModule& module,
const std::string& action,
const std::string& value)
421 module.getStatus().set (getModuleStatusBit(value));
422 else if (action == reset_t)
423 module.getStatus().reset(getModuleStatusBit(value));
429 catch(
const std::exception&) {
443 inline bool apply(
JPMT& pmt,
const std::string& action,
const std::string& value)
449 else if (action == reset_t)
456 catch(
const std::exception&) {
480 return (action !=
"" && !
data.empty());
490 bool apply(
JModule& module)
const
492 switch (
data.size()) {
495 return ::apply(module, action);
498 return ::apply(module, action, data[0]);
501 return ::apply(module, action, data[0], data[1]);
504 return ::apply(module, action,
JVector3D(data[0], data[1], data[2]));
507 return ::apply(module, action,
JQuaternion3D(data[0], data[1], data[2], data[3]));
522 friend inline std::istream&
operator>>(std::istream& in, JModifier& modifier)
524 if (in >> modifier.action) {
526 modifier.data.clear();
528 for (
double x; in >>
x; ) {
529 modifier.data.push_back(x);
532 in.clear(std::ios_base::eofbit);
546 friend inline std::ostream&
operator<<(std::ostream& out,
const JModifier& modifier)
548 out << modifier.action;
550 for (std::vector<double>::const_iterator i = modifier.data.begin(); i != modifier.data.end(); ++i) {
573 inline const JModifier& getModifier(
const int id,
const JModifier& modifier)
579 const string::size_type pos = modifier.action.find(rand_t);
581 if (pos != string::npos) {
583 JModifier&
result = buffer[id][modifier.action][modifier.data.size()];
587 result.action = modifier.action.substr(pos + rand_t.length());
589 for (
size_t i = 0; i != modifier.data.size(); ++i) {
590 result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
606 struct JModuleModifier {
620 bool apply(
JModule& module)
const
622 return ::apply(module, action, value);
633 friend inline std::istream&
operator>>(std::istream& in, JModuleModifier& modifier)
635 return in >> modifier.action >> modifier.value;
646 friend inline std::ostream&
operator<<(std::ostream& out,
const JModuleModifier& modifier)
648 out << modifier.action;
650 out << modifier.value;
664 struct JPMTModifier {
678 bool apply(
JPMT& pmt)
const
680 return ::apply(pmt, action, value);
691 friend inline std::istream&
operator>>(std::istream& in, JPMTModifier& modifier)
693 return in >> modifier.action >> modifier.value;
704 friend inline std::ostream&
operator<<(std::ostream& out,
const JPMTModifier& modifier)
706 out << modifier.action;
708 out << modifier.value;
730 static const char SEPARATOR =
'-';
749 if (in >> range.
first) {
753 if (in.peek() == (
int) JRange_t::SEPARATOR) {
778 return out << range.
first << JRange_t::SEPARATOR << range.
second;
790 inline void print(std::ostream& out,
const JModule& module,
const JModifier& modifier)
795 out <<
"Modifier" <<
' '
797 << setw(10) << module.
getID() <<
' '
798 <<
"action " << modifier << endl;
814 out <<
"module modifier" <<
' '
815 <<
"(" << setw(10) <<
id.getID() <<
")" <<
' '
816 <<
"action" <<
' ' << modifier.action <<
' '
817 <<
"value" <<
' ' << modifier.value << endl;
828 inline void print(std::ostream& out,
const JPMTIdentifier& pmt,
const JPMTModifier& modifier)
833 out <<
"PMT modifier" <<
' '
834 <<
"(" << setw(10) << pmt.
getID() <<
"," << setw(2) << pmt.
getPMTAddress() <<
")" <<
' '
835 <<
"action" <<
' ' << modifier.action <<
' '
836 <<
"value" <<
' ' << modifier.value << endl;
954 typedef JToken<
';'> JToken_t;
963 JModuleModifier> > wip;
981 JParser<> zap(
"Auxiliary program to modify detector.");
998 zap[
'O'] =
make_field(option,
"sort modules: "\
999 "0 -> no sort; 1 -> module identifier; 2 -> module location") = 0, 1, 2;
1000 zap[
'q'] =
make_field(squash,
"squash meta data");
1005 catch(
const exception &error) {
1006 FATAL(error.what() << endl);
1009 gRandom->SetSeed(0);
1011 const int ns = ((keep.empty() ? 0 : 1) +
1012 (rm .empty() ? 0 : 1) +
1013 (
id .empty() ? 0 : 1) +
1014 (del .empty() ? 0 : 1));
1017 FATAL(
"Use either option -k, -r, -m or -D." << endl);
1035 if (
detector.setToLatestVersion()) {
1036 NOTICE(
"Set detector version to " <<
detector.getVersion() << endl);
1048 for (vector<JToken_t>::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
1050 istringstream is(*i);
1063 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ) {
1065 bool __rm__ = !keep.empty() && rm.empty();
1067 for (vector<JRange_t>::const_iterator i = keep.begin(); i != keep.end(); ++i) {
1073 for (vector<JRange_t>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
1080 __rm__ = find(
id.begin(),
id.end(), module->
getID()) ==
id.end();
1083 const auto range = del.equal_range(module->
getString());
1085 for (
auto i = range.
first; i != range.
second; ++i) {
1086 if (i->second == module->
getFloor()) {
1092 module = detector.erase(module);
1101 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1103 if (module->
getID() == i->first || i->first == WILDCARD ){
1106 print(cout, *module, i->second);
1109 if (!i->second.apply(*module)) {
1110 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1119 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1121 if (module->
getString() == i->first || i->first == WILDCARD) {
1123 const JModifier modifier = getModifier(module->
getString(), i->second);
1126 print(cout, *module, i->second);
1129 if (!modifier.apply(*module)) {
1130 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1140 const string action(
"fix distance between floors 0 and 1");
1144 DEBUG(
"String " << setw(4) << i->first <<
' ' << action <<
' ' <<
FIXED(7,3) << i->second << endl);
1155 module.set(JVector3D(module.getX(), module.getY(), z1 - i->second));
1159 ERROR(
"No valid action: " << i->first <<
' ' << action << endl);
1167 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1171 if (module->
getString() == i->first || i->first == WILDCARD) {
1173 const JModifier modifier = getModifier(module->
getString(), i->second);
1176 print(cout, *module, i->second);
1179 if (!modifier.apply(*module)) {
1180 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1190 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1192 if (module->
getID() == i->first || i->first == WILDCARD ){
1195 print(cout, *module, i->second);
1198 if (!i->second.apply(*module)) {
1199 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1208 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1210 if (module->
getID() == i->first.getModuleID() || i->first.getModuleID() == WILDCARD) {
1213 print(cout, i->first, i->second);
1216 if (i->first.getPMTAddress() == WILDCARD) {
1219 if (!i->second.apply(module->
getPMT(pmt))) {
1220 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1224 }
else if (i->first.getPMTAddress() >= 0 &&
1226 !i->second.apply(module->
getPMT(i->first.getPMTAddress()))) {
1227 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1234 if (!alt.empty() || !ring.empty()) {
1237 FATAL(
"Invalid detector identifier " <<
detector.getID() << endl);
1242 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1251 print(cout,
id, i->second);
1254 if (!i->second.apply(module->
getPMT(
id.getPMTAddress()))) {
1255 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1259 const auto range = ring.equal_range(module->
getID());
1261 for (
auto i = range.
first; i != range.
second; ++i) {
1265 modifier.
ring = (char) toupper(modifier.
ring);
1267 if (modifier.
ring !=
'A') {
1271 for (
size_t i = 0; i !=
module->size(); ++i) {
1275 if (address.
ring == modifier.
ring) {
1276 buffer[address] = (*module)[i];
1280 for (
size_t i = 0; i !=
module->size(); ++i) {
1284 if (address.
ring == modifier.
ring) {
1288 while (position > 6) { position -= 6; }
1289 while (position < 1) { position += 6; }
1293 DEBUG(
"Module " << setw(10) << module->
getID() <<
' ' << address <<
" <= " << source << endl);
1295 (*module)[i] = buffer[source];
Data structure for detector geometry and calibration.
int main(int argc, char **argv)
Direct access to location in detector data structure.
Base class for data structures with artithmetic capabilities.
General purpose messaging.
#define DEBUG(A)
Message macros.
Direct access to module in detector data structure.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
I/O formatting auxiliaries.
Auxiliary class to define a range between two values.
Data structure for time calibration.
Lookup table for PMT addresses in detector.
const JModuleAddressMap & get(const int id) const
Get module address map.
Router for direct addressing of location data in detector data structure.
bool hasLocation(const JLocation &location) const
Has module.
const JModuleAddress & getAddress(const JLocation &location) const
Get address of location.
Logical location of module.
const JLocation & getLocation() const
Get location.
int getFloor() const
Get floor number.
int getString() const
Get string number.
Lookup table for PMT addresses in optical module.
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
const JPMTPhysicalAddress & getPMTPhysicalAddress(const int tdc) const
Get PMT physical address.
int first
index of module in detector data structure
Data structure for a composite optical module.
const JPMT & getPMT(const int index) const
Get PMT.
int getPMTAddress() const
Get PMT address (= TDC).
Data structure for PMT physical address.
char ring
ring number ['A','F']
int position
position within ring [1,6]
Data structure for PMT geometry, calibration and status.
Utility class to parse parameter values.
const JPosition3D & getPosition() const
Get position.
Data structure for unit quaternion in three dimensions.
Data structure for vector in three dimensions.
double getY() const
Get y position.
double getZ() const
Get z position.
double getX() const
Get x position.
Auxiliary class for object identification.
int getID() const
Get identifier.
Wrapper class around string.
Utility class to parse command line options.
static const std::string string_t
string
std::ostream & print(std::ostream &out, const JTestSummary &summary, T __begin, T __end, const bool useColors=true, const JFormat_t &formatting=JFormat_t(18, 3, std::ios::fixed))
Print test summary.
std::istream & operator>>(std::istream &in, JAHRSCalibration &calibration)
Read AHRS calibration from input stream.
std::ostream & operator<<(std::ostream &out, const JAHRSCalibration &calibration)
Write AHRS calibration to output stream.
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
static const JGetPMTStatusBit getPMTStatusBit
Function object to map key to PMT status bit.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool is_valid(const json &js)
Check validity of JSon data.
Auxiliary data structure for floating point format specification.
Type definition of range.
JRange_t()
Default constructor.
Auxiliary class for handling status.
int getStatus() const
Get status.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...