190{
  193 
  194  typedef JHVTable::JHVTableTypes        JHVTableType_t;
  196  
  197  string      inputFile;
  199  JHVTable_t  HVtable;
  200 
  202 
  203  string      login;
  204  string      locationID;
  205  int         elapsedTime = 0;  
  206 
  207  double      minHV       = -1500;
  208  double      maxHV       = - 800;
  209  
  211 
  212  try {
  213 
  215 
  219    
  221 
  224 
  225    JParser<> zap(
"Auxiliary program to treat failed high-voltage tuning results.");
 
  226    
  227    zap[
'f'] = 
make_field(inputFile,    
"input file");
 
  234    
  235    zap(argc, argv);
  236    
  237  } catch(const exception &error) {
  238    
  239    FATAL(error.what() << endl);
 
  240  }
  241 
  242  if (login.empty() || locationID.empty()) {
  243    FATAL(
"Missing user information (please specify via -#login and -#locationID).");    
 
  244  }
  245  
  246 
  247  const JUUID& UUID = JUUID::rndm();
 
  248 
  250 
  251  timer.
sub(elapsedTime);
 
  252 
  253 
  254  
  255 
  257  string             DBTestType;
  259  
  261  
  263    
  265 
  266    ifstream ifs(inputFile.c_str());
  267 
  268    ifs >> js;
  269    ifs.close();
  270 
  271    
  272    
  273    json::const_iterator i0 = js.find(APIVersion_t);
  274 
  275    if (i0 != js.cend()) {
  276      
  277      istringstream iss(i0->get<string>());
  278      
  279      iss >> DBAPIVersion;
  280    }
  281 
  283    
  284    json::const_iterator i1 = js.find(Data_t);
  285    
  287        (i1 != js.cend() && i1->size() > 0)) {
  288 
  289      DBTestType   = (*i1)[0].at(Test_t + Type_t).get<string>();
  290 
  291      JHVCalibration_t::setVersion(getDBVersionTuneHV(DBTestType));
  292      
  294      metaInfoStr += (*i1)[0].at(Provenance_t + Info_t).at(Configuration_t).get<string>();
  295      
  296    } else {
  297 
  298      DBTestType   = js.at(Test_t + Type_t).get<string>();
  299 
  300      JHVCalibration_t::setVersion(getDBVersionTuneHV(DBTestType));
  301      
  303    }
  304 
  305    
  306    
  307    if (pmtSet.empty()) {
  308      
  309      for (JHVCalibration::iterator it = HVcals.begin(); it != HVcals.end(); ++it) {
  310      
  311        if (it->result != OK_t) {
  312          toEdit.push_back(*it);
  313        }
  314      }
  315      
  316    } else {
  317 
  319 
  320        JHVCalibration::iterator pmt = find_if(HVcals.begin(), HVcals.end(),
  321                                               make_predicate(&JHVCalibration_t::getNumber, it->getNumber()));
  322        if (pmt != HVcals.end()) {
  323 
  324          if (pmt->result == OK_t) {
  325            WARNING(
"Editing " << OK_t << 
" result for " << pmt->getUPI() << endl);
 
  326          }
  327          
  328          toEdit.push_back(*pmt);
  329        }
  330      }
  331    }
  332    
  333  } else {
  334 
  335    ERROR(inputFile << 
" is not a JSON file." << endl);
 
  336  }
  337 
  338    
  339  if (!HVtable.second.empty()) {
  340 
  341    NOTICE(
"Setting " << (HVtable.first == JHVTableType_t::VENDOR_HV ? 
"vendor " : 
"run-specific ") <<
 
  342           "PMT high-voltages from file " <<  HVtable.second << "..." << endl);
  343 
  344    JHVTable getHV(HVtable.second.c_str(), HVtable.first);
  345 
  346    for (JHVCalibration::iterator i = toEdit.begin(); i != toEdit.end(); ++i) {
  347 
  349      const double  HV  = getHV(upi.
getNumber());
 
  350 
  351      if (HV > minHV && HV < maxHV) {
  352          
  353        i->supplyVoltage  = getHV(upi.
getNumber());
 
  354        i->result         = OK_t;
  355          
  356      } else {
  357          
  358        WARNING(
"Invalid high-voltage for PMT " << upi   << 
" (" << 
FIXED(7,1) << HV    <<
 
  359                " not within [ " << 
FIXED(7,1)  << minHV << 
", " << 
FIXED(7,1) << maxHV << 
"]); skip." << endl);
 
  360      }
  361    }
  362    
  363  } else {
  364      
  365    NOTICE(
"Setting high-voltages manually..." << endl);
 
  366    
  367    for (JHVCalibration::iterator i = toEdit.begin(); i != toEdit.end(); ++i) {
  368 
  369      NOTICE(
"Please specify high-voltage for " << 
RIGHT(30) << i->getUPI() << 
":" << endl);
 
  370        
  371      double manualHV;
  372      cin >> manualHV;
  373 
  374      while (manualHV < minHV || manualHV > maxHV) {
  375            
  376        WARNING(
"Specified high-voltage is not within range ["     <<
 
  377                FIXED(7,1) << minHV << 
", " << 
FIXED(7,1) << maxHV <<
 
  378                "]; Please specify again." << endl);
  379            
  380        cin >> manualHV;            
  381      }
  382          
  383      i->supplyVoltage = manualHV;
  384      i->result        = OK_t;
  385    }
  386  }
  387  
  388  
  390 
  392    
  393    json error           = { {Message_t,              
""                      },
 
  394                             {Code_t,                 OK_t                    },
  395                             {Arguments_t,            json::array()           } };
  396    
  397    json metaData        = { {Configuration_t,        metaInfoStr             },
 
  399    
  401                             {User_t,                 login                   },
  402                             {Location_t,             locationID              },
  403                             {Start_t + Time_t,       timer.
toString()        },
 
  404                             {End_t   + Time_t,       timer().
toString()      },
 
  405                             {Test_t  + Type_t,       DBTestType              },
  406                             {Tests_t,                
json(toEdit)            } };
 
  407      
  409    js[Data_t + Type_t]  = 
MAKE_STRING(
"ProductTestSession");
 
  411    js[Error_t]          = 
json(error);
 
  414    js[Data_t][0]        = 
json(data);
 
  415    
  416  } else {
  417 
  418    js[User_t]           = login;
  419    js[Location_t]       = locationID;
  420    js[Test_t + Type_t]  = DBTestType;
  421    js[Start_t + Time_t] = timer.
toString();
 
  422    js[End_t + Time_t]   = timer().
toString();
 
  423    js[Tests_t]          = 
json(toEdit);
 
  424  }
  425  
  426 
  428 
  429  ofs << setw(2) << setprecision(8);
  430  ofs << js;
  431 
  432  ofs.close();
  433  
  434  return 0;
  435}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
#define MAKE_STRING(A)
Make string.
 
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
 
Utility class to parse parameter values.
 
Utility class to parse command line options.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
bool isJSONFile(const char *file_name)
Check file format.
 
Auxiliary data structure for floating point format specification.
 
Universal product identifier (UPI).
 
const JUPI_t & getUPI() const
Get UPI.
 
int getNumber() const
Get serial number.
 
Auxiliary data structure for general purpose version number.
 
version_type getMajorVersion() const
Get major version.
 
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
 
Auxiliary class for date and time.
 
std::string toString() const
Get ASCII formatted date and time.
 
void sub(const time_t t1)
Subtract given time.
 
Auxiliary data structure for alignment of data.