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.
61{
62
63 ROOT::EnableImplicitMT();
64
65
67
68
69
70 gQwOptions.AddOptions()(
"single-output-file", po::value<bool>()->default_bool_value(
false),
"Write a single output file");
71 gQwOptions.AddOptions()(
"print-errorcounters", po::value<bool>()->default_bool_value(
true),
"Print summary of error counters");
72 gQwOptions.AddOptions()(
"write-promptsummary", po::value<bool>()->default_bool_value(
false),
"Write PromptSummary");
73 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)");
74 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)");
75
76
77 if (argc == 1) {
79 exit(0);
80 }
81
82
83
84
85
89
92
94
95
97
99
100
101
104
105
106 #ifdef __USE_DATABASE__
108 #endif
109
110
111
112
113 Int_t run_number = 0;
115
116
117
120
121
123
126
127
129
130
134
135
136
139 detectors.ListPublishedValues();
140
141
142
143
144
145
146
147
148
151
152
154
155
157
158
162
163
165 patternsum_per_burst.DisablePairs();
166
167
170 patternsum.DisablePairs();
172 burstsum.DisablePairs();
173
174
175 #ifdef __USE_DATABASE__
176 database.SetupOneRun(eventbuffer);
177 #endif
178
179
183
184
185 if (
gQwOptions.GetValue<
bool>(
"single-output-file")) {
186
188 burstrootfile = historootfile = treerootfile;
189
191
192 } else {
193
194 treerootfile =
new QwRootFile(run_label +
".trees");
195 burstrootfile =
new QwRootFile(run_label +
".bursts");
196 historootfile =
new QwRootFile(run_label +
".histos");
197
198
199 detectors.PrintParamFileList();
203 }
204 #ifdef __USE_DATABASE__
205 if (database.AllowsWriteAccess()) {
206 database.FillParameterFiles(detectors);
207 }
208 #endif
209
213 detectors.ShareHistograms(ringoutput);
214
215
221 burstrootfile->
ConstructTreeBranches(
"burst",
"Burst level data tree", patternsum_per_burst,
"|stat");
222
223
224#ifdef HAS_RNTUPLE_SUPPORT
225 treerootfile->ConstructNTupleFields("evt", "MPS event data RNTuple", ringoutput);
226 treerootfile->ConstructNTupleFields("mul", "Helicity event data RNTuple", helicitypattern);
227 burstrootfile->ConstructNTupleFields("pr_yield", "Pair yield RNTuple", helicitypattern.GetPairYield(),"yield_");
228 burstrootfile->ConstructNTupleFields("pr_asym", "Pair asymmetry RNTuple", helicitypattern.GetPairAsymmetry(),"asym_");
229 treerootfile->ConstructNTupleFields("slow", "EPICS and slow control RNTuple", epicsevent);
230 burstrootfile->ConstructNTupleFields("burst", "Burst level data RNTuple", patternsum_per_burst, "|stat");
231#endif
232
236
237 datahandlerarray_evt.ConstructTreeBranches(treerootfile, "evt_");
238 datahandlerarray_mul.ConstructTreeBranches(treerootfile);
239 datahandlerarray_burst.ConstructTreeBranches(burstrootfile, "burst_", "|stat");
240
241
242#ifdef HAS_RNTUPLE_SUPPORT
243 datahandlerarray_evt.ConstructNTupleFields(treerootfile, "evt_");
244 datahandlerarray_mul.ConstructNTupleFields(treerootfile);
245 datahandlerarray_burst.ConstructNTupleFields(burstrootfile, "burst_", "|stat");
246#endif
247
251
252
253#ifdef HAS_RNTUPLE_SUPPORT
254 treerootfile->ConstructNTupleFields("evts", "Running sum RNTuple", eventsum, "|stat");
255 treerootfile->ConstructNTupleFields("muls", "Running sum RNTuple", patternsum, "|stat");
256 burstrootfile->ConstructNTupleFields("bursts", "Burst running sum RNTuple", burstsum, "|stat");
257#endif
258
259
260
261
262
263
264
265 eventsum.ClearEventData();
266 patternsum.ClearEventData();
267 burstsum.ClearEventData();
268
269 helicitypattern.ClearEventData();
270 patternsum_per_burst.ClearEventData();
271
272
273
274
276 helicitypattern.UpdateBlinder();
277 }else{
278
279#ifdef __USE_DATABASE__
280 helicitypattern.UpdateBlinder(&database);
281#endif
282 }
283
284
285
286
293 helicitypattern.UpdateBlinder(epicsevent);
294
295 break;
296 }
297 }
298 }
300
303 }
304
305
306#ifdef CALLGRIND_START_INSTRUMENTATION
307 if (
gQwOptions.GetValue<
bool>(
"callgrind-instr-start-event-loop")) {
309 CALLGRIND_START_INSTRUMENTATION;
310 }
311#endif
312
313
315
316
318
320 }
321
322
323
324
329 helicitypattern.UpdateBlinder(epicsevent);
330
333
334
335#ifdef HAS_RNTUPLE_SUPPORT
336 treerootfile->FillNTupleFields(epicsevent);
337 treerootfile->FillNTuple("slow");
338#endif
339 }
340 }
341
342
343
345
346
347
349
350
351 detectors.ProcessEvent();
352
353
354
355 if (detectors.ApplySingleEventCuts()) {
356
357
358 eventring.push(detectors);
359
360
361 if (eventring.IsReady()) {
362 ringoutput = eventring.pop();
363 ringoutput.IncrementErrorCounters();
364
365
366
367 eventsum.AccumulateRunningSum(ringoutput);
368
369
371
372
375
376
377#ifdef HAS_RNTUPLE_SUPPORT
378 treerootfile->FillNTupleFields(ringoutput);
379 treerootfile->FillNTuple("evt");
380#endif
381
382
383 datahandlerarray_evt.ProcessDataHandlerEntry();
384
385
387
388
389 datahandlerarray_evt.FillTreeBranches(treerootfile);
390
391
392#ifdef HAS_RNTUPLE_SUPPORT
393 datahandlerarray_evt.FillNTupleFields(treerootfile);
394#endif
395
396
397 helicitypattern.LoadEventData(ringoutput);
398
399 if (helicitypattern.PairAsymmetryIsGood()) {
400 patternsum.AccumulatePairRunningSum(helicitypattern);
401
402
407
408
409#ifdef HAS_RNTUPLE_SUPPORT
410 burstrootfile->FillNTupleFields("pr_yield", helicitypattern.GetPairYield());
411 burstrootfile->FillNTupleFields("pr_asym", helicitypattern.GetPairAsymmetry());
412 burstrootfile->FillNTuple("pr_yield");
413 burstrootfile->FillNTuple("pr_asym");
414#endif
415
416
417 helicitypattern.ClearPairData();
418 }
419
420
421 if (helicitypattern.IsGoodAsymmetry()) {
422 patternsum.AccumulateRunningSum(helicitypattern);
423
424
426
427
430
431
432#ifdef HAS_RNTUPLE_SUPPORT
433 treerootfile->FillNTupleFields(helicitypattern);
434 treerootfile->FillNTuple("mul");
435#endif
436
437
438 datahandlerarray_mul.ProcessDataHandlerEntry();
439 datahandlerarray_burst.ProcessDataHandlerEntry();
440
441
443
444
445 datahandlerarray_mul.FillTreeBranches(treerootfile);
446
447
448#ifdef HAS_RNTUPLE_SUPPORT
449 datahandlerarray_mul.FillNTupleFields(treerootfile);
450#endif
451
452
453 patternsum_per_burst.AccumulateRunningSum(helicitypattern);
454
455
456
457
458
459 if (patternsum_per_burst.IsEndOfBurst()) {
460
461
462 patternsum_per_burst.CalculateRunningAverage();
463
464
465 burstsum.AccumulateRunningSum(patternsum_per_burst);
466
467 if (
gQwOptions.GetValue<
bool>(
"print-burstsum")) {
470 patternsum_per_burst.PrintValue();
471 }
472
473
475
476
479
480
481#ifdef HAS_RNTUPLE_SUPPORT
482 burstrootfile->FillNTupleFields(patternsum_per_burst);
483 burstrootfile->FillNTuple("burst");
484#endif
485
486
487 datahandlerarray_burst.FinishDataHandler();
488
489
491
492
493 datahandlerarray_burst.FillTreeBranches(burstrootfile);
494
495
496#ifdef HAS_RNTUPLE_SUPPORT
497 datahandlerarray_burst.FillNTupleFields(burstrootfile);
498#endif
499
500 helicitypattern.IncrementBurstCounter();
501 datahandlerarray_mul.UpdateBurstCounter(helicitypattern.GetBurstCounter());
502 datahandlerarray_burst.UpdateBurstCounter(helicitypattern.GetBurstCounter());
503
504 patternsum_per_burst.ClearEventData();
505 datahandlerarray_burst.ClearEventData();
506 }
507
508
509 helicitypattern.ClearEventData();
510
511 }
512
513 }
514
515 }
516
517 }
518
519
521 eventring.Unwind();
522
523
524#ifdef CALLGRIND_START_INSTRUMENTATION
525 if (
gQwOptions.GetValue<
bool>(
"callgrind-instr-stop-event-loop")) {
526 CALLGRIND_STOP_INSTRUMENTATION;
528 }
529#endif
530
531
532
533
534 if (patternsum_per_burst.HasBurstData()){
535
536 patternsum_per_burst.CalculateRunningAverage();
537
538
539 burstsum.AccumulateRunningSum(patternsum_per_burst);
540
541 if (
gQwOptions.GetValue<
bool>(
"print-burstsum")) {
544 patternsum_per_burst.PrintValue();
545 }
546
547
549
550
553
554
555#ifdef HAS_RNTUPLE_SUPPORT
556 burstrootfile->FillNTupleFields(patternsum_per_burst);
557 burstrootfile->FillNTuple("burst");
558#endif
559
560
561 datahandlerarray_burst.FinishDataHandler();
562
563
565
566
567 datahandlerarray_burst.FillTreeBranches(burstrootfile);
568
569
570#ifdef HAS_RNTUPLE_SUPPORT
571 datahandlerarray_burst.FillNTupleFields(burstrootfile);
572#endif
573 patternsum_per_burst.PrintIndexMapFile(run_number);
574 }
575
576
577
578
579 ringoutput.AtEndOfEventLoop();
580
581 QwMessage <<
"Number of events processed at end of run: "
583
584
585 datahandlerarray_evt.FinishDataHandler();
586 datahandlerarray_mul.FinishDataHandler();
587
588
589 eventsum.CalculateRunningAverage();
590 patternsum.CalculateRunningAverage();
591 burstsum.CalculateRunningAverage();
592
593
594 if (
gQwOptions.GetValue<
bool>(
"print-runningsum")) {
597 eventsum.PrintValue();
598 }
601
602
603#ifdef HAS_RNTUPLE_SUPPORT
604 treerootfile->FillNTupleFields(eventsum);
605 treerootfile->FillNTuple("evts");
606#endif
607
608 if (
gQwOptions.GetValue<
bool>(
"print-patternsum")) {
611 patternsum.PrintValue();
612 }
615
616
617#ifdef HAS_RNTUPLE_SUPPORT
618 treerootfile->FillNTupleFields(patternsum);
619 treerootfile->FillNTuple("muls");
620#endif
621
622 if (
gQwOptions.GetValue<
bool>(
"print-burstsum")) {
625 burstsum.PrintValue();
626 }
629
630
631#ifdef HAS_RNTUPLE_SUPPORT
632 burstrootfile->FillNTupleFields(burstsum);
633 burstrootfile->FillNTuple("bursts");
634#endif
635
636
638
639
640
641
642
643
644
645
646
647
648 if (treerootfile == historootfile) {
649
650#ifdef HAS_RNTUPLE_SUPPORT
651 if (
gQwOptions.GetValue<
bool>(
"enable-rntuples") &&
gQwOptions.GetValue<
bool>(
"disable-trees")) {
652
653 treerootfile->
Close();
654 } else {
655#endif
656
657 treerootfile->
Write(0, TObject::kOverwrite);
658 treerootfile->
Close();
659#ifdef HAS_RNTUPLE_SUPPORT
660 }
661#endif
662 delete treerootfile; treerootfile = 0; burstrootfile = 0; historootfile = 0;
663 } else {
664
665#ifdef HAS_RNTUPLE_SUPPORT
666 if (
gQwOptions.GetValue<
bool>(
"enable-rntuples") &&
gQwOptions.GetValue<
bool>(
"disable-trees")) {
667
668 treerootfile->
Close();
669 burstrootfile->
Close();
670 historootfile->
Close();
671 } else {
672#endif
673
674 treerootfile->
Write(0, TObject::kOverwrite);
675 burstrootfile->
Write(0, TObject::kOverwrite);
676 historootfile->
Write(0, TObject::kOverwrite);
677 treerootfile->
Close();
678 burstrootfile->
Close();
679 historootfile->
Close();
680#ifdef HAS_RNTUPLE_SUPPORT
681 }
682#endif
683 delete treerootfile; treerootfile = 0;
684 delete burstrootfile; burstrootfile = 0;
685 delete historootfile; historootfile = 0;
686 }
687
688
689 if (
gQwOptions.GetValue<
bool>(
"print-errorcounters")) {
691 ringoutput.PrintErrorCounters();
692 }
693
694 if (
gQwOptions.GetValue<
bool>(
"write-promptsummary")) {
695
696
697
698 datahandlerarray_mul.WritePromptSummary(&promptsummary, "asymmetry");
699 patternsum.WritePromptSummary(&promptsummary);
701 }
702
703 #ifdef __USE_DATABASE__
704 database.SetupOneRun(eventbuffer);
705
706
707 if (database.AllowsWriteAccess()) {
708 patternsum.FillDB(&database);
709 patternsum.FillErrDB(&database);
710 epicsevent.
FillDB(&database);
711 ringoutput.FillDB_MPS(&database, "optics");
712 }
713 #endif
714
715
716
717
719
720
721
722
725 }
726
728
729 return 0;
730}
#define QwMessage
Predefined log drain for regular messages.
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
const std::string getenv_safe_string(const char *name)
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.