14#ifdef HAS_RNTUPLE_SUPPORT
16#include <ROOT/RNTupleModel.hxx>
17#include <ROOT/RNTupleWriter.hxx>
25#ifdef __USE_DATABASE__
26#include "QwParitySchema.h"
54 TString varname, varvalue;
67 UInt_t numbanks = UInt_t(bankindex+1);
70 std::pair<Int_t, Int_t>(
fWord.size(),
fWord.size()));
83 QwWarning <<
"QwBeamMod::LoadChannelMap: Unrecognized declaration "
114 localModChannelID.
Print();
115 std::cout<<
"line ok=";
116 if(lineok) std::cout<<
"TRUE"<<std::endl;
117 else std::cout<<
"FALSE"<<std::endl;
143 localModChannelID.
Print();
144 std::cout<<
"line ok=";
145 if(lineok) std::cout<<
"TRUE"<<std::endl;
146 else std::cout<<
"FALSE"<<std::endl;
151 if (localModChannelID.
fmoduletype ==
"SIS3801D32") {
173 localModChannelID.
Print();
174 std::cout<<
"line ok=";
175 if(lineok) std::cout<<
"TRUE"<<std::endl;
176 else std::cout<<
"FALSE"<<std::endl;
181 if (localModChannelID.
modnum<=0) wordsofar+=1;
182 else wordsofar+= localModChannelID.
modnum;
197 fWord.push_back(localword);
200 if (localword.
fWordName ==
"bm_pattern_number") {
204 if(namech==
"ffb_status")
207 if(namech ==
"bmwobj"){
220 std::cout<<
"Done with Load map channel \n";
224 for(
size_t i=0;i<
fWord.size();i++)
257 if (paramfile.
ReturnValue(
"vqwk_buffer_offset",offset)) {
267 if (paramfile.
ReturnValue(
"scaler_buffer_offset",offset)) {
287 device_type.ToUpper();
289 device_name.ToUpper();
291 if (device_type ==
"VQWK"||device_type==
"SCALER" ||device_type==
"SIS3801D24" ||device_type==
"SIS3801D32"){
292 device_name.ToLower();
302 QwMessage <<
" Type " << device_type <<
" Name " << device_name <<
" Index [" << det_index <<
"] "
303 <<
" device flag " << eventcut_flag <<
QwLog::endl;
307 }
else if (device_type ==
"WORD" && device_name==
"FFB_STATUS"){
309 }
else if (device_type ==
"WORD" && device_name==
"BMWOBJ"){
326 Bool_t burpstatus = kFALSE;
341 Bool_t ldebug=kFALSE;
346 if(ldebug)std::cout<<
"QwBeamMod::LoadInputParameters("<< pedestalfile<<
")\n";
352 if(ldebug)std::cout<<
" line read so far ="<<lineread<<
"\n";
360 varname.Remove(TString::kBoth,
' ');
377 if(ldebug) std::cout<<
" line read in the pedestal + cal file ="<<lineread<<
" \n";
388 Bool_t lkDEBUG=kFALSE;
393 if (index>=0 && num_words>0){
396 QwMessage <<
"QwBeamMod::ProcessEvBuffer: "
397 <<
"Begin processing ROC" << roc_id
398 <<
" and subbank "<<bank_id
400 if (buffer[0]==0xf0f0f0f0 && num_words%2==1){
404 QwMessage <<
"QwBeamMod::ProcessEvBuffer: "
405 <<
"Skipped padding word 0xf0f0f0f0 at beginning of buffer."
412 std::cout<<
"found modulation data for "<<
fModChannelID[i].fmodulename<<std::endl;
413 std::cout<<
"word left to read in this buffer:"<<num_words-
fModChannelID[i].fWordInSubbank<<std::endl;
424 if(
fWord[i].fWordInSubbank+1<= (Int_t) num_words) {
425 fWord[i].fValue=buffer[
fWord[i].fWordInSubbank];
428 QwWarning <<
"QwBeamMod::ProcessEvBuffer: There is not enough word in the buffer to read data for "
430 QwWarning <<
"QwBeamMod::ProcessEvBuffer: Words in this buffer:" << num_words
431 <<
" trying to read word number =" <<
fWord[i].fWordInSubbank <<
QwLog::endl;
435 QwDebug <<
"QwBeamMod::ProcessEvBuffer: Done with Processing this event" <<
QwLog::endl;
436 for(
size_t i=0;i<
fWord.size();i++) {
437 std::cout <<
" word number = " << i <<
" ";
453 Bool_t test_Mod=kTRUE;
454 Bool_t test_BCM1=kTRUE;
462 test_BCM1 =
fModChannel[i]->ApplySingleEventCuts();
463 test_Mod &= test_BCM1;
473 if(!test_BCM1 &&
bDEBUG) std::cout<<
"******* QwBeamMod::SingleEventCuts()->BCM[ "<<i<<
" , "<<
fModChannel[i]->GetElementName()<<
" ] ******" << std::endl;
523 std::cout<<
"*********QwBeamMod Error Summary****************"<<std::endl;
546 ErrorFlag |=
fModChannel[i]->GetEventcutErrorFlag();
584 for (
size_t i=0;i<
fWord.size();i++)
593 Bool_t ldebug=kFALSE;
596 std::cout<<
"QwBeamMod::GetDetectorIndex\n";
597 std::cout<<
fModChannelID.size()<<
" already registered detector\n";
615 for(
size_t i=0;i<
fWord.size();i++) {
617 if(
fWord[i].fWordName==name){
638 for(
size_t i=0;i<input->
fWord.size();i++)
691 for(
size_t i=0;i<innumer->
fWord.size();i++)
692 this->
fWord[i].fValue=innumer->
fWord[i].fValue;
711 if(
typeid(*value)!=
typeid(*
this))
736 if (folder != NULL) folder->cd();
739 if (prefix !=
"")
return;
766 if (ramp < 0)
return;
777 if (pattern < 0 || pattern > 4)
return;
792 Double_t ramp_block = ramp_block_41 - ramp_block_32;
802 fModChannel[i]->ConstructBranchAndVector(tree, prefix, values);
807 for (
size_t i=0; i<
fWord.size(); i++) {
809 basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length());
810 basename +=
fWord[i].fWordName;
826 for (
size_t i = 0; i <
fWord.size(); i++){
836#ifdef HAS_RNTUPLE_SUPPORT
837void QwBeamMod::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
842 fModChannel[i]->ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
846 for (
size_t i=0; i<
fWord.size(); i++) {
847 basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length());
848 basename +=
fWord[i].fWordName;
849 values.push_back(0.0);
850 fieldPtrs.push_back(model->MakeField<Double_t>(basename.Data()));
854void QwBeamMod::FillNTupleVector(std::vector<Double_t>& values)
const
861 for (
size_t i = 0; i <
fWord.size(); i++){
862 values[index++] =
fWord[i].fValue;
878 for(
size_t i=0;i<
fWord.size();i++)
886 std::cout<<
"============================="<<std::endl;
887 std::cout<<
" Detector ID="<<i<<std::endl;
900 QwMessage <<
"Index of this detector in the vector of similar detector= "<<
910#ifdef __USE_DATABASE__
914 Bool_t local_print_flag =
false;
916 if(local_print_flag) {
917 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
919 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
922 std::vector<QwParitySchema::beam_optics_row> entrylist;
924 UInt_t analysis_id = db->GetAnalysisID();
926 for(
size_t bpm = 0; bpm <
fModChannel.size(); bpm++) {
927 for(
size_t pattern = 0; pattern < 5; pattern++) {
930 QwParitySchema::beam_optics table;
931 QwParitySchema::beam_optics_row row;
932 row[table.analysis_id] = analysis_id;
933 row[table.monitor_id] = 0;
934 row[table.modulation_type_id] = pattern;
936 row[table.offset] = 0.0;
937 row[table.amplitude] = 0.0;
938 row[table.phase] = 0.0;
939 row[table.o_error] = 0.0;
940 row[table.a_error] = 0.0;
941 row[table.p_error] = 0.0;
942 row[table.gof_para] = 0.0;
944 entrylist.push_back(row);
948 if(local_print_flag) {
954 if( entrylist.size() ) {
955 auto c = db->GetScopedConnection();
956 for (
const auto& entry : entrylist) {
957 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.
#define REGISTER_SUBSYSTEM_FACTORY(A)
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
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)
Subsystem for beam modulation studies and FFB handling.
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)