29#ifdef HAS_RNTUPLE_SUPPORT
30 , fEnableRNTuples(kFALSE)
36#ifdef QW_ENABLE_MAPFILE
40 TString mapfilename =
"/dev/shm/";
42 mapfilename +=
"/QwMemMapFile.map";
47 QwError <<
"Memory-mapped file " << mapfilename
52 QwMessage <<
"================== RealTime Producer Memory Map File =================" <<
QwLog::endl;
54 QwMessage <<
"======================================================================" <<
QwLog::endl;
60 TString hostname = gSystem -> HostName();
68 rootfilename += Form(
"/%s%s.%s.%d.root",
70 hostname.Data(), pid);
79 if (gSystem->AccessPathName(rootfilename.Data()) == 0) {
80 QwVerbose <<
"Removing existing temporary file before RECREATE: " << rootfilename <<
QwLog::endl;
81 gSystem->Unlink(rootfilename.Data());
87 if (gSystem->AccessPathName(rootfilename.Data()) == 0) {
89 int unlink_result = gSystem->Unlink(rootfilename.Data());
90 if (unlink_result == 0) {
101 fRootFile =
new TFile(rootfilename.Data(),
"RECREATE",
"myfile1");
103 QwError <<
"ROOT file " << rootfilename
111 TString run_condition_name = Form(
"condition_%s", run_label.Data());
112 TList *run_cond_list = (TList*)
fRootFile -> FindObjectAny(run_condition_name);
113 if (not run_cond_list) {
151 TString rootfilename =
fRootFile->GetName();
169 err = remove( rootfilename.Data() );
183 std::map< const std::string, std::vector<QwRootTree*> >::iterator map_iter;
184 std::vector<QwRootTree*>::iterator vec_iter;
186 for (vec_iter = map_iter->second.begin(); vec_iter != map_iter->second.end(); vec_iter++) {
201 "directory of the output ROOT files");
206 "stem of the output ROOT filename");
210 (
"enable-mapfile", po::value<bool>()->default_bool_value(
false),
211 "enable output to memory-mapped file\n(likely requires circular-buffer too)");
213 (
"write-temporary-rootfiles", po::value<bool>()->default_bool_value(
true),
214 "When writing ROOT files, use the PID to create a temporary filename");
218 (
"disable-tree", po::value<std::vector<std::string>>()->composing(),
219 "disable output to tree regex");
221 (
"disable-trees", po::value<bool>()->default_bool_value(
false),
222 "disable output to all trees");
224 (
"disable-histos", po::value<bool>()->default_bool_value(
false),
225 "disable output to all histograms");
229 (
"disable-mps-tree", po::value<bool>()->default_bool_value(
false),
230 "disable helicity window output");
232 (
"disable-pair-tree", po::value<bool>()->default_bool_value(
false),
233 "disable helicity pairs output");
235 (
"disable-hel-tree", po::value<bool>()->default_bool_value(
false),
236 "disable helicity pattern output");
238 (
"disable-burst-tree", po::value<bool>()->default_bool_value(
false),
239 "disable burst tree");
241 (
"disable-slow-tree", po::value<bool>()->default_bool_value(
false),
242 "disable slow control tree");
244#ifdef HAS_RNTUPLE_SUPPORT
247 (
"enable-rntuples", po::value<bool>()->default_bool_value(
false),
248 "enable RNTuple output");
253 (
"num-mps-accepted-events", po::value<int>()->default_value(0),
254 "number of accepted consecutive MPS events");
256 (
"num-mps-discarded-events", po::value<int>()->default_value(0),
257 "number of discarded consecutive MPS events");
259 (
"num-hel-accepted-events", po::value<int>()->default_value(0),
260 "number of accepted consecutive pattern events");
262 (
"num-hel-discarded-events", po::value<int>()->default_value(0),
263 "number of discarded consecutive pattern events");
265 (
"mapfile-update-interval", po::value<int>()->default_value(-1),
266 "Events between a map file update");
269 options.
AddOptions(
"ROOT performance options")
270 (
"autoflush", po::value<int>()->default_value(0),
272 options.
AddOptions(
"ROOT performance options")
273 (
"autosave", po::value<int>()->default_value(300000000),
275 options.
AddOptions(
"ROOT performance options")
276 (
"basket-size", po::value<int>()->default_value(16000),
277 "TTree basket size");
278 options.
AddOptions(
"ROOT performance options")
279 (
"circular-buffer", po::value<int>()->default_value(0),
280 "TTree circular buffer");
281 options.
AddOptions(
"ROOT performance options")
282 (
"compression-algorithm", po::value<int>()->default_value(1),
283 "TFile compression algorithm (1=ZLIB, 2=LZMA, 4=LZ4, 5=ZSTD, default=1 ZLIB)");
284 options.
AddOptions(
"ROOT performance options")
285 (
"compression-level", po::value<int>()->default_value(1),
286 "TFile compression level (default = 1, no compression = 0)");
304#ifndef QW_ENABLE_MAPFILE
307 QwWarning <<
"QwRootFile::ProcessOptions: "
308 <<
"The 'enable-mapfile' flag is not supported by the ROOT "
309 "version with which this app is built. Disabling it."
316#ifdef HAS_RNTUPLE_SUPPORT
318 fEnableRNTuples = options.
GetValue<
bool>(
"enable-rntuples");
324 std::for_each(v.begin(), v.end(), [&](
const std::string& s){ this->DisableTree(s); });
352 if ((ROOT_VERSION_CODE < ROOT_VERSION(5,26,00)) &&
fAutoFlush != -30000000){
354 QwWarning <<
"QwRootFile::ProcessOptions: "
355 <<
"The 'autoflush' flag is not supported by ROOT version "
378 for (
auto& tree : pair.second) {
379 if (tree && tree->GetTree()) {
380 Long64_t entries = tree->GetTree()->GetEntries();
389#ifdef HAS_RNTUPLE_SUPPORT
391 for (
auto& pair : fNTupleByName) {
392 for (
auto& ntuple : pair.second) {
393 if (ntuple && ntuple->fCurrentEvent > 0) {
401 TList* l = d->GetListOfKeys();
404 for(
int i=0; i < l->GetEntries(); ++i) {
405 const char* name = l->At(i)->GetName();
406 TObject* obj = d->FindObjectAny(name);
417 if ( TString(name).Contains(
"parameter_file") ) {
421 if ( TString(name).Contains(
"mapfile") ) {
424 if ( TString(name).Contains(
"_condition") ) {
428 if ( TString(name).Contains(
"slow") ) {
433 if (obj->IsA()->InheritsFrom(
"TDirectory" )) {
434 if (this->
HasAnyFilled( (TDirectory*)obj ))
return true;
437 if (obj->IsA()->InheritsFrom(
"TTree" )) {
438 Long64_t entries = ((TTree*) obj)->GetEntries();
439 if ( entries )
return true;
442 if (obj->IsA()->InheritsFrom(
"TH1" )) {
443 Double_t entries = ((TH1*) obj)->GetEntries();
444 if ( entries )
return true;
#define QwVerbose
Predefined log drain for verbose messages.
#define QwError
Predefined log drain for errors.
#define QwWarning
Predefined log drain for warnings.
#define QwMessage
Predefined log drain for regular messages.
ROOT file and tree management wrapper classes.
Run condition management and metadata.
static std::ostream & endl(std::ostream &)
End of the line.
Command-line and configuration file options processor.
std::vector< T > GetValueVector(const std::string &key)
Get a list of templated values.
T GetValue(const std::string &key)
Get a templated value.
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
static const TString kUnitsName
static Double_t kUnitsValue[]
TString fRootFileStem
ROOT file stem.
TFile * fRootFile
ROOT file.
virtual ~QwRootFile()
Destructor.
TString fRootFileDir
ROOT files dir.
void DisableTree(const TString ®exp)
Add regexp to list of disabled trees names.
Int_t fCompressionAlgorithm
Bool_t HasAnyFilled(void)
Search for non-empty trees or histograms in the file.
static std::string fDefaultRootFileDir
Default ROOT files dir.
static const Int_t kMaxMapFileSize
Int_t WriteObject(const T *obj, const char *name, Option_t *option="", Int_t bufsize=0)
Write any object to the ROOT file (only valid for TFile)
void ProcessOptions(QwOptions &options)
Process the configuration options.
UInt_t fNumHelEventsToSkip
std::map< const std::string, std::vector< QwRootTree * > > fTreeByName
Tree names, addresses, and types.
void DisableHisto(const TString ®exp)
Add regexp to list of disabled histogram directories.
UInt_t fNumMpsEventsToSave
static std::string fDefaultRootFileStem
Default ROOT file stem.
static void DefineOptions(QwOptions &options)
Define the configuration options.
UInt_t fNumHelEventsToSave
TMapFile * fMapFile
Map file.
QwRootFile()
Private default constructor.
UInt_t fCircularBufferSize
static const Long64_t kMaxTreeSize
Maximum tree size.
UInt_t fNumMpsEventsToSkip
Prescaling of events written to tree.
Run condition and quality management.