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.
60{
61
62 ROOT::EnableImplicitMT();
63
64
66
67
68
69 gQwOptions.AddOptions()(
"single-output-file", po::value<bool>()->default_bool_value(
false),
"Write a single output file");
70 gQwOptions.AddOptions()(
"print-errorcounters", po::value<bool>()->default_bool_value(
true),
"Print summary of error counters");
71 gQwOptions.AddOptions()(
"write-promptsummary", po::value<bool>()->default_bool_value(
false),
"Write PromptSummary");
72 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)");
73 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)");
74
75
76 if (argc == 1) {
78 exit(0);
79 }
80
81
82
83
84
88
91
93
94
96
98
99
100
103
104
105 #ifdef __USE_DATABASE__
107 #endif
108
109
110
111
112 Int_t run_number = 0;
114
115
116
119
120
122
125
126
128
129
133
134
135
138 detectors.ListPublishedValues();
139
140
141
142
143
144
145
146
147
150
151
153
154
156
157
161
162
164 patternsum_per_burst.DisablePairs();
165
166
169 patternsum.DisablePairs();
171 burstsum.DisablePairs();
172
173
174 #ifdef __USE_DATABASE__
175 database.SetupOneRun(eventbuffer);
176 #endif
177
178
182
183
184 if (
gQwOptions.GetValue<
bool>(
"single-output-file")) {
185
187 burstrootfile = historootfile = treerootfile;
188
190
191 } else {
192
193 treerootfile =
new QwRootFile(run_label +
".trees");
194 burstrootfile =
new QwRootFile(run_label +
".bursts");
195 historootfile =
new QwRootFile(run_label +
".histos");
196
197
198 detectors.PrintParamFileList();
202 }
203 #ifdef __USE_DATABASE__
204 if (database.AllowsWriteAccess()) {
205 database.FillParameterFiles(detectors);
206 }
207 #endif
208
212 detectors.ShareHistograms(ringoutput);
213
214
220 burstrootfile->
ConstructTreeBranches(
"burst",
"Burst level data tree", patternsum_per_burst,
"|stat");
221
222
223#ifdef HAS_RNTUPLE_SUPPORT
224 treerootfile->ConstructNTupleFields("evt", "MPS event data RNTuple", ringoutput);
225 treerootfile->ConstructNTupleFields("mul", "Helicity event data RNTuple", helicitypattern);
226 burstrootfile->ConstructNTupleFields("pr_yield", "Pair yield RNTuple", helicitypattern.GetPairYield(),"yield_");
227 burstrootfile->ConstructNTupleFields("pr_asym", "Pair asymmetry RNTuple", helicitypattern.GetPairAsymmetry(),"asym_");
228 treerootfile->ConstructNTupleFields("slow", "EPICS and slow control RNTuple", epicsevent);
229 burstrootfile->ConstructNTupleFields("burst", "Burst level data RNTuple", patternsum_per_burst, "|stat");
230#endif
231
235
236 datahandlerarray_evt.ConstructTreeBranches(treerootfile, "evt_");
237 datahandlerarray_mul.ConstructTreeBranches(treerootfile);
238 datahandlerarray_burst.ConstructTreeBranches(burstrootfile, "burst_", "|stat");
239
240
241#ifdef HAS_RNTUPLE_SUPPORT
242 datahandlerarray_evt.ConstructNTupleFields(treerootfile, "evt_");
243 datahandlerarray_mul.ConstructNTupleFields(treerootfile);
244 datahandlerarray_burst.ConstructNTupleFields(burstrootfile, "burst_", "|stat");
245#endif
246
250
251
252#ifdef HAS_RNTUPLE_SUPPORT
253 treerootfile->ConstructNTupleFields("evts", "Running sum RNTuple", eventsum, "|stat");
254 treerootfile->ConstructNTupleFields("muls", "Running sum RNTuple", patternsum, "|stat");
255 burstrootfile->ConstructNTupleFields("bursts", "Burst running sum RNTuple", burstsum, "|stat");
256#endif
257
258
259
260
261
262
263
264 eventsum.ClearEventData();
265 patternsum.ClearEventData();
266 burstsum.ClearEventData();
267
268 helicitypattern.ClearEventData();
269 patternsum_per_burst.ClearEventData();
270
271
272
273
275 helicitypattern.UpdateBlinder();
276 }else{
277
278#ifdef __USE_DATABASE__
279 helicitypattern.UpdateBlinder(&database);
280#endif
281 }
282
283
284
285
292 helicitypattern.UpdateBlinder(epicsevent);
293
294 break;
295 }
296 }
297 }
299
302 }
303
304
305#ifdef CALLGRIND_START_INSTRUMENTATION
306 if (
gQwOptions.GetValue<
bool>(
"callgrind-instr-start-event-loop")) {
308 CALLGRIND_START_INSTRUMENTATION;
309 }
310#endif
311
312
314
315
317
319 }
320
321
322
323
328 helicitypattern.UpdateBlinder(epicsevent);
329
332
333
334#ifdef HAS_RNTUPLE_SUPPORT
335 treerootfile->FillNTupleFields(epicsevent);
336 treerootfile->FillNTuple("slow");
337#endif
338 }
339 }
340
341
342
344
345
346
348
349
350 detectors.ProcessEvent();
351
352
353
354 if (detectors.ApplySingleEventCuts()) {
355
356
357 eventring.push(detectors);
358
359
360 if (eventring.IsReady()) {
361 ringoutput = eventring.pop();
362 ringoutput.IncrementErrorCounters();
363
364
365
366 eventsum.AccumulateRunningSum(ringoutput);
367
368
370
371
374
375
376#ifdef HAS_RNTUPLE_SUPPORT
377 treerootfile->FillNTupleFields(ringoutput);
378 treerootfile->FillNTuple("evt");
379#endif
380
381
382 datahandlerarray_evt.ProcessDataHandlerEntry();
383
384
386
387
388 datahandlerarray_evt.FillTreeBranches(treerootfile);
389
390
391#ifdef HAS_RNTUPLE_SUPPORT
392 datahandlerarray_evt.FillNTupleFields(treerootfile);
393#endif
394
395
396 helicitypattern.LoadEventData(ringoutput);
397
398 if (helicitypattern.PairAsymmetryIsGood()) {
399 patternsum.AccumulatePairRunningSum(helicitypattern);
400
401
406
407
408#ifdef HAS_RNTUPLE_SUPPORT
409 burstrootfile->FillNTupleFields("pr_yield", helicitypattern.GetPairYield());
410 burstrootfile->FillNTupleFields("pr_asym", helicitypattern.GetPairAsymmetry());
411 burstrootfile->FillNTuple("pr_yield");
412 burstrootfile->FillNTuple("pr_asym");
413#endif
414
415
416 helicitypattern.ClearPairData();
417 }
418
419
420 if (helicitypattern.IsGoodAsymmetry()) {
421 patternsum.AccumulateRunningSum(helicitypattern);
422
423
425
426
429
430
431#ifdef HAS_RNTUPLE_SUPPORT
432 treerootfile->FillNTupleFields(helicitypattern);
433 treerootfile->FillNTuple("mul");
434#endif
435
436
437 datahandlerarray_mul.ProcessDataHandlerEntry();
438 datahandlerarray_burst.ProcessDataHandlerEntry();
439
440
442
443
444 datahandlerarray_mul.FillTreeBranches(treerootfile);
445
446
447#ifdef HAS_RNTUPLE_SUPPORT
448 datahandlerarray_mul.FillNTupleFields(treerootfile);
449#endif
450
451
452 patternsum_per_burst.AccumulateRunningSum(helicitypattern);
453
454
455
456
457
458 if (patternsum_per_burst.IsEndOfBurst()) {
459
460
461 patternsum_per_burst.CalculateRunningAverage();
462
463
464 burstsum.AccumulateRunningSum(patternsum_per_burst);
465
466 if (
gQwOptions.GetValue<
bool>(
"print-burstsum")) {
469 patternsum_per_burst.PrintValue();
470 }
471
472
474
475
478
479
480#ifdef HAS_RNTUPLE_SUPPORT
481 burstrootfile->FillNTupleFields(patternsum_per_burst);
482 burstrootfile->FillNTuple("burst");
483#endif
484
485
486 datahandlerarray_burst.FinishDataHandler();
487
488
490
491
492 datahandlerarray_burst.FillTreeBranches(burstrootfile);
493
494
495#ifdef HAS_RNTUPLE_SUPPORT
496 datahandlerarray_burst.FillNTupleFields(burstrootfile);
497#endif
498
499 helicitypattern.IncrementBurstCounter();
500 datahandlerarray_mul.UpdateBurstCounter(helicitypattern.GetBurstCounter());
501 datahandlerarray_burst.UpdateBurstCounter(helicitypattern.GetBurstCounter());
502
503 patternsum_per_burst.ClearEventData();
504 datahandlerarray_burst.ClearEventData();
505 }
506
507
508 helicitypattern.ClearEventData();
509
510 }
511
512 }
513
514 }
515
516 }
517
518
520 eventring.Unwind();
521
522
523#ifdef CALLGRIND_START_INSTRUMENTATION
524 if (
gQwOptions.GetValue<
bool>(
"callgrind-instr-stop-event-loop")) {
525 CALLGRIND_STOP_INSTRUMENTATION;
527 }
528#endif
529
530
531
532
533 if (patternsum_per_burst.HasBurstData()){
534
535 patternsum_per_burst.CalculateRunningAverage();
536
537
538 burstsum.AccumulateRunningSum(patternsum_per_burst);
539
540 if (
gQwOptions.GetValue<
bool>(
"print-burstsum")) {
543 patternsum_per_burst.PrintValue();
544 }
545
546
548
549
552
553
554#ifdef HAS_RNTUPLE_SUPPORT
555 burstrootfile->FillNTupleFields(patternsum_per_burst);
556 burstrootfile->FillNTuple("burst");
557#endif
558
559
560 datahandlerarray_burst.FinishDataHandler();
561
562
564
565
566 datahandlerarray_burst.FillTreeBranches(burstrootfile);
567
568
569#ifdef HAS_RNTUPLE_SUPPORT
570 datahandlerarray_burst.FillNTupleFields(burstrootfile);
571#endif
572 patternsum_per_burst.PrintIndexMapFile(run_number);
573 }
574
575
576
577
578 ringoutput.AtEndOfEventLoop();
579
580 QwMessage <<
"Number of events processed at end of run: "
582
583
584 datahandlerarray_evt.FinishDataHandler();
585 datahandlerarray_mul.FinishDataHandler();
586
587
588 eventsum.CalculateRunningAverage();
589 patternsum.CalculateRunningAverage();
590 burstsum.CalculateRunningAverage();
591
592
593 if (
gQwOptions.GetValue<
bool>(
"print-runningsum")) {
596 eventsum.PrintValue();
597 }
600
601
602#ifdef HAS_RNTUPLE_SUPPORT
603 treerootfile->FillNTupleFields(eventsum);
604 treerootfile->FillNTuple("evts");
605#endif
606
607 if (
gQwOptions.GetValue<
bool>(
"print-patternsum")) {
610 patternsum.PrintValue();
611 }
614
615
616#ifdef HAS_RNTUPLE_SUPPORT
617 treerootfile->FillNTupleFields(patternsum);
618 treerootfile->FillNTuple("muls");
619#endif
620
621 if (
gQwOptions.GetValue<
bool>(
"print-burstsum")) {
624 burstsum.PrintValue();
625 }
628
629
630#ifdef HAS_RNTUPLE_SUPPORT
631 burstrootfile->FillNTupleFields(burstsum);
632 burstrootfile->FillNTuple("bursts");
633#endif
634
635
637
638
639
640
641
642
643
644
645
646
647 if (treerootfile == historootfile) {
648
649#ifdef HAS_RNTUPLE_SUPPORT
650 if (
gQwOptions.GetValue<
bool>(
"enable-rntuples") &&
gQwOptions.GetValue<
bool>(
"disable-trees")) {
651
652 treerootfile->
Close();
653 } else {
654#endif
655
656 treerootfile->
Write(0, TObject::kOverwrite);
657 treerootfile->
Close();
658#ifdef HAS_RNTUPLE_SUPPORT
659 }
660#endif
661 delete treerootfile; treerootfile = 0; burstrootfile = 0; historootfile = 0;
662 } else {
663
664#ifdef HAS_RNTUPLE_SUPPORT
665 if (
gQwOptions.GetValue<
bool>(
"enable-rntuples") &&
gQwOptions.GetValue<
bool>(
"disable-trees")) {
666
667 treerootfile->
Close();
668 burstrootfile->
Close();
669 historootfile->
Close();
670 } else {
671#endif
672
673 treerootfile->
Write(0, TObject::kOverwrite);
674 burstrootfile->
Write(0, TObject::kOverwrite);
675 historootfile->
Write(0, TObject::kOverwrite);
676 treerootfile->
Close();
677 burstrootfile->
Close();
678 historootfile->
Close();
679#ifdef HAS_RNTUPLE_SUPPORT
680 }
681#endif
682 delete treerootfile; treerootfile = 0;
683 delete burstrootfile; burstrootfile = 0;
684 delete historootfile; historootfile = 0;
685 }
686
687
688 if (
gQwOptions.GetValue<
bool>(
"print-errorcounters")) {
690 ringoutput.PrintErrorCounters();
691 }
692
693 if (
gQwOptions.GetValue<
bool>(
"write-promptsummary")) {
694
695
696
697 datahandlerarray_mul.WritePromptSummary(&promptsummary, "asymmetry");
698 patternsum.WritePromptSummary(&promptsummary);
700 }
701
702 #ifdef __USE_DATABASE__
703 database.SetupOneRun(eventbuffer);
704
705
706 if (database.AllowsWriteAccess()) {
707 patternsum.FillDB(&database);
708 patternsum.FillErrDB(&database);
709 epicsevent.
FillDB(&database);
710 ringoutput.FillDB_MPS(&database, "optics");
711 }
712 #endif
713
714
715
716
718
719
720
721
724 }
725
727
728 return 0;
729}
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.