79 for(
size_t i=0;i<this->
fWord.size();i++)
81 this->
fWord[i].fWordName=source.
fWord[i].fWordName;
82 this->
fWord[i].fModuleType=source.
fWord[i].fModuleType;
83 this->
fWord[i].fWordType=source.
fWord[i].fWordType;
118 (
"helicity.seed", po::value<int>(),
119 "Number of bits in random seed");
121 (
"helicity.bitpattern", po::value<std::string>(),
122 "Helicity bit pattern: 0x1 (pair), 0x9 (quartet), 0x69 (octet), 0x666999 (hexo-quad), 0x66669999 (octo-quad)");
124 (
"helicity.patternoffset", po::value<int>(),
125 "Set 1 when pattern starts with 1 or 0 when starts with 0");
127 (
"helicity.patternphase", po::value<int>(),
128 "Maximum pattern phase");
130 (
"helicity.delay", po::value<int>(),
131 "Default delay is 2 patterns, set at the helicity map file.");
133 (
"helicity.toggle-mode", po::value<bool>()->default_bool_value(
false),
134 "Activates helicity toggle-mode, overriding the 'delay', 'patternphase', 'bitpattern', and 'seed' options.");
143 if (options.
HasValue(
"helicity.patternoffset")) {
144 if (options.
GetValue<
int>(
"helicity.patternoffset") == 1
145 || options.
GetValue<
int>(
"helicity.patternoffset") == 0) {
151 if (options.
HasValue(
"helicity.patternphase")) {
152 if (options.
GetValue<
int>(
"helicity.patternphase") % 2 == 0) {
158 if (options.
HasValue(
"helicity.seed")) {
159 if (options.
GetValue<
int>(
"helicity.seed") == 24
160 || options.
GetValue<
int>(
"helicity.seed") == 30) {
166 if (options.
HasValue(
"helicity.delay")) {
171 if (options.
HasValue(
"helicity.bitpattern")) {
173 << options.
GetValue<std::string>(
"helicity.bitpattern")
175 std::string hex = options.
GetValue<std::string>(
"helicity.bitpattern");
180 if (options.
GetValue<
bool>(
"helicity.toggle-mode")) {
205 for (
size_t i=0;i<
fWord.size();i++)
305 Bool_t ldebug=kFALSE;
307 static UInt_t lastuserbits = 0xFF;
310 if(scaleroffset==1 || scaleroffset==0) {
316 lastuserbits = userbits;
318 if (lastuserbits==0xFF) {
321 if ((lastuserbits & 0x8) == 0x8) {
331 if ((lastuserbits & 0x4) == 0x4){
342 QwError <<
" QwHelicity::ProcessEvent finding a missed read event in the scaler" <<
QwLog::endl;
344 std::cout <<
" QwHelicity::ProcessEvent :" << scaleroffset <<
" events were missed \n";
345 std::cout <<
" before manipulation \n";
354 for (UInt_t i=0;i<scaleroffset;i++) {
367 std::cout <<
" after manipulation \n";
377 static Bool_t firstevent = kTRUE;
378 static Bool_t firstpattern = kTRUE;
379 static Bool_t fake_the_counters=kFALSE;
398 if (!fake_the_counters){
409 firstpattern = kFALSE;
438 QwError <<
"QwHelicity::ProcessEvent read event# ("
449 QwError <<
"QwHelicity::ProcessEvent: The Multiplet Sync bit is set, but the Pattern Phase is ("
465 QwError <<
"QwHelicity::ProcessEvent: Both the H+ and H- bits are set: thisinputregister=="
485 static Bool_t firstpattern = kTRUE;
488 firstpattern = kFALSE;
494 QwError <<
"QwHelicity::ProcessEvent read event# ("
530 Bool_t ldebug = kFALSE;
547 QwError <<
"QwHelicity::ProcessEvent no instructions on how to decode the helicity !!!!" <<
QwLog::endl;
585 std::vector<UInt_t> localbuffer;
591 UInt_t userbit = 0x0;
596 localbuffer.push_back(0x1);
597 localbuffer.push_back(0xa);
598 localbuffer.push_back(0xa);
599 localbuffer.push_back(0x0);
600 localbuffer.push_back(0x20);
601 localbuffer.push_back(userbit);
603 for (
int i = 0; i < 64; i++) localbuffer.push_back(0x0);
607 UInt_t input_register = 0x0;
613 localbuffer.push_back(input_register);
614 localbuffer.push_back(0x0);
619 for (
int i = 0; i < 17; i++) localbuffer.push_back(0x0);
628 std::vector<UInt_t> subbankheader;
629 std::vector<UInt_t> rocheader;
630 if (localbuffer.size() > 0) {
633 subbankheader.clear();
634 subbankheader.push_back(localbuffer.size() + 1);
635 subbankheader.push_back((
fCurrentBank_ID << 16) | (0x01 << 8) | (1 & 0xff));
640 rocheader.push_back(subbankheader.size() + localbuffer.size() + 1);
641 rocheader.push_back((
fCurrentROC_ID << 16) | (0x10 << 8) | (1 & 0xff));
645 buffer.insert(buffer.end(), rocheader.begin(), rocheader.end());
646 buffer.insert(buffer.end(), subbankheader.begin(), subbankheader.end());
647 buffer.insert(buffer.end(), localbuffer.begin(), localbuffer.end());
653 Bool_t ldebug=kFALSE;
676 if (mapstr.
PopValue(
"patternphase",value)) {
680 if (mapstr.
PopValue(
"patternbits",valuestr)) {
683 if (mapstr.
PopValue(
"inputregmask_fakemps",value)) {
686 if (mapstr.
PopValue(
"inputregmask_helicity",value)) {
690 if (mapstr.
PopValue(
"inputregmask_helplus",value)) {
693 if (mapstr.
PopValue(
"inputregmask_helminus",value)) {
696 if (mapstr.
PopValue(
"inputregmask_pattsync",value)) {
699 if (mapstr.
PopValue(
"inputregmask_pairsync",value)) {
702 if (mapstr.
PopValue(
"fakempsbit",value)) {
706 if (mapstr.
PopValue(
"numberpatternsdelayed",value)) {
709 if (mapstr.
PopValue(
"randseedbits",value)) {
710 if (value==24 || value==30)
713 if (mapstr.
PopValue(
"patternphaseoffset",value)) {
716 if (mapstr.
PopValue(
"helpluseventtype",value)) {
719 if (mapstr.
PopValue(
"helminuseventtype",value)) {
722 if (mapstr.
PopValue(
"helicitydecodingmode",valuestr)) {
723 if (valuestr==
"InputRegisterMode") {
726 }
else if (valuestr==
"UserbitMode"){
729 }
else if (valuestr==
"HelLocalyMadeUp"){
732 }
else if (valuestr==
"InputMollerMode") {
736 QwError <<
"The helicity decoding mode read in file " << mapfile
737 <<
" is not recognized in function QwHelicity::LoadChannelMap \n"
744 if ((bankindex+1)>0){
745 UInt_t numbanks = UInt_t(bankindex+1);
748 std::pair<Int_t, Int_t>(
fWord.size(),
fWord.size()));
769 if (modnum<=0) wordsofar+=1;
770 else wordsofar+=modnum;
771 }
else if(modtype!=
"WORD"|| dettype!=
"helicitydata") {
772 QwError <<
"QwHelicity::LoadChannelMap: Unknown detector type: "
773 << dettype <<
", the detector " << namech <<
" will not be decoded "
786 fWord.push_back(localword);
804 if(namech.Contains(
"mps_counter")) {
807 if(namech.Contains(
"pat_counter")) {
817 std::cout <<
"Done with Load map channel \n";
818 for(
size_t i=0;i<
fWord.size();i++)
820 std::cout <<
" kUserbit=" <<
kUserbit <<
"\n";
830 QwDebug <<
"QwHelicity::LoadChannelMap:"
831 <<
" We are in Moller Helicity Mode, with HelPlusEventType = "
836 QwError <<
"QwHelicity::LoadChannelMap:"
837 <<
" We are in Moller Helicity Mode, and the HelPlus and HelMinus event types are not set properly."
840 <<
". Please correct the helicity map file!"
859 Bool_t lkDEBUG = kFALSE;
866 if (index >= 0 && num_words > 0) {
869 QwDebug <<
"QwHelicity::ProcessEvBuffer: "
870 <<
"Begin processing ROC" << roc_id
871 <<
" and subbank " << bank_id
872 <<
" number of words=" << num_words <<
QwLog::endl;
875 if(
fWord[i].fWordInSubbank+1<= (Int_t) num_words) {
876 fWord[i].fValue=buffer[
fWord[i].fWordInSubbank];
878 QwWarning <<
"QwHelicity::ProcessEvBuffer: There is not enough word in the buffer to read data for "
880 QwWarning <<
"QwHelicity::ProcessEvBuffer: Words in this buffer:" << num_words
881 <<
" trying to read word number =" <<
fWord[i].fWordInSubbank <<
QwLog::endl;
885 QwDebug <<
"QwHelicity::ProcessEvBuffer: Done with Processing this event" <<
QwLog::endl;
886 for(
size_t i=0;i<
fWord.size();i++) {
887 std::cout <<
"QwHelicity::ProcessEvBuffer: word number = " << i <<
" ";
900 if (folder != NULL) folder->cd();
911 basename=
"pattern_polarity";
914 for (
size_t i=0; i<
fWord.size(); i++){
915 basename=
"hel_"+
fWord[i].fWordName;
924 basename=prefix+
"delta_event_number";
927 basename=prefix+
"delta_pattern_number";
930 basename=prefix+
"pattern_phase";
933 basename=prefix+
"helicity";
936 for (
size_t i=0; i<
fWord.size(); i++){
937 basename=prefix+
fWord[i].fWordName;
943 QwError <<
"QwHelicity::ConstructHistograms this prefix--" << prefix <<
"-- is not unknown:: no histo created" <<
QwLog::endl;
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 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 state management and pattern recognition.
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.
T GetTypedNextToken()
Get next token into specific type.
Bool_t PopValue(const std::string keyname, T &retvalue)
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
void SetCommentChars(const std::string value)
Set various sets of special characters.
const std::pair< TString, TString > GetParamFileNameContents()
Word-level data manipulation and bit operations.
BankID_t fCurrentBank_ID
Bank ID (and Marker word) that is currently being processed;.
Int_t GetSubbankIndex() const
UInt_t GetEventTypeMask() const
Get event type mask.
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)
ROCID_t fCurrentROC_ID
ROC ID that is currently being processed.
Bool_t HasDataLoaded() const
Int_t LoadEventCuts(TString filename) override
Optional event cut file.
Bool_t CheckIORegisterMask(const UInt_t &ioregister, const UInt_t &mask) const
void ProcessEventInputRegisterMode()
void ProcessOptions(QwOptions &options) override
Process the command line options.
void ClearEventData() override
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
Int_t LoadInputParameters(TString pedestalfile) override
Mandatory parameter file definition.
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Int_t LoadChannelMap(TString mapfile) override
Mandatory map file definition.
QwHelicity()
Private default constructor (not implemented, will throw linker error on use)
UInt_t fInputReg_HelMinus
@ kDefaultInputReg_FakeMPS
@ kDefaultInputReg_PatternSync
@ kDefaultInputReg_HelPlus
@ kDefaultInputReg_HelMinus
Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
TODO: The non-event-type-aware ProcessEvBuffer routine should be replaced with the event-type-aware v...
void ProcessEventUserbitMode()
Process helicity information from userbit configuration data.
UInt_t fInputReg_PairSync
UInt_t fInputReg_PatternSync
Bool_t ApplySingleEventCuts() override
Apply the single event cuts.
void ProcessEventInputMollerMode()
void ProcessEvent() override
void EncodeEventData(std::vector< UInt_t > &buffer) override
void SetHelicityBitPattern(TString hex)
void SetHelicityDelay(Int_t delay)
static const std::vector< UInt_t > kDefaultHelicityBitPattern
std::vector< std::pair< Int_t, Int_t > > fWordsPerSubbank
std::vector< QwWord > fWord
UInt_t BuildHelicityBitPattern(Int_t patternsize)
Int_t fActualPatternPolarity
True polarity of the current pattern.
QwHelicityBase()
Private default constructor (not implemented, will throw linker error on use)
Bool_t fSuppressMPSErrorMsgs
Int_t fPatternPhaseOffset
UInt_t kEventTypeHelMinus
Int_t fNumMissedEventBlocks
Int_t fPreviousPatternPolarity
True polarity of the previous pattern.
std::vector< UInt_t > fHelicityBitPattern
Int_t fHelicityDecodingMode
static const Int_t kUndefinedHelicity
Int_t fDelayedPatternPolarity
Reported polarity of the current pattern.
Int_t fPatternPhaseNumberOld
Int_t fPatternPhaseNumber
Int_t fPatternNumberFirst
void SetHistoTreeSave(const TString &prefix)
void ClearErrorCounters()