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 = kFALSE;
195 static Bool_t firstpattern = kTRUE;
198 firstpattern = kFALSE;
203 QwError <<
"QwHelicityDecoder::ProcessEvent read event# ("
257 QwOut <<
"===========================\n"
258 <<
"This event: Event#, Pattern#, PatternPhase#="
262 QwOut <<
"Previous event: Event#, Pattern#, PatternPhase#="
266 QwOut <<
"delta = \n(fEventNumberOld)-(fMaxPatternPhase)x(fPatternNumberOld)-(fPatternPhaseNumberOld)= "
268 QwOut <<
"Helicity Reported, Delayed, Actual ="
302 if (mapstr.
PopValue(
"patternphase",value)) {
321 Bool_t lkDEBUG = kFALSE;
325 if (index >= 0 && num_words > 0) {
329 uint32_t type_last = 15;
330 uint32_t time_last = 0;
331 uint32_t decoder_index = 0;
332 uint32_t num_decoder_words = 1;
334 uint32_t slot_id_ev_hd = 0;
335 uint32_t slot_id_dnv = 0;
336 uint32_t slot_id_fill = 0;
355 std::cerr <<
"Not enough words in the bank:"<< std::endl;
359 for (
size_t i=0; i<num_words; i++){
366 if(decoder_index < num_decoder_words)
370 printf(
"%8X - decoder data(%d) = %d\n", data, (decoder_index - 1),
379 printf(
"%8X - decoder data(%d) = %d\n", data, (decoder_index - 1),
382 num_decoder_words = 1;
387 if(data & 0x80000000)
390 type = (data & 0x78000000) >> 27;
401 slot_id_hd = (data & 0x7C00000) >> 22;
402 mod_id_hd = (data & 0x3C0000) >> 18;
403 n_evts = (data & 0x000FF);
404 blk_num = (data & 0x3FF00) >> 8;
407 (
"%8X - BLOCK HEADER - slot = %d id = %d n_evts = %d n_blk = %d\n",
408 data, slot_id_hd, mod_id_hd, n_evts,
413 slot_id_tr = (data & 0x7C00000) >> 22;
414 n_words = (data & 0x3FFFFF);
416 printf(
"%8X - BLOCK TRAILER - slot = %d n_words = %d\n",
417 data, slot_id_tr, n_words);
423 slot_id_ev_hd = (data & 0x07C00000) >> 22;
424 evt_num_1 = (data & 0x00000FFF);
425 trig_time = (data & 0x003FF000) >> 12;
428 (
"%8X - EVENT HEADER - slot = %d evt_num = %d trig_time = %d (%X)\n",
429 data, slot_id_ev_hd, evt_num_1, trig_time,
438 time_1 = (data & 0x7FFFFFF);
440 printf(
"%8X - TRIGGER TIME 1 - time = %X\n", data,
449 time_2 = (data & 0xFFFFF);
451 printf(
"%8X - TRIGGER TIME 2 - time = %X\n", data,
456 printf(
"%8X - TRIGGER TIME - (ERROR)\n", data);
458 time_last = time_now;
464 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
469 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
474 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
479 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
483 num_decoder_words = (data & 0x3F);
486 printf(
"%8X - DECODER HEADER = %d (NUM DECODER WORDS = %d)\n",
487 data, type, num_decoder_words);
492 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
497 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
502 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
507 printf(
"%8X - UNDEFINED TYPE = %d\n", data, type);
512 printf(
"%8X - END OF EVENT = %d\n", data, type);
516 slot_id_dnv = (data & 0x7C00000) >> 22;
518 printf(
"%8X - DATA NOT VALID = %d slot = %d\n", data,
523 slot_id_fill = (data & 0x7C00000) >> 22;
525 printf(
"%8X - FILLER WORD = %d slot = %d\n", data, type,
595 UShort_t firstbits[nbits];
596 for (
unsigned int i = 0; i < nbits; i++) firstbits[i] = (seed >> i) & 0x1;
607 if (TRegexp(
"diff_").Index(prefix,&len) == 0
608 || TRegexp(
"asym[1-9]*_").Index(prefix,&len) == 0)
610 else if (TRegexp(
"yield_").Index(prefix,&len) == 0)
620 if (folder != NULL) folder->cd();
631 basename=
"pattern_polarity";
634 for (
size_t i=0; i<
fWord.size(); i++){
635 basename=
"hel_"+
fWord[i].fWordName;
644 basename=prefix+
"delta_event_number";
647 basename=prefix+
"delta_pattern_number";
650 basename=prefix+
"pattern_phase";
653 basename=prefix+
"helicity";
656 for (
size_t i=0; i<
fWord.size(); i++){
657 basename=prefix+
fWord[i].fWordName;
663 QwError <<
"QwHelicityDecoder::ConstructHistograms this prefix--" << prefix <<
"-- is not unknown:: no histo created" <<
QwLog::endl;
684 for (
size_t i=0; i<
fWord.size(); i++){
706 for (
size_t i=0; i<
fWord.size(); i++){
729 basename =
"hd_actual_helicity";
731 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
733 basename =
"hd_delayed_helicity";
735 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
737 basename =
"hd_reported_helicity";
739 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
741 basename =
"hd_pattern_phase";
743 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
745 basename =
"hd_pattern_number";
747 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
749 basename =
"hd_pattern_seed";
751 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
753 basename =
"hd_event_number";
755 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
757 basename =
"hd_event_Polarity";
759 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
761 basename =
"hd_Reported_Pattern_Hel";
763 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
765 basename =
"hd_num_tstable_fall";
767 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
769 basename =
"hd_num_pair_sync";
771 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
773 basename =
"hd_time_since_tstable";
775 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
777 basename =
"hd_time_since_tsettle";
779 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
781 basename =
"hd_last_duration_tstable";
783 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
785 basename =
"hd_last_duration_tsettle";
787 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
789 for (
size_t i=0; i<
fWord.size(); i++)
791 basename =
fWord[i].fWordName;
793 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
798 basename =
"hd_actual_helicity";
800 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
802 basename =
"hd_actual_pattern_polarity";
804 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
806 basename =
"hd_actual_previous_pattern_polarity";
808 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
810 basename =
"hd_delayed_pattern_polarity";
812 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
814 basename =
"hd_pattern_number";
816 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
818 basename =
"hd_pattern_seed";
820 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
822 for (
size_t i=0; i<
fWord.size(); i++)
824 basename =
fWord[i].fWordName;
826 tree->Branch(basename, &(values.
back<Double_t>()), basename+
"/I");
829 std::cout <<
"after construction size " << values.
size() << std::endl;
851 basename =
"hd_delayed_helicity";
854 basename =
"hd_reported_helicity";
857 basename =
"hd_pattern_phase";
860 basename =
"hd_pattern_number";
863 basename =
"hd_pattern_seed";
866 basename =
"hd_event_number";
869 basename =
"hd_event_Polarity";
872 basename =
"hd_Reported_Pattern_Hel";
877 basename =
"hd_actual_helicity";
880 basename =
"hd_actual_pattern_polarity";
883 basename =
"hd_actual_previous_pattern_polarity";
886 basename =
"hd_delayed_pattern_polarity";
889 basename =
"hd_pattern_number";
892 basename =
"hd_pattern_seed";
895 for (
size_t i=0; i<
fWord.size(); i++)
897 basename =
fWord[i].fWordName;
898 tree->Branch(basename, &
fWord[i].fValue, basename+
"/I");
920 basename =
"hd_delayed_helicity";
923 basename =
"hd_reported_helicity";
926 basename =
"hd_pattern_phase";
929 basename =
"hd_pattern_number";
932 basename =
"hd_pattern_seed";
935 basename =
"hd_event_number";
938 basename =
"hd_event_Polarity";
941 basename =
"hd_Reported_Pattern_Hel";
946 basename =
"hd_actual_helicity";
949 basename =
"hd_actual_pattern_polarity";
952 basename =
"hd_actual_previous_pattern_polarity";
955 basename =
"hd_delayed_pattern_polarity";
958 basename =
"hd_pattern_number";
961 basename =
"hd_pattern_seed";
964 for (
size_t i=0; i<
fWord.size(); i++)
966 basename =
fWord[i].fWordName;
967 tree->Branch(basename,&
fWord[i].fValue, basename+
"/I");
998 for (
size_t i=0; i<
fWord.size(); i++)
1009 for (
size_t i=0; i<
fWord.size(); i++){
1019 Int_t ldebug = kFALSE;
1021 if(ldebug) std::cout <<
"Entering QwHelicityDecoder::RunPredictor for fEventNumber, " <<
fEventNumber
1056 std::cout <<
"Predicted Polarity ::: Delayed ="
1059 std::cout <<
"Predicted Helicity ::: Delayed Helicity=" <<
fHelicityDelayed
1070 Bool_t ldebug=kFALSE;
1072 if(ldebug) std::cout <<
"Entering QwHelicityDecoder::PredictHelicity \n";
1073 if(ldebug) std::cout <<
"QwHelicityDecoder::PredictHelicity=>Predicting the helicity \n";
1076 if(ldebug) std::cout <<
"n_ranbit exiting the function = " <<
n_ranbits <<
"\n";
1091 QwWarning <<
"QwHelicityDecoder : SetHelicityDelay :: helicity delay is set to 0."
1092 <<
" Disabling helicity predictor and using reported helicity information."
1100 QwError <<
"QwHelicityDecoder::SetHelicityDelay We cannot handle negative delay in the prediction of delayed helicity. Exiting.." <<
QwLog::endl;
1125 Bool_t ldebug = kFALSE;
1133 for(
size_t i=0;i<input->
fWord.size();i++)
1134 this->
fWord[i].fValue=input->
fWord[i].fValue;
1170 std::cout <<
"QwHelicityDecoder::operator = this->fPatternNumber=" << this->
fPatternNumber << std::endl;
1171 std::cout <<
"input->fPatternNumber=" << input->
fPatternNumber <<
"\n";
1221 for (
size_t i=0; i<
fWord.size(); i++) {
1223 std::min(
fWord[i].fValue, input->
fWord[i].fValue);
1254 if(
typeid(*value)!=
typeid(*
this)) {
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.
Helper functions and utilities for ROOT histogram management.
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
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.