47 std::shared_ptr<G4NtupleBookingManager> bookingManager,
48 G4bool rowWise, G4bool rowMode,
49 tools::impi* impi, G4int mpiSize)
55 for ( G4int rank = 0; rank < mpiSize; rank++ ) {
79 auto ntuple = ntupleDescription->GetNtuple();
82 std::vector<tools::wroot::branch*> mainBranches;
83 ntuple->get_branches(mainBranches);
84 std::vector<tools::uint32> basketSizes;
85 tools_vforcit(tools::wroot::branch*, mainBranches, it) {
86 basketSizes.push_back((*it)->basket_size());
89 auto g4RootFile = fFileManager->CreateNtupleFile(ntupleDescription);
90 auto ntupleFile = std::get<0>(*g4RootFile);
92 tools::uint32 basketSize = fFileManager->GetBasketSize();
93 unsigned int basketEntries = fFileManager->GetBasketEntries();
99 if ( !
fImpi->pack(
id)) {
100 G4cerr <<
"pack(id) failed." << G4endl;
104 if ( !
fImpi->bpack(fRowWise) ) {
105 G4cerr <<
"bpack(fRowWise) failed."<< G4endl;
109 if ( !
fImpi->bpack(ntupleFile->byte_swap())) {
110 G4cerr <<
"bpack(byte_swap) failed." << G4endl;
114 if ( !
fImpi->pack(ntupleFile->compression()) ) {
115 G4cerr <<
"pack(compression) failed." << G4endl;
119 if ( !
fImpi->pack(ntupleFile->dir().seek_directory())) {
121 G4cerr <<
"pack(seek) failed." << G4endl;
126 if ( !
fImpi->pack(basketSize) ) {
127 G4cerr <<
"pack(basketSize) failed." << G4endl;
131 if ( !
fImpi->bpack(fRowMode) ) {
132 G4cerr <<
"bpack(fRowMode) failed." << G4endl;
135 if ( !
fImpi->vpack(basketSizes) ) {
136 G4cerr <<
"vpack(basketSizes) failed." << G4endl;
139 if ( !
fImpi->pack(basketEntries) ) {
140 G4cerr <<
"pack(basketEntries) failed." << G4endl;
146 G4cerr <<
"send_buffer() failed." << G4endl;
151 G4cout <<
"Sent ntuple description to slave on rank " << slaveRank << G4endl;
186 unsigned long numberOfEndFill = 0;
188 G4bool verbose = IsVerbose(kVL2);
197 G4cerr <<
"!!! wait_buffer() failed." << std::endl;
201 tools::uint32 protocol;
202 if ( !
fImpi->unpack(protocol)) {
203 G4cerr <<
"unpack(protocol) failed."<< G4endl;
207 if ( protocol == tools::wroot::mpi_protocol_basket() ) {
212 tools::uint32 ntupleId;
213 if ( !
fImpi->unpack(ntupleId) ) {
214 G4cerr <<
"unpack(ntuple_id) failed."<< std::endl;
218 if ( ntupleId >= fNtupleVector.size() ) {
219 std::cerr <<
"!!! unknown ntupleId " << ntupleId << std::endl;
224 auto mainNtuple = fNtupleVector[ntupleId];
227 if ( ! mainNtuple->mpi_add_basket(*
fImpi)) {
228 std::cerr <<
"mainNtuple->mpi_add_basket() failed." << std::endl;
232 else if ( protocol == tools::wroot::mpi_protocol_baskets() ) {
238 tools::uint32 ntupleId;
239 if ( !
fImpi->unpack(ntupleId) ) {
240 G4cerr <<
"unpack(ntuple_id) failed."<< std::endl;
244 if ( ntupleId >= fNtupleVector.size() ) {
245 std::cerr <<
"!!! unknown ntupleId " << ntupleId << std::endl;
250 auto mainNtuple = fNtupleVector[ntupleId];
253 if ( ! mainNtuple->mpi_add_baskets(*
fImpi)) {
254 std::cerr <<
"mainNtuple->mpi_add_baskets() failed." << std::endl;
258 else if ( protocol==tools::wroot::mpi_protocol_end_fill() ) {
263 tools::uint32 ntupleId;
264 if ( !
fImpi->unpack(ntupleId) ) {
265 G4cerr <<
"unpack(ntuple_id) failed."<< std::endl;
269 if ( ntupleId >= fNtupleVector.size() ) {
270 std::cerr <<
"!!! unknown ntupleId " << ntupleId << std::endl;
275 auto mainNtuple = fNtupleVector[ntupleId];
278 if ( ! mainNtuple->mpi_end_fill(*
fImpi) ) {
279 G4cerr <<
"main_ntuple->mpi_end_fill() failed." << std::endl;
285 if ( numberOfEndFill ==
fSlaveRanks.size() )
break;
288 G4cerr <<
"unknown protocol " << protocol << G4endl;