37 static const int WILDCARD = -1;
39 static const char EOL =
';';
41 static const std::string reset_t =
"reset";
42 static const std::string set_t =
"set";
43 static const std::string add_t =
"add";
44 static const std::string sub_t =
"sub";
45 static const std::string rot_t =
"rot";
46 static const std::string mul_t =
"mul";
47 static const std::string via_t =
"via";
48 static const std::string assign_t =
"assign";
50 static const std::string rand_t =
"rand";
51 static const std::string randset_t = rand_t + set_t;
52 static const std::string randadd_t = rand_t + add_t;
53 static const std::string randsub_t = rand_t + sub_t;
54 static const std::string randrot_t = rand_t + rot_t;
55 static const std::string randmul_t = rand_t + mul_t;
56 static const std::string randvia_t = rand_t + via_t;
58 static const std::string RESET_t =
"RESET";
59 static const std::string SET_t =
"SET";
60 static const std::string ADD_t =
"ADD";
61 static const std::string SUB_t =
"SUB";
85 return (action !=
"" && !data.empty());
95 bool apply(
JModule& module)
const
97 switch (data.size()) {
100 return apply(module, action);
103 return apply(module, action, data[0]);
106 return apply(module, action,
JVector3D(data[0], data[1], 0.0));
109 return apply(module, action,
JVector3D(data[0], data[1], data[2]));
112 return apply(module, action,
JQuaternion3D(data[0], data[1], data[2], data[3]));
127 friend inline std::istream&
operator>>(std::istream&
in, JModifier& modifier)
131 if (in >> modifier.id >> modifier.action) {
133 modifier.data.clear();
135 for (
double x; in >> x; ) {
136 modifier.data.push_back(x);
139 in.clear(ios_base::eofbit);
153 friend inline std::ostream&
operator<<(std::ostream& out,
const JModifier& modifier)
157 out << modifier.action;
180 static bool apply(
JModule& module,
const std::string& action)
182 if (action == reset_t) {
186 for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
193 }
else if (action == RESET_t) {
200 }
else if (action == SET_t) {
224 static bool apply(
JModule& module,
const std::string& action,
const double value)
226 if (action == set_t) {
230 }
else if (action == add_t) {
234 }
else if (action == sub_t) {
238 }
else if (action == rot_t) {
248 }
else if (action == mul_t) {
259 }
else if (action == via_t) {
263 }
else if (action == SET_t) {
267 }
else if (action == ADD_t) {
271 }
else if (action == SUB_t) {
275 }
else if (action == randadd_t) {
277 module.
add(gRandom->Gaus(0.0, value));
279 }
else if (action == randsub_t) {
281 module.
sub(gRandom->Gaus(0.0, value));
283 }
else if (action == randrot_t){
293 }
else if (action == randmul_t) {
304 }
else if (action == randvia_t) {
306 module.
add(gRandom->Gaus(0.0, value) * module.
getFloor());
308 }
else if (action == assign_t) {
310 module.
setID((
int) value);
329 static bool apply(
JModule& module,
const std::string& action,
const JVector3D& pos)
332 gRandom->Gaus(0.0, pos.
getY()),
333 gRandom->Gaus(0.0, pos.
getZ()));
337 else if (action == add_t)
339 else if (action == sub_t)
341 else if (action == randset_t)
343 else if (action == randadd_t)
345 else if (action == randsub_t)
366 else if (action == ADD_t)
368 else if (action == SUB_t)
385 inline const JModifier& getModifier(
const int id,
const JModifier& modifier)
391 const string::size_type pos = modifier.action.find(rand_t);
393 if (pos != string::npos) {
395 JModifier&
result = buffer[id][modifier.action][modifier.data.size()];
397 if (!result.is_valid()) {
400 result.action = modifier.action.substr(pos + rand_t.length());
402 for (
size_t i = 0; i != modifier.data.size(); ++i) {
403 result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
419 template<
class JAddress_t>
437 bool apply(
JPMT& pmt)
const
441 if (action == set_t) {
445 }
else if (action == reset_t) {
456 catch(
const std::exception&) {}
469 friend inline std::istream&
operator>>(std::istream& in, JPMTModifier& modifier)
471 return in >>
static_cast<JAddress_t&
>(modifier) >> modifier.action >> modifier.value;
482 friend inline std::ostream&
operator<<(std::ostream& out,
const JPMTModifier& modifier)
484 out << static_cast<const JAddress_t&>(modifier);
486 out << modifier.action;
488 out << modifier.value;
507 static const char SEPARATOR =
'-';
524 friend inline std::istream&
operator>>(std::istream& in, JRange_t&
range)
526 if (in >> range.first) {
528 range.second = range.first;
530 if (in.peek() == (int) JRange_t::SEPARATOR) {
553 friend inline std::ostream&
operator<<(std::ostream& out,
const JRange_t& range)
555 return out << range.first << JRange_t::SEPARATOR << range.second;
650 int main(
int argc,
char **argv)
670 JParser<> zap(
"Auxiliary program to modify detector.");
687 catch(
const exception &error) {
688 FATAL(error.what() << endl);
704 if ((keep.empty() ? 0 : 1 +
705 rm .empty() ? 0 : 1 +
706 id .empty() ? 0 : 1) > 1) {
707 FATAL(
"Use either option -k, -r or -m." << endl);
713 if (
detector.setToLatestVersion()) {
714 NOTICE(
"Set detector version to " <<
detector.getVersion() << endl);
723 istringstream
is(*i);
730 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ) {
732 bool __rm__ = !keep.empty() && rm.empty();
747 __rm__ = find(
id.begin(),
id.end(), module->
getID()) ==
id.end();
750 const auto range = del.equal_range(module->
getString());
752 for (
auto i = range.first; i != range.second; ++i) {
753 if (i->second == module->
getFloor()) {
767 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
769 if (module->
getID() == i->id || i->id == WILDCARD ){
771 DEBUG(
"Modifier" <<
' '
773 << setw(10) << module->
getID() <<
' '
774 <<
"action" <<
' ' << i->action <<
JEEPZ() << i->data << endl);
776 if (!i->apply(*module)) {
777 ERROR(
"No valid action: " << *i << endl);
786 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
788 if (module->
getString() == i->id || i->id == WILDCARD) {
790 const JModifier& modifier = getModifier(module->
getString(), *i);
792 DEBUG(
"Modifier" <<
' '
794 << setw(10) << module->
getID() <<
' '
795 <<
"action" <<
' ' << modifier.action <<
JEEPZ() << modifier.data << endl);
797 if (!modifier.apply(*module)) {
798 ERROR(
"No valid action: " << *i << endl);
805 for (
vector< JPMTModifier<JPMTIdentifier> >::const_iterator i = pmt.begin(); i != pmt.end(); ++i) {
807 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
809 if (module->
getID() == i->getModuleID() || i->getModuleID() == WILDCARD) {
811 DEBUG(
"PMT modifier" <<
' '
812 <<
"(" << setw(10) << module->
getID() <<
"," << setw(2) << i->getPMTAddress() <<
")" <<
' '
813 <<
"action" <<
' ' << i->action <<
' '
814 <<
"value" <<
' ' << i->value << endl);
816 if (i->getPMTAddress() == WILDCARD) {
819 if (!i->apply(module->
getPMT(pmt))) {
820 ERROR(
"No valid action: " << *i << endl);
824 }
else if (i->getPMTAddress() < 0 ||
826 !i->apply(module->
getPMT(i->getPMTAddress()))) {
827 ERROR(
"No valid action: " << *i << endl);
836 FATAL(
"Invalid detector identifier " <<
detector.getID() << endl);
841 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
845 for (
vector< JPMTModifier<JPMTPhysicalAddress> >::const_iterator i = alt.begin(); i != alt.end(); ++i) {
849 DEBUG(
"PMT modifier" <<
' '
850 <<
"(" << setw(10) << module->
getID() <<
"," << setw(2) << tdc <<
")" <<
' '
851 <<
"action" <<
' ' << i->action <<
' '
852 <<
"value" <<
' ' << i->value << endl);
854 if (!i->apply(module->
getPMT(tdc))) {
855 ERROR(
"No valid action: " << *i << endl);
void set(const int bit)
Set PMT status.
Utility class to parse command line options.
static const JGetPMTStatusBit getPMTStatusBit
Function object to map key to PMT status bit.
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.
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.
Auxiliary class for controlling PMT status.
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.
void reset(const int bit)
Reset PMT status.
Data structure for detector geometry and calibration.
const JModuleAddressMap & get(const int id) const
Get module address map.
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.
#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.
bool is_valid(const json &js)
Check validity of JSon data.
Data structure for PMT geometry and calibration.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
JPosition3D getPosition(const Vec &pos)
Get position.
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.
static const JModule & getInstance()
Get reference to unique instance of this class object.
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.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi mv $WORKDIR/fit.root $MODULE_ROOT typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Data structure for unit quaternion in three dimensions.
Direct access to module in detector data structure.
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.
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.
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 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.
#define DEBUG(A)
Message macros.
double getT0() const
Get time offset.
int main(int argc, char *argv[])