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 addx_t =
"addx";
52 static const std::string addy_t =
"addy";
53 static const std::string addz_t =
"addz";
54 static const std::string subx_t =
"subx";
55 static const std::string suby_t =
"suby";
56 static const std::string subz_t =
"subz";
57 static const std::string add_t =
"add";
58 static const std::string sub_t =
"sub";
59 static const std::string rot_t =
"rot";
60 static const std::string mul_t =
"mul";
61 static const std::string div_t =
"div";
62 static const std::string tilt_t =
"tilt";
63 static const std::string swap_t =
"swap";
65 static const std::string assign_t =
"assign";
66 static const std::string locate_t =
"locate";
67 static const std::string string_t =
"string";
69 static const std::string rand_t =
"rand";
70 static const std::string randset_t = rand_t + set_t;
71 static const std::string randadd_t = rand_t + add_t;
72 static const std::string randsub_t = rand_t + sub_t;
73 static const std::string randrot_t = rand_t + rot_t;
74 static const std::string randmul_t = rand_t + mul_t;
75 static const std::string randdiv_t = rand_t + div_t;
76 static const std::string randtilt_t = rand_t + tilt_t;
78 static const std::string RESET_t =
"RESET";
79 static const std::string SET_t =
"SET";
80 static const std::string ADD_t =
"ADD";
81 static const std::string SUB_t =
"SUB";
82 static const std::string ROT_t =
"ROT";
92 inline bool apply(
JModule& module,
const std::string& action)
94 if (action == reset_t) {
100 for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
105 }
else if (action == RESET_t) {
128 inline bool apply(
JModule& module,
const std::string& action,
const double value)
130 if (action == set_t) {
134 }
else if (action == setx_t) {
138 }
else if (action == addx_t) {
142 }
else if (action == subx_t) {
146 }
else if (action == sety_t) {
150 }
else if (action == addy_t) {
154 }
else if (action == suby_t) {
158 }
else if (action == setz_t) {
162 }
else if (action == addz_t) {
166 }
else if (action == subz_t) {
170 }
else if (action == add_t) {
174 }
else if (action == sub_t) {
178 }
else if (action == rot_t) {
188 }
else if (action == mul_t) {
203 }
else if (action == div_t) {
218 }
else if (action == SET_t) {
222 }
else if (action == ADD_t) {
226 }
else if (action == SUB_t) {
230 }
else if (action == ROT_t) {
234 }
else if (action == randadd_t) {
236 module.
add(gRandom->Gaus(0.0, value));
238 }
else if (action == randsub_t) {
240 module.
sub(gRandom->Gaus(0.0, value));
242 }
else if (action == randrot_t){
252 }
else if (action == randmul_t) {
260 }
else if (action == randdiv_t) {
268 }
else if (action == assign_t) {
270 module.
setID((
int) value);
272 }
else if (action == string_t) {
294 inline bool apply(
JModule& module,
const std::string& action,
const double first,
const double second)
296 if (action == tilt_t) {
298 const double Tx =
first;
299 const double Ty = second;
300 const double Tz = sqrt(1.0 - Tx*Tx - Ty*Ty);
302 const double x = Tx * module.
getZ() + module.
getX();
303 const double y = Ty * module.
getZ() + module.
getY();
304 const double z = Tz * module.
getZ();
308 }
else if (action == locate_t) {
312 }
else if (action == swap_t) {
314 std::swap(module[(
int) first], module[(
int) second]);
333 inline bool apply(
JModule& module,
const std::string& action,
const JVector3D& pos)
336 gRandom->Gaus(0.0, pos.
getY()),
337 gRandom->Gaus(0.0, pos.
getZ()));
341 else if (action == add_t)
343 else if (action == sub_t)
345 else if (action == randset_t)
347 else if (action == randadd_t)
349 else if (action == randsub_t)
370 else if (action == ADD_t)
372 else if (action == SUB_t)
391 inline bool apply(
JModule& module,
const std::string& action,
const std::string& value)
397 else if (action == reset_t)
404 catch(
const std::exception&) {
418 inline bool apply(
JPMT& pmt,
const std::string& action,
const std::string& value)
424 else if (action == reset_t)
431 catch(
const std::exception&) {
455 return (action !=
"" && !data.empty());
465 bool apply(
JModule& module)
const
467 switch (data.size()) {
470 return ::apply(module, action);
473 return ::apply(module, action, data[0]);
476 return ::apply(module, action, data[0], data[1]);
479 return ::apply(module, action,
JVector3D(data[0], data[1], data[2]));
482 return ::apply(module, action,
JQuaternion3D(data[0], data[1], data[2], data[3]));
497 friend inline std::istream&
operator>>(std::istream&
in, JModifier& modifier)
499 if (in >> modifier.action) {
501 modifier.data.clear();
503 for (
double x; in >>
x; ) {
504 modifier.data.push_back(x);
507 in.clear(std::ios_base::eofbit);
521 friend inline std::ostream&
operator<<(std::ostream& out,
const JModifier& modifier)
523 out << modifier.action;
548 inline const JModifier& getModifier(
const int id,
const JModifier& modifier)
554 const string::size_type pos = modifier.action.find(rand_t);
556 if (pos != string::npos) {
558 JModifier&
result = buffer[id][modifier.action][modifier.data.size()];
560 if (!result.is_valid()) {
562 result.action = modifier.action.substr(pos + rand_t.length());
564 for (
size_t i = 0; i != modifier.data.size(); ++i) {
565 result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
581 struct JModuleModifier {
595 bool apply(
JModule& module)
const
597 return ::apply(module, action, value);
608 friend inline std::istream&
operator>>(std::istream& in, JModuleModifier& modifier)
610 return in >> modifier.action >> modifier.value;
621 friend inline std::ostream&
operator<<(std::ostream& out,
const JModuleModifier& modifier)
623 out << modifier.action;
625 out << modifier.value;
639 struct JPMTModifier {
653 bool apply(
JPMT& pmt)
const
655 return ::apply(pmt, action, value);
666 friend inline std::istream&
operator>>(std::istream& in, JPMTModifier& modifier)
668 return in >> modifier.action >> modifier.value;
679 friend inline std::ostream&
operator<<(std::ostream& out,
const JPMTModifier& modifier)
681 out << modifier.action;
683 out << modifier.value;
705 static const char SEPARATOR =
'-';
724 if (in >> range.
first) {
728 if (in.peek() == (int) JRange_t::SEPARATOR) {
753 return out << range.
first << JRange_t::SEPARATOR << range.
second;
765 inline void print(std::ostream& out,
const JModule& module,
const JModifier& modifier)
770 out <<
"Modifier" <<
' '
772 << setw(10) << module.
getID() <<
' '
773 <<
"action" <<
' ' << modifier.action <<
JEEPZ() << modifier.data << endl;
789 out <<
"module modifier" <<
' '
790 <<
"(" << setw(10) <<
id.getID() <<
")" <<
' '
791 <<
"action" <<
' ' << modifier.action <<
' '
792 <<
"value" <<
' ' << modifier.value << endl;
803 inline void print(std::ostream& out,
const JPMTIdentifier& pmt,
const JPMTModifier& modifier)
808 out <<
"PMT modifier" <<
' '
809 <<
"(" << setw(10) << pmt.
getID() <<
"," << setw(2) << pmt.
getPMTAddress() <<
")" <<
' '
810 <<
"action" <<
' ' << modifier.action <<
' '
811 <<
"value" <<
' ' << modifier.value << endl;
913 int main(
int argc,
char **argv)
927 JModuleModifier> > wip;
942 JParser<> zap(
"Auxiliary program to modify detector.");
957 zap[
'O'] =
make_field(option,
"sort modules") = 0, 1, 2;
958 zap[
'q'] =
make_field(squash,
"squash meta data");
963 catch(
const exception &error) {
964 FATAL(error.what() << endl);
980 if ((keep.empty() ? 0 : 1 +
981 rm .empty() ? 0 : 1 +
982 id .empty() ? 0 : 1) > 1) {
983 FATAL(
"Use either option -k, -r or -m." << endl);
992 if (
detector.setToLatestVersion()) {
993 NOTICE(
"Set detector version to " <<
detector.getVersion() << endl);
1007 istringstream
is(*i);
1018 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ) {
1020 bool __rm__ = !keep.empty() &&
rm.empty();
1035 __rm__ = find(
id.begin(),
id.end(), module->
getID()) ==
id.end();
1038 const auto range = del.equal_range(module->
getString());
1040 for (
auto i = range.
first; i != range.
second; ++i) {
1041 if (i->second == module->
getFloor()) {
1055 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1057 if (module->
getID() == i->first || i->first == WILDCARD ){
1060 print(cout, *module, i->second);
1063 if (!i->second.apply(*module)) {
1064 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1073 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1075 if (module->
getString() == i->first || i->first == WILDCARD) {
1077 const JModifier modifier = getModifier(module->
getString(), i->second);
1080 print(cout, *module, i->second);
1083 if (!modifier.apply(*module)) {
1084 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1093 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1097 if (module->
getString() == i->first || i->first == WILDCARD) {
1099 const JModifier modifier = getModifier(module->
getString(), i->second);
1102 print(cout, *module, i->second);
1105 if (!modifier.apply(*module)) {
1106 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1116 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1118 if (module->
getID() == i->first || i->first == WILDCARD ){
1121 print(cout, *module, i->second);
1124 if (!i->second.apply(*module)) {
1125 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1134 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1136 if (module->
getID() == i->first.getModuleID() || i->first.getModuleID() == WILDCARD) {
1139 print(cout, i->first, i->second);
1142 if (i->first.getPMTAddress() == WILDCARD) {
1145 if (!i->second.apply(module->
getPMT(pmt))) {
1146 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1150 }
else if (i->first.getPMTAddress() >= 0 &&
1152 !i->second.apply(module->
getPMT(i->first.getPMTAddress()))) {
1153 ERROR(
"No valid action: " << i->first <<
' ' << i->second << endl);
1163 FATAL(
"Invalid detector identifier " <<
detector.getID() << endl);
1168 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1177 print(cout,
id, i->second);
1180 if (!i->second.apply(module->
getPMT(
id.getPMTAddress()))) {
1181 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.
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)...
Data structure for time calibration.
static const JGetModuleStatusBit getModuleStatusBit
Function object to map key to module status bit.
JRange_t()
Default constructor.
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.
int getStatus() const
Get status.
Type definition of range.
I/O formatting auxiliaries.
Data structure for vector in three dimensions.
void setQuaternion(const JQuaternion3D &quaternion)
Set quaternion.
Logical location of module.
const JLocation & getLocation() const
Get location.
#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.
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.
JQuaternion3D & normalise()
Normalise quaternion.
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS 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.