Skip to content

Commit

Permalink
jobsplitter:AddAlias() to parser commend /control/alias
Browse files Browse the repository at this point in the history
  • Loading branch information
gsize committed Jun 27, 2017
1 parent 33fb2ae commit d7e1d4b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions cluster_tools/jobsplitter/include/GateMacfileParser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ public:
std::vector<G4String> listOfActorName;
std::vector<G4String> listOfEnabledActorType;
std::vector<G4String> listOfEnabledActorName;
// Add alias
std::vector<G4String> listOfAliases;
std::vector<bool> listOfUsedAliases;
// Member functions
void InsertAliases();
void AddAliases();
void InsertSubMacros(std::ofstream& output,G4int splitNumber,std::ofstream& splitfile);
void DealWithTimeCommands(std::ofstream& output,G4int splitNumber,std::ofstream& splitfile);
void IgnoreRandomEngineCommand();
Expand Down
41 changes: 32 additions & 9 deletions cluster_tools/jobsplitter/src/GateMacfileParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ GateMacfileParser::GateMacfileParser(G4String macfileName,G4int numberOfSplits,G
addSliceBool = false;
readSliceBool = false;
lambda=-1;
usedAliases = new bool[nAliases];
for(int i=0;i<nAliases;i++)usedAliases[i]=false;
// usedAliases = new bool[nAliases];
//for(int i=0;i<nAliases;i++)usedAliases[i]=false;
for(int i=0;i<nAliases;i++)listOfUsedAliases.push_back(false);
for(int i=0;i<nAliases;i++) listOfAliases.push_back(aliasesPtr[i]);
oldSplitNumber=-1;

//root,ascii are enabled by default but we skeep that in cluster mode
Expand Down Expand Up @@ -169,6 +171,7 @@ G4int GateMacfileParser::GenerateResolvedMacro(G4String outputName,G4int splitNu
{
FormatMacline();
InsertAliases();
AddAliases();
LookForEnableOutput();
InsertOutputFileNames(splitNumber,splitfile);
SearchForActors(splitNumber,outputMacfile,splitfile);
Expand Down Expand Up @@ -202,12 +205,13 @@ G4int GateMacfileParser::GenerateResolvedMacro(G4String outputName,G4int splitNu
if (enabledOutput+listOfEnabledActorName.size()==0) G4cerr << "***** Warning: No output module nor actor are enabled !" << endl;
// Check if all aliases from the command line are used
bool flag=true;
for (G4int i=1;i<nAliases;i+=2) flag&=usedAliases[i];
nAliases = (G4int)listOfUsedAliases.size();
for (G4int i=1;i<nAliases;i+=2) flag&=listOfUsedAliases[i];
if(flag==false)
{
G4cerr<<"Could not use the following aliases from the command line:"<<G4endl;
for (G4int i=1;i<nAliases;i+=2)
if(!usedAliases[i]) G4cout<<" "<<aliases[i]<<G4endl;
if(!listOfUsedAliases[i]) G4cout<<" "<<listOfAliases[i]<<G4endl;
return 1;
}
}
Expand All @@ -219,19 +223,36 @@ G4int GateMacfileParser::GenerateResolvedMacro(G4String outputName,G4int splitNu
void GateMacfileParser::InsertAliases()
{
G4String insert;
nAliases = (G4int)(listOfAliases.size());
for (G4int i=1;i<nAliases;i+=2)
{
if (macline.contains("{"+aliases[i]+"}"))
if (macline.contains("{"+listOfAliases[i]+"}"))
{
insert=aliases[i-1];
G4int position=macline.find("{"+aliases[i]+"}",0);
G4int length=2+aliases[i].size();
insert=listOfAliases[i-1];
G4int position=macline.find("{"+listOfAliases[i]+"}",0);
G4int length=2+listOfAliases[i].size();
macline.replace(position,length,insert);
usedAliases[i]=true;
listOfUsedAliases[i]=true;
}
}
}

void GateMacfileParser::AddAliases()
{
if (macline.contains("/control/alias"))
{
G4String tmpStr = macline.substr(15,256);
int position = tmpStr.find(" ");
listOfAliases.push_back( tmpStr.substr(position+1,tmpStr.size()-position));
listOfUsedAliases.push_back(false);
nAliases++;
listOfAliases.push_back( tmpStr.substr(0,position));
listOfUsedAliases.push_back(false);
nAliases++;
// G4cout<<listOfAliases[nAliases-1] <<":"<<listOfAliases[nAliases-2]<<G4endl;
}
}

void GateMacfileParser::InsertSubMacros(ofstream& output,G4int splitNumber,ofstream& splitfile)
{
if (macline.contains("/control/execute"))
Expand Down Expand Up @@ -261,6 +282,7 @@ void GateMacfileParser::InsertSubMacros(ofstream& output,G4int splitNumber,ofstr
{
FormatMacline();
InsertAliases();
AddAliases();
LookForEnableOutput();
InsertOutputFileNames(splitNumber,splitfile);
SearchForActors(splitNumber,output,splitfile);
Expand Down Expand Up @@ -357,6 +379,7 @@ void GateMacfileParser::DealWithTimeCommands(ofstream& output,G4int splitNumber,
G4int position=subMacline.find(" ",0);
G4String timeStart_str=subMacline.substr(0,position);
G4String timeUnit_tmp=subMacline.substr(position+1,subMacline.length());
// G4cout<< macline<<" :star= " << timeStart_str<< " :unit="<< timeUnit_tmp<< ":"<<timeUnit <<G4endl;
if (timeUnit==" -1 ") timeUnit=timeUnit_tmp;
else if (timeUnit!=timeUnit_tmp)
{
Expand Down

0 comments on commit d7e1d4b

Please sign in to comment.