Newer
Older
fits_write_record(fptr, " ------------------------------------------------------------------------", &FitStatus);
// Table 11 Detector Setup keywords
// su::getValue<float>(m_sashaSetup["DIT"], floatValue);
// fits_write_key(fptr, TFLOAT, "DET DIT", &floatValue, "Detector Integration Time", &FitStatus);
// intValue = su::convertStringToType<int>(sashaNumReads["value"].getValue());
// fits_write_key(fptr, TINT, "DET NREADS", &intValue, "Number of Reads", &FitStatus);
// intValue = su::convertStringToType<int>(sashaNumDrops["value"].getValue());
// fits_write_key(fptr, TINT, "DET NDROPS", &intValue, "Number of Drops", &FitStatus);
// intValue = su::convertStringToType<int>(sashaNumGroups["value"].getValue());
// fits_write_key(fptr, TINT, "DET NGROUPS", &intValue, "Number of Groups", &FitStatus);
// intValue = su::convertStringToType<int>(sashaNumCoadds["value"].getValue());
// fits_write_key(fptr, TINT, "DET NCOADDS", &intValue, "Number of Coadditions", &FitStatus);
// intValue = su::convertStringToType<int>(sashaNumSeqs["value"].getValue());
// fits_write_key(fptr, TINT, "DET NDIT", &intValue, "Number of DITs", &FitStatus);
fits_write_key(fptr, TSTRING, "DET READOUT", su::get_char_star(sashaReadout["value"].getValue()), "Readout Mode", &FitStatus);
intValue = su::convertStringToType<int>(sashaSeqNum["value"].getValue());
fits_write_key(fptr, TINT, "DET CEXP", &intValue, "Current exposure", &FitStatus);
fits_write_key(fptr, TINT, "DET XMIN", &xmin, "Minimum of X-axis", &FitStatus);
fits_write_key(fptr, TINT, "DET XMAX", &xmax, "Maximum of X-axis", &FitStatus);
fits_write_key(fptr, TINT, "DET YMIN", &ymin, "Minimum of Y-axis", &FitStatus);
fits_write_key(fptr, TINT, "DET YMAX", &ymax, "Maximum of Y-axis", &FitStatus);
// fits_write_key(fptr, TLOGICAL,"DET NEXTASBG", &intValue, "Next", &FitStatus);
// fits_write_key(fptr, TLOGICAL,"DET PREVASBG", &intValue, "Previous", &FitStatus);
intValue = sashaSave["value"].getSwitchState() == IElement::On;
fits_write_key(fptr, TLOGICAL,"DET SAVE", &intValue, "Save Flag on SASHA", &FitStatus);
fits_write_record(fptr, " ------------------------------------------------------------------------", &FitStatus);
// Table 12 RTC Setup Keywords
intValue = su::convertStringToType<int>(m_rtcKeywords["TTWINCOORDX"]);
fits_write_key(fptr, TINT, "TTWINCOORDX", &intValue, "Distance in rows from px in full frame", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTWINCOORDY"]);
fits_write_key(fptr, TINT, "TTWINCOORDY", &intValue, "Distance in cols from px in full frame", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTWINROWS"]);
fits_write_key(fptr, TINT, "TTWINROWS", &intValue, "Tiptilt Window Rows", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTWINCOLS"]);
fits_write_key(fptr, TINT, "TTWINCOLS", &intValue, "Tiptilt Window Columns", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTFRAMERATE"]);
fits_write_key(fptr, TINT, "TTFRAMERATE", &intValue, "TipTilt frame rate", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTCAMTINT"]);
fits_write_key(fptr, TFLOAT, "TTCAMTINT", &floatValue, "TipTilt Camera integration time", &FitStatus);
// if(m_pGetRtcStatus){ intValue = su::convertStringToType<int>(m_pGetRtcStatus("TTLOOPENABLED"));}
intValue = su::convertStringToType<int>(m_rtcKeywords["TTLOOPENABLED"]);
fits_write_key(fptr, TLOGICAL,"TTLOOPENABLED", &intValue, "Flag indicating fast tip/tilt loop status", &FitStatus);
// fits_write_key(fptr, TLOGICAL,"TTHISTORYENABLED", &intValue, "Number of images save", &FitStatus);
// fits_write_key(fptr, TSTRING, "TTTIMEHISTORYFILE", (char *)"", "Time History Filename", &FitStatus);
// fits_write_key(fptr, TINT, "TTTIMEHISTLEN", &intValue, "Number of history lines if history is enabled", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTDMMAXPOWER"]);
fits_write_key(fptr, TFLOAT, "TTDMMAXPOWER", &floatValue, "Max Power allowed to DM", &FitStatus);
fits_write_key(fptr, TSTRING, "TTBIASFILE", su::get_char_star(m_rtcKeywords["TTBIASFILE"]), "Bias File", &FitStatus);
fits_write_key(fptr, TSTRING, "TTDMFLATFILE", su::get_char_star(m_rtcKeywords["TTDMFLATFILE"]), "Flat File", &FitStatus);
if(m_pGetRtcStatus && !m_bFastSavingMode){m_rtcKeywords["TTSENSORTEMP"] = m_pGetRtcStatus("TTSENSORTEMP");}
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTSENSORTEMP"]);
fits_write_key(fptr, TFLOAT, "TTSENSORTEMP", &floatValue, "sensor temperature in degree C", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTCENTROIDGAINX"]);
fits_write_key(fptr, TFLOAT, "TTCENTROIDGAINX", &floatValue, "TipTilt gain on centroid X", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTCENTROIDGAINY"]);
fits_write_key(fptr, TFLOAT, "TTCENTROIDGAINY", &floatValue, "TipTilt gain on centroid Y", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTCENTROIDORIGX"]);
fits_write_key(fptr, TFLOAT, "TTCENTROIDORIGX", &floatValue, "X Origin position in [-1,1] coordinates", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTCENTROIDORIGY"]);
fits_write_key(fptr, TFLOAT, "TTCENTROIDORIGY", &floatValue, "Y Origin position in [-1,1] coordinates", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTDMMODESNUM"]);
fits_write_key(fptr, TINT, "TTDMMODESNUM", &intValue, "number of modes in zonal influence matrix", &FitStatus);
fits_write_key(fptr, TSTRING, "TTPIXELGAINFILE", su::get_char_star(m_rtcKeywords["TTPIXELGAINFILE"]), "Gain factor for each pixel in which the centroid is calculated", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTPIXELENABLED"]);
fits_write_key(fptr, TLOGICAL,"TTPIXELENABLED", &intValue, "Enable saving frames on memory", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTPIXELDECIMATION"]);
fits_write_key(fptr, TINT, "TTPIXELDECIMATION", &intValue, "Frame saving decimation factor", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTDIAGENABLED"]);
fits_write_key(fptr, TLOGICAL,"TTDIAGENABLED", &intValue, "Diagnostic enabled", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTDIAGDECIMATION"]);
fits_write_key(fptr, TINT, "TTDIAGDECIMATION", &intValue, "TipTilt diagnostic decimation factor", &FitStatus);
fits_write_record(fptr, " ------------------------------------------------------------------------", &FitStatus);
int WCSAXES = 2;
fits_write_key(fptr, TINT, "WCSAXES ", &WCSAXES, "Dimensionality of WCS: 2 for image, 3 for spectrum", &FitStatus);
if(WCSAXES == 2)
fits_write_key(fptr, TSTRING, "CTYPE1 ", (char *)"RA---TAN", "Pixel coordinate system", &FitStatus);
fits_write_key(fptr, TSTRING, "CTYPE2 ", (char *)"DEC--TAN", "Pixel coordinate system", &FitStatus);
fits_write_key(fptr, TSTRING, "RADESYS ", (char *)"ICRS", "reference system", &FitStatus);
fits_write_key(fptr, TSTRING, "CUNIT1 ", (char *)"deg", "Unit of coordinate transformation", &FitStatus);
fits_write_key(fptr, TSTRING, "CUNIT2 ", (char *)"deg", "Unit of coordinate transformation", &FitStatus);
floatValue2 = 0.0000040277777777777;
fits_write_key(fptr, TFLOAT, "CDELT1 ", &floatValue2,"Increment along axis 1 as [CUNIT1]/pxl", &FitStatus);
fits_write_key(fptr, TFLOAT, "CDELT2 ", &floatValue2,"Increment along axis 2 as [CUNIT2]/pxl", &FitStatus);
float ra_tel_deg = tenv.achieved_ra/suc::DEGREE, ra_point_offset = 0.f, ra_guide_offset = 0.f, ra_shark = 0.f;
float dec_tel_deg = tenv.achieved_dec/suc::DEGREE, dec_point_offset = 0.f, dec_guide_offset = 0.f, dec_shark = 0.f;
floatValue = ra_tel_deg + ra_point_offset + ra_guide_offset + ra_shark;
fits_write_key(fptr, TFLOAT, "CRVAL1 ", &floatValue, "RA at CRPIX1 in units CUNIT1", &FitStatus);
floatValue = dec_tel_deg + dec_point_offset + dec_guide_offset + dec_shark;
fits_write_key(fptr, TFLOAT, "CRVAL2 ", &floatValue, "DEC at CRPIX2 in units CUNIT2", &FitStatus);
floatValue = 58.1f + 885.f - xmin;
fits_write_key(fptr, TFLOAT, "CRPIX1 ", &floatValue, "Value of X Ref. pixel", &FitStatus);
floatValue = 51.5f + 1020.f - ymin;
fits_write_key(fptr, TFLOAT, "CRPIX2 ", &floatValue, "Value of Y Ref. pixel", &FitStatus);
double sign = (m_bTest01 ? 1. : -1.);
floatValue = std::cos((ih.derotator.position1 - gDrotRef + sign*tenv.parallactic_angle)*suc::DEGREE);
fits_write_key(fptr, TFLOAT, "PC1_1 ", &floatValue, "Scale in [CUNIT1]/pixel", &FitStatus);
int flip = -1;
floatValue *= flip;
fits_write_key(fptr, TFLOAT, "PC2_2 ", &floatValue, "Scale in [CUNIT2]/pixel", &FitStatus);
floatValue = std::sin((ih.derotator.position1 - gDrotRef + sign*tenv.parallactic_angle)*suc::DEGREE);
fits_write_key(fptr, TFLOAT, "PC1_2 ", &floatValue, "Rotation and skew", &FitStatus);
fits_write_key(fptr, TFLOAT, "PC2_1 ", &floatValue, "Rotation and skew", &FitStatus);
{
fits_write_key(fptr, TSTRING, "CTYPE1 ", (char *)"WAVE", "Pixel coordinate system", &FitStatus);
fits_write_key(fptr, TSTRING, "CTYPE2 ", strValue, "Pixel coordinate system", &FitStatus);
fits_write_key(fptr, TSTRING, "CTYPE3 ", strValue, "Pixel coordinate system", &FitStatus);
fits_write_key(fptr, TSTRING, "CUNIT1 ", strValue, "Unit of coordinate transformation", &FitStatus);
fits_write_key(fptr, TSTRING, "CUNIT2 ", strValue, "Unit of coordinate transformation", &FitStatus);
fits_write_key(fptr, TSTRING, "CUNIT3 ", strValue, "Unit of coordinate transformation", &FitStatus);
fits_write_key(fptr, TFLOAT, "CRVAL1 ", &floatValue, "Wavelength at CRPIX1", &FitStatus);
fits_write_key(fptr, TFLOAT, "CRVAL2 ", &floatValue, "RA at CRPIX1 in units CUNIT1", &FitStatus);
fits_write_key(fptr, TFLOAT, "CRVAL3 ", &floatValue, "DEC at CRPIX2 in units CUNIT2", &FitStatus);
fits_write_key(fptr, TFLOAT, "CD1_1 ", &floatValue, "Increment for CTYPE1", &FitStatus);
fits_write_key(fptr, TFLOAT, "CD2_2 ", &floatValue, "Increment for CTYPE2", &FitStatus);
fits_write_key(fptr, TFLOAT, "CD3_3 ", &floatValue, "Increment for CTYPE3", &FitStatus);
fits_write_key(fptr, TINT, "DISPAXIS ", &intValue, "Dispersion axis (1=rows; 2=columns)", &FitStatus);
fits_write_key(fptr, TSTRING, "DISPUNIT ", strValue, "Units for coordinate along DISPAXIS", &FitStatus);
fits_write_key(fptr, TSTRING, "DISPWC ", strValue, "Approximate central dispersion coordinate on detector [DISPAXIS]", &FitStatus);
fits_write_key(fptr, TSTRING, "DISPDW ", strValue, "Approximate central dispersion per pixel on the detector", &FitStatus);
}
// TODO : Table 15 Enclosure, environment, and weather specific keywords
fits_write_record(fptr, " ------------------------------------------------------------------------", &FitStatus);
![Davide Ricci Davide Ricci's avatar](/gitlab/uploads/-/system/user/avatar/261/avatar.png?width=72)
Davide Ricci
committed
// fits_write_key(fptr, TFLOAT, "DOMEPAN ", &floatValue, "Dome position angle [degrees E of N]", &FitStatus);
// fits_write_key(fptr, TFLOAT, "DOMTEM ", &floatValue, "Dome temperature [degrees C]", &FitStatus);
// fits_write_key(fptr, TFLOAT, "DOMHUM ", &floatValue, "Dome relative humidity [%]", &FitStatus);
// fits_write_key(fptr, TFLOAT, "DOMDEWPT ", &floatValue, "Dome dew point [degrees C]", &FitStatus);
fits_write_record(fptr, " ------------------------------------------------------------------------", &FitStatus);
![Davide Ricci Davide Ricci's avatar](/gitlab/uploads/-/system/user/avatar/261/avatar.png?width=72)
Davide Ricci
committed
// fits_write_key(fptr, TFLOAT, "ENVTEM ", &tenv.lbt_temp, "Outside temperature, C, at MJD-OBS", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVPRE ", &tenv.lbt_pressure, "Atmospheric pressure [mbar]", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVWIN ", &tenv.smt_wind_speed, "Outside wind speed (m/s) at MJD-OBS", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVDIR ", &tenv.smt_wind_dir, "(degrees) Direction of wind: E from N", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVHUM ", &tenv.lbt_humidity, "Outside relative humidity % at MJD-OBS", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVDEWPT ", &tenv.lbt_dewpoint, "Outside dew point (degrees C) at MJD-OBS", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVTAU ", &tenv.smt_tau, "Opacity at 225 GHz, from SMT", &FitStatus);
// fits_write_key(fptr, TFLOAT, "SEEING ", &tenv.dimm_seeing, "Seeing estimate from S-H WFS", &FitStatus);
// std::string operator_comment = " no comment by operator ";
// fits_write_key(fptr, TSTRING, "WEATHER ", su::get_char_star(operator_comment), "Comment by telescope operator or observer", &FitStatus);
// fits_write_key(fptr, TFLOAT, "SEEWAV ", &floatValue, "Wavelength for seeing estimate", &FitStatus);
// fits_write_key(fptr, TFLOAT, "SEECAL ", &floatValue, "Seeing: S-H to seeing calibration curve", &FitStatus);
U8_LLOG("");
return FitStatus;
}
void SeqDataMgr::getTelescopeEnv(STelescopeEnv & env)
{
// DIMMFWHM DIMM seeing, [arcsecs] DIMMSeeing (DIMMSeeingZenith, DIMMSeeingElevation)
// DIMMFLUX DIMM mean centroid flux DIMMMeanFlux
// LBTWLINK Weather Station Link State LBTWeatherAlive (LBTWeatherAliveFront)
// LBTPRES Ambient Pressure [hPa] LBTPressure
// LBTTEMP Ambient Temperature [deg C] LBTTemp
// LBTHUM LBT Relative Humidity [percent] LBTHumidity
// LBTDWPT LBT Dew Point [deg C] LBTDewPoint
static Nice::Date lastCall;
Nice::Date currentCall = Nice::Date::now();
if(currentCall - lastCall < Nice::Time::seconds(5))return;
lbto::result res;
lbto::DDstruct ddt;
lbto::SeqDD dd;
ddt.DDname = "DIMMSeeingZenith"; //1
dd.push_back(ddt);
ddt.DDname = "DIMMSeeingElevation"; //2
ddt.DDname = "LBTWeatherAlive"; //3
ddt.DDname = "LBTPressure"; //4
ddt.DDname = "LBTTemp"; //5
ddt.DDname = "LBTHumidity"; //6
ddt.DDname = "LBTDewPoint"; //7
ddt.DDname = "LBTWindSpeed"; //8 15
ddt.DDname = "LBTWindDir"; //9 15
ddt.DDname = "LBTWindDirRaw"; //10 15
ddt.DDname = "LBTWindSpeedFront"; //11 15
ddt.DDname = "LBTWindDirFront"; //12 15
ddt.DDname = "LBTWindDirFrontRaw"; //13 15
ddt.DDname = "ELPosition"; //14 8
ddt.DDname = "AZPosition"; //15 9
ddt.DDname = "L_AOOffsetX"; // WFS_LBTI_SX_baysidex_L_PSO_CUR 1; WFS_LBTI_SX_auxloops_L_modalplotTask_MAG //16 17
ddt.DDname = "L_AOOffsetY"; //17 18
ddt.DDname = "L_AOOffsetZ"; //18 19
ddt.DDname = "L_DECOffset"; //19 20
ddt.DDname = "L_RAOffset"; //20 21
ddt.DDname = "L_TargetRA"; //21 22
ddt.DDname = "L_TargetDEC"; //22 23
ddt.DDname = "L_AchievedRA"; //23 24
ddt.DDname = "L_AchievedDEC"; //24 25
ddt.DDname = "ParAngle"; //25 26
ddt.DDname = "L_AchievedALT"; //26 27
ddt.DDname = "L_AchievedAZ"; //27 28
ddt.DDname = "AZTrackingState"; //28 29
ddt.DDname = "ELTrackingState"; //29 31
ddt.DDname = "MountAchievedRAHMS"; //30 32
ddt.DDname = "MountAchievedDECDMS"; //31 33
ddt.DDname = "AirMass"; //32 34
ddt.DDname = "L_LBCRotatorAngle"; //33 35
ddt.DDname = "L_LBCPositionAngle"; //34 36
ddt.DDname = "L_LBCSetupState"; //35 37
ddt.DDname = "L_MODSInstConfig"; //36 38
dd.push_back(ddt);
ddt.DDname = "L_NSRATRKRate"; //37 39
ddt.DDname = "L_NSDECTRKRate"; //38 40
ddt.DDname = "MoonAlt"; //39 41
ddt.DDname = "MoonAz"; //40 42
dd.push_back(ddt);
ddt.DDname = "SunAlt"; //41 43
ddt.DDname = "SunAz"; //42 44
ddt.DDname = "LST"; //43 45
dd.push_back(ddt);
//ddt.DDname = "UTC";
//dd.push_back(ddt);
bool get_parameters = true;
int retry_counter = 0;
while(get_parameters)
{
get_parameters = false;
try
{
res = m_iif->iifGetParameter(dd);
}
catch(Basda::ServiceIsBusyException)
{
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
{
W_LLOG("Busy : retrying " << retry_counter);
}
retry_counter++;
get_parameters = true;
usleep(50000);
continue;
}
catch(const std::exception& e)
{
W_LLOG(e.what());
return;
}
catch(...)
{
std::string what = boost::current_exception_diagnostic_information();
std::string toErase = "std::exception::what :";
size_t pos = what.find(toErase);
if(pos != std::string::npos)what.erase(pos, toErase.length());
what.erase(std::remove(what.begin(), what.end(), '\n'), what.end());
std::stringstream log_msg;
log_msg << "Error trying getting DD parmateres : " << what;
W_LLOG(log_msg.str());
return;
}
}
if(res.rescode == EXIT_SUCCESS)
{
double temp;
// std::vector<std::string>::const_iterator it;
// int counter = 0;
// for(it = res.resmsg.begin(); it < res.resmsg.end(); it++)
// {
// counter++;
// U9_LLOG(counter << " ~ " << *it);
// }
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
env.dimm_seeing_zenith = atof(res.resmsg[1].c_str()); //1
env.dimm_seeing_elevation = atof(res.resmsg[2].c_str()); //2
env.lbt_weather_alive = (bool)atoi(res.resmsg[3].c_str()); //3
env.lbt_pressure = atof(res.resmsg[4].c_str()); //4
env.lbt_temp = atof(res.resmsg[5].c_str()); //5
U9_LLOG(env.lbt_temp);
env.lbt_humidity = atof(res.resmsg[6].c_str()); //6
env.lbt_dewpoint = atof(res.resmsg[7].c_str()); //7
env.lbt_wind_speed = atof(res.resmsg[8].c_str()); //8
env.lbt_wind_dir = atof(res.resmsg[9].c_str()); //9
env.lbt_wind_dir_raw = atof(res.resmsg[10].c_str()); //10
env.lbt_wind_speed_front = atof(res.resmsg[11].c_str()); //11
env.lbt_wind_dir_front = atof(res.resmsg[12].c_str()); //12
env.lbt_wind_dir_raw_front = atof(res.resmsg[13].c_str()); //13
env.mcs_elevation = atof(res.resmsg[14].c_str())/3600; //14
env.mcs_azimuth = atof(res.resmsg[15].c_str())/3600; //15
env.ao_offsetx = atof(res.resmsg[16].c_str()); //16
env.ao_offsety = atof(res.resmsg[17].c_str()); //17
env.ao_offsetz = atof(res.resmsg[18].c_str()); //18
env.target_decoffset = atof(res.resmsg[19].c_str()); //19
env.target_raoffset = atof(res.resmsg[20].c_str()); //20
env.target_ra = atof(res.resmsg[21].c_str()); //21
env.target_dec = atof(res.resmsg[22].c_str()); //22
env.achieved_ra = atof(res.resmsg[23].c_str()); //23
env.achieved_dec = atof(res.resmsg[24].c_str()); //24
env.parallactic_angle = atof(res.resmsg[25].c_str()); //25
env.achieved_alt = atof(res.resmsg[26].c_str()); //26
env.achieved_az = atof(res.resmsg[27].c_str()); //27
env.az_tracking_state = res.resmsg[28]; //28
env.el_tracking_state = res.resmsg[29]; //29
env.tcs_ra = res.resmsg[30]; //30
env.tcs_dec = res.resmsg[31]; //31
env.air_mass = atof(res.resmsg[32].c_str()); //32
// env.rot_angle = atof(res.resmsg[33].c_str()); //33
// env.pos_angle = atof(res.resmsg[34].c_str()); //34
env.tel_conf = atof(res.resmsg[35].c_str()); //35
env.ins_mode = atof(res.resmsg[36].c_str()); //36
env.tel_trk_RA = atof(res.resmsg[37].c_str()); //37
env.tel_trk_DEC = atof(res.resmsg[38].c_str()); //38
env.moon_alt = atof(res.resmsg[39].c_str()); //39
env.moon_az = atof(res.resmsg[40].c_str()); //40
env.sun_alt = atof(res.resmsg[41].c_str()); //41
env.sun_az = atof(res.resmsg[42].c_str()); //42
env.lst = atof(res.resmsg[43].c_str()); //43
// env.utc = atof(res.resmsg[40].c_str());
}
else
{
for(unsigned int i = 0; i < res.resmsg.size(); i++)
{
U9_LLOG(res.resmsg[i]);
}
}
}
std::string SeqDataMgr::GetReadoutRegion(int & xmin, int & xmax, int & ymin, int & ymax)
{
xmin = xmax = ymin = ymax = 0;
std::map<std::string, indi::IElement>::const_iterator itRegion;
const std::map<std::string, indi::IElement> & elements = sashaReadoutRegion.getElements();
itRegion = elements.find("x1");
![Davide Ricci Davide Ricci's avatar](/gitlab/uploads/-/system/user/avatar/261/avatar.png?width=72)
Davide Ricci
committed
{
if(!su::getValue<int>(itRegion->second.get(), xmin)){ W_LLOG("Could not get readout region XMIN value");}
![Davide Ricci Davide Ricci's avatar](/gitlab/uploads/-/system/user/avatar/261/avatar.png?width=72)
Davide Ricci
committed
}
else { W_LLOG("Could not find readout region XMIN value");}
itRegion = elements.find("x2");
if(itRegion != elements.end())
{
if(!su::getValue<int>(itRegion->second.get(), xmax)){ W_LLOG("Could not get readout region XMAX value");}
}
else { W_LLOG("Could not find readout region XMAX value");}
itRegion = elements.find("y1");
if(itRegion != elements.end())
{
if(!su::getValue<int>(itRegion->second.get(), ymin)){ W_LLOG("Could not get readout region YMIN value");}
}
else { W_LLOG("Could not find readout region YMIN value");}
itRegion = elements.find("y2");
if(itRegion != elements.end())
{
if(!su::getValue<int>(itRegion->second.get(), ymax)){ W_LLOG("Could not get readout region YMAX value");}
}
else { W_LLOG("Could not find readout region YMAX value");}
std::stringstream activeRegion;
activeRegion << "["<< xmin <<":"<< xmax <<", "<< ymin <<":"<< ymax << "]";
return activeRegion.str();
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
int SeqDataMgr::sashaEnableSave(const std::map<std::string, std::string> & _dSashaSetup)
{
// To be Implemented
U6_LLOG(__FUNCTION__ << " ~ DEPRECATED");
Ice::Int status = EXIT_SUCCESS;
#ifdef UNDEFINED
IProperty sashaSave(IProperty::Switch), recvProp;
std::map<std::string, std::string>::const_iterator itFind;
itFind = _dSashaSetup.find("SAVE");
// m_ptrIc->connect();
// NOTE while alive, indiserver does not close the connection to the client.
// U1_LLOG("Command sasha to save to file");
U1_LLOG("Command sasha to save to file");
sashaSave.setDevice("sasha_save");
sashaSave.setName("enable_save");
sashaSave.setPerm(IProperty::ReadWrite);
sashaSave.setState(IProperty::Busy);
sashaSave.add(IElement("value"));
// Switch properties can have value On or Off
sashaSave["value"].setSwitchState(IElement::Off);
U1_LLOG(sashaSave.getType());
if((su::str_tolower(itFind->second) == "true") || (itFind->second == "1"))
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
{
sashaSave["value"].setSwitchState(IElement::On);
}
}
//
m_ptrIc2->send_new_property_wait2(sashaSave, recvProp);
#endif
// status = m_ptrIc->close();
U8_LLOG(__FUNCTION__);
return status;
}
int SeqDataMgr::sashaGetFitsFile(const std::map<std::string, std::string> & _dSashaSetup, const std::string & _instMode, std::string & _outFilename)
{
U6_LLOG(__FUNCTION__ << " ~ DEPRECATED");
int status = EXIT_FAILURE;
#ifdef UNDEFINED
std::string strObjname = "test";
Ice::CommunicatorPtr dataMgrIC;
// std::ostringstream streamRsync;
// std::ostringstream streamFileNum;
// std::ostringstream streamFileName;
std::ofstream fout;
// --Ice.Config=$INSROOT/etc/data_mgr/data_mgr-ice.cfg
// char* argvDataMgr[] = { "SequencerI::sashaGetFITSFile",
// "--Ice.Config=/opt/tan/etc/data_mgr/data_mgr-ice.cfg" };
// int argcDataMgr = 2;
// CFITSIO related
//
// Saving file to disk
// filename format is SHARKNIR.YYYY-MM-DDThh:mm:ss.ssssssZ.<_instMode>.fits
// this is passed to data manager for future use in mearging headers
// and saved in output parameter
//
// get date of file creation by INDI in ISO8601 format
dateISO8601 = recvProp.getTimeStamp().getFormattedIso8601Str();
filenameSASHA = "SHARKNIR." + dateISO8601 + "." + _instMode + ".SASHA.fits";
filenameSHINS = "SHARKNIR." + dateISO8601 + "." + _instMode + ".fits";
/* what follows is most likely old code to be erased
at this moment dataMgr will take care of ingesting file to
LBT archive mount point
// setting filenameSASHA as filename of acquired FITS file to data_mgr for its reference
// NOTE: may not be necessary
dataMgrIC = Ice::initialize(argcDataMgr, argvDataMgr);
Ice::ObjectPrx base = dataMgrIC->stringToProxy("dataManagerAdapter:default -p 10501");
sd::fitsFilePrx archiver = sd::fitsFilePrx::checkedCast(base);
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
throw("Invalid Proxy");
// setting name of SASHA produced FITS in data manager component
status = archiver->setCurrentFilenameSASHA(filenameSASHA);
U4_LLOG(archiver->getCurrentFilenameSASHA());
// creating fits file with no data and with complete+populated header.
status = archiver->createEmptyAndPopulateHeader(filnameSHINS, bitpix, naxis, vecNaxes);
status = archiver->mergeHeadersAndCopyData(filenameSHINS, filenameSASHA);
*/
}
}
}
}
}
if(dataMgrIC)dataMgrIC->destroy();
// creating standard vectors with keywords values and comments for SHINS part of header.
// These vectors will be passed to data manager which will merge them to SASHA header
// by creating in place a FITS header and merging it to SASHA header, without creating
// a second file on disk
// create header only fits file to fill with SHINS values for keywords
// try
// {
// dataMgrIC = Ice::initialize(argcDataMgr, argvDataMgr);
// Ice::ObjectPrx base = dataMgrIC->stringToProxy("dataManagerAdapter:default -p 10501");
// sd::fitsFilePrx archiver = sd::fitsFilePrx::checkedCast(base);
// throw("Invalid Proxy");
// status = archiver->saveSASHABLOB(toBitsBlob, counter);
// status = archiver->setCurrentFilenameSASHA(_outFilenameSASHA);
// }
// catch(const Ice::Exception& ex)
// catch(const char* msg)
// if(dataMgrIC)dataMgrIC->destroy();
// timeOut = su::convertStringToType<long>(itDit->second)*
// su::convertStringToType<float>(itNDit->second)*std::pow(10,6); // time out have to be in micro seconds
// U1_LLOG("time out = " << timeOut*2 << " micro seconds");
// IndiProperty sashaSaveFileNum(IndiProperty::Text);
// IndiProperty sharknirUTCDate(IndiProperty::Number);
// the method shouhld check on remote INDI property for info on exposure status
// alredy done by sashaExpose, but to control twice is better
// _outFilenameSASHA = "No Filename Retrieved";
// boost::thread fits_notify_thread(inotifierInstance.start, _remotePathToWatch,
// boost::ref(_outFilenameSASHA),
// timeOut*6); // create and start thread
// fits_notify_thread.join(); // Wait for thread to finish
// check on _outFilenameSASHA
// fits_notify_thread should have timeout parameter for INotifier::start
itFind = _dSashaSetup.find("OBJECTNAME");
if(!(itFind == _dSashaSetup.end()))strObjname = itFind->second;
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
// sashaSaveFileNum = init_indi_property("sasha_save", "largest_filenum", IndiProperty::Text, std::vector<std::string>(1, "value"));
// vecElemNames.push_back("JD");
// vecElemNames.push_back("UTC");
// vecElemNames.push_back("UTCDate");
// vecElemNames.push_back("LT");
// vecElemNames.push_back("LST");
// vecElemNames.push_back("MoonAz");
// vecElemNames.push_back("MoonAlt");
// vecElemNames.push_back("MoonElong");
// vecElemNames.push_back("MoonLit");
// vecElemNames.push_back("SunAz");
// vecElemNames.push_back("SunAlt");
// sharknirUTCDate = init_indi_property("sharknir_time", "Now",
// IndiProperty::Number,
// vecElemNames);
// // NOTE while alive, indiserver does not close the connection to the client.
// U1_LLOG("Asking INDI for file number ...");
// m_ptrIc2->send_get_property_wait(sashaSaveFileNum, recvProp);
// streamFileNum << std::setfill('0') << std::setw(6)
// << recvProp["value"].getValue() << std::setfill(' ');
// recvProp.clear();
// U1_LLOG("Asking INDI for UTC date ... ");
// m_ptrIc2->send_get_property_wait(sharknirUTCDate, recvProp);
// strUTCDate = recvProp["UTCDate"].getValue().substr(2,recvProp["UTCDate"].getValue().size()-2);
// U1_LLOG("Got " << recvProp["UTCDate"].getValue());
// U1_LLOG("Extracted " << strUTCDate);
// streamRsync << "rsync -avzh " << su::get_LLOGin() << "@sashaws::fits/" << strUTCDate
// << "/sa_" << strUTCDate << "_" << streamFileNum.str()
// << ".fits " << dataDir
// << "SHARKNIR_" << strObjname << "_" << recvProp["UTCDate"].getValue()
// << "_" << streamFileNum.str() << ".fits";
// streamFileName << "SHARKNIR_" << strObjname << "_" << recvProp["UTCDate"].getValue()
// << "_" << streamFileNum.str() << ".fits";
// status = std::system(streamRsync.str().c_str());
}
#endif
U8_LLOG("");
return status;
}
// Patch to get rid of the timeout problem of sasha driver. NREAD is sent whenever NDIT changes and no other parameters are sent
int SeqDataMgr::sashaEndSetup(std::map<std::string, std::string> & _dTimeoutSetup, bool ndit_changed)
{
U6_LLOG(__FUNCTION__);
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
if(ndit_changed && _dTimeoutSetup.empty())
{
IProperty & prop = m_sashaProps.find("NREADS")->second;
const std::map<std::string, indi::IElement> elements = prop.getElements();
if(elements.find("value") != elements.end())
{
_dTimeoutSetup["NREADS"] = prop["value"].getValue();
}
else
{
std::stringstream log_msg;
log_msg << "Error : IProperty \"" << prop.getDevice() << "." << prop.getName() << "\" from INDI Server has changed";
E_LLOG(log_msg.str());
throw(std::runtime_error(log_msg.str()));
}
}
std::map<std::string, std::string>::iterator itSetup;
int num_properties = _dTimeoutSetup.size();
int counter = 0, sent_properties = 0;
try
{
for(itSetup = _dTimeoutSetup.begin(); itSetup != _dTimeoutSetup.end(); itSetup++)
{
if(m_getFitsAbortFlag)break;
counter++;
IProperty & prop = m_sashaProps.find(itSetup->first)->second;
const std::map<std::string, indi::IElement> elements = prop.getElements();
bool bPropError = false, bSetProperty = false;
if(itSetup->first == "NCOADDS")
{
const std::map<std::string, indi::IElement> acquire_elements = sashaAcquire.getElements();
U9_LLOG(__FUNCTION__ << " ~ " << itSetup->second << " ~ " << sashaAcquire["num_coadds"].getValue())
if(acquire_elements.find("num_coadds") != acquire_elements.end())
{
if(m_bForcePropertySet || sashaAcquire["num_coadds"].getValue() != itSetup->second)
{
sashaAcquire["num_coadds"].setValue(itSetup->second);
m_sashaPropsSet["ACQUIRE"] = false;
SendNewProperty(sashaAcquire);
U9_LLOG(__FUNCTION__ << " ~ NCOADDS SENT");
if(elements.find("value") != elements.end())
{
if(m_bForcePropertySet || itSetup->second != prop["value"].getValue())
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
{
prop["value"].setValue<int>(su::convertStringToType<int>(itSetup->second));
bSetProperty = true;
}
}
else
bPropError = true;
if(bPropError)
{
std::stringstream log_msg;
log_msg << "Error : IProperty \"" << prop.getDevice() << "." << prop.getName() << "\" from INDI Server has changed";
E_LLOG(log_msg.str());
throw(std::runtime_error(log_msg.str()));
}
else if(bSetProperty || (sent_properties == 0 && counter == num_properties))
{
m_sashaPropsSet[itSetup->first] = false;
SendNewProperty(prop);
sent_properties++;
}
}
bool wait_result = false;
wait_result = WaitSetMessages(60000000);
if(!wait_result)status = EXIT_FAILURE;
}
catch(...)
{
E_LLOG(__FUNCTION__);
U8_LLOG("");
throw;
}
U8_LLOG("");
return status;
}
int SeqDataMgr::sashaSetup(const std::map<std::string, std::string> & _dSashaExpose)
{
U6_LLOG(__FUNCTION__);
int status = EXIT_SUCCESS;
m_exposeMutex.lock();
for(itSashaSetup = m_sashaSetup.begin(); itSashaSetup != m_sashaSetup.end(); itSashaSetup++)
{
if(itSashaSetup->first == suc::instrument_mode)
itSashaSetup->second = "UNDEF";
itSashaSetup->second.clear();
}
std::map<std::string, std::string>::const_iterator itSetup;
for(itSetup = _dSashaExpose.begin(); itSetup != _dSashaExpose.end(); itSetup++)
{
U9_LLOG("Keyword : " << itSetup->first << "; Value : " << itSetup->second);
{
std::stringstream log_msg;
log_msg << "Keyword not allowed in sashaExpose : " << itSetup->first;
E_LLOG(log_msg.str());
throw(std::invalid_argument(log_msg.str()));
}
bool bForceTimeoutRefresh = false;
bool ndit_changed = false;
checkContinuousFlag();
std::map<std::string, std::string> incomingSetup = _dSashaExpose;
std::map<std::string, std::string> timeoutSetup;
timeoutSetup = su::extract_setup(m_timeoutSetup, incomingSetup);
for(itSetup = incomingSetup.begin(); itSetup != incomingSetup.end(); itSetup++)
{
if(m_getFitsAbortFlag)break;
if(itSetup->first == "DIT" || itSetup->first == "InstrumentMode")
{
}
else
{
// U9_LLOG("setup : " << itSetup->first << ":" << itSetup->second);
IProperty & prop = m_sashaProps.find(itSetup->first)->second;
const std::map<std::string, indi::IElement> elements = prop.getElements();
bool bPropError = false, bSetProperty = false;
if(itSetup->first == "SAVE")
{
bool bSave = true;
su::get_bool_from_setup(_dSashaExpose, "SAVE", bSave);
std::map<std::string, indi::IElement>::const_iterator itEl;
if(elements.find("value") != elements.end())
{
indi::IElement::SwitchStateType switch_state = (bSave ? IElement::On : IElement::Off);
if(m_bForcePropertySet || prop["value"].getSwitchState() != switch_state)
{
prop["value"].setSwitchState(switch_state);
// U9_LLOG("Setting : " << "value" << " to " << bSave);
bSetProperty = true;
}
}
else
bPropError = true;
}
else if(itSetup->first == "OBJECTNAME")
{
if(elements.find("value") != elements.end())
{
std::string current_name = prop["value"].getValue();
if(m_bForcePropertySet || current_name != itSetup->second)
{
prop["value"].setValue(itSetup->second);
bSetProperty = true;
else
bPropError = true;
}
// else if(itSetup->first == "NCOADDS")
// {
// if(elements.find("num_coadds") != elements.end())
// prop["num_coadds"].setValue<int>(su::convertStringToType<int>(itSetup->second));
// else
// bPropError = true;
// }
else if(itSetup->first == "READOUT")
{
if(elements.find("value") != elements.end())
if(m_bForcePropertySet || prop["value"].getValue() != itSetup->second)
{
prop["value"].setValue(itSetup->second);
bSetProperty = true;
}
}
else
bPropError = true;
}
else
{
if(elements.find("value") != elements.end())
{
// int value = su::convertStringToType<int>(prop["value"].getValue());
if(m_bForcePropertySet || itSetup->second != prop["value"].getValue())
if(itSetup->first == "NDIT")ndit_changed = true;
prop["value"].setValue<int>(su::convertStringToType<int>(itSetup->second));
bSetProperty = true;
}
}
else
bPropError = true;
}
if(bPropError)
{
std::stringstream log_msg;
log_msg << "Error : IProperty \"" << prop.getDevice() << "." << prop.getName() << "\" from INDI Server has changed";
E_LLOG(log_msg.str());
throw(std::runtime_error(log_msg.str()));
}
else if(bSetProperty)
{
m_sashaPropsSet[itSetup->first] = false;
SendNewProperty(prop);
}
}
}
{
const std::map<std::string, indi::IElement> elements = sashaObjName.getElements();
if(elements.find("value") != elements.end())
{
m_sashaPropsSet["OBJECTNAME"] = false;
sashaObjName["value"].setValue(m_TcsPreset.object_name);
SendNewProperty(sashaObjName);
}
}
bool wait_result = false;
wait_result = WaitSetMessages(60000000);
if(!wait_result)status = EXIT_FAILURE;
int status2 = sashaEndSetup(timeoutSetup, ndit_changed);
if(status == EXIT_FAILURE || status2 == EXIT_FAILURE)status = EXIT_FAILURE;
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
}
catch(...)
{
m_exposeMutex.unlock();
U8_LLOG("");
throw;
}
m_exposeMutex.unlock();
U8_LLOG(__FUNCTION__ << " exiting");
return status;
}
int SeqDataMgr::sashaSetFrequency(const std::map<std::string, std::string> & _dSashaExpose)
{
U6_LLOG(__FUNCTION__);
int status = EXIT_SUCCESS;
m_exposeMutex.lock();
try
{
std::map<std::string, std::string>::const_iterator itSetup;
itSetup = _dSashaExpose.find("FREQUENCY");
if(itSetup != _dSashaExpose.end())
{
IProperty & prop = m_sashaProps.find(itSetup->first)->second;
const std::map<std::string, indi::IElement> elements = prop.getElements();
if(elements.find("value") != elements.end())
{
if(m_bForcePropertySet || prop["value"].getValue() != itSetup->second)
{
prop["value"].setValue(itSetup->second);
m_sashaPropsSet[itSetup->first] = false;
SendNewProperty(prop);
//camera reinitializes and readout region is reset
m_sashaPropsSet["READOUT"] = false;
WaitSetMessages(60000000);
}
}
else
{
U9_LLOG("Error: frequency property from INDI server has changed");
}
}
}
catch(...)
{
m_exposeMutex.unlock();
U8_LLOG("");
throw;
}
m_exposeMutex.unlock();
U8_LLOG(__FUNCTION__ << " exiting");
return status;
}
int SeqDataMgr::checkContinuousFlag()
{
int status = EXIT_SUCCESS;
if(!(sashaExposeProp["value"].getSwitchState() == IElement::Off))
{
m_sashaPropsSet["STOP"] = false;
sashaStop["value"].setSwitchState(IElement::On);
SendNewProperty(sashaStop);
m_sashaPropsSet["EXPOSE"] = false;
U6_LLOG(__FUNCTION__ << " ~ Clearing Expose Property");
WaitSetMessages(10000000);
m_sashaPropsSet["EXPOSE"] = false;
WaitSetMessages(10000000);
}
// if(!(sashaEnableCont["value"].getSwitchState() == IElement::Off))
// enable_cont property is resetted every time because is sometimes found misaligned with the one on the indi server
{
m_sashaPropsSet["CONTINUOUS"] = false;
sashaEnableCont["value"].setSwitchState(IElement::Off);
SendNewProperty(sashaEnableCont);
WaitSetMessages(10000000);
}
return status;
}
int SeqDataMgr::sashaExpose2(std::vector<std::string> & out_files)
{
U6_LLOG(__FUNCTION__);
int status = EXIT_SUCCESS;
m_exposeMutex.lock();
![Davide Ricci Davide Ricci's avatar](/gitlab/uploads/-/system/user/avatar/261/avatar.png?width=72)
Davide Ricci
committed
m_getFitsAbortFlag = 0;
checkContinuousFlag();
m_last_generated_files.clear();
if(m_bSaveOnlyExposedFiles && !m_getFitsAbortFlag)
{
sashaBlob.setBLOBEnable(IProperty::Also);
SendNewProperty(sashaBlob);
}
bool wait_result = false;
wait_result = WaitSetMessages(60000000);
if(!m_getFitsAbortFlag)
{
m_sashaPropsSet["EXPOSE"] = false;
sashaExposeProp["value"].setSwitchState(IElement::On);
SendNewProperty(sashaExposeProp);
m_ExpectedBlobs = su::convertStringToType<int>(sashaNumSeqs["value"].getValue());
m_bInstrumentSetupUpdated = false;
updateInstrumentHeader();
wait_result = WaitSetMessages(30000000);
}
if(!m_getFitsAbortFlag)
{
m_bBlobArrived = false;
}
if(m_bSaveOnlyExposedFiles)
{
if(m_ExpectedBlobs > 0)WaitBLOB(20000);
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
sashaBlob.setBLOBEnable(IProperty::Never);
SendNewProperty(sashaBlob);
}
if(!wait_result)status = EXIT_FAILURE;
if(m_getFitsAbortFlag)
{
throw(std::runtime_error("Error acquisition aborted by user"));
}
}
catch(...)
{
m_exposeMutex.unlock();
if(m_getFitsAbortFlag)m_getFitsAbortFlag--;
U8_LLOG("");
throw;
}
if(m_getFitsAbortFlag)m_getFitsAbortFlag--;
m_exposeMutex.unlock();
out_files = m_last_generated_files;
m_last_generated_files.clear();
U8_LLOG(__FUNCTION__ << " exiting");
return status;
}
void SeqDataMgr::abortExposure()
{
m_getFitsAbortFlag = 1;
SendNewProperty(sashaStop);
}
bool SeqDataMgr::WaitSetMessages(int timeout)
{
bool wait_sets = true;
int waited_time = 0;
int sleep_time = 1000;
std::stringstream log_msg;
while(wait_sets)
{
usleep(sleep_time);
waited_time += sleep_time;
sleep_time = 49000*(waited_time == 1000) + 50000*(waited_time > 1000);
std::map<std::string, bool>::iterator itSet;