Import Geant4 11.2.0 source tree
This commit is contained in:
@@ -92,7 +92,7 @@ template <typename T>
|
||||
G4bool G4TNtupleManager<NT, FT>::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const T& value)
|
||||
{
|
||||
if (fNewCycle && fNtupleVector.empty()) {
|
||||
if (fNewCycle) {
|
||||
CreateNtuplesFromBooking(*fNtupleBookingVector);
|
||||
fNewCycle = false;
|
||||
}
|
||||
@@ -168,20 +168,28 @@ G4int G4TNtupleManager<NT, FT>::CreateNtuple(G4NtupleBooking* ntupleBooking)
|
||||
}
|
||||
|
||||
// Do not create ntuple if it is inactivated
|
||||
if ( fState.GetIsActivation() &&
|
||||
( ! ntupleDescription->GetActivation() ) ) return G4Analysis::kInvalidId;
|
||||
// or if it was deleted
|
||||
if ( ( ntupleBooking->GetDeleted() ) ||
|
||||
( fState.GetIsActivation() &&
|
||||
( ! ntupleDescription->GetActivation() ) ) ) return G4Analysis::kInvalidId;
|
||||
|
||||
// Do not create ntuple if it already exists
|
||||
if ( ntupleDescription->GetNtuple() != nullptr ) {
|
||||
G4Analysis::Warn(
|
||||
"Ntuple " + to_string(ntupleBooking->fNtupleId) +
|
||||
" already exists.", fkClass, "CreateNtuple");
|
||||
return ntupleBooking->fNtupleId;
|
||||
}
|
||||
|
||||
// create ntuple
|
||||
// Create ntuple
|
||||
CreateTNtupleFromBooking(ntupleDescription);
|
||||
|
||||
// Update ntuple vector if ntuple was created
|
||||
if ( ntupleDescription->GetNtuple() != nullptr ) {
|
||||
// Allocate the ntuple vector element(s) if needed
|
||||
while ( index >= G4int(fNtupleVector.size()) ) {
|
||||
fNtupleVector.push_back(nullptr);
|
||||
}
|
||||
fNtupleVector[index] = ntupleDescription->GetNtuple();
|
||||
}
|
||||
|
||||
// finish created ntuple
|
||||
auto fromBooking = true;
|
||||
FinishTNtuple(ntupleDescription, fromBooking);
|
||||
@@ -243,6 +251,38 @@ G4TNtupleManager<NT, FT>::Clear()
|
||||
Message(G4Analysis::kVL2, "clear", "ntuples");
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename NT, typename FT>
|
||||
G4bool
|
||||
G4TNtupleManager<NT, FT>::Delete(G4int id)
|
||||
{
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
Message(G4Analysis::kVL4, "delete", "ntuple ntupleId " + to_string(id));
|
||||
}
|
||||
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(id, "Delete", true);
|
||||
|
||||
if (ntupleDescription == nullptr) return false;
|
||||
|
||||
// Delete ntuple and update ntuple description
|
||||
delete ntupleDescription->GetNtuple();
|
||||
ntupleDescription->SetNtuple(nullptr);
|
||||
// ntupleDescription->SetDeleted(true, keepSetting);
|
||||
|
||||
// Update ntuple vector
|
||||
if (! fNtupleVector.empty()) {
|
||||
auto index = id - GetFirstId();
|
||||
fNtupleVector[index] = nullptr;
|
||||
}
|
||||
|
||||
// Register freed Id
|
||||
// fFreeIds.insert(id);
|
||||
|
||||
Message(G4Analysis::kVL2, "delete", "ntuple ntupleId " + to_string(id));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename NT, typename FT>
|
||||
G4bool G4TNtupleManager<NT, FT>::FillNtupleIColumn(
|
||||
@@ -408,76 +448,3 @@ G4TNtupleManager<NT, FT>::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleVector.end();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename NT, typename FT>
|
||||
G4int G4TNtupleManager<NT, FT>::GetNofNtuples() const
|
||||
{
|
||||
return G4int(fNtupleVector.size());
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename NT, typename FT>
|
||||
G4bool G4TNtupleManager<NT, FT>::List(std::ostream& output, G4bool onlyIfActive)
|
||||
{
|
||||
// Save current output stream formatting
|
||||
std::ios_base::fmtflags outputFlags(output.flags() );
|
||||
|
||||
// Define optimal field widths
|
||||
size_t maxNameLength = 0;
|
||||
size_t maxTitleLength = 0;
|
||||
// size_t maxEntries = 0;
|
||||
size_t nofActive = 0;
|
||||
for (size_t i = 0; i < fNtupleDescriptionVector.size(); ++i) {
|
||||
// auto ntuple = fNtupleVector[i];
|
||||
const auto& ntupleBooking = fNtupleDescriptionVector[i]->GetNtupleBooking();
|
||||
if (ntupleBooking.name().length() > maxNameLength) {
|
||||
maxNameLength = ntupleBooking.name().length();
|
||||
}
|
||||
if (ntupleBooking.title().length() > maxTitleLength) {
|
||||
maxTitleLength = ntupleBooking.title().length();
|
||||
}
|
||||
// if (ntuple->entries() > maxEntries) {
|
||||
// maxEntries = ntuple->entries();
|
||||
// }
|
||||
if (fNtupleDescriptionVector[i]->GetActivation()) {
|
||||
++nofActive;
|
||||
}
|
||||
}
|
||||
size_t maxIdWidth = std::to_string(fNtupleVector.size() + GetFirstId()).length();
|
||||
// size_t maxEntriesWidth = std::to_string(maxEntries).length();
|
||||
// update string width for adde double quotas
|
||||
maxNameLength += 2;
|
||||
maxTitleLength += 2;
|
||||
|
||||
// List general info
|
||||
output << "Ntuple: " << nofActive << " active ";
|
||||
if (! onlyIfActive) {
|
||||
output << " of " << GetNofNtuples() << " defined ";
|
||||
}
|
||||
output << G4endl;
|
||||
|
||||
// List objects
|
||||
for (size_t i = 0; i < fNtupleDescriptionVector.size(); ++i) {
|
||||
// auto ntuple = fNtupleVector[i];
|
||||
const auto& ntupleBooking = fNtupleDescriptionVector[i]->GetNtupleBooking();
|
||||
|
||||
// skip inactivated objcets
|
||||
if (fState.GetIsActivation() && onlyIfActive && (! fNtupleDescriptionVector[i]->GetActivation())) continue;
|
||||
|
||||
// print selected info
|
||||
output << " id: " << std::setw((G4int)maxIdWidth) << GetFirstId() + i
|
||||
<< " name: \"" << std::setw((G4int)maxNameLength) << std::left << ntupleBooking.name() + "\""
|
||||
<< " title: \"" << std::setw((G4int)maxTitleLength) << std::left << ntupleBooking.title() + "\"";
|
||||
// << " entries: " << std::setw((G4int)maxEntriesWidth) << ntuple->entries();
|
||||
if (! onlyIfActive) {
|
||||
output << " active: " << std::boolalpha << fNtupleDescriptionVector[i]->GetActivation();
|
||||
}
|
||||
output << G4endl;
|
||||
}
|
||||
|
||||
// Restore the output stream formatting
|
||||
output.flags(outputFlags);
|
||||
|
||||
return output.good();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user