Enable implicit multi-threading in e.g. TTree::Fill
Define additional command line arguments and the configuration filename, and we define the options that can be used in them (using QwOptions).
First, fill the search paths for the parameter files; this sets a static variable within the QwParameterFile class which will be used by all instances. The "scratch" directory should be first.
59{
60
61 ROOT::EnableImplicitMT();
62
63
65
66
67
68 gQwOptions.AddOptions()(
"single-output-file", po::value<bool>()->default_bool_value(
false),
"Write a single output file");
69 gQwOptions.AddOptions()(
"print-errorcounters", po::value<bool>()->default_bool_value(
true),
"Print summary of error counters");
70 gQwOptions.AddOptions()(
"write-promptsummary", po::value<bool>()->default_bool_value(
false),
"Write PromptSummary");
71 gQwOptions.AddOptions()(
"callgrind-instr-start-event-loop", po::value<bool>()->default_bool_value(
false),
"Start callgrind instrumentation with main event loop (with --instr-atstart=no)");
72 gQwOptions.AddOptions()(
"callgrind-instr-stop-event-loop", po::value<bool>()->default_bool_value(
false),
"Stop callgrind instrumentation with main event loop (with --instr-atstart=no)");
73
74
75 if (argc == 1) {
77 exit(0);
78 }
79
80
81
82
83
87
90
92
93
95
97
98
99
102
103
104 #ifdef __USE_DATABASE__
106 #endif
107
108
109
110
111 Int_t run_number = 0;
113
114
115
118
119
121
124
125
127
128
132
133
134
137 detectors.ListPublishedValues();
138
139
140
141
142
143
144
145
146
149
150
152
153
155
156
160
161
163 patternsum_per_burst.DisablePairs();
164
165
168 patternsum.DisablePairs();
170 burstsum.DisablePairs();
171
172
173 #ifdef __USE_DATABASE__
174 database.SetupOneRun(eventbuffer);
175 #endif
176
177
181
182
183 if (
gQwOptions.GetValue<
bool>(
"single-output-file")) {
184
186 burstrootfile = historootfile = treerootfile;
187
189
190 } else {
191
192 treerootfile =
new QwRootFile(run_label +
".trees");
193 burstrootfile =
new QwRootFile(run_label +
".bursts");
194 historootfile =
new QwRootFile(run_label +
".histos");
195
196
197 detectors.PrintParamFileList();
201 }
202 #ifdef __USE_DATABASE__
203 if (database.AllowsWriteAccess()) {
204 database.FillParameterFiles(detectors);
205 }
206 #endif
207
211 detectors.ShareHistograms(ringoutput);
212
213
219 burstrootfile->
ConstructTreeBranches(
"burst",
"Burst level data tree", patternsum_per_burst,
"|stat");
220
221
222#ifdef HAS_RNTUPLE_SUPPORT
223 treerootfile->ConstructNTupleFields("evt", "MPS event data RNTuple", ringoutput);
224 treerootfile->ConstructNTupleFields("mul", "Helicity event data RNTuple", helicitypattern);
225 burstrootfile->ConstructNTupleFields("pr_yield", "Pair yield RNTuple", helicitypattern.GetPairYield(),"yield_");
226 burstrootfile->ConstructNTupleFields("pr_asym", "Pair asymmetry RNTuple", helicitypattern.GetPairAsymmetry(),"asym_");
227 treerootfile->ConstructNTupleFields("slow", "EPICS and slow control RNTuple", epicsevent);
228 burstrootfile->ConstructNTupleFields("burst", "Burst level data RNTuple", patternsum_per_burst, "|stat");
229#endif
230
234
235 datahandlerarray_evt.ConstructTreeBranches(treerootfile, "evt_");
236 datahandlerarray_mul.ConstructTreeBranches(treerootfile);
237 datahandlerarray_burst.ConstructTreeBranches(burstrootfile, "burst_", "|stat");
238
239
240#ifdef HAS_RNTUPLE_SUPPORT
241 datahandlerarray_evt.ConstructNTupleFields(treerootfile, "evt_");
242 datahandlerarray_mul.ConstructNTupleFields(treerootfile);
243 datahandlerarray_burst.ConstructNTupleFields(burstrootfile, "burst_", "|stat");
244#endif
245
249
250
251#ifdef HAS_RNTUPLE_SUPPORT
252 treerootfile->ConstructNTupleFields("evts", "Running sum RNTuple", eventsum, "|stat");
253 treerootfile->ConstructNTupleFields("muls", "Running sum RNTuple", patternsum, "|stat");
254 burstrootfile->ConstructNTupleFields("bursts", "Burst running sum RNTuple", burstsum, "|stat");
255#endif
256
257
258
259
260
261
262
263 eventsum.ClearEventData();
264 patternsum.ClearEventData();
265 burstsum.ClearEventData();
266
267 helicitypattern.ClearEventData();
268 patternsum_per_burst.ClearEventData();
269
270
271
272
274 helicitypattern.UpdateBlinder();
275 }else{
276
277#ifdef __USE_DATABASE__
278 helicitypattern.UpdateBlinder(&database);
279#endif
280 }
281
282
283
284
291 helicitypattern.UpdateBlinder(epicsevent);
292
293 break;
294 }
295 }
296 }
298
301 }
302
303
304#ifdef CALLGRIND_START_INSTRUMENTATION
305 if (
gQwOptions.GetValue<
bool>(
"callgrind-instr-start-event-loop")) {
307 CALLGRIND_START_INSTRUMENTATION;
308 }
309#endif
310
311
313
314
316
318 }
319
320
321
322
327 helicitypattern.UpdateBlinder(epicsevent);
328
331
332
333#ifdef HAS_RNTUPLE_SUPPORT
334 treerootfile->FillNTupleFields(epicsevent);
335 treerootfile->FillNTuple("slow");
336#endif
337 }
338 }
339
340
341
343
344
345
347
348
349 detectors.ProcessEvent();
350
351
352
353 if (detectors.ApplySingleEventCuts()) {
354
355
356 eventring.push(detectors);
357
358
359 if (eventring.IsReady()) {
360 ringoutput = eventring.pop();
361 ringoutput.IncrementErrorCounters();
362
363
364
365 eventsum.AccumulateRunningSum(ringoutput);
366
367
369
370
373
374
375#ifdef HAS_RNTUPLE_SUPPORT
376 treerootfile->FillNTupleFields(ringoutput);
377 treerootfile->FillNTuple("evt");
378#endif
379
380
381 datahandlerarray_evt.ProcessDataHandlerEntry();
382
383
385
386
387 datahandlerarray_evt.FillTreeBranches(treerootfile);
388
389
390#ifdef HAS_RNTUPLE_SUPPORT
391 datahandlerarray_evt.FillNTupleFields(treerootfile);
392#endif
393
394
395 helicitypattern.LoadEventData(ringoutput);
396
397 if (helicitypattern.PairAsymmetryIsGood()) {
398 patternsum.AccumulatePairRunningSum(helicitypattern);
399
400
405
406
407#ifdef HAS_RNTUPLE_SUPPORT
408 burstrootfile->FillNTupleFields("pr_yield", helicitypattern.GetPairYield());
409 burstrootfile->FillNTupleFields("pr_asym", helicitypattern.GetPairAsymmetry());
410 burstrootfile->FillNTuple("pr_yield");
411 burstrootfile->FillNTuple("pr_asym");
412#endif
413
414
415 helicitypattern.ClearPairData();
416 }
417
418
419 if (helicitypattern.IsGoodAsymmetry()) {
420 patternsum.AccumulateRunningSum(helicitypattern);
421
422
424
425
428
429
430#ifdef HAS_RNTUPLE_SUPPORT
431 treerootfile->FillNTupleFields(helicitypattern);
432 treerootfile->FillNTuple("mul");
433#endif
434
435
436 datahandlerarray_mul.ProcessDataHandlerEntry();
437 datahandlerarray_burst.ProcessDataHandlerEntry();
438
439
441
442
443 datahandlerarray_mul.FillTreeBranches(treerootfile);
444
445
446#ifdef HAS_RNTUPLE_SUPPORT
447 datahandlerarray_mul.FillNTupleFields(treerootfile);
448#endif
449
450
451 patternsum_per_burst.AccumulateRunningSum(helicitypattern);
452
453
454
455
456
457 if (patternsum_per_burst.IsEndOfBurst()) {
458
459
460 patternsum_per_burst.CalculateRunningAverage();
461
462
463 burstsum.AccumulateRunningSum(patternsum_per_burst);
464
465 if (
gQwOptions.GetValue<
bool>(
"print-burstsum")) {
468 patternsum_per_burst.PrintValue();
469 }
470
471
473
474
477
478
479#ifdef HAS_RNTUPLE_SUPPORT
480 burstrootfile->FillNTupleFields(patternsum_per_burst);
481 burstrootfile->FillNTuple("burst");
482#endif
483
484
485 datahandlerarray_burst.FinishDataHandler();
486
487
489
490
491 datahandlerarray_burst.FillTreeBranches(burstrootfile);
492
493
494#ifdef HAS_RNTUPLE_SUPPORT
495 datahandlerarray_burst.FillNTupleFields(burstrootfile);
496#endif
497
498 helicitypattern.IncrementBurstCounter();
499 datahandlerarray_mul.UpdateBurstCounter(helicitypattern.GetBurstCounter());
500 datahandlerarray_burst.UpdateBurstCounter(helicitypattern.GetBurstCounter());
501
502 patternsum_per_burst.ClearEventData();
503 datahandlerarray_burst.ClearEventData();
504 }
505
506
507 helicitypattern.ClearEventData();
508
509 }
510
511 }
512
513 }
514
515 }
516
517
519 eventring.Unwind();
520
521
522#ifdef CALLGRIND_START_INSTRUMENTATION
523 if (
gQwOptions.GetValue<
bool>(
"callgrind-instr-stop-event-loop")) {
524 CALLGRIND_STOP_INSTRUMENTATION;
526 }
527#endif
528
529
530
531
532 if (patternsum_per_burst.HasBurstData()){
533
534 patternsum_per_burst.CalculateRunningAverage();
535
536
537 burstsum.AccumulateRunningSum(patternsum_per_burst);
538
539 if (
gQwOptions.GetValue<
bool>(
"print-burstsum")) {
542 patternsum_per_burst.PrintValue();
543 }
544
545
547
548
551
552
553#ifdef HAS_RNTUPLE_SUPPORT
554 burstrootfile->FillNTupleFields(patternsum_per_burst);
555 burstrootfile->FillNTuple("burst");
556#endif
557
558
559 datahandlerarray_burst.FinishDataHandler();
560
561
563
564
565 datahandlerarray_burst.FillTreeBranches(burstrootfile);
566
567
568#ifdef HAS_RNTUPLE_SUPPORT
569 datahandlerarray_burst.FillNTupleFields(burstrootfile);
570#endif
571 patternsum_per_burst.PrintIndexMapFile(run_number);
572 }
573
574
575
576
577 ringoutput.AtEndOfEventLoop();
578
579 QwMessage <<
"Number of events processed at end of run: "
581
582
583 datahandlerarray_evt.FinishDataHandler();
584 datahandlerarray_mul.FinishDataHandler();
585
586
587 eventsum.CalculateRunningAverage();
588 patternsum.CalculateRunningAverage();
589 burstsum.CalculateRunningAverage();
590
591
592 if (
gQwOptions.GetValue<
bool>(
"print-runningsum")) {
595 eventsum.PrintValue();
596 }
599
600
601#ifdef HAS_RNTUPLE_SUPPORT
602 treerootfile->FillNTupleFields(eventsum);
603 treerootfile->FillNTuple("evts");
604#endif
605
606 if (
gQwOptions.GetValue<
bool>(
"print-patternsum")) {
609 patternsum.PrintValue();
610 }
613
614
615#ifdef HAS_RNTUPLE_SUPPORT
616 treerootfile->FillNTupleFields(patternsum);
617 treerootfile->FillNTuple("muls");
618#endif
619
620 if (
gQwOptions.GetValue<
bool>(
"print-burstsum")) {
623 burstsum.PrintValue();
624 }
627
628
629#ifdef HAS_RNTUPLE_SUPPORT
630 burstrootfile->FillNTupleFields(burstsum);
631 burstrootfile->FillNTuple("bursts");
632#endif
633
634
636
637
638
639
640
641
642
643
644
645
646 if (treerootfile == historootfile) {
647
648#ifdef HAS_RNTUPLE_SUPPORT
649 if (
gQwOptions.GetValue<
bool>(
"enable-rntuples") &&
gQwOptions.GetValue<
bool>(
"disable-trees")) {
650
651 treerootfile->
Close();
652 } else {
653#endif
654
655 treerootfile->
Write(0, TObject::kOverwrite);
656 treerootfile->
Close();
657#ifdef HAS_RNTUPLE_SUPPORT
658 }
659#endif
660 delete treerootfile; treerootfile = 0; burstrootfile = 0; historootfile = 0;
661 } else {
662
663#ifdef HAS_RNTUPLE_SUPPORT
664 if (
gQwOptions.GetValue<
bool>(
"enable-rntuples") &&
gQwOptions.GetValue<
bool>(
"disable-trees")) {
665
666 treerootfile->
Close();
667 burstrootfile->
Close();
668 historootfile->
Close();
669 } else {
670#endif
671
672 treerootfile->
Write(0, TObject::kOverwrite);
673 burstrootfile->
Write(0, TObject::kOverwrite);
674 historootfile->
Write(0, TObject::kOverwrite);
675 treerootfile->
Close();
676 burstrootfile->
Close();
677 historootfile->
Close();
678#ifdef HAS_RNTUPLE_SUPPORT
679 }
680#endif
681 delete treerootfile; treerootfile = 0;
682 delete burstrootfile; burstrootfile = 0;
683 delete historootfile; historootfile = 0;
684 }
685
686
687 if (
gQwOptions.GetValue<
bool>(
"print-errorcounters")) {
689 ringoutput.PrintErrorCounters();
690 }
691
692 if (
gQwOptions.GetValue<
bool>(
"write-promptsummary")) {
693
694
695
696 datahandlerarray_mul.WritePromptSummary(&promptsummary, "asymmetry");
697 patternsum.WritePromptSummary(&promptsummary);
699 }
700
701 #ifdef __USE_DATABASE__
702 database.SetupOneRun(eventbuffer);
703
704
705 if (database.AllowsWriteAccess()) {
706 patternsum.FillDB(&database);
707 patternsum.FillErrDB(&database);
708 epicsevent.
FillDB(&database);
709 ringoutput.FillDB_MPS(&database, "optics");
710 }
711 #endif
712
713
714
715
717
718
719
720
723 }
724
726
727 return 0;
728}
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
const std::string getenv_safe_string(const char *name)
#define QwMessage
Predefined log drain for regular messages.
void DefineOptionsParity(QwOptions &options)
EPICS slow controls data management.
Bool_t HasDataLoaded() const
void ProcessOptions(QwOptions &options)
Process the configuration options.
Int_t LoadChannelMap(TString mapfile)
void CalculateRunningValues()
void FillDB(QwParityDB *db)
Event buffer management for reading and processing CODA data.
TString GetRunLabel() const
Returns a string like <run#> or <run#>.<file#>
Int_t CloseStream()
Closes a currently open event stream.
Int_t OpenNextStream()
Opens the event stream (file or ET) based on the internal flags.
void ProcessOptions(QwOptions &options)
Sets internal flags based on the QwOptions.
Bool_t FillSubsystemData(QwSubsystemArray &subsystems)
Int_t GetSegmentNumber() const
Return CODA file segment number.
TString GetStartSQLTime()
Int_t GetRunNumber() const
Return CODA file run number.
Bool_t IsROCConfigurationEvent()
Int_t GetPhysicsEventNumber()
Bool_t FillEPICSData(QwEPICSEvent &epics)
Bool_t FillSubsystemConfigurationData(QwSubsystemArray &subsystems)
static std::ostream & endl(std::ostream &)
End of the line.
static void AppendToSearchPath(const TString &searchdir)
Add a directory to the search path.
static void SetCurrentRunNumber(const UInt_t runnumber)
Set the current run number for looking up the appropriate parameter file.
A wrapper class for a ROOT file or memory mapped file.
Int_t FillTree(const std::string &name)
Fill the tree with name.
Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
void ConstructTreeBranches(const std::string &name, const std::string &desc, T &object, const std::string &prefix="")
Construct the tree branches of a generic object.
void FillHistograms(T &object)
Fill histograms of the subsystem array.
void FillTreeBranches(const std::string &name, const T &object)
Fill the tree branches of a generic object by tree name.
Int_t WriteParamFileList(const TString &name, T &object)
void ConstructHistograms(const std::string &name, T &object)
Construct the histograms of a generic object.
void ConstructObjects(const std::string &name, T &object)
Construct the histograms of a generic object.
Virtual base class for the parity handlers.
Ring buffer of subsystem snapshots for burp/stability handling.
Manages yields/differences/asymmetries for helicity patterns.
Subsystem array container specialized for parity analysis with asymmetry calculations.