Exemplo n.º 1
0
void ConfigSetup::Init(const char *fileName)
{
	std::vector<std::string> line;

	//ADDED LINES TO GET PREFIX PATH AND 
	//CONVERT CHAR ARRY TO STRING TYPE TO GET PREFIX PATH
	//string prefix;
	std::string inputString(fileName);

	size_t found = inputString.rfind('/');
	if (found != std::string::npos)
		prefix = inputString.substr(0, inputString.find_last_of('/')) + '/';
	//END ADD LINE
	
	reader.Open(fileName);
	while(reader.readNextLine(line))
	{
		if(line[0] == "Restart") {
			in.restart.enable = checkBool(line[1]);
		} else if(line[0] == "FirstStep") {
			in.restart.step = stringtoi(line[1]);
		} else if(line[0] == "PRNG") {
			in.prng.kind = line[1];
		} else if(line[0] == "Random_Seed") {
			in.prng.seed = stringtoi(line[1]);
		} else if(line[0] == "ParaTypeCHARMM") {
			if(checkBool(line[1]))
			{
				in.ffKind.numOfKinds++;
				in.ffKind.isEXOTIC = false;
				in.ffKind.isMARTINI = false;
				in.ffKind.isCHARMM = true;
				std::cout << "REMINDER: CHARMM force field has been selected!" << std::endl;
			}
		} else if(line[0] == "ParaTypeEXOTIC") {
			if(checkBool(line[1]))
			{
				in.ffKind.numOfKinds++;
				in.ffKind.isCHARMM = false;
				in.ffKind.isMARTINI = false;
			        in.ffKind.isEXOTIC = true;
				std::cout << "REMINDER: EXOTIC force field has been selected!" << std::endl;
		}
		} else if(line[0] == "ParaTypeMARTINI") {
			if(checkBool(line[1]))
			{
				in.ffKind.numOfKinds ++;
				in.ffKind.isEXOTIC = false;
				in.ffKind.isMARTINI = true;
				in.ffKind.isCHARMM = true;
				std::cout << "REMINDER: MARTINI force field has been selected!" << std::endl;
			}
		} else if(line[0] == "Parameters") {
			in.files.param.name = prefix + line[1]; //ADDED PREFIX
		} else if(line[0] == "Coordinates") {
			uint boxnum = stringtoi(line[1]);
			if(boxnum >= BOX_TOTAL)
			{
				std::cout<< "Error: This simulation requires only " << BOX_TOTAL << " number of PDB file(s)!" << std::endl;
				exit(0);
			}
			in.files.pdb.name[boxnum] = prefix + line[2]; //ADDED PREFIX
		} else if(line[0] == "Structure") {
			uint boxnum = stringtoi(line[1]);
			if(boxnum >= BOX_TOTAL)
			{
				std::cout<< "Error: This simulation requires only " << BOX_TOTAL << " number of PSF file(s)!" << std::endl;
				exit(0);
			}
			in.files.psf.name[boxnum] = prefix + line[2]; //ADDED PREFIX
		}
#if ENSEMBLE == GEMC
		else if(line[0] == "GEMC")
		{
			if(line[1] == "NVT")
			{
				sys.gemc.kind = mv::GEMC_NVT;
				std::cout<< " NVT_GEMC simulation has been selected " << std::endl;
			}
			else if(line[1] == "NPT")
			{
				sys.gemc.kind = mv::GEMC_NPT;
				std::cout<< " NPT_GEMC simulation has been selected " << std::endl;
                        } 
		}
		else if(line[0] == "Pressure")
		{
			sys.gemc.pressure = stringtod(line[1]);
			std::cout<< " Pressure of system has been set to " << sys.gemc.pressure << " bar " << std::endl;
			sys.gemc.pressure *= unit::BAR_TO_K_MOLECULE_PER_A3;
		}
#endif
		else if(line[0] == "Temperature")
		{
			sys.T.inKelvin = stringtod(line[1]);
		}
		else if(line[0] == "Potential")
		{
			if(line[1] == "VDW")
				sys.ff.VDW_KIND = sys.ff.VDW_STD_KIND;
			else if(line[1] == "SHIFT")
				sys.ff.VDW_KIND = sys.ff.VDW_SHIFT_KIND;
			else if(line[1] == "SWITCH")
				sys.ff.VDW_KIND = sys.ff.VDW_SWITCH_KIND;
		}
		else if(line[0] == "LRC")
		{
			sys.ff.doTailCorr = checkBool(line[1]);
		}
		else if(line[0] == "Rswitch")
		{
			sys.ff.rswitch = stringtod(line[1]);
		}
		else if(line[0] == "Rcut")
		{
			sys.ff.cutoff = stringtod(line[1]);
		}
		else if(line[0] == "Exclude")
		{
			if(line[1] == sys.exclude.EXC_ONETWO)
				sys.exclude.EXCLUDE_KIND = sys.exclude.EXC_ONETWO_KIND;
			else if(line[1] == sys.exclude.EXC_ONETHREE)
				sys.exclude.EXCLUDE_KIND = sys.exclude.EXC_ONETHREE_KIND;
			else if(line[1] == sys.exclude.EXC_ONEFOUR)
				sys.exclude.EXCLUDE_KIND = sys.exclude.EXC_ONEFOUR_KIND;
		}
		else if(line[0] == "Ewald")
		{
			sys.elect.ewald = checkBool(line[1]);
			sys.elect.readEwald = true;
		}
		else if(line[0] == "ElectroStatic")
		{
			sys.elect.enable = checkBool(line[1]);
			sys.elect.readElect = true;
		}
		else if(line[0] == "Tolerance")
		{
			sys.elect.tolerance = stringtod(line[1]);
			sys.elect.alpha = sqrt(-1 * log(sys.elect.tolerance))/
			  sys.ff.cutoff;
			sys.elect.recip_rcut = 2 * (-log(sys.elect.tolerance))/
			  sys.ff.cutoff;
		}
		else if(line[0] == "1-4scaling")
		{
			sys.elect.oneFourScale = stringtod(line[1]);
		}
		else if(line[0] == "Dielectric")
		{
			sys.elect.dielectric = stringtod(line[1]);
		}
		else if(line[0] == "RunSteps")
		{
			sys.step.total = stringtoi(line[1]);
		}
		else if(line[0] == "EqSteps")
		{
			sys.step.equil = stringtoi(line[1]);
		}
		else if(line[0] == "AdjSteps")
		{
			sys.step.adjustment = stringtoi(line[1]);
		}
		else if(line[0] == "DisFreq")
		{
			sys.moves.displace = stringtod(line[1]);
		}
		else if(line[0] == "IntraSwapFreq")
		{
			sys.moves.intraSwap = stringtod(line[1]);
		}
		else if(line[0] == "RotFreq")
		{
			sys.moves.rotate = stringtod(line[1]);
		} 
#ifdef VARIABLE_VOLUME
		else if(line[0] == "VolFreq")
		{
			sys.moves.volume = stringtod(line[1]);
		}
#endif
#ifdef VARIABLE_PARTICLE_NUMBER
		else if(line[0] == "SwapFreq")
		{
#if ENSEMBLE == NVT
		        sys.moves.transfer = 0.000;
#else
			sys.moves.transfer = stringtod(line[1]);
#endif
		}
#endif
		else if(line[0] == "BoxDim") {
			uint box = stringtoi(line[1]);
			if(box < BOX_TOTAL)
			{
				XYZ temp;
				sys.volume.boxCoordRead++;
				sys.volume.hasVolume = (sys.volume.boxCoordRead == BOX_TOTAL);
				temp.x = stringtod(line[2]);
				temp.y = stringtod(line[3]);
				temp.z = stringtod(line[4]);

				sys.volume.axis.Set(box, temp);
			}
			else
			{
				std::cout<< "Error: This simulation requires only " << BOX_TOTAL << " number of box dimension(s)!" << std::endl;
				exit(0);
			}
		}
#ifdef VARIABLE_PARTICLE_NUMBER
		else if(line[0] == "CBMC_First")
		{
			sys.cbmcTrials.nonbonded.first = stringtoi(line[1]);
		}
		else if(line[0] == "CBMC_Nth")
		{
			sys.cbmcTrials.nonbonded.nth = stringtoi(line[1]);
		}
		else if(line[0] == "CBMC_Ang")
		{
			sys.cbmcTrials.bonded.ang = stringtoi(line[1]);
		} 
		else if(line[0] == "CBMC_Dih")
		{
			sys.cbmcTrials.bonded.dih = stringtoi(line[1]);
		}
#endif
#if ENSEMBLE == GCMC
		else if(line[0] == "ChemPot") {
			if(line.size() != 3)
			{
				std::cout << "Error: Chemical potential parameters have not been specified!" << std::endl;
				exit(0);
			}
			std::string resName = line[1];
			double val = stringtod(line[2]);
			sys.chemPot.cp[resName] = val;
		} 
#endif
		else if(line[0] == "OutputName") 
		{
			out.statistics.settings.uniqueStr.val = line[1];
		} 
		else if(line[0] == "CoordinatesFreq") 
		{
			out.state.settings.enable = checkBool(line[1]);
			out.state.settings.frequency = stringtoi(line[2]);
		} 
		else if(line[0] == "RestartFreq") 
		{
			out.restart.settings.enable = checkBool(line[1]);
			out.restart.settings.frequency = stringtoi(line[2]);
		} 
		else if(line[0] == "ConsoleFreq") 
		{
			out.console.enable = checkBool(line[1]);
			out.console.frequency = stringtoi(line[2]);
		} 
		else if(line[0] == "BlockAverageFreq") 
		{
			out.statistics.settings.block.enable = checkBool(line[1]);
			out.statistics.settings.block.frequency = stringtoi(line[2]);
		} 
		else if(line[0] == "FluctuationFreq") 
		{
			out.statistics.settings.fluct.enable = checkBool(line[1]);
			out.statistics.settings.fluct.frequency = stringtoi(line[2]);
		} 
#if ENSEMBLE == GCMC
		else if(line[0] == "HistogramFreq") 
		{
			out.statistics.settings.hist.enable = checkBool(line[1]);
			out.statistics.settings.hist.frequency = stringtoi(line[2]);
		}
		else if(line[0] == "DistName")
		{
			out.state.files.hist.histName = line[1];
		}
		else if(line[0] == "HistName")
		{
			out.state.files.hist.sampleName = line[1];
		} 
		else if(line[0] == "RunNumber") 
		{
			out.state.files.hist.number = line[1];
		} 
		else if(line[0] == "RunLetter") 
		{
			out.state.files.hist.letter = line[1];
		} 
		else if(line[0] == "SampleFreq") 
		{
			out.state.files.hist.stepsPerHistSample = stringtoi(line[1]);
		}
#endif
		else if(line[0] == "OutEnergy") {
			out.statistics.vars.energy.block = checkBool(line[1]);
			out.statistics.vars.energy.fluct = checkBool(line[2]);
			out.statistics.vars.energy.hist = checkBool(line[3]);
		} else if(line[0] == "OutPressure") {
			out.statistics.vars.pressure.block = checkBool(line[1]);
			out.statistics.vars.pressure.fluct = checkBool(line[2]);
			out.statistics.vars.pressure.hist = checkBool(line[3]);
		}
#ifdef VARIABLE_PARTICLE_NUMBER
		else if(line[0] == "OutMolNum") {
			out.statistics.vars.molNum.block = checkBool(line[1]);
			out.statistics.vars.molNum.fluct = checkBool(line[2]);
			out.statistics.vars.molNum.hist = checkBool(line[3]);
		} else if(line[0] == "OutAcceptAngles") {
			out.statistics.vars.acceptAngles.block = checkBool(line[1]);
			out.statistics.vars.acceptAngles.fluct = checkBool(line[2]);
			out.statistics.vars.acceptAngles.hist = checkBool(line[3]);
		}
#endif
#ifdef VARIABLE_DENSITY
		else if(line[0] == "OutDensity") {
			out.statistics.vars.density.block = checkBool(line[1]);
			out.statistics.vars.density.fluct = checkBool(line[2]);
			out.statistics.vars.density.hist = checkBool(line[3]);
		}
#endif
#ifdef VARIABLE_VOLUME
		else if(line[0] == "OutVolume") {
			out.statistics.vars.volume.block = checkBool(line[1]);
			out.statistics.vars.volume.fluct = checkBool(line[2]);
			out.statistics.vars.volume.hist = checkBool(line[3]);
		}
#endif
		else{
			cout << "Warning: Unknown input " << line[0] << "!" << endl;
		}
		// Clear and get ready for the next line
		line.clear();
	}

	//*********** Fill in the default values if not specified ***********//
	fillDefaults();

	//*********** Verify inputs ***********//
	verifyInputs();
}
Exemplo n.º 2
0
  bool CREAMClient::stat(const std::string& jobid, Job& job) {
    logger.msg(VERBOSE, "Creating and sending a status request");

    action = "JobInfo";

    PayloadSOAP req(cream_ns);
    XMLNode xjobId = req.NewChild("types:" + action + "Request").NewChild("types:jobId");
    xjobId.NewChild("types:id") = jobid;
    xjobId.NewChild("types:creamURL") = client->GetURL().str();

    XMLNode response;
    if (!process(req, response)) return false;

    XMLNode jobInfoNode;
    jobInfoNode = response["result"]["jobInfo"];

    XMLNode lastStatusNode = jobInfoNode.Path("status").back();

    if (lastStatusNode["name"]) {
      job.State = JobStateCREAM((std::string)lastStatusNode["name"]);
    }
    if (lastStatusNode["failureReason"]) {
      job.Error.push_back((std::string)lastStatusNode["failureReason"]);
    }
    
    if (!job.State) {
      logger.msg(VERBOSE, "Unable to retrieve job status.");
      return false;
    }

    if (ISVALID(jobInfoNode["jobId"]["id"])) {
      job.IDFromEndpoint = (std::string)jobInfoNode["jobId"]["id"];
    }
    if (ISVALID(jobInfoNode["type"]))
      job.Type = (std::string)jobInfoNode["type"];
    if (ISVALID(jobInfoNode["JDL"])) {
      job.JobDescription = "egee:jdl";
      job.JobDescriptionDocument = (std::string)jobInfoNode["JDL"];

      std::list<JobDescription> jds;
      if (JobDescription::Parse(job.JobDescriptionDocument, jds) && !jds.empty()) {
        if (!jds.front().Application.Input.empty())
          job.StdIn = jds.front().Application.Input;

        if (!jds.front().Application.Output.empty())
          job.StdOut = jds.front().Application.Output;

        if (!jds.front().Application.Error.empty())
          job.StdErr = jds.front().Application.Error;

        if (!jds.front().Resources.QueueName.empty()) {
          job.Queue = jds.front().Resources.QueueName;
        }
      }
    }
    if (ISVALID(lastStatusNode["exitCode"]))
      job.ExitCode = stringtoi((std::string)lastStatusNode["exitCode"]);
    if (ISVALID(jobInfoNode["delegationProxyInfo"])) {
      /* Format of delegationProxyInfo node.
      [ isRFC="<true|false>";
        valid from="<mon>/<date>/<yy> <hour>:<min> <AM|PM> (<timezone>)";
        valid to="<mon>/<date>/<yy> <hour>:<min> <AM|PM> (<timezone>)";
        holder DN="<DN>";
        holder AC issuer="<DN>";
        VO="<VO-name>";
        AC issuer="<DN>";
        VOMS attributes=<VOMS-Attributes>
      ]
      */
      
      std::string delegationProxy = (std::string)jobInfoNode["delegationProxyInfo"];
      std::size_t lBracketPos = delegationProxy.find('['), rBracketPos = delegationProxy.rfind(']');
      if (lBracketPos != std::string::npos && rBracketPos != std::string::npos) {
        delegationProxy = trim(delegationProxy.substr(lBracketPos, rBracketPos - lBracketPos));
      }
      std::list<std::string> tDelegInfo;
      tokenize(delegationProxy, tDelegInfo, ";");
      for (std::list<std::string>::iterator it = tDelegInfo.begin();
           it != tDelegInfo.end(); ++it) {
        std::list<std::string> keyValuePair;
        tokenize(*it, keyValuePair, "=", "\"", "\"");
        if (keyValuePair.size() != 2) continue;
        if (lower(trim(keyValuePair.front())) == "holder dn") job.Owner = trim(keyValuePair.back(), " \"");
        if (lower(trim(keyValuePair.front())) == "valid to")  stringtoTime(trim(keyValuePair.back(), " \""), job.ProxyExpirationTime);
      }
    }
    if (ISVALID(jobInfoNode["localUser"]))
      job.LocalOwner = (std::string)jobInfoNode["localUser"];
    if (ISVALID(jobInfoNode["lastCommand"])) {
      int job_register_id_first = -1;
      int job_register_id_last = -1;
      int job_start_id_first = -1;
      int job_start_id_last = -1;
      int local_id = 0;
      while (true) {
        if (!jobInfoNode["lastCommand"][local_id])
          break;
        if ((std::string)jobInfoNode["lastCommand"][local_id]["name"] == "JOB_REGISTER") {
          if (job_register_id_first == -1 && job_register_id_last == -1) {
            job_register_id_first = local_id;
            job_register_id_last = local_id;
          }
          else if (job_register_id_last > -1)
            job_register_id_last = local_id;
        }  //end of the JOB_REGISTER

        if ((std::string)jobInfoNode["lastCommand"][local_id]["name"] == "JOB_START") {
          if (job_start_id_first == -1 && job_start_id_last == -1) {
            job_start_id_first = local_id;
            job_start_id_last = local_id;
          }
          else if (job_start_id_last > -1)
            job_start_id_last = local_id;
        }  //end of the JOB_START
        local_id++;
      }

      //dependent on JOB_REGISTER
      if (job_register_id_first > -1)
        if (ISVALID(jobInfoNode["lastCommand"][job_register_id_first]["creationTime"])) {
          Time time((std::string)jobInfoNode["lastCommand"][job_register_id_first]["creationTime"]);
          if (time.GetTime() != -1)
            job.SubmissionTime = time;
        }

      if (job_register_id_last > -1)
        if (ISVALID(jobInfoNode["lastCommand"][job_register_id_last]["creationTime"])) {
          Time time((std::string)jobInfoNode["lastCommand"][job_register_id_last]["creationTime"]);
          if (time.GetTime() != -1)
            job.CreationTime = time;
        }
      //end of the JOB_REGISTER

      //dependent on JOB_START
      if (job_start_id_first > -1) {
        if (ISVALID(jobInfoNode["lastCommand"][job_start_id_first]["startSchedulingTime"])) {
          Time time((std::string)jobInfoNode["lastCommand"][job_start_id_first]["startSchedulingTime"]);
          if (time.GetTime() != -1)
            job.ComputingManagerSubmissionTime = time;
        }

        if (ISVALID(jobInfoNode["lastCommand"][job_start_id_first]["startProcessingTime"])) {
          Time time((std::string)jobInfoNode["lastCommand"][job_start_id_first]["startProcessingTime"]);
          if (time.GetTime() != -1)
            job.StartTime = time;
        }
      }

      if (job_start_id_last > -1)
        if (ISVALID(jobInfoNode["lastCommand"][job_start_id_last]["executionCompletedTime"])) {
          Time time((std::string)jobInfoNode["lastCommand"][job_start_id_last]["executionCompletedTime"]);
          if (time.GetTime() != -1)
            job.ComputingManagerEndTime = time;
        }
      //end of the JOB_START
    } //end of the LastCommand
    if (ISVALID(lastStatusNode["timestamp"]) && (job.State() == "DONE-OK" || job.State() == "DONE-FAILED")) {
      Time time((std::string)lastStatusNode["timestamp"]);
      if (time.GetTime() != -1)
        job.EndTime = time;
    }

    return true;
  }
Exemplo n.º 3
0
  void GLUE2::ParseExecutionTargets(XMLNode glue2tree, std::list<ComputingServiceType>& targets) {

    XMLNode GLUEService = glue2tree;
    if(GLUEService.Name() != "ComputingService") {
      GLUEService = glue2tree["ComputingService"];
    }

    for (; GLUEService; ++GLUEService) {
      ComputingServiceType cs;

      if (GLUEService["ID"]) {
        cs->ID = (std::string)GLUEService["ID"];
      }
      if (GLUEService["Name"]) {
        cs->Name = (std::string)GLUEService["Name"];
      }
      if (GLUEService["Capability"]) {
        for (XMLNode n = GLUEService["Capability"]; n; ++n) {
          cs->Capability.insert((std::string)n);
        }
      }
      if (GLUEService["Type"]) {
        cs->Type = (std::string)GLUEService["Type"];
      } else {
        logger.msg(VERBOSE, "The Service doesn't advertise its Type.");
      }
      if (GLUEService["QualityLevel"]) {
        cs->QualityLevel = (std::string)GLUEService["QualityLevel"];
      } else {
        logger.msg(VERBOSE, "The ComputingService doesn't advertise its Quality Level.");
      }
      if (GLUEService["TotalJobs"]) {
        cs->TotalJobs = stringtoi((std::string)GLUEService["TotalJobs"]);
      }
      if (GLUEService["RunningJobs"]) {
        cs->RunningJobs = stringtoi((std::string)GLUEService["RunningJobs"]);
      }
      if (GLUEService["WaitingJobs"]) {
        cs->WaitingJobs = stringtoi((std::string)GLUEService["WaitingJobs"]);
      }
      if (GLUEService["StagingJobs"]) {
        cs->StagingJobs = stringtoi((std::string)GLUEService["StagingJobs"]);
      }
      if (GLUEService["SuspendedJobs"]) {
        cs->SuspendedJobs = stringtoi((std::string)GLUEService["SuspendedJobs"]);
      }
      if (GLUEService["PreLRMSWaitingJobs"]) {
        cs->PreLRMSWaitingJobs = stringtoi((std::string)GLUEService["PreLRMSWaitingJobs"]);
      }
      // The GLUE2 specification does not have attribute ComputingService.LocalRunningJobs
      //if (GLUEService["LocalRunningJobs"]) {
      //  cs->LocalRunningJobs = stringtoi((std::string)GLUEService["LocalRunningJobs"]);
      //}
      // The GLUE2 specification does not have attribute ComputingService.LocalWaitingJobs
      //if (GLUEService["LocalWaitingJobs"]) {
      //  cs->LocalWaitingJobs = stringtoi((std::string)GLUEService["LocalWaitingJobs"]);
      //}
      // The GLUE2 specification does not have attribute ComputingService.LocalSuspendedJobs
      //if (GLUEService["LocalSuspendedJobs"]) {
      //  cs->LocalWaitingJobs = stringtoi((std::string)GLUEService["LocalSuspendedJobs"]);
      //}


      XMLNode xmlCENode = GLUEService["ComputingEndpoint"];
      int endpointID = 0;
      for(;(bool)xmlCENode;++xmlCENode) {
        ComputingEndpointType ComputingEndpoint;
        if (xmlCENode["URL"]) {
          ComputingEndpoint->URLString = (std::string)xmlCENode["URL"];
        } else {
          logger.msg(VERBOSE, "The ComputingEndpoint has no URL.");
        }
        if (xmlCENode["HealthState"]) {
          ComputingEndpoint->HealthState = (std::string)xmlCENode["HealthState"];
        } else {
          logger.msg(VERBOSE, "The Service advertises no Health State.");
        }
        if (xmlCENode["HealthStateInfo"]) {
          ComputingEndpoint->HealthStateInfo = (std::string)xmlCENode["HealthStateInfo"];
        }
        if (xmlCENode["Capability"]) {
          for (XMLNode n = xmlCENode["Capability"]; n; ++n) {
            ComputingEndpoint->Capability.insert((std::string)n);
          }
        }
        if (xmlCENode["QualityLevel"]) {
          ComputingEndpoint->QualityLevel = (std::string)xmlCENode["QualityLevel"];
        } else {
          logger.msg(VERBOSE, "The ComputingEndpoint doesn't advertise its Quality Level.");
        }

        if (xmlCENode["Technology"]) {
          ComputingEndpoint->Technology = (std::string)xmlCENode["Technology"];
        }
        if (xmlCENode["InterfaceName"]) {
          ComputingEndpoint->InterfaceName = lower((std::string)xmlCENode["InterfaceName"]);
        } else if (xmlCENode["Interface"]) { // No such attribute according to GLUE2 document. Legacy/backward compatibility?
          ComputingEndpoint->InterfaceName = lower((std::string)xmlCENode["Interface"]);
        } else {
          logger.msg(VERBOSE, "The ComputingService doesn't advertise its Interface.");
        }
        if (xmlCENode["InterfaceVersion"]) {
          for (XMLNode n = xmlCENode["InterfaceVersion"]; n; ++n) {
            ComputingEndpoint->InterfaceVersion.push_back((std::string)n);
          }
        }
        if (xmlCENode["InterfaceExtension"]) {
          for (XMLNode n = xmlCENode["InterfaceExtension"]; n; ++n) {
            ComputingEndpoint->InterfaceExtension.push_back((std::string)n);
          }
        }
        if (xmlCENode["SupportedProfile"]) {
          for (XMLNode n = xmlCENode["SupportedProfile"]; n; ++n) {
            ComputingEndpoint->SupportedProfile.push_back((std::string)n);
          }
        }
        if (xmlCENode["Implementor"]) {
          ComputingEndpoint->Implementor = (std::string)xmlCENode["Implementor"];
        }
        if (xmlCENode["ImplementationName"]) {
          if (xmlCENode["ImplementationVersion"]) {
            ComputingEndpoint->Implementation =
              Software((std::string)xmlCENode["ImplementationName"],
                       (std::string)xmlCENode["ImplementationVersion"]);
          } else {
            ComputingEndpoint->Implementation = Software((std::string)xmlCENode["ImplementationName"]);
          }
        }
        if (xmlCENode["ServingState"]) {
          ComputingEndpoint->ServingState = (std::string)xmlCENode["ServingState"];
        } else {
          logger.msg(VERBOSE, "The ComputingEndpoint doesn't advertise its Serving State.");
        }
        if (xmlCENode["IssuerCA"]) {
          ComputingEndpoint->IssuerCA = (std::string)xmlCENode["IssuerCA"];
        }
        if (xmlCENode["TrustedCA"]) {
          XMLNode n = xmlCENode["TrustedCA"];
          while (n) {
            // Workaround to drop non-conforming records generated by EGI services
            std::string subject = (std::string)n;
            if(CheckConformingDN(subject)) {
              ComputingEndpoint->TrustedCA.push_back(subject);
            }
            ++n; //The increment operator works in an unusual manner (returns void)
          }
        }
        if (xmlCENode["DowntimeStart"]) {
          ComputingEndpoint->DowntimeStarts = (std::string)xmlCENode["DowntimeStart"];
        }
        if (xmlCENode["DowntimeEnd"]) {
          ComputingEndpoint->DowntimeEnds = (std::string)xmlCENode["DowntimeEnd"];
        }
        if (xmlCENode["Staging"]) {
          ComputingEndpoint->Staging = (std::string)xmlCENode["Staging"];
        }
        if (xmlCENode["JobDescription"]) {
          for (XMLNode n = xmlCENode["JobDescription"]; n; ++n) {
            ComputingEndpoint->JobDescriptions.push_back((std::string)n);
          }
        }

        if (xmlCENode["TotalJobs"]) {
          ComputingEndpoint->TotalJobs = stringtoi((std::string)xmlCENode["TotalJobs"]);
        }
        if (xmlCENode["RunningJobs"]) {
          ComputingEndpoint->RunningJobs = stringtoi((std::string)xmlCENode["RunningJobs"]);
        }
        if (xmlCENode["WaitingJobs"]) {
          ComputingEndpoint->WaitingJobs = stringtoi((std::string)xmlCENode["WaitingJobs"]);
        }
        if (xmlCENode["StagingJobs"]) {
          ComputingEndpoint->StagingJobs = stringtoi((std::string)xmlCENode["StagingJobs"]);
        }
        if (xmlCENode["SuspendedJobs"]) {
          ComputingEndpoint->SuspendedJobs = stringtoi((std::string)xmlCENode["SuspendedJobs"]);
        }
        if (xmlCENode["PreLRMSWaitingJobs"]) {
          ComputingEndpoint->PreLRMSWaitingJobs = stringtoi((std::string)xmlCENode["PreLRMSWaitingJobs"]);
        }
        // The GLUE2 specification does not have attribute ComputingEndpoint.LocalRunningJobs
        //if (xmlCENode["LocalRunningJobs"]) {
        //  ComputingEndpoint->LocalRunningJobs = stringtoi((std::string)xmlCENode["LocalRunningJobs"]);
        //}
        // The GLUE2 specification does not have attribute ComputingEndpoint.LocalWaitingJobs
        //if (xmlCENode["LocalWaitingJobs"]) {
        //  ComputingEndpoint->LocalWaitingJobs = stringtoi((std::string)xmlCENode["LocalWaitingJobs"]);
        //}
        // The GLUE2 specification does not have attribute ComputingEndpoint.LocalSuspendedJobs
        //if (xmlCENode["LocalSuspendedJobs"]) {
        //  ComputingEndpoint->LocalSuspendedJobs = stringtoi((std::string)xmlCENode["LocalSuspendedJobs"]);
        //}

        cs.ComputingEndpoint.insert(std::pair<int, ComputingEndpointType>(endpointID++, ComputingEndpoint));
      }

      XMLNode xComputingShare = GLUEService["ComputingShare"];
      int shareID = 0;
      for (;(bool)xComputingShare;++xComputingShare) {
        ComputingShareType ComputingShare;

        if (xComputingShare["FreeSlots"]) {
          ComputingShare->FreeSlots = stringtoi((std::string)xComputingShare["FreeSlots"]);
        }
        if (xComputingShare["FreeSlotsWithDuration"]) {
          // Format: ns[:t] [ns[:t]]..., where ns is number of slots and t is the duration.
          ComputingShare->FreeSlotsWithDuration.clear();

          const std::string fswdValue = (std::string)xComputingShare["FreeSlotsWithDuration"];
          std::list<std::string> fswdList;
          tokenize(fswdValue, fswdList);
          for (std::list<std::string>::iterator it = fswdList.begin();
               it != fswdList.end(); it++) {
            std::list<std::string> fswdPair;
            tokenize(*it, fswdPair, ":");
            long duration = LONG_MAX;
            int freeSlots = 0;
            if (fswdPair.size() > 2 || !stringto(fswdPair.front(), freeSlots) || (fswdPair.size() == 2 && !stringto(fswdPair.back(), duration)) ) {
              logger.msg(VERBOSE, "The \"FreeSlotsWithDuration\" attribute published by \"%s\" is wrongly formatted. Ignoring it.");
              logger.msg(DEBUG, "Wrong format of the \"FreeSlotsWithDuration\" = \"%s\" (\"%s\")", fswdValue, *it);
              continue;
            }

            ComputingShare->FreeSlotsWithDuration[Period(duration)] = freeSlots;
          }
        }
        if (xComputingShare["UsedSlots"]) {
          ComputingShare->UsedSlots = stringtoi((std::string)xComputingShare["UsedSlots"]);
        }
        if (xComputingShare["RequestedSlots"]) {
          ComputingShare->RequestedSlots = stringtoi((std::string)xComputingShare["RequestedSlots"]);
        }
        if (xComputingShare["Name"]) {
          ComputingShare->Name = (std::string)xComputingShare["Name"];
        }
        if (xComputingShare["MaxWallTime"]) {
          ComputingShare->MaxWallTime = (std::string)xComputingShare["MaxWallTime"];
        }
        if (xComputingShare["MaxTotalWallTime"]) {
          ComputingShare->MaxTotalWallTime = (std::string)xComputingShare["MaxTotalWallTime"];
        }
        if (xComputingShare["MinWallTime"]) {
          ComputingShare->MinWallTime = (std::string)xComputingShare["MinWallTime"];
        }
        if (xComputingShare["DefaultWallTime"]) {
          ComputingShare->DefaultWallTime = (std::string)xComputingShare["DefaultWallTime"];
        }
        if (xComputingShare["MaxCPUTime"]) {
          ComputingShare->MaxCPUTime = (std::string)xComputingShare["MaxCPUTime"];
        }
        if (xComputingShare["MaxTotalCPUTime"]) {
          ComputingShare->MaxTotalCPUTime = (std::string)xComputingShare["MaxTotalCPUTime"];
        }
        if (xComputingShare["MinCPUTime"]) {
          ComputingShare->MinCPUTime = (std::string)xComputingShare["MinCPUTime"];
        }
        if (xComputingShare["DefaultCPUTime"]) {
          ComputingShare->DefaultCPUTime = (std::string)xComputingShare["DefaultCPUTime"];
        }
        if (xComputingShare["MaxTotalJobs"]) {
          ComputingShare->MaxTotalJobs = stringtoi((std::string)xComputingShare["MaxTotalJobs"]);
        }
        if (xComputingShare["MaxRunningJobs"]) {
          ComputingShare->MaxRunningJobs = stringtoi((std::string)xComputingShare["MaxRunningJobs"]);
        }
        if (xComputingShare["MaxWaitingJobs"]) {
          ComputingShare->MaxWaitingJobs = stringtoi((std::string)xComputingShare["MaxWaitingJobs"]);
        }
        if (xComputingShare["MaxPreLRMSWaitingJobs"]) {
          ComputingShare->MaxPreLRMSWaitingJobs = stringtoi((std::string)xComputingShare["MaxPreLRMSWaitingJobs"]);
        }
        if (xComputingShare["MaxUserRunningJobs"]) {
          ComputingShare->MaxUserRunningJobs = stringtoi((std::string)xComputingShare["MaxUserRunningJobs"]);
        }
        if (xComputingShare["MaxSlotsPerJob"]) {
          ComputingShare->MaxSlotsPerJob = stringtoi((std::string)xComputingShare["MaxSlotsPerJob"]);
        }
        if (xComputingShare["MaxStageInStreams"]) {
          ComputingShare->MaxStageInStreams = stringtoi((std::string)xComputingShare["MaxStageInStreams"]);
        }
        if (xComputingShare["MaxStageOutStreams"]) {
          ComputingShare->MaxStageOutStreams = stringtoi((std::string)xComputingShare["MaxStageOutStreams"]);
        }
        if (xComputingShare["SchedulingPolicy"]) {
          ComputingShare->SchedulingPolicy = (std::string)xComputingShare["SchedulingPolicy"];
        }
        if (xComputingShare["MaxMainMemory"]) {
          ComputingShare->MaxMainMemory = stringtoi((std::string)xComputingShare["MaxMainMemory"]);
        }
        if (xComputingShare["MaxVirtualMemory"]) {
          ComputingShare->MaxVirtualMemory = stringtoi((std::string)xComputingShare["MaxVirtualMemory"]);
        }
        if (xComputingShare["MaxDiskSpace"]) {
          ComputingShare->MaxDiskSpace = stringtoi((std::string)xComputingShare["MaxDiskSpace"]);
        }
        if (xComputingShare["DefaultStorageService"]) {
          ComputingShare->DefaultStorageService = (std::string)xComputingShare["DefaultStorageService"];
        }
        if (xComputingShare["Preemption"]) {
          ComputingShare->Preemption = ((std::string)xComputingShare["Preemption"] == "true") ? true : false;
        }
        if (xComputingShare["EstimatedAverageWaitingTime"]) {
          ComputingShare->EstimatedAverageWaitingTime = (std::string)xComputingShare["EstimatedAverageWaitingTime"];
        }
        if (xComputingShare["EstimatedWorstWaitingTime"]) {
          ComputingShare->EstimatedWorstWaitingTime = stringtoi((std::string)xComputingShare["EstimatedWorstWaitingTime"]);
        }
        if (xComputingShare["ReservationPolicy"]) {
          ComputingShare->ReservationPolicy = stringtoi((std::string)xComputingShare["ReservationPolicy"]);
        }

        cs.ComputingShare.insert(std::pair<int, ComputingShareType>(shareID++, ComputingShare));
      }

      /*
       * A ComputingShare is linked to multiple ExecutionEnvironments.
       * Due to bug 2101 multiple ExecutionEnvironments per ComputingShare
       * will be ignored. The ExecutionEnvironment information will only be
       * stored if there is one ExecutionEnvironment associated with a
       * ComputingShare.
       */
      /*
       * TODO: Store ExecutionEnvironment information in the list of
       * ExecutionEnvironmentType objects and issue a warning when the
       * resources published in multiple ExecutionEnvironment are
       * requested in a job description document.
       */

      int managerID = 0;
      for (XMLNode xComputingManager = GLUEService["ComputingManager"]; (bool)xComputingManager; ++xComputingManager) {
        ComputingManagerType ComputingManager;
        if (xComputingManager["ProductName"]) {
          ComputingManager->ProductName = (std::string)xComputingManager["ProductName"];
        }
        // The GlUE2 specification does not have attribute ComputingManager.Type
        //if (xComputingManager["Type"]) {
        //  ComputingManager->Type = (std::string)xComputingManager["Type"];
        //}
        if (xComputingManager["ProductVersion"]) {
          ComputingManager->ProductVersion = (std::string)xComputingManager["ProductVersion"];
        }
        if (xComputingManager["Reservation"]) {
          ComputingManager->Reservation = ((std::string)xComputingManager["Reservation"] == "true");
        }
        if (xComputingManager["BulkSubmission"]) {
          ComputingManager->BulkSubmission = ((std::string)xComputingManager["BulkSubmission"] == "true");
        }
        if (xComputingManager["TotalPhysicalCPUs"]) {
          ComputingManager->TotalPhysicalCPUs = stringtoi((std::string)xComputingManager["TotalPhysicalCPUs"]);
        }
        if (xComputingManager["TotalLogicalCPUs"]) {
          ComputingManager->TotalLogicalCPUs = stringtoi((std::string)xComputingManager["TotalLogicalCPUs"]);
        }
        if (xComputingManager["TotalSlots"]) {
          ComputingManager->TotalSlots = stringtoi((std::string)xComputingManager["TotalSlots"]);
        }
        if (xComputingManager["Homogeneous"]) {
          ComputingManager->Homogeneous = ((std::string)xComputingManager["Homogeneous"] == "true");
        }
        if (xComputingManager["NetworkInfo"]) {
          for (XMLNode n = xComputingManager["NetworkInfo"]; n; ++n) {
            ComputingManager->NetworkInfo.push_back((std::string)n);
          }
        }
        if (xComputingManager["WorkingAreaShared"]) {
          ComputingManager->WorkingAreaShared = ((std::string)xComputingManager["WorkingAreaShared"] == "true");
        }
        if (xComputingManager["WorkingAreaFree"]) {
          ComputingManager->WorkingAreaFree = stringtoi((std::string)xComputingManager["WorkingAreaFree"]);
        }
        if (xComputingManager["WorkingAreaTotal"]) {
          ComputingManager->WorkingAreaTotal = stringtoi((std::string)xComputingManager["WorkingAreaTotal"]);
        }
        if (xComputingManager["WorkingAreaLifeTime"]) {
          ComputingManager->WorkingAreaLifeTime = (std::string)xComputingManager["WorkingAreaLifeTime"];
        }
        if (xComputingManager["CacheFree"]) {
          ComputingManager->CacheFree = stringtoi((std::string)xComputingManager["CacheFree"]);
        }
        if (xComputingManager["CacheTotal"]) {
          ComputingManager->CacheTotal = stringtoi((std::string)xComputingManager["CacheTotal"]);
        }
        for (XMLNode n = xComputingManager["Benchmark"]; n; ++n) {
          double value;
          if (n["Type"] && n["Value"] &&
              stringto((std::string)n["Value"], value)) {
            (*ComputingManager.Benchmarks)[(std::string)n["Type"]] = value;
          } else {
            logger.msg(VERBOSE, "Couldn't parse benchmark XML:\n%s", (std::string)n);
            continue;
          }
        }
        for (XMLNode n = xComputingManager["ApplicationEnvironments"]["ApplicationEnvironment"]; n; ++n) {
          ApplicationEnvironment ae((std::string)n["AppName"], (std::string)n["AppVersion"]);
          ae.State = (std::string)n["State"];
          if (n["FreeSlots"]) {
            ae.FreeSlots = stringtoi((std::string)n["FreeSlots"]);
          }
          //else {
          //  ae.FreeSlots = ComputingShare->FreeSlots; // Non compatible??, i.e. a ComputingShare is unrelated to the ApplicationEnvironment.
          //}
          if (n["FreeJobs"]) {
            ae.FreeJobs = stringtoi((std::string)n["FreeJobs"]);
          } else {
            ae.FreeJobs = -1;
          }
          if (n["FreeUserSeats"]) {
            ae.FreeUserSeats = stringtoi((std::string)n["FreeUserSeats"]);
          } else {
            ae.FreeUserSeats = -1;
          }
          ComputingManager.ApplicationEnvironments->push_back(ae);
        }

        int eeID = 0;
        for (XMLNode xExecutionEnvironment = xComputingManager["ExecutionEnvironments"]["ExecutionEnvironment"]; (bool)xExecutionEnvironment; ++xExecutionEnvironment) {
          ExecutionEnvironmentType ExecutionEnvironment;
          if (xExecutionEnvironment["Platform"]) {
            ExecutionEnvironment->Platform = (std::string)xExecutionEnvironment["Platform"];
          }

          if (xExecutionEnvironment["MainMemorySize"]) {
            ExecutionEnvironment->MainMemorySize = stringtoi((std::string)xExecutionEnvironment["MainMemorySize"]);
          }

          if (xExecutionEnvironment["OSName"]) {
            if (xExecutionEnvironment["OSVersion"]) {
              if (xExecutionEnvironment["OSFamily"]) {
                ExecutionEnvironment->OperatingSystem = Software((std::string)xExecutionEnvironment["OSFamily"],
                                                                 (std::string)xExecutionEnvironment["OSName"],
                                                                 (std::string)xExecutionEnvironment["OSVersion"]);
              }
              else {
                ExecutionEnvironment->OperatingSystem = Software((std::string)xExecutionEnvironment["OSName"],
                                                                 (std::string)xExecutionEnvironment["OSVersion"]);
              }
            }
            else {
              ExecutionEnvironment->OperatingSystem = Software((std::string)xExecutionEnvironment["OSName"]);
            }
          }

          if (xExecutionEnvironment["ConnectivityIn"]) {
            ExecutionEnvironment->ConnectivityIn = (lower((std::string)xExecutionEnvironment["ConnectivityIn"]) == "true");
          }

          if (xExecutionEnvironment["ConnectivityOut"]) {
            ExecutionEnvironment->ConnectivityOut = (lower((std::string)xExecutionEnvironment["ConnectivityOut"]) == "true");
          }
          ComputingManager.ExecutionEnvironment.insert(std::pair<int, ExecutionEnvironmentType>(eeID++, ExecutionEnvironment));
        }

        cs.ComputingManager.insert(std::pair<int, ComputingManagerType>(managerID++, ComputingManager));
      }

      targets.push_back(cs);
    }
  }