21#ifdef __USE_DATABASE__
22#include "QwParitySchema.h"
54 (
"helicity.seed", po::value<int>(),
55 "Number of bits in random seed");
57 (
"helicity.bitpattern", po::value<std::string>(),
58 "Helicity bit pattern: 0x1 (pair), 0x9 (quartet), 0x69 (octet), 0x666999 (hexo-quad), 0x66669999 (octo-quad)");
60 (
"helicity.patternoffset", po::value<int>(),
61 "Set 1 when pattern starts with 1 or 0 when starts with 0");
63 (
"helicity.patternphase", po::value<int>(),
64 "Maximum pattern phase");
66 (
"helicity.delay", po::value<int>(),
67 "Default delay is 2 patterns, set at the helicity map file.");
69 (
"helicity.toggle-mode", po::value<bool>()->default_bool_value(
false),
70 "Activates helicity toggle-mode, overriding the 'delay', 'patternphase', 'bitpattern', and 'seed' options.");
79 if (options.
HasValue(
"helicity.patternoffset")) {
80 if (options.
GetValue<
int>(
"helicity.patternoffset") == 1
81 || options.
GetValue<
int>(
"helicity.patternoffset") == 0) {
87 if (options.
HasValue(
"helicity.patternphase")) {
88 if (options.
GetValue<
int>(
"helicity.patternphase") % 2 == 0) {
94 if (options.
HasValue(
"helicity.seed")) {
95 if (options.
GetValue<
int>(
"helicity.seed") == 24
96 || options.
GetValue<
int>(
"helicity.seed") == 30) {
102 if (options.
HasValue(
"helicity.delay")) {
107 if (options.
HasValue(
"helicity.bitpattern")) {
109 << options.
GetValue<std::string>(
"helicity.bitpattern")
111 std::string hex = options.
GetValue<std::string>(
"helicity.bitpattern");
118 if (options.
GetValue<
bool>(
"helicity.toggle-mode")) {
143 for (
size_t i=0;i<
fWord.size();i++)
190 Bool_t ldebug = kTRUE;
195 static Bool_t firstpattern = kTRUE;
198 firstpattern = kFALSE;
203 QwError <<
"QwHelicityDecoder::ProcessEvent read event# ("
254 QwOut <<
"===========================\n"
255 <<
"This event: Event#, Pattern#, PatternPhase#="
259 QwOut <<
"Previous event: Event#, Pattern#, PatternPhase#="
263 QwOut <<
"delta = \n(fEventNumberOld)-(fMaxPatternPhase)x(fPatternNumberOld)-(fPatternPhaseNumberOld)= "
265 QwOut <<
"Helicity Reported, Delayed, Actual ="
299 if (mapstr.
PopValue(
"patternphase",value)) {
318 Bool_t lkDEBUG = kFALSE;
322 if (index >= 0 && num_words > 0) {
326 uint32_t type_last = 15;
327 uint32_t time_last = 0;
328 uint32_t decoder_index = 0;
329 uint32_t num_decoder_words = 1;
331 uint32_t slot_id_ev_hd = 0;
332 uint32_t slot_id_dnv = 0;
333 uint32_t slot_id_fill = 0;
352 std::cerr <<
"Not enough words in the bank:"<< std::endl;
356 for (
size_t i=0; i<num_words; i++){
363 if(decoder_index < num_decoder_words)
367 printf(
"%8X - decoder data(%d) = %d\n", data, (decoder_index - 1),
376 printf(
"%8X - decoder data(%d) = %d\n", data, (decoder_index - 1),
379 num_decoder_words = 1;
384 if(data & 0x80000000)
387 type = (data & 0x78000000) >> 27;
398 slot_id_hd = (data & 0x7C00000) >> 22;
399 mod_id_hd = (data & 0x3C0000) >> 18;
400 n_evts = (data & 0x000FF);
401 blk_num = (data & 0x3FF00) >> 8;
404 (
"%8X - BLOCK HEADER - slot = %d id = %d n_evts = %d n_blk = %d\n",
405 data, slot_id_hd, mod_id_hd, n_evts,
410 slot_id_tr = (data & 0x7C00000) >> 22;
411 n_words = (data & 0x3FFFFF);
413 printf(
"%8X - BLOCK TRAILER - slot = %d n_words = %d\n",
414 data, slot_id_tr, n_words);
420 slot_id_ev_hd = (data & 0x07C00000) >> 22;
421 evt_num_1 = (data & 0x00000FFF);
422 trig_time = (data & 0x003FF000) >> 12;
425 (
"%8X - EVENT HEADER - slot = %d evt_num = %d trig_time = %d (%X)\n",
426 data, slot_id_ev_hd, evt_num_1, trig_time,
435 time_1 = (data & 0x7FFFFFF);
437 printf(
"%8X - TRIGGER TIME 1 - time = %X\n", data,
446 time_2 = (data & 0xFFFFF);
448 printf(
"%8X - TRIGGER TIME 2 - time = %X\n", data,
453 printf(
"%8X - TRIGGER TIME - (ERROR)\n", data);
455 time_last = time_now;
461 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
466 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
471 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
476 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
480 num_decoder_words = (data & 0x3F);
483 printf(
"%8X - DECODER HEADER = %d (NUM DECODER WORDS = %d)\n",
484 data, type, num_decoder_words);
489 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
494 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
499 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
504 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
509 printf(
"%8X - END OF EVENT = %d\n", data, type);
513 slot_id_dnv = (data & 0x7C00000) >> 22;
515 printf(
"%8X - DATA NOT VALID = %d slot = %d\n", data,
520 slot_id_fill = (data & 0x7C00000) >> 22;
522 printf(
"%8X - FILLER WORD = %d slot = %d\n", data, type,
592 UShort_t firstbits[nbits];
593 for (
unsigned int i = 0; i < nbits; i++) firstbits[i] = (seed >> i) & 0x1;
604 if (TRegexp(
"diff_").Index(prefix,&len) == 0
605 || TRegexp(
"asym[1-9]*_").Index(prefix,&len) == 0)
607 else if (TRegexp(
"yield_").Index(prefix,&len) == 0)
617 if (folder != NULL) folder->cd();
628 basename=
"pattern_polarity";
631 for (
size_t i=0; i<
fWord.size(); i++){
632 basename=
"hel_"+
fWord[i].fWordName;
641 basename=prefix+
"delta_event_number";
644 basename=prefix+
"delta_pattern_number";
647 basename=prefix+
"pattern_phase";
650 basename=prefix+
"helicity";
653 for (
size_t i=0; i<
fWord.size(); i++){
654 basename=prefix+
fWord[i].fWordName;
660 QwError <<
"QwHelicityDecoder::ConstructHistograms this prefix--" << prefix <<
"-- is not unknown:: no histo created" <<
QwLog::endl;
681 for (
size_t i=0; i<
fWord.size(); i++){
703 for (
size_t i=0; i<
fWord.size(); i++){
726 basename =
"hd_actual_helicity";
728 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
730 basename =
"hd_delayed_helicity";
732 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
734 basename =
"hd_reported_helicity";
736 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
738 basename =
"hd_pattern_phase";
740 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
742 basename =
"hd_pattern_number";
744 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
746 basename =
"hd_pattern_seed";
748 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
750 basename =
"hd_event_number";
752 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
754 basename =
"hd_event_Polarity";
756 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
758 basename =
"hd_Reported_Pattern_Hel";
760 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
762 for (
size_t i=0; i<
fWord.size(); i++)
764 basename =
fWord[i].fWordName;
766 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
771 basename =
"hd_actual_helicity";
773 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
775 basename =
"hd_actual_pattern_polarity";
777 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
779 basename =
"hd_actual_previous_pattern_polarity";
781 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
783 basename =
"hd_delayed_pattern_polarity";
785 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
787 basename =
"hd_pattern_number";
789 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
791 basename =
"hd_pattern_seed";
793 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
795 for (
size_t i=0; i<
fWord.size(); i++)
797 basename =
fWord[i].fWordName;
799 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
802 std::cout <<
"after construction size " << values.
size() << std::endl;
824 basename =
"hd_delayed_helicity";
827 basename =
"hd_reported_helicity";
830 basename =
"hd_pattern_phase";
833 basename =
"hd_pattern_number";
836 basename =
"hd_pattern_seed";
839 basename =
"hd_event_number";
842 basename =
"hd_event_Polarity";
845 basename =
"hd_Reported_Pattern_Hel";
850 basename =
"hd_actual_helicity";
853 basename =
"hd_actual_pattern_polarity";
856 basename =
"hd_actual_previous_pattern_polarity";
859 basename =
"hd_delayed_pattern_polarity";
862 basename =
"hd_pattern_number";
865 basename =
"hd_pattern_seed";
868 for (
size_t i=0; i<
fWord.size(); i++)
870 basename =
fWord[i].fWordName;
871 tree->Branch(basename, &
fWord[i].fValue, basename+
"/I");
893 basename =
"hd_delayed_helicity";
896 basename =
"hd_reported_helicity";
899 basename =
"hd_pattern_phase";
902 basename =
"hd_pattern_number";
905 basename =
"hd_pattern_seed";
908 basename =
"hd_event_number";
911 basename =
"hd_event_Polarity";
914 basename =
"hd_Reported_Pattern_Hel";
919 basename =
"hd_actual_helicity";
922 basename =
"hd_actual_pattern_polarity";
925 basename =
"hd_actual_previous_pattern_polarity";
928 basename =
"hd_delayed_pattern_polarity";
931 basename =
"hd_pattern_number";
934 basename =
"hd_pattern_seed";
937 for (
size_t i=0; i<
fWord.size(); i++)
939 basename =
fWord[i].fWordName;
940 tree->Branch(basename,&
fWord[i].fValue, basename+
"/I");
963 for (
size_t i=0; i<
fWord.size(); i++)
974 for (
size_t i=0; i<
fWord.size(); i++){
984 Int_t ldebug = kFALSE;
986 if(ldebug) std::cout <<
"Entering QwHelicityDecoder::RunPredictor for fEventNumber, " <<
fEventNumber
1021 std::cout <<
"Predicted Polarity ::: Delayed ="
1024 std::cout <<
"Predicted Helicity ::: Delayed Helicity=" <<
fHelicityDelayed
1035 Bool_t ldebug=kFALSE;
1037 if(ldebug) std::cout <<
"Entering QwHelicityDecoder::PredictHelicity \n";
1038 if(ldebug) std::cout <<
"QwHelicityDecoder::PredictHelicity=>Predicting the helicity \n";
1041 if(ldebug) std::cout <<
"n_ranbit exiting the function = " <<
n_ranbits <<
"\n";
1056 QwWarning <<
"QwHelicityDecoder : SetHelicityDelay :: helicity delay is set to 0."
1057 <<
" Disabling helicity predictor and using reported helicity information."
1065 QwError <<
"QwHelicityDecoder::SetHelicityDelay We cannot handle negative delay in the prediction of delayed helicity. Exiting.." <<
QwLog::endl;
1090 Bool_t ldebug = kFALSE;
1098 for(
size_t i=0;i<input->
fWord.size();i++)
1099 this->
fWord[i].fValue=input->
fWord[i].fValue;
1128 std::cout <<
"QwHelicityDecoder::operator = this->fPatternNumber=" << this->
fPatternNumber << std::endl;
1129 std::cout <<
"input->fPatternNumber=" << input->
fPatternNumber <<
"\n";
1179 for (
size_t i=0; i<
fWord.size(); i++) {
1181 std::min(
fWord[i].fValue, input->
fWord[i].fValue);
1212 if(
typeid(*value)!=
typeid(*
this)) {
Helper functions and utilities for ROOT histogram management.
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
A logfile class, based on an identical class in the Hermes analyzer.
#define QwOut
Predefined log drain for explicit output.
#define QwError
Predefined log drain for errors.
#define QwWarning
Predefined log drain for warnings.
#define QwMessage
Predefined log drain for regular messages.
#define QwDebug
Predefined log drain for debugging output.
ROOT file and tree management wrapper classes.
static const UInt_t kErrorFlag_Helicity
static const UInt_t kGlobalCut
static const UInt_t kEventCutMode3
Helicity data decoder from the data file.
std::vector< TH1_ptr > fHistograms
Histograms associated with this data element.
Utility class for histogram creation and management.
static std::ostream & endl(std::ostream &)
End of the line.
Command-line and configuration file options processor.
T GetValue(const std::string &key)
Get a templated value.
bool HasValue(const std::string &key)
Has this key been defined.
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Configuration file parser with flexible tokenization and search capabilities.
Bool_t PopValue(const std::string keyname, T &retvalue)
void SetCommentChars(const std::string value)
Set various sets of special characters.
const std::pair< TString, TString > GetParamFileNameContents()
A helper class to manage a vector of branch entries for ROOT trees.
size_type size() const noexcept
void push_back(const std::string &name, const char type='D')
void SetValue(size_type index, Double_t val)
Int_t GetSubbankIndex() const
virtual VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
void RegisterRocBankMarker(QwParameterFile &mapstr)
static void DefineOptions()
Define options function (note: no virtual static functions in C++)
std::map< TString, TString > fDetectorMaps
Map of file name to full path or content.
VQwSubsystem(const TString &name)
Constructor with name.
void SetDataLoaded(Bool_t flag)
Bool_t HasDataLoaded() const
std::vector< QwWord > fWord
UInt_t BuildHelicityBitPattern(Int_t patternsize)
Int_t fActualPatternPolarity
True polarity of the current pattern.
UInt_t GetRandomSeed(UShort_t *first24randbits)
QwHelicityBase()
Private default constructor (not implemented, will throw linker error on use)
Bool_t fSuppressMPSErrorMsgs
Int_t fPatternPhaseOffset
virtual UInt_t GetRandbit(UInt_t &ranseed)
Int_t fNumMissedEventBlocks
Int_t fPreviousPatternPolarity
True polarity of the previous pattern.
std::vector< UInt_t > fHelicityBitPattern
UInt_t GetRandbit30(UInt_t &ranseed)
Int_t fDelayedPatternPolarity
Reported polarity of the current pattern.
Int_t fPatternPhaseNumberOld
Int_t fPatternPhaseNumber
Int_t fPatternNumberFirst
static const Int_t kUndefinedHelicity
virtual void ProcessEvent() override
void MergeCounters(VQwSubsystem *value)
Int_t fLast_Duration_TStable
Int_t fTime_since_TStable
VQwSubsystem & operator=(VQwSubsystem *value) override
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
Int_t fReportedPatternHel
Int_t LoadChannelMap(TString mapfile) override
Mandatory map file definition.
void FillTreeVector(QwRootTreeBranchVector &values) const override
Fill the tree vector.
Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
TODO: The non-event-type-aware ProcessEvBuffer routine should be replaced with the event-type-aware v...
virtual void ClearEventData() override
void AccumulateRunningSum(VQwSubsystem *value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
Update the running sums for devices.
Bool_t Compare(VQwSubsystem *source)
void SetFirstBits(UInt_t nbits, UInt_t firstbits)
QwHelicityDecoder()
Private default constructor (not implemented, will throw linker error on use)
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override
Bool_t ApplySingleEventCuts() override
Apply the single event cuts.
void ConstructBranch(TTree *tree, TString &prefix) override
Construct the branch and tree vector.
VQwSubsystem & operator+=(VQwSubsystem *value) override
void ProcessOptions(QwOptions &options) override
Process the command line options.
void EncodeEventData(std::vector< UInt_t > &buffer) override
static const Int_t fNumDecoderWords
Int_t fTime_since_TSettle
static const std::vector< UInt_t > kDefaultHelicityBitPattern
void SetHelicityBitPattern(TString hex)
Int_t LoadInputParameters(TString pedestalfile) override
Mandatory parameter file definition.
Int_t LoadEventCuts(TString filename) override
Optional event cut file.
void CheckPatternNum(VQwSubsystem *value)
UInt_t fEvtHistory_PatSync
UInt_t fEvtHistory_ReportedHelicity
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
UInt_t fPatHistory_ReportedHelicity
Int_t fLast_Duration_TSettle
void SetHelicityDelay(Int_t delay)
UInt_t fEvtHistory_PairSync
void FillHDVariables(uint32_t data, uint32_t index)
void FillHistograms() override
Fill the histograms for this subsystem.
void SetHistoTreeSave(const TString &prefix)
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Construct the branch and tree vector.