16 #define MYSQLPP_SSQLS_NO_STATICS
33 (
"QwMainCerenkovDetector.normalize",
35 "Normalize the detectors by beam current");
48 QwWarning <<
"QwMainCerenkovDetector::ProcessOptions: "
49 <<
"Detector yields WILL NOT be normalized."
63 Bool_t status = kTRUE;
109 device_type.ToLower();
110 device_prop.ToLower();
113 if (device_type ==
"integrationpmt") {
115 }
else if (device_type ==
"combinedpmt") {
120 if (tmp_channel == NULL) {
121 QwError <<
"QwBeamLine::PublishInternalValues(): " << publish_name <<
" not found" <<
QwLog::endl;
124 QwDebug <<
"QwBeamLine::PublishInternalValues(): " << publish_name <<
" found" <<
QwLog::endl;
137 Bool_t ldebug=kFALSE;
139 std::vector<TString> combinedchannelnames;
140 std::vector<Double_t> weight;
141 Int_t currentrocread=0;
142 Int_t currentbankread=0;
144 Int_t currentsubbankindex=-1;
151 TString varname, varvalue;
154 while (mapstr.ReadNextLine())
156 mapstr.TrimComment(
'!');
157 mapstr.TrimWhitespace();
158 if (mapstr.LineIsEmpty())
continue;
160 if (mapstr.HasVariablePair(
"=",varname,varvalue))
168 currentrocread=value;
171 else if (varname==
"bank")
173 currentbankread=value;
176 else if (varname==
"sample_size")
183 Bool_t lineok = kTRUE;
184 TString keyword =
"";
185 TString keyword2 =
"";
186 TString modtype =
"";
187 TString dettype =
"";
192 modtype = mapstr.GetTypedNextToken<TString>();
194 if (modtype ==
"VQWK")
196 modnum = mapstr.GetTypedNextToken<Int_t>();
197 channum = mapstr.GetTypedNextToken<Int_t>();
198 dettype = mapstr.GetTypedNextToken<TString>();
200 namech = mapstr.GetTypedNextToken<TString>();
203 keyword = mapstr.GetTypedNextToken<TString>();
205 keyword2 = mapstr.GetTypedNextToken<TString>();
208 else if (modtype ==
"VPMT")
210 channum = mapstr.GetTypedNextToken<Int_t>();
211 Int_t combinedchans = mapstr.GetTypedNextToken<Int_t>();
212 dettype = mapstr.GetTypedNextToken<TString>();
214 namech = mapstr.GetTypedNextToken<TString>();
216 combinedchannelnames.clear();
217 for (
int i=0; i<combinedchans; i++)
219 TString nameofcombinedchan = mapstr.GetTypedNextToken<TString>();
220 nameofcombinedchan.ToLower();
221 combinedchannelnames.push_back(nameofcombinedchan);
224 for (
int i=0; i<combinedchans; i++)
226 weight.push_back( mapstr.GetTypedNextToken<Double_t>());
228 keyword = mapstr.GetTypedNextToken<TString>();
230 keyword2 = mapstr.GetTypedNextToken<TString>();
235 if (currentsubbankindex!=
GetSubbankIndex(currentrocread,currentbankread))
248 if (modtype==
"VQWK"){
254 else if (modtype==
"VPMT")
257 localMainDetID.
fWeight = weight;
262 QwError <<
"QwMainCerenkovDetector::LoadChannelMap: Unknown module type: "
263 << modtype <<
", the detector "<<namech<<
" will not be decoded "
271 QwError <<
"QwMainCerenkovDetector::LoadChannelMap: Unknown detector type: "
272 << dettype <<
", the detector "<<namech<<
" will not be decoded "
281 if (localMainDetID.
fIndex==-1)
286 if (keyword==
"not_blindable"
287 || keyword2==
"not_blindable")
291 if (keyword==
"not_normalizable"
292 || keyword2==
"not_normalizable")
304 if (keyword==
"not_normalizable"
305 || keyword2==
"not_normalizable")
309 if (keyword==
"not_blindable"
310 || keyword2 ==
"not_blindable")
322 localMainDetID.
Print();
323 std::cout<<
"line ok=";
324 if (lineok) std::cout<<
"TRUE"<<std::endl;
326 std::cout<<
"FALSE"<<std::endl;
346 std::cout<<
"fMainDetID[i].fCombinedChannelNames.size()="
347 <<
fMainDetID[i].fCombinedChannelNames.size()<<std::endl<<
"name list: ";
348 for (
size_t n=0; n<
fMainDetID[i].fCombinedChannelNames.size(); n++)
349 std::cout<<
" "<<
fMainDetID[i].fCombinedChannelNames[n];
350 std::cout<<std::endl;
354 for (
size_t j=0; j<
fMainDetID[i].fCombinedChannelNames.size(); j++)
362 std::cout<<
"found a to-be-combined channel candidate"<<std::endl;
369 if ((Int_t)
fMainDetID[i].fCombinedChannelNames.size()==chanmatched)
371 for (
size_t l=0; l<
fMainDetID[i].fCombinedChannelNames.size(); l++)
380 std::cout<<
"linked a combined channel"<<std::endl;
384 std::cerr<<
"cannot combine void channels for "<<
fMainDetID[i].fdetectorname<<std::endl;
393 mapstr.RewindToFileStart();
395 std::vector<TString> publishinfo;
397 if (varvalue ==
"PUBLISH") {
402 for (
int ii = 0; ii < 4; ii++) {
404 if (varvalue.Length()) {
405 publishinfo.push_back(varvalue);
408 if (publishinfo.size() == 4)
422 std::cout<<
"Done with Load channel map\n";
435 Int_t eventcut_flag = 1;
440 while (mapstr.ReadNextLine())
443 mapstr.TrimComment(
'!');
444 mapstr.TrimWhitespace();
445 if (mapstr.LineIsEmpty())
continue;
446 TString varname, varvalue;
447 if (mapstr.HasVariablePair(
"=",varname,varvalue))
449 if (varname==
"EVENTCUTS")
458 TString device_type = mapstr.GetTypedNextToken<TString>();
459 device_type.ToLower();
460 TString device_name = mapstr.GetTypedNextToken<TString>();
461 device_name.ToLower();
463 if (det_index == -1) {
469 Double_t LLX = mapstr.GetTypedNextToken<Double_t>();
470 Double_t ULX = mapstr.GetTypedNextToken<Double_t>();
471 varvalue = mapstr.GetTypedNextToken<TString>();
473 Double_t stabilitycut = mapstr.GetTypedNextToken<Double_t>();
483 Double_t LLX = mapstr.GetTypedNextToken<Double_t>();
484 Double_t ULX = mapstr.GetTypedNextToken<Double_t>();
485 varvalue = mapstr.GetTypedNextToken<TString>();
487 Double_t stabilitycut = mapstr.GetTypedNextToken<Double_t>();
515 Bool_t ldebug=kFALSE;
526 while (mapstr.ReadNextLine())
529 if (ldebug)std::cout<<
" line read so far ="<<lineread<<
"\n";
530 mapstr.TrimComment(
'!');
531 mapstr.TrimWhitespace();
532 if (mapstr.LineIsEmpty())
continue;
535 varname = mapstr.GetTypedNextToken<TString>();
537 varname.Remove(TString::kBoth,
' ');
538 varped= mapstr.GetTypedNextToken<Double_t>();
539 varcal= mapstr.GetTypedNextToken<Double_t>();
540 if (ldebug) std::cout<<
"inputs for channel "<<varname
541 <<
": ped="<<varped<<
": cal="<<varcal<<
"\n";
542 Bool_t notfound=kTRUE;
557 if (ldebug) std::cout<<
" line read in the pedestal + cal file ="<<lineread<<
" \n";
586 for (
size_t i = 0; i <
fMainDetID.size(); i++)
597 for (
size_t i = 0; i <
fMainDetID.size(); i++)
608 for (
size_t i = 0; i <
fMainDetID.size(); i++)
619 std::vector<UInt_t> elements;
623 for (
size_t i = 0; i <
fMainDetID.size(); i++)
631 std::vector<UInt_t> subbankheader;
632 std::vector<UInt_t> rocheader;
633 if (elements.size() > 0)
637 subbankheader.clear();
638 subbankheader.push_back(elements.size() + 1);
639 subbankheader.push_back((
fCurrentBank_ID << 16) | (0x01 << 8) | (1 & 0xff));
644 rocheader.push_back(subbankheader.size() + elements.size() + 1);
645 rocheader.push_back((
fCurrentROC_ID << 16) | (0x10 << 8) | (1 & 0xff));
649 buffer.insert(buffer.end(), rocheader.begin(), rocheader.end());
650 buffer.insert(buffer.end(), subbankheader.begin(), subbankheader.end());
651 buffer.insert(buffer.end(), elements.begin(), elements.end());
675 Bool_t lkDEBUG=kFALSE;
679 if (index>=0 && num_words>0)
683 std::cout <<
"QwMainCerenkovDetector::ProcessEvBuffer: "
684 <<
"Begin processing ROC" << roc_id
685 <<
" and subbank "<<bank_id
686 <<
" number of words="<<num_words<<std::endl;
697 std::cout<<
"found IntegrationPMT data for "<<
fMainDetID[i].fdetectorname<<std::endl;
698 std::cout<<
"word left to read in this buffer:"<<num_words-
fMainDetID[i].fWordInSubbank<<std::endl;
717 if(!status &&
bDEBUG) std::cout<<
"******* QwMainCerenkovDetector::SingleEventCuts()->IntegrationPMT[ "<<i<<
" , "<<
fIntegrationPMT[i].GetElementName()<<
" ] ******\n";
721 if(!status &&
bDEBUG) std::cout<<
"******* QwMainCerenkovDetector::SingleEventCuts()->CombinedPMT[ "<<i<<
" , "<<
fCombinedPMT[i].GetElementName()<<
" ] ******\n";
933 std::cout<<
"QwMainCerenkovDetector::ProcessEvent_2(): processing with exchanged data"<<std::endl;
934 std::cout<<
"pedestal, calfactor, average volts = "<<pedestal<<
", "<<calfactor<<
", "<<volts<<std::endl;
941 QwWarning<<
"QwMainCerenkovDetector::ProcessEvent_2(): could not get all external values."<<
QwLog::endl;
998 tmp=
"QwIntegrationPMT";
1007 tmp=
"QwCombinedPMT";
1041 if (
typeid(*value)!=
typeid(*
this))
1230 if (
Compare(const_cast<VQwSubsystemParity*>(subsys))) {
1233 if (yield == 0)
return;
1250 Bool_t ldebug=kFALSE;
1253 std::cout<<
"QwMainCerenkovDetector::GetDetectorIndex\n";
1254 std::cout<<
"type_id=="<<type_id<<
" name="<<name<<
"\n";
1255 std::cout<<
fMainDetID.size()<<
" already registered detector\n";
1266 std::cout<<
"testing against ("<<
fMainDetID[i].fTypeID
1267 <<
","<<
fMainDetID[i].fdetectorname<<
")=>"<<result<<
"\n";
1276 TString tmpname = name;
1289 QwMessage <<
"QwMainCerenkovDetector::GetIntegrationPMT: cannot find channel " << tmpname <<
QwLog::endl;
1295 TString tmpname = name;
1308 QwMessage <<
"QwMainCerenkovDetector::GetCombinedPMT: cannot find channel " << tmpname <<
QwLog::endl;
1320 catch (std::exception&
e)
1322 std::cerr << e.what() << std::endl;
1329 Bool_t local_print_flag =
false;
1331 if(local_print_flag) {
1332 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
1334 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
1337 std::vector<QwDBInterface> interface;
1338 std::vector<QwParitySSQLS::md_data> entrylist;
1342 TString measurement_type;
1352 for(j=0; j<interface.size(); j++) {
1353 interface.at(j).SetAnalysisID( analysis_id );
1354 interface.at(j).SetMainDetectorID( db );
1355 interface.at(j).SetMeasurementTypeID( measurement_type );
1356 interface.at(j).PrintStatus( local_print_flag );
1357 interface.at(j).AddThisEntryToList( entrylist );
1367 for(j=0; j<interface.size(); j++) {
1368 interface.at(j).SetAnalysisID( analysis_id );
1369 interface.at(j).SetMainDetectorID( db );
1370 interface.at(j).SetMeasurementTypeID( measurement_type );
1371 interface.at(j).PrintStatus( local_print_flag );
1372 interface.at(j).AddThisEntryToList( entrylist );
1375 if(local_print_flag) {
1383 if( entrylist.size() ) {
1384 mysqlpp::Query query= db->
Query();
1385 query.insert(entrylist.begin(), entrylist.end());
1389 QwMessage <<
"QwMainCerenkovDetector::FillDB :: This is the case when the entrlylist contains nothing in "<< datatype.Data() <<
QwLog::endl;
1406 std::cout<<
"Name of the subsystem ="<<
fSystemName<<
"\n";
1408 std::cout<<
"there are "<<
fIntegrationPMT.size()<<
" IntegrationPMT \n";
1409 std::cout<<
" "<<
fCombinedPMT.size()<<
" CombinedPMT \n";
1411 std::cout<<
" Printing Running AVG and other channel info"<<std::endl;
1423 std::cout<<
"============================="<<std::endl;
1424 std::cout<<
" Detector ID="<<i<<std::endl;
1436 Bool_t local_print_flag =
false;
1437 if(local_print_flag){
1438 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
1440 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
1444 std::vector<QwErrDBInterface> interface;
1445 std::vector<QwParitySSQLS::md_errors> entrylist;
1456 for(j=0; j<interface.size(); j++) {
1457 interface.at(j).SetAnalysisID ( analysis_id );
1458 interface.at(j).SetMainDetectorID ( db );
1459 interface.at(j).PrintStatus ( local_print_flag );
1460 interface.at(j).AddThisEntryToList( entrylist );
1470 for(j=0; j<interface.size(); j++) {
1471 interface.at(j).SetAnalysisID ( analysis_id );
1472 interface.at(j).SetMainDetectorID ( db );
1473 interface.at(j).PrintStatus ( local_print_flag );
1474 interface.at(j).AddThisEntryToList( entrylist );
1477 if(local_print_flag) {
1485 if( entrylist.size() ) {
1486 mysqlpp::Query query= db->
Query();
1487 query.insert(entrylist.begin(), entrylist.end());
1491 QwMessage <<
"QwMainCerenkovDetector::FillErrDB :: This is the case when the entrlylist contains nothing in "<< datatype.Data() <<
QwLog::endl;
1503 Bool_t local_print_flag =
true;
1504 if(local_print_flag){
1505 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
1507 QwMessage <<
" --------------------------------------------------------------- " <<
QwLog::endl;
1520 std::cout<<std::endl<<
"Detector name= "<<
fdetectorname<<std::endl;
1523 std::cout<<
"module type= "<<
fmoduletype<<std::endl;
1525 std::cout<<
"Index of this detector in the vector of similar detector= "<<
fIndex<<std::endl;
1526 std::cout<<
"Subelement index= "<<
fSubelement<<std::endl;
1527 std::cout<<
"==========================================\n";
Int_t GetSubbankIndex() const
void ConstructBranch(TTree *tree, TString &prefix)
Construct the branch and tree vector.
#define QwMessage
Predefined log drain for regular messages.
void Normalize(VQwDataElement *denom)
std::map< TString, TString > fDetectorMaps
EQwPMTInstrumentType GetQwPMTInstrumentType(TString name)
UInt_t GetEventcutErrorFlag()
Return the error flag to the top level routines related to stability checks and ErrorFlag updates...
void FillTreeVector(std::vector< Double_t > &values) const
Fill the tree vector.
Bool_t bIsExchangedDataValid
#define default_bool_value(b)
void FillHistograms()
Fill the histograms for this subsystem.
void WritePromptSummary(QwPromptSummary *ps, TString type)
std::vector< Double_t > fWeight
Bool_t Connect()
Open a connection to the database using the predefined parameters.
void SetNormalizability(Bool_t isnormalizable)
void SetRandomEventAsymmetry(Double_t asymmetry)
Int_t LoadEventCuts(TString filename)
Load the event cuts file.
const QwIntegrationPMT * GetChannel(const TString name) const
void IncrementErrorCounters()
Increment the error counters.
static UInt_t GetUInt(const TString &varvalue)
std::string GetNextToken(const std::string &separatorchars)
Get next token as a string.
void Difference(VQwSubsystem *value1, VQwSubsystem *value2)
Class for blinding data, adapted from G0 blinder class.
virtual UInt_t UpdateErrorFlag()
Uses the error flags of contained data elements to update Returns the error flag to the top level rou...
void TrimComment(const char commentchar)
const QwIntegrationPMT * GetIntegrationPMT(const TString name) const
std::vector< QwIntegrationPMT > fIntegrationPMT
Virtual base class for the parity subsystems.
QwBeamCharge fTargetCharge
void Blind(const QwBlinder *blinder)
Blind the asymmetry.
void ProcessOptions(QwOptions &options)
EQwPMTInstrumentType GetDetectorTypeID(TString name)
TString GetQwPMTInstrumentTypeName(EQwPMTInstrumentType type)
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
std::vector< QwMainCerenkovDetectorID > fMainDetID
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
void SetRandomEventParameters(Double_t mean, Double_t sigma)
static void PrintErrorCounterHead()
void FillDB(QwParityDB *db, TString datatype)
Fill the database.
QwParameterFile * ReadNextSection(std::string &secname, const bool keep_header=false)
std::vector< QwCombinedPMT > fCombinedPMT
T GetValue(const std::string &key)
Get a templated value.
Bool_t PublishInternalValues() const
void PrintValue() const
Print values of all channels.
Bool_t FileHasModuleHeader(const std::string &secname)
The pure virtual base class of all data elements.
#define QwDebug
Predefined log drain for debugging output.
static void DefineOptions()
Define options function (note: no virtual static functions in C++)
A logfile class, based on an identical class in the Hermes analyzer.
void FillErrDB(QwParityDB *db, TString datatype)
Int_t LoadChannelMap(TString mapfile)
Mandatory map file definition.
void DoNormalization(Double_t factor=1.0)
VQwSubsystem & operator-=(VQwSubsystem *value)
TString fSystemName
Name of this subsystem.
void PrintInfo() const
Print some information about the subsystem.
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Construct the branch and tree vector.
mysqlpp::Query Query(const char *qstr=0)
void SetBlindability(Bool_t isblindable)
void SetBlindability(Bool_t isblindable)
void CalculateRunningAverage()
Calculate the average for all good events.
Bool_t Compare(VQwSubsystem *source)
void ProcessEvent_2()
Process the event data again, including data from other subsystems. Not all derived classes will requ...
std::vector< std::vector< TString > > fPublishList
List of parameters to be published (loaded at the channel map)
const QwCombinedPMT * GetCombinedPMT(const TString name) const
void PrintErrorCounters() const
Report the number of events failed due to HW and event cut failures.
The pure virtual base class of all subsystems.
Bool_t ApplySingleEventCuts()
Apply the single event cuts.
A color changing class for the output stream.
Int_t fCurrentROC_ID
ROC ID that is currently being processed.
Int_t RegisterSubbank(const UInt_t bank_id)
Tell the object that it will decode data from this sub-bank in the ROC currently open for registratio...
virtual Int_t RegisterROCNumber(const UInt_t roc_id, const UInt_t bank_id=0)
Tell the object that it will decode data from this ROC and sub-bank.
void SetNormalizability(Bool_t isnormalizable)
static std::ostream & endl(std::ostream &)
End of the line.
void ExchangeProcessedData()
void PrintDetectorID() const
std::vector< TString > fCombinedChannelNames
VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
const QwVQWK_Channel * GetChannel(const TString name) const
Int_t LoadInputParameters(TString pedestalfile)
Mandatory parameter file definition.
Bool_t RequestExternalValue(const TString &name, VQwHardwareChannel *value) const
Request a named value which is owned by an external subsystem; the request will be handled by the par...
VQwSubsystem & operator+=(VQwSubsystem *value)
Int_t GetDetectorIndex(EQwPMTInstrumentType TypeID, TString name)
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
void AccumulateRunningSum(VQwSubsystem *value)
Update the running sums for devices.
static TString DetermineMeasurementTypeID(TString type, TString suffix="", Bool_t forcediffs=kFALSE)
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom)
Int_t ProcessEvBuffer(const UInt_t roc_id, const UInt_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...
void DeaccumulateRunningSum(VQwSubsystem *value)
remove one entry from the running sums for devices
void EncodeEventData(std::vector< UInt_t > &buffer)
Bool_t PublishInternalValue(const TString &name, const TString &desc, const VQwHardwareChannel *value) const
Publish a variable name to the parent subsystem array.
static void PrintErrorCounterTail()
static Int_t GetBufferOffset(Int_t moduleindex, Int_t channelindex)
const QwVQWK_Channel * GetChannel(const TString name) const
EQwPMTInstrumentType fTypeID
#define QwWarning
Predefined log drain for warnings.
void Scale(Double_t factor)
void RandomizeEventData(int helicity=0, Double_t time=0.0)
Int_t fCurrentBank_ID
Bank ID that is currently being processed.
static const Bool_t bDEBUG
QwParameterFile * ReadUntilNextModule(const bool add_current_line=false)
#define RegisterSubsystemFactory(A)
#define QwError
Predefined log drain for errors.
UInt_t GetGlobalErrorFlag(TString evtype, Int_t evMode, Double_t stabilitycut)
TString GetSubsystemName() const
void Sum(VQwSubsystem *value1, VQwSubsystem *value2)