44 static const int WILDCARD = -1;
46 static const std::string reset_t =
"reset";
47 static const std::string set_t =
"set";
48 static const std::string setx_t =
"setx";
49 static const std::string sety_t =
"sety";
50 static const std::string setz_t =
"setz";
51 static const std::string add_t =
"add";
52 static const std::string sub_t =
"sub";
53 static const std::string rot_t =
"rot";
54 static const std::string mul_t =
"mul";
55 static const std::string div_t =
"div";
56 static const std::string tilt_t =
"tilt";
57 static const std::string swap_t =
"swap";
59 static const std::string assign_t =
"assign";
60 static const std::string locate_t =
"locate";
61 static const std::string string_t =
"string";
63 static const std::string rand_t =
"rand";
64 static const std::string randset_t = rand_t + set_t;
65 static const std::string randadd_t = rand_t + add_t;
66 static const std::string randsub_t = rand_t + sub_t;
67 static const std::string randrot_t = rand_t + rot_t;
68 static const std::string randmul_t = rand_t + mul_t;
69 static const std::string randdiv_t = rand_t + div_t;
70 static const std::string randtilt_t = rand_t + tilt_t;
72 static const std::string RESET_t =
"RESET";
73 static const std::string SET_t =
"SET";
74 static const std::string ADD_t =
"ADD";
75 static const std::string SUB_t =
"SUB";
76 static const std::string ROT_t =
"ROT";
86 inline bool apply(
JModule& module,
const std::string& action)
88 if (action == reset_t) {
94 for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
99 }
else if (action == RESET_t) {
104 }
else if (action == SET_t) {
130 inline bool apply(
JModule& module,
const std::string& action,
const double value)
132 if (action == set_t) {
136 }
else if (action == setx_t) {
140 }
else if (action == sety_t) {
144 }
else if (action == setz_t) {
148 }
else if (action == add_t) {
152 }
else if (action == sub_t) {
156 }
else if (action == rot_t) {
166 }
else if (action == mul_t) {
174 }
else if (action == div_t) {
182 }
else if (action == SET_t) {
186 }
else if (action == ADD_t) {
190 }
else if (action == SUB_t) {
194 }
else if (action == ROT_t) {
198 }
else if (action == randadd_t) {
200 module.
add(gRandom->Gaus(0.0, value));
202 }
else if (action == randsub_t) {
204 module.
sub(gRandom->Gaus(0.0, value));
206 }
else if (action == randrot_t){
216 }
else if (action == randmul_t) {
224 }
else if (action == randdiv_t) {
232 }
else if (action == assign_t) {
234 module.
setID((
int) value);
236 }
else if (action == string_t) {
258 inline bool apply(
JModule& module,
const std::string& action,
const double first,
const double second)
260 if (action == tilt_t) {
262 const double Tx =
first;
263 const double Ty = second;
264 const double Tz = sqrt(1.0 - Tx*Tx - Ty*Ty);
266 const double x = Tx * module.
getZ() + module.
getX();
267 const double y = Ty * module.
getZ() + module.
getY();
268 const double z = Tz * module.
getZ();
272 }
else if (action == locate_t) {
276 }
else if (action == swap_t) {
278 std::swap(module[(
int) first], module[(
int) second]);
297 inline bool apply(
JModule& module,
const std::string& action,
const JVector3D& pos)
300 gRandom->Gaus(0.0, pos.
getY()),
301 gRandom->Gaus(0.0, pos.
getZ()));
305 else if (action == add_t)
307 else if (action == sub_t)
309 else if (action == randset_t)
311 else if (action == randadd_t)
313 else if (action == randsub_t)
334 else if (action == ADD_t)
336 else if (action == SUB_t)
353 inline bool apply(
JModule& module,
const std::string& action,
const std::string& value)
359 else if (action == reset_t)
366 catch(
const std::exception&) {
380 inline bool apply(
JPMT& pmt,
const std::string& action,
const std::string& value)
386 else if (action == reset_t)
393 catch(
const std::exception&) {
417 return (action !=
"" && !data.empty());
427 bool apply(
JModule& module)
const
429 switch (data.size()) {
432 return ::apply(module, action);
435 return ::apply(module, action, data[0]);
438 return ::apply(module, action, data[0], data[1]);
441 return ::apply(module, action,
JVector3D(data[0], data[1], data[2]));
444 return ::apply(module, action,
JQuaternion3D(data[0], data[1], data[2], data[3]));
459 friend inline std::istream&
operator>>(std::istream&
in, JModifier& modifier)
461 if (in >> modifier.action) {
463 modifier.data.clear();
465 for (
double x; in >>
x; ) {
466 modifier.data.push_back(x);
469 in.clear(std::ios_base::eofbit);
483 friend inline std::ostream&
operator<<(std::ostream& out,
const JModifier& modifier)
485 out << modifier.action;
510 inline const JModifier& getModifier(
const int id,
const JModifier& modifier)
516 const string::size_type pos = modifier.action.find(rand_t);
518 if (pos != string::npos) {
520 JModifier&
result = buffer[id][modifier.action][modifier.data.size()];
522 if (!result.is_valid()) {
524 result.action = modifier.action.substr(pos + rand_t.length());
526 for (
size_t i = 0; i != modifier.data.size(); ++i) {
527 result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
543 struct JModuleModifier {
557 bool apply(
JModule& module)
const
559 return ::apply(module, action, value);
570 friend inline std::istream&
operator>>(std::istream& in, JModuleModifier& modifier)
572 return in >> modifier.action >> modifier.value;
583 friend inline std::ostream&
operator<<(std::ostream& out,
const JModuleModifier& modifier)
585 out << modifier.action;
587 out << modifier.value;
601 struct JPMTModifier {
615 bool apply(
JPMT& pmt)
const
617 return ::apply(pmt, action, value);
628 friend inline std::istream&
operator>>(std::istream& in, JPMTModifier& modifier)
630 return in >> modifier.action >> modifier.value;
641 friend inline std::ostream&
operator<<(std::ostream& out,
const JPMTModifier& modifier)
643 out << modifier.action;
645 out << modifier.value;
667 static const char SEPARATOR =
'-';
684 friend inline std::istream&
operator>>(std::istream& in, JRange_t&
range)
686 if (in >> range.first) {
688 range.second = range.first;
690 if (in.peek() == (int) JRange_t::SEPARATOR) {
713 friend inline std::ostream&
operator<<(std::ostream& out,
const JRange_t& range)
715 return out << range.first << JRange_t::SEPARATOR << range.second;
727 inline void print(std::ostream& out,
const JModule& module,
const JModifier& modifier)
732 out <<
"Modifier" <<
' '
734 << setw(10) << module.
getID() <<
' '
735 <<
"action" <<
' ' << modifier.action <<
JEEPZ() << modifier.data << endl;
751 out <<
"module modifier" <<
' '
752 <<
"(" << setw(10) <<
id.getID() <<
")" <<
' '
753 <<
"action" <<
' ' << modifier.action <<
' '
754 <<
"value" <<
' ' << modifier.value << endl;
765 inline void print(std::ostream& out,
const JPMTIdentifier& pmt,
const JPMTModifier& modifier)
770 out <<
"PMT modifier" <<
' '
771 <<
"(" << setw(10) << pmt.
getID() <<
"," << setw(2) << pmt.
getPMTAddress() <<
")" <<
' '
772 <<
"action" <<
' ' << modifier.action <<
' '
773 <<
"value" <<
' ' << modifier.value << endl;
877 int main(
int argc,
char **argv)
891 JModuleModifier> > wip;
905 JParser<> zap(
"Auxiliary program to modify detector.");
920 zap[
'O'] =
make_field(option,
"sort modules") = 0, 1, 2;
925 catch(
const exception &error) {
926 FATAL(error.what() << endl);
942 if ((keep.empty() ? 0 : 1 +
943 rm .empty() ? 0 : 1 +
944 id .empty() ? 0 : 1) > 1) {
945 FATAL(
"Use either option -k, -r or -m." << endl);
951 if (
detector.setToLatestVersion()) {
952 NOTICE(
"Set detector version to " <<
detector.getVersion() << endl);
966 istringstream
is(*i);
977 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ) {
979 bool __rm__ = !keep.empty() &&
rm.empty();
994 __rm__ = find(
id.begin(),
id.end(), module->
getID()) ==
id.end();
997 const auto range = del.equal_range(module->
getString());
999 for (
auto i = range.first; i != range.second; ++i) {
1000 if (i->second == module->
getFloor()) {
1014 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1016 if (module->
getID() == i->first || i->first == WILDCARD ){
1019 print(cout, *module, i->second);
1022 if (!i->second.apply(*module)) {
1023 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1032 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1034 if (module->
getString() == i->first || i->first == WILDCARD) {
1036 const JModifier modifier = getModifier(module->
getString(), i->second);
1039 print(cout, *module, i->second);
1042 if (!modifier.apply(*module)) {
1043 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1052 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1056 if (module->
getString() == i->first || i->first == WILDCARD) {
1058 const JModifier modifier = getModifier(module->
getString(), i->second);
1061 print(cout, *module, i->second);
1064 if (!modifier.apply(*module)) {
1065 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1075 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1077 if (module->
getID() == i->first || i->first == WILDCARD ){
1080 print(cout, *module, i->second);
1083 if (!i->second.apply(*module)) {
1084 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1093 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1095 if (module->
getID() == i->first.getModuleID() || i->first.getModuleID() == WILDCARD) {
1098 print(cout, i->first, i->second);
1101 if (i->first.getPMTAddress() == WILDCARD) {
1104 if (!i->second.apply(module->
getPMT(pmt))) {
1105 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1109 }
else if (i->first.getPMTAddress() < 0 ||
1111 !i->second.apply(module->
getPMT(i->first.getPMTAddress()))) {
1112 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1122 FATAL(
"Invalid detector identifier " <<
detector.getID() << endl);
1127 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1136 print(cout,
id, i->second);
1139 if (!i->second.apply(module->
getPMT(
id.getPMTAddress()))) {
1140 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
Utility class to parse command line options.
static const JGetPMTStatusBit getPMTStatusBit
Function object to map key to PMT status bit.
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
int getFloor() const
Get floor number.
Data structure for a composite optical module.
static const double HYDROPHONE_DELAYTIME_US
Hydrophone delay time [us].
JQuaternion3D getConjugate() const
Get conjugate of this quaternion.
void setLocation(const JLocation &location)
Set location.
const JCalibration & getCalibration() const
Get calibration.
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
Utility class to parse parameter values.
std::iterator_traits< T >::value_type getAverage(T __begin, T __end)
Get average.
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
void subT0(const double t0)
Subtract time offset.
Lookup table for PMT addresses in detector.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
void reset(const int bit)
Reset PMT status.
Data structure for time calibration.
static const JGetModuleStatusBit getModuleStatusBit
Function object to map key to module status bit.
Data structure for detector geometry and calibration.
const JModuleAddressMap & get(const int id) const
Get module address map.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
const JQuaternion3D & getQuaternion() const
Get quaternion.
JModule & sub(const JVector3D &pos)
Subtract position.
Lookup table for PMT addresses in optical module.
I/O formatting auxiliaries.
static const double PIEZO_DELAYTIME_US
Piezo delay time [us].
Data structure for vector in three dimensions.
void setQuaternion(const JQuaternion3D &quaternion)
Set quaternion.
Logical location of module.
const JLocation & getLocation() const
Get location.
void set(const int bit)
Set PMT status.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
int getID() const
Get identifier.
Auxiliary class for handling status.
This class represents a rotation around the z-axis.
bool is_valid(const json &js)
Check validity of JSon data.
Data structure for PMT geometry, calibration and status.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
JPosition3D getPosition(const Vec &pos)
Get position.
int getPMTAddress() const
Get PMT address (= TDC).
double getY() const
Get y position.
Auxiliary data structure for streaming of STL containers.
const JPosition3D & getPosition() const
Get position.
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
const JPMT & getPMT(const int index) const
Get PMT.
void rotate(const JRotation3D &R)
Rotate module.
General purpose messaging.
Auxiliary data structure for sequence of same character.
Data structure for unit quaternion in three dimensions.
Direct access to module in detector data structure.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
int getString() const
Get string number.
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
const JStatus & getStatus() const
Get status.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void setT0(const double t0)
Set time offset.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
Auxiliary class for object identification.
Wrapper class around string.
void setCalibration(const JCalibration &cal)
Set calibration.
void setID(const int id)
Set identifier.
double getX() const
Get x position.
Base class for data structures with artithmetic capabilities.
void addT0(const double t0)
Add time offset.
Data structure for position in three dimensions.
Data structure for PMT physical address.
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
JModule & set(const JVector3D &pos)
Set position.
double getZ() const
Get z position.
JModule & add(const JVector3D &pos)
Add position.
double getT0() const
Get time offset.