Skip to content

Commit

Permalink
KSWriteASCII: Improve code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
2xB committed Dec 10, 2024
1 parent 9eb956c commit 2ccfce5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
10 changes: 9 additions & 1 deletion Kassiopeia/Writers/Include/KSWriteASCII.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class KSWriteASCII : public KSComponentTemplate<KSWriteASCII, KSWriter>
~Data();

void Start(const unsigned int& anIndex);
void Fill();
std::string ValuesAsString();
void MakeTitle(KSComponent* aComponent, int aTrack);


private:
std::string fLabel;
std::string fType;
Expand Down Expand Up @@ -65,6 +66,7 @@ class KSWriteASCII : public KSComponentTemplate<KSWriteASCII, KSWriter>
void SetPrecision(const unsigned int& aValue);

katrin::KTextFile* TextFile();
void Write(std::string str);
int Precision() const;

protected:
Expand Down Expand Up @@ -163,6 +165,12 @@ inline katrin::KTextFile* KSWriteASCII::TextFile()
{
return fTextFile;
}

inline void KSWriteASCII::Write(std::string str)
{
for (char& it : str)
fTextFile->File()->put(it);
}

inline int KSWriteASCII::Precision() const
{
Expand Down
23 changes: 9 additions & 14 deletions Kassiopeia/Writers/Source/KSWriteASCII.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,19 @@ void KSWriteASCII::Data::Start(const unsigned int& anIndex)
return;
}

void KSWriteASCII::Data::Fill()
std::string KSWriteASCII::Data::ValuesAsString()
{
KSComponent* tComponent;
OutputObjectASCII* tOutputObjectASCII;
vector<KSComponent*>::iterator tIt;
string result;

for (tIt = fComponents.begin(); tIt != fComponents.end(); ++tIt) {
tComponent = (*tIt);
tComponent->PullUpdate();
}

string str;
for (auto& outputObjectASCII : fOutputObjectASCIIs) {
tOutputObjectASCII = outputObjectASCII;
str = tOutputObjectASCII->getValue();

for (char& it : str)
fWriter->TextFile()->File()->put(it);
for (OutputObjectASCII*& outputObjectASCII : fOutputObjectASCIIs) {
result += outputObjectASCII->getValue();
}

for (tIt = fComponents.begin(); tIt != fComponents.end(); ++tIt) {
Expand All @@ -132,7 +127,7 @@ void KSWriteASCII::Data::Fill()
}

fLength++;
return;
return result;
}

void KSWriteASCII::Data::MakeTitle(KSComponent* aComponent, int aTrack)
Expand Down Expand Up @@ -520,7 +515,7 @@ void KSWriteASCII::ExecuteRun()
fRunLastStepIndex = fStepIndex - 1;

for (auto& activeRunComponent : fActiveRunComponents)
activeRunComponent.second->Fill();
Write(activeRunComponent.second->ValuesAsString());

fRunIndex++;
fRunFirstEventIndex = fEventIndex;
Expand All @@ -541,7 +536,7 @@ void KSWriteASCII::ExecuteEvent()
fEventLastStepIndex = fStepIndex - 1;

for (auto& activeEventComponent : fActiveEventComponents)
activeEventComponent.second->Fill();
Write(activeEventComponent.second->ValuesAsString());

fEventIndex++;
fEventFirstTrackIndex = fTrackIndex;
Expand All @@ -558,7 +553,7 @@ void KSWriteASCII::ExecuteTrack()

fTextFile->File()->put('\n');
for (auto& activeTrackComponent : fActiveTrackComponents)
activeTrackComponent.second->Fill();
Write(activeTrackComponent.second->ValuesAsString());

wtrmsg(eNormal) << "ASCII output was written to file <" << fTextFile->GetName() << ">" << eom;
fTextFile->Close();
Expand Down Expand Up @@ -603,7 +598,7 @@ void KSWriteASCII::ExecuteStep()
wtrmsg_debug("ASCII writer <" << GetName() << "> is filling a step" << eom);

for (auto& activeStepComponent : fActiveStepComponents)
activeStepComponent.second->Fill();
Write(activeStepComponent.second->ValuesAsString());
}

fStepIndex++;
Expand Down

0 comments on commit 2ccfce5

Please sign in to comment.