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(0x0);
597 localbuffer.push_back(0x20);
598 localbuffer.push_back(userbit);
600 for (
int i = 0; i < 64; i++) localbuffer.push_back(0x0);
604 UInt_t input_register = 0x0;
610 localbuffer.push_back(input_register);
611 localbuffer.push_back(0x0);
616 for (
int i = 0; i < 17; i++) localbuffer.push_back(0x0);
625 std::vector<UInt_t> subbankheader;
626 std::vector<UInt_t> rocheader;
627 if (localbuffer.size() > 0) {
630 subbankheader.clear();
631 subbankheader.push_back(localbuffer.size() + 1);
632 subbankheader.push_back((
fCurrentBank_ID << 16) | (0x01 << 8) | (1 & 0xff));
637 rocheader.push_back(subbankheader.size() + localbuffer.size() + 1);
638 rocheader.push_back((
fCurrentROC_ID << 16) | (0x10 << 8) | (1 & 0xff));
642 buffer.insert(buffer.end(), rocheader.begin(), rocheader.end());
643 buffer.insert(buffer.end(), subbankheader.begin(), subbankheader.end());
644 buffer.insert(buffer.end(), localbuffer.begin(), localbuffer.end());
650 Bool_t ldebug=kFALSE;
673 if (mapstr.
PopValue(
"patternphase",value)) {
677 if (mapstr.
PopValue(
"patternbits",valuestr)) {
680 if (mapstr.
PopValue(
"inputregmask_fakemps",value)) {
683 if (mapstr.
PopValue(
"inputregmask_helicity",value)) {
687 if (mapstr.
PopValue(
"inputregmask_helplus",value)) {
690 if (mapstr.
PopValue(
"inputregmask_helminus",value)) {
693 if (mapstr.
PopValue(
"inputregmask_pattsync",value)) {
696 if (mapstr.
PopValue(
"inputregmask_pairsync",value)) {
699 if (mapstr.
PopValue(
"fakempsbit",value)) {
703 if (mapstr.
PopValue(
"numberpatternsdelayed",value)) {
706 if (mapstr.
PopValue(
"randseedbits",value)) {
707 if (value==24 || value==30)
710 if (mapstr.
PopValue(
"patternphaseoffset",value)) {
713 if (mapstr.
PopValue(
"helpluseventtype",value)) {
716 if (mapstr.
PopValue(
"helminuseventtype",value)) {
719 if (mapstr.
PopValue(
"helicitydecodingmode",valuestr)) {
720 if (valuestr==
"InputRegisterMode") {
723 }
else if (valuestr==
"UserbitMode"){
726 }
else if (valuestr==
"HelLocalyMadeUp"){
729 }
else if (valuestr==
"InputMollerMode") {
733 QwError <<
"The helicity decoding mode read in file " << mapfile
734 <<
" is not recognized in function QwHelicity::LoadChannelMap \n"
741 if ((bankindex+1)>0){
742 UInt_t numbanks = UInt_t(bankindex+1);
745 std::pair<Int_t, Int_t>(
fWord.size(),
fWord.size()));
766 if (modnum<=0) wordsofar+=1;
767 else wordsofar+=modnum;
768 }
else if(modtype!=
"WORD"|| dettype!=
"helicitydata") {
769 QwError <<
"QwHelicity::LoadChannelMap: Unknown detector type: "
770 << dettype <<
", the detector " << namech <<
" will not be decoded "
783 fWord.push_back(localword);
801 if(namech.Contains(
"mps_counter")) {
804 if(namech.Contains(
"pat_counter")) {
814 std::cout <<
"Done with Load map channel \n";
815 for(
size_t i=0;i<
fWord.size();i++)
817 std::cout <<
" kUserbit=" <<
kUserbit <<
"\n";
827 QwDebug <<
"QwHelicity::LoadChannelMap:"
828 <<
" We are in Moller Helicity Mode, with HelPlusEventType = "
833 QwError <<
"QwHelicity::LoadChannelMap:"
834 <<
" We are in Moller Helicity Mode, and the HelPlus and HelMinus event types are not set properly."
837 <<
". Please correct the helicity map file!"
856 Bool_t lkDEBUG = kFALSE;
863 if (index >= 0 && num_words > 0) {
866 QwDebug <<
"QwHelicity::ProcessEvBuffer: "
867 <<
"Begin processing ROC" << roc_id
868 <<
" and subbank " << bank_id
869 <<
" number of words=" << num_words <<
QwLog::endl;
872 if(
fWord[i].fWordInSubbank+1<= (Int_t) num_words) {
873 fWord[i].fValue=buffer[
fWord[i].fWordInSubbank];
875 QwWarning <<
"QwHelicity::ProcessEvBuffer: There is not enough word in the buffer to read data for "
877 QwWarning <<
"QwHelicity::ProcessEvBuffer: Words in this buffer:" << num_words
878 <<
" trying to read word number =" <<
fWord[i].fWordInSubbank <<
QwLog::endl;
882 QwDebug <<
"QwHelicity::ProcessEvBuffer: Done with Processing this event" <<
QwLog::endl;
883 for(
size_t i=0;i<
fWord.size();i++) {
884 std::cout <<
"QwHelicity::ProcessEvBuffer: word number = " << i <<
" ";
897 if (folder != NULL) folder->cd();
908 basename=
"pattern_polarity";
911 for (
size_t i=0; i<
fWord.size(); i++){
912 basename=
"hel_"+
fWord[i].fWordName;
921 basename=prefix+
"delta_event_number";
924 basename=prefix+
"delta_pattern_number";
927 basename=prefix+
"pattern_phase";
930 basename=prefix+
"helicity";
933 for (
size_t i=0; i<
fWord.size(); i++){
934 basename=prefix+
fWord[i].fWordName;
940 QwError <<
"QwHelicity::ConstructHistograms this prefix--" << prefix <<
"-- is not unknown:: no histo created" <<
QwLog::endl;
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.
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 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()