14#ifdef HAS_RNTUPLE_SUPPORT
16#include <ROOT/RNTupleModel.hxx>
17#include <ROOT/RNTupleWriter.hxx>
25#ifdef __USE_DATABASE__
26#include "QwParitySchema.h"
51 TString varname, varvalue;
64 UInt_t numbanks = UInt_t(bankindex+1);
67 std::pair<Int_t, Int_t>(
fWord.size(),
fWord.size()));
80 QwWarning <<
"QwBeamMod::LoadChannelMap: Unrecognized declaration "
111 localModChannelID.
Print();
112 std::cout<<
"line ok=";
113 if(lineok) std::cout<<
"TRUE"<<std::endl;
114 else std::cout<<
"FALSE"<<std::endl;
140 localModChannelID.
Print();
141 std::cout<<
"line ok=";
142 if(lineok) std::cout<<
"TRUE"<<std::endl;
143 else std::cout<<
"FALSE"<<std::endl;
148 if (localModChannelID.
fmoduletype ==
"SIS3801D32") {
170 localModChannelID.
Print();
171 std::cout<<
"line ok=";
172 if(lineok) std::cout<<
"TRUE"<<std::endl;
173 else std::cout<<
"FALSE"<<std::endl;
178 if (localModChannelID.
modnum<=0) wordsofar+=1;
179 else wordsofar+= localModChannelID.
modnum;
194 fWord.push_back(localword);
197 if (localword.
fWordName ==
"bm_pattern_number") {
201 if(namech==
"ffb_status")
204 if(namech ==
"bmwobj"){
217 std::cout<<
"Done with Load map channel \n";
221 for(
size_t i=0;i<
fWord.size();i++)
254 if (paramfile.
ReturnValue(
"vqwk_buffer_offset",offset)) {
264 if (paramfile.
ReturnValue(
"scaler_buffer_offset",offset)) {
284 device_type.ToUpper();
286 device_name.ToUpper();
288 if (device_type ==
"VQWK"||device_type==
"SCALER" ||device_type==
"SIS3801D24" ||device_type==
"SIS3801D32"){
289 device_name.ToLower();
299 QwMessage <<
" Type " << device_type <<
" Name " << device_name <<
" Index [" << det_index <<
"] "
300 <<
" device flag " << eventcut_flag <<
QwLog::endl;
304 }
else if (device_type ==
"WORD" && device_name==
"FFB_STATUS"){
306 }
else if (device_type ==
"WORD" && device_name==
"BMWOBJ"){
323 Bool_t burpstatus = kFALSE;
338 Bool_t ldebug=kFALSE;
343 if(ldebug)std::cout<<
"QwBeamMod::LoadInputParameters("<< pedestalfile<<
")\n";
349 if(ldebug)std::cout<<
" line read so far ="<<lineread<<
"\n";
357 varname.Remove(TString::kBoth,
' ');
374 if(ldebug) std::cout<<
" line read in the pedestal + cal file ="<<lineread<<
" \n";
385 Bool_t lkDEBUG=kFALSE;
390 if (index>=0 && num_words>0){
393 QwMessage <<
"QwBeamMod::ProcessEvBuffer: "
394 <<
"Begin processing ROC" << roc_id
395 <<
" and subbank "<<bank_id
397 if (buffer[0]==0xf0f0f0f0 && num_words%2==1){
401 QwMessage <<
"QwBeamMod::ProcessEvBuffer: "
402 <<
"Skipped padding word 0xf0f0f0f0 at beginning of buffer."
409 std::cout<<
"found modulation data for "<<
fModChannelID[i].fmodulename<<std::endl;
410 std::cout<<
"word left to read in this buffer:"<<num_words-
fModChannelID[i].fWordInSubbank<<std::endl;
421 if(
fWord[i].fWordInSubbank+1<= (Int_t) num_words) {
422 fWord[i].fValue=buffer[
fWord[i].fWordInSubbank];
425 QwWarning <<
"QwBeamMod::ProcessEvBuffer: There is not enough word in the buffer to read data for "
427 QwWarning <<
"QwBeamMod::ProcessEvBuffer: Words in this buffer:" << num_words
428 <<
" trying to read word number =" <<
fWord[i].fWordInSubbank <<
QwLog::endl;
432 QwDebug <<
"QwBeamMod::ProcessEvBuffer: Done with Processing this event" <<
QwLog::endl;
433 for(
size_t i=0;i<
fWord.size();i++) {
434 std::cout <<
" word number = " << i <<
" ";
450 Bool_t test_Mod=kTRUE;
451 Bool_t test_BCM1=kTRUE;
459 test_BCM1 =
fModChannel[i]->ApplySingleEventCuts();
460 test_Mod &= test_BCM1;
470 if(!test_BCM1 &&
bDEBUG) std::cout<<
"******* QwBeamMod::SingleEventCuts()->BCM[ "<<i<<
" , "<<
fModChannel[i]->GetElementName()<<
" ] ******" << std::endl;
520 std::cout<<
"*********QwBeamMod Error Summary****************"<<std::endl;
543 ErrorFlag |=
fModChannel[i]->GetEventcutErrorFlag();
581 for (
size_t i=0;i<
fWord.size();i++)
590 Bool_t ldebug=kFALSE;
593 std::cout<<
"QwBeamMod::GetDetectorIndex\n";
594 std::cout<<
fModChannelID.size()<<
" already registered detector\n";
612 for(
size_t i=0;i<
fWord.size();i++) {
614 if(
fWord[i].fWordName==name){
636 for(
size_t i=0;i<input->
fWord.size();i++)
689 for(
size_t i=0;i<innumer->
fWord.size();i++)
690 this->
fWord[i].fValue=innumer->
fWord[i].fValue;
709 if(
typeid(*value)!=
typeid(*
this))
734 if (folder != NULL) folder->cd();
737 if (prefix !=
"")
return;
764 if (ramp < 0)
return;
775 if (pattern < 0 || pattern > 4)
return;
790 Double_t ramp_block = ramp_block_41 - ramp_block_32;
800 fModChannel[i]->ConstructBranchAndVector(tree, prefix, values);
805 for (
size_t i=0; i<
fWord.size(); i++) {
807 basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length());
808 basename +=
fWord[i].fWordName;
824 for (
size_t i = 0; i <
fWord.size(); i++){
834#ifdef HAS_RNTUPLE_SUPPORT
835void QwBeamMod::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
840 fModChannel[i]->ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
844 for (
size_t i=0; i<
fWord.size(); i++) {
845 basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length());
846 basename +=
fWord[i].fWordName;
847 values.push_back(0.0);
848 fieldPtrs.push_back(model->MakeField<Double_t>(basename.Data()));
852void QwBeamMod::FillNTupleVector(std::vector<Double_t>& values)
const
859 for (
size_t i = 0; i <
fWord.size(); i++){
860 values[index++] =
fWord[i].fValue;
876 for(
size_t i=0;i<
fWord.size();i++)
884 std::cout<<
"============================="<<std::endl;
885 std::cout<<
" Detector ID="<<i<<std::endl;
898 QwMessage <<
"Index of this detector in the vector of similar detector= "<<
908#ifdef __USE_DATABASE__
912 Bool_t local_print_flag =
false;
914 if(local_print_flag) {
915 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
917 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
920 std::vector<QwParitySchema::beam_optics_row> entrylist;
922 UInt_t analysis_id = db->GetAnalysisID();
924 for(
size_t bpm = 0; bpm <
fModChannel.size(); bpm++) {
925 for(
size_t pattern = 0; pattern < 5; pattern++) {
928 QwParitySchema::beam_optics table;
929 QwParitySchema::beam_optics_row row;
930 row[table.analysis_id] = analysis_id;
931 row[table.monitor_id] = 0;
932 row[table.modulation_type_id] = pattern;
934 row[table.offset] = 0.0;
935 row[table.amplitude] = 0.0;
936 row[table.phase] = 0.0;
937 row[table.o_error] = 0.0;
938 row[table.a_error] = 0.0;
939 row[table.p_error] = 0.0;
940 row[table.gof_para] = 0.0;
942 entrylist.push_back(row);
946 if(local_print_flag) {
952 if( entrylist.size() ) {
953 auto c = db->GetScopedConnection();
954 for (
const auto& entry : entrylist) {
955 c->QueryExecute(entry.insert_into());
Helper functions and utilities for ROOT histogram management.
Base and derived classes for scaler channel data handling.
class QwScaler_Channel< 0x00ffffff, 0 > QwSIS3801D24_Channel
class QwScaler_Channel< 0xffffffff, 0 > QwSIS3801D32_Channel
A logfile class, based on an identical class in the Hermes analyzer.
#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.
Parameter file parsing and management.
static const UInt_t kGlobalCut
static const UInt_t kBModErrorFlag
static const UInt_t kEventCutMode3
static const UInt_t kBModFFBErrorFlag
UInt_t GetGlobalErrorFlag(TString evtype, Int_t evMode, Double_t stabilitycut)
Beam modulation subsystem for parity analysis.
std::vector< TH1_ptr > fHistograms
Histograms associated with this data element.
static std::ostream & endl(std::ostream &)
End of the line.
Command-line and configuration file options processor.
Configuration file parser with flexible tokenization and search capabilities.
T GetTypedNextToken()
Get next token into specific type.
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
void SetCommentChars(const std::string value)
Set various sets of special characters.
void TrimComment(const char commentchar)
const std::pair< TString, TString > GetParamFileNameContents()
Bool_t ReturnValue(const std::string keyname, T &retvalue)
A helper class to manage a vector of branch entries for ROOT trees.
size_type size() const noexcept
std::string LeafList(size_type start_index=0) const
void push_back(const std::string &name, const char type='D')
void SetValue(size_type index, Double_t val)
static Int_t GetBufferOffset(Int_t scalerindex, Int_t wordindex, UInt_t header=1)
Concrete hardware channel for VQWK ADC modules (6x32-bit words)
static void PrintErrorCounterTail()
static Int_t GetBufferOffset(Int_t moduleindex, Int_t channelindex)
static void PrintErrorCounterHead()
Word-level data manipulation and bit operations.
Abstract base for concrete hardware channels implementing dual-operator pattern.
void InitializeChannel(TString name)
Initialize the fields in this object.
BankID_t fCurrentBank_ID
Bank ID (and Marker word) that is currently being processed;.
TString fSystemName
Name of this subsystem.
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)
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
Mapping information for beam modulation channels.
QwModChannelID(Int_t subbankid, Int_t wordssofar, TString name, TString modtype, QwBeamMod *obj)
void ClearEventData() override
void LoadEventCuts_Line(QwParameterFile &mapstr, TString &varvalue, Int_t &eventcut_flag) override
static const Bool_t bDEBUG
void LoadEventCuts_Init() override
VQwSubsystem & operator-=(VQwSubsystem *value) override
Bool_t CheckForBurpFail(const VQwSubsystem *subsys) override
Report the number of events failed due to HW and event cut failures.
void PrintErrorCounters() const override
VQwSubsystem & operator=(VQwSubsystem *value) override
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
VQwSubsystem & operator+=(VQwSubsystem *value) override
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
void ProcessOptions(QwOptions &options) override
Process the command line options.
void AccumulateRunningSum(VQwSubsystem *, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
Update the running sums for devices.
Int_t LoadChannelMap(TString mapfile) override
Mandatory map file definition.
void FillHistograms() override
Fill the histograms for this subsystem.
void ProcessEvent_2() override
Process the event data again, including data from other subsystems. Not all derived classes will requ...
Int_t LoadInputParameters(TString pedestalfile) override
Mandatory parameter file definition.
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
void CalculateRunningAverage() override
Calculate the average for all good events.
void WritePromptSummary(QwPromptSummary *ps, TString type) override
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override
void FillTreeVector(QwRootTreeBranchVector &values) const override
Fill the tree vector.
std::vector< VQwHardwareChannel * > fModChannel
UInt_t GetEventcutErrorFlag() override
Return the error flag to the top level routines related to stability checks and ErrorFlag updates.
Int_t GetDetectorIndex(TString name)
void Scale(Double_t factor) override
Bool_t Compare(VQwSubsystem *source)
std::vector< QwWord > fWord
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 ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Construct the branch and tree vector.
void ProcessEvent() override
void IncrementErrorCounters() override
Increment the error counters.
std::vector< std::pair< Int_t, Int_t > > fWordsPerSubbank
std::vector< QwModChannelID > fModChannelID
Bool_t ApplySingleEventCuts() override
Apply the single event cuts.
void LoadEventCuts_Fin(Int_t &eventcut_flag) override
virtual void PrintValue() const
Print values of all channels.
virtual void FillDB_MPS(QwParityDB *, TString)
Fill the database with MPS-based variables Note that most subsystems don't need to do this.
virtual void FillDB(QwParityDB *, TString)
Fill the database.
virtual UInt_t UpdateErrorFlag()
Uses the error flags of contained data elements to update Returns the error flag to the top level rou...
virtual void FillErrDB(QwParityDB *, TString)