#include #include #include #include #include "libCfg.h" #include "libdb.h" #include "libPIDF.h" // This subroutinte will return a list of UnitIDs in a virtual std::vector GetUnitIDs (SDDAS_ULONG data_key) { std::vector ret_val; int p_errno; int num_units; if (ALL_OKAY != (p_errno = ReadPidf (data_key, "", NOTUSED, NOTUSED, NOTUSED, TOTALUNITS, (void *) &num_units))) { std::cerr << "GetSensors: ERROR - could not get number of units!" << std::endl; } // Last, with the list of units, place into the list // which ones match the unit id for (int whichUnit = 0; whichUnit < num_units; whichUnit++) { int unit_id; if (ALL_OKAY != (p_errno = ReadPidf (data_key, "", PIDF_UNITS, NOTUSED, whichUnit, UNITID, (void *) &unit_id))) { std::cerr << "GetSensors: ERROR - could not get unit id!" << std::endl; } if (find (ret_val.begin(), ret_val.end(), unit_id) == ret_val.end()) ret_val.push_back (unit_id); } return (ret_val); } std::vector GetScanUnits (SDDAS_ULONG data_key) { // read the number of scan blocks int p_errno; int num_blocks; std::vector scan_units; std::vector ret_val; if (ALL_OKAY != (p_errno = ReadPidf (data_key, "", SWEEP_STEP, NOTUSED, NOTUSED, NUMOF, (void *) &num_blocks))) { return (scan_units); } // for each of the scan blocks, read the units_index for (int whichBlock = 0; whichBlock < num_blocks; whichBlock++) { int number_tot_scans; if ((p_errno = ReadPidf (data_key, "", SWEEP_STEP, whichBlock, NOTUSED, NUNITS, (void *) &number_tot_scans)) == ALL_OKAY) { for (int i = 0; i < number_tot_scans; i++) { int unit_num; if ((p_errno = ReadPidf (data_key, "", SWEEP_STEP, whichBlock, i, UNITNUM, (void *) &unit_num)) == ALL_OKAY) { if (find (scan_units.begin(), scan_units.end(), unit_num) == scan_units.end()) scan_units.push_back (unit_num); } // read the var_units int var_unit; if ((ReadPidf (data_key, "", SWEEP_STEP, whichBlock, i, VARUNITUBNUM, (void *) &var_unit)) != ALL_OKAY) { var_unit = -1; } if (find (scan_units.begin(), scan_units.end(), var_unit) == scan_units.end()) scan_units.push_back (var_unit); } } } // remove the -1 if it exists std::vector::iterator result = std::remove (scan_units.begin (), scan_units.end (), -1); scan_units.erase (result, scan_units.end()); // delete dangling elements from the vector // Last, with the list of units, place into the list // which ones match the unit id for (unsigned int whichUnit = 0; whichUnit < scan_units.size (); whichUnit++) { int unit_id; if (ALL_OKAY != (p_errno = ReadPidf (data_key, "", PIDF_UNITS, NOTUSED, scan_units [whichUnit], UNITID, (void *) &unit_id))) { std::cerr << "GetSensors: ERROR - could not get unit id!" << std::endl; } if (find (ret_val.begin(), ret_val.end(), unit_id) == ret_val.end()) ret_val.push_back (unit_id); } // remove all the units read from the list return ret_val; } int main (int argc, char **argv) { SDDAS_ULONG key = 0; if (argc < 2) { puts ("Error! Usage: unitsList P M E I V or "); puts ("Error! Usage: unitsList filename"); return -1; } if (argc > 2) { dbInitialize (); CfgInit (); key = dbGetDataKey (argv [1], argv [2], argv [3], argv [4], argv [5]); if (key == 0) { printf ("dump_pidf: Can't open (%s/%s/%s/%s/%s)\n", argv [1], argv [2], argv [3], argv [4], argv [5]); exit (-1); } } else { char vinst [MAXPATHLEN]; char *beginning; memset (vinst, 0, sizeof (vinst)); beginning = strrchr (argv [1], '/'); if (beginning == NULL) beginning = argv [1]; else beginning++; strncpy (vinst, beginning, strcspn (beginning, ".")); PIDF_SetFileName (argv [1], vinst); } std::vector allUnitIDs = GetUnitIDs (key); std::vector scanUnits = GetScanUnits (key); std::vector goodUnitIDs (allUnitIDs.size () + scanUnits.size ()); std::vector ::iterator endIter; endIter = set_difference (allUnitIDs.begin (), allUnitIDs.end (), scanUnits.begin (), scanUnits.end (), goodUnitIDs.begin ()); goodUnitIDs.erase (endIter, goodUnitIDs.end ()); std::cout << "DATA UNITS" << std::endl; for (unsigned int i = 0; i < goodUnitIDs.size (); i++) { std::cout << goodUnitIDs [i] << std::endl; } std::cout << std::endl; if (!scanUnits.empty ()) { std::cout << "SCAN UNITS" << std::endl; for (unsigned int i = 0; i < scanUnits.size (); i++) { std::cout << scanUnits [i] << std::endl; } std::cout << std::endl; } if (argc > 2) CfgTerm (); return (0); }