Message: Re: thread merge problem Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: thread merge problem 

Forum: Multithreading
Re: Question thread merge problem (Huan Yao)
Re: None Re: thread merge problem (Ivana Hrivnacova)
Date: 23 Jan, 2017
From: Huan Yao <Huan Yao>

On Mon, 23 Jan 2017 11:14:33 GMT, Ivana Hrivnacova wrote:
> Hello,
>
> Could you, please, give more details how do you define your ntuple? Do
> you have just one ntuple with two vector columns or one ntuple for the
> vector<int> and another one for vector<double> ? And do you save also
> other information in this or these ntuple(s)?
>
> Thank you,
>


Here are some parts of my codes. Hopefully it will clarify your request.

1. --------------In ActionInitialization--------------
void ActionInitialization::BuildForMaster() const {
  SetUserAction(new RunActionMaster);
}


void ActionInitialization::Build() const {
  SetUserAction(new RunAction);
}

2. --------------In RunActionMaster--------------
G4Run* RunActionMaster::GenerateRun() {
  return new Run;
}

void RunActionMaster::BeginOfRunAction(const G4Run* aRun) {
  auto hist = (Histo::GetInstance());
  hist->BeginOfHisto();
  hist->OpenFile();
}

void RunActionMaster::EndOfRunAction(const G4Run* aRun) {

  const G4int rank = G4MPImanager::GetManager()->GetRank();
  auto hist = Histo::GetInstance();
  hist->EndOfHisto(true);
}



3. --------------In RunAction--------------
G4Run* RunAction::GenerateRun() {
  return new Run;
}

void RunAction::BeginOfRunAction(const G4Run* aRun) {
  Histo* hist = Histo::GetInstance();
  hist->BeginOfHisto();
  hist->OpenFile();
}


void RunAction::EndOfRunAction(const G4Run* aRun) {
  Histo* hist = Histo::GetInstance();
  hist->EndOfHisto(G4Threading::IsMasterThread());
}

4. --------------In Histo--------------
#include "g4root.hh"

G4ThreadLocal Histo* Histo::fManager = NULL;

Histo* Histo::GetInstance() {
  if (!fManager) {
    fManager = new Histo();
    G4AutoDelete::Register(fManager);
  }
  return fManager;
}

void Histo::BeginOfHisto() {
  // Recalled from RunAction->BeginOfHiston
  Book();
}

//There is one directory "T"
//in the directory, few trees depending on which detector is used.
//so I just post one simplified version
//one tree includes branches with vector<int>, vector<double>, doube
void Histo::Book() {
  auto analysisManager = G4AnalysisManager::Instance();
  analysisManager->SetNtupleMerging(fIsMergeFile);<----control by message
  analysisManager->SetFirstNtupleId(0);
  analysisManager->SetFirstNtupleColumnId(0);
  analysisManager->SetNtupleDirectoryName("T");
  analysisManager->CreateNtuple("tree1", "tree1");
    analysisManager->CreateNtupleIColumn("vec_int", vector<int> vi);
    analysisManager->CreateNtupleDColumn("vec_double", vector<int> vd);
  analysisManager->CreateNtupleDColumn("double");
  analysisManager->FinishNtuple();
}

void Histo::OpenFile() {
  auto analysisManager = G4AnalysisManager::Instance();
  G4String fname = fFileName;
#if defined(G4_USE_MPI) && defined(__linux__)
  G4int rank = G4MPImanager::GetManager()->GetRank();
  fname += "_rank_" + std::to_string(rank);
#endif
  G4bool fileOpen = analysisManager->OpenFile(fname.data());
  if (!fileOpen) {
    G4cerr << "\n---> HistoManager::Save(): cannot open "
      << analysisManager->GetFileName() << G4endl;
    return;
  }
}

G4bool Histo::Save() {
  auto analysisManager = G4AnalysisManager::Instance();
  G4bool isOk = false;
  isOk = analysisManager->Write();
  if (!isOk) { printf("threadID=%d, Write is not working.\n", G4Threading::G4GetThreadId()); }
  return isOk;
}
G4bool Histo::Close() {
  auto analysisManager = G4AnalysisManager::Instance();
  G4bool isOk = false;

  isOk = analysisManager->CloseFile();
  if (!isOk) { printf("threadID=%d, CloseFile is not working.\n", G4Threading::G4GetThreadId()); }
  return isOk;
}
void Histo::EndOfHisto(const G4bool& isClose) {
  Save();
  if (isClose) { Close(); }
}

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: thread merge problem   (Ivana Hrivnacova - 23 Jan, 2017)
(_ None: Re: thread merge problem   (Huan Yao - 27 Jan, 2017)
(_ None: Re: thread merge problem   (Ivana Hrivnacova - 07 Feb, 2017)
(_ None: Re: thread merge problem   (Huan Yao - 12 Feb, 2017)
(_ None: Re: thread merge problem   (Ivana Hrivnacova - 23 Feb, 2017)
 Add Message Add Message
to: "Re: thread merge problem"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews