36 #include "THaEvtTypeHandler.h"
49 #include "THaGlobals.h"
61 #include "THaVarList.h"
78 : THaEvtTypeHandler(name,description),
79 fBCM_Gain(0), fBCM_Offset(0), fBCM_SatOffset(0), fBCM_SatQuadratic(0), fBCM_delta_charge(0),
80 evcount(0), evcountR(0.0), ifound(0), fNormIdx(-1),
82 dvars(0),dvars_prev_read(0), dvarsFirst(0), fScalerTree(0), fUseFirstEvent(
kTRUE),
83 fOnlySyncEvents(
kFALSE), fOnlyBanks(
kFALSE), fDelayedType(-1),
84 fClockChan(-1), fLastClock(0), fClockOverflows(0)
100 Podd::DeleteContainer(
scalers);
121 cout <<
"THcScalerEvtHandler::End Analyzing " <<
fDelayedEvents.size() <<
" delayed scaler events" << endl;
127 if (fDebugFile) *fDebugFile <<
"scaler tree ptr "<<
fScalerTree<<endl;
167 {
"BCM_Names", &bcm_namelist, kString},
179 vector<string> bcm_names = Podd::vsplit(bcm_namelist);
181 fBCM_Name.push_back(bcm_names[i]+
".scal");
212 if ( !IsMyEvent(evdata->
GetEvType()) )
return -1;
215 *fDebugFile << endl <<
"---------------------------------- "<<endl<<endl;
216 *fDebugFile <<
"\nEnter THcScalerEvtHandler for fName = "<<fName<<endl;
226 TString sname2 = sname1 + fName;
227 TString sname3 = fName +
" Scaler Data";
230 *fDebugFile <<
"\nAnalyze 1st time for fName = "<<fName<<endl;
231 *fDebugFile << sname2 <<
" " <<sname3<<endl;
247 for (
size_t i = 0; i <
scalerloc.size(); i++) {
262 memcpy(datacopy,rdata,evlen*
sizeof(
UInt_t));
265 if (fDebugFile) *fDebugFile<<
"\n\nTHcScalerEvtHandler :: Debugging event type "<<dec<<evdata->
GetEvType()<<
" event num = " << evdata->
GetEvNum() << endl<<endl;
268 if (fDebugFile) *fDebugFile <<
"scaler tree ptr "<<
fScalerTree<<endl;
288 *fDebugFile <<
"Bank: " << hex << *p << dec <<
" len: " << *(p-1) << endl;
290 if((*p & 0xff00) == 0x1000) {
292 }
else if (((*p & 0xff00) == 0x100) && (*p != 0xC0000100)) {
300 UInt_t tag = (*p>>16) & 0xffff;
309 if(onlysync && num==0) {
333 *fDebugFile <<
"Scaler Header: " << hex << *p << dec;
335 for(
size_t j=0; j<
scalers.size(); j++) {
337 nskip =
scalers[j]->GetNumChan() + 1;
340 *fDebugFile <<
" found (" << j <<
") skip " << nskip << endl;
363 *fDebugFile <<
"Finished with decoding. "<<endl;
364 *fDebugFile <<
" Found flag = "<<
ifound<<endl;
383 cout <<
" ******************* Severe Warning ****************************" << endl;
384 cout <<
" In THcScalerEvtHandler have found fDeltaTime is zero !! " << endl;
385 cout <<
" ******************* Alert DAQ experts ****************************" << endl;
389 for (
size_t i = 0; i <
scalerloc.size(); i++) {
394 if (fDebugFile) *fDebugFile <<
"Debug dvarsFirst "<<i<<
" "<<ivar<<
" "<<idx<<
" "<<ichan<<endl;
401 dvars[ivar] = scaldata;
421 if (match!=string::npos)
446 if (fDebugFile) *fDebugFile <<
" dvarsFirst "<<
scalerloc[ivar]->ikind<<
" "<<
dvarsFirst[ivar]<<endl;
467 if (match!=string::npos)
489 if (fDebugFile) *fDebugFile <<
" dvarsFirst "<<
scalerloc[ivar]->ikind<<
" "<<
dvarsFirst[ivar]<<endl;
493 cout <<
"THcScalerEvtHandler:: ERROR:: incorrect index "<<ivar<<
" "<<idx<<
" "<<ichan<<endl;
496 if (fDebugFile) *fDebugFile <<
"Debug dvars "<<i<<
" "<<ivar<<
" "<<idx<<
" "<<ichan<<endl;
530 if (match!=string::npos)
550 dvars[ivar]=cur_temp;
575 if (fDebugFile) *fDebugFile <<
" dvars "<<
scalerloc[ivar]->ikind<<
" "<<
dvars[ivar]<<endl;
577 cout <<
"THcScalerEvtHandler:: ERROR:: incorrect index "<<ivar<<
" "<<idx<<
" "<<ichan<<endl;
583 for (
size_t i = 0; i <
scalerloc.size(); i++) {
605 if (match!=string::npos)
647 cout <<
"Howdy ! We are initializing THcScalerEvtHandler !! name = "
650 if(eventtypes.size()==0) {
651 eventtypes.push_back(0);
655 dfile = fName +
"scaler.txt";
661 sname = fName+sname0;
663 FILE *fi = Podd::OpenDBFile(sname.
Data(), date);
665 cout <<
"Cannot find db file for "<<fName<<
" scaler event handler"<<endl;
671 string scomment =
"#";
672 string svariable =
"variable";
674 vector<string> dbline;
676 while( fgets(cbuf, LEN, fi) != NULL) {
677 std::string
sin(cbuf);
678 std::string sinput(sin.substr(0,sin.find_first_of(
"#")));
679 if (fDebugFile) *fDebugFile <<
"string input "<<sinput<<endl;
680 dbline = Podd::vsplit(sinput);
681 if (dbline.size() > 0) {
683 if (pos1 != minus1)
continue;
685 if (pos1 != minus1 && dbline.size()>4) {
687 for (
size_t j=5; j<dbline.size(); j++) sdesc = sdesc+
" "+dbline[j];
688 UInt_t islot = atoi(dbline[1].c_str());
689 UInt_t ichan = atoi(dbline[2].c_str());
690 UInt_t ikind = atoi(dbline[3].c_str());
692 *fDebugFile <<
"add var "<<dbline[1]<<
" desc = "<<sdesc<<
" islot= "<<islot<<
" "<<ichan<<
" "<<ikind<<endl;
693 TString tsname(dbline[4].c_str());
695 AddVars(tsname,tsdesc,islot,ichan,ikind);
703 if (fDebugFile) *fDebugFile <<
"map ? "<<dbline[0]<<
" "<<smap<<
" "<<pos1<<
" "<<dbline.size()<<endl;
704 if (pos1 != minus1 && dbline.size()>6) {
705 Int_t imodel, icrate, islot, inorm;
708 sscanf(sinput.c_str(),
"%s %d %d %d %x %x %d \n",cdum,&imodel,&icrate,&islot, &header, &mask, &inorm);
709 if ((
fNormSlot >= 0) && (
fNormSlot != inorm)) cout <<
"THcScalerEvtHandler::WARN: contradictory norm slot "<<
fNormSlot<<
" "<<inorm<<endl;
713 if (dbline.size()>8) {
714 clkchan = atoi(dbline[7].c_str());
715 clkfreq = 1.0*atoi(dbline[8].c_str());
720 *fDebugFile <<
"map line "<<dec<<imodel<<
" "<<icrate<<
" "<<islot<<endl;
721 *fDebugFile <<
" header 0x"<<hex<<header<<
" 0x"<<mask<<dec<<
" "<<inorm<<
" "<<clkchan<<
" "<<clkfreq<<endl;
759 scalers[idx]->SetHeader(header, mask);
765 cout <<
"Setting scaler clock ... channel = "<<clkchan<<
" ... freq = "<<clkfreq<<endl;
766 if (fDebugFile) *fDebugFile <<
"Setting scaler clock ... channel = "<<clkchan<<
" ... freq = "<<clkfreq<<endl;
768 if (islot !=
fNormSlot) cout <<
"THcScalerEvtHandler:: WARN: contradictory norm slot ! "<<islot<<endl;
779 if (fDebugFile) *fDebugFile <<
"fNormIdx = "<<
fNormIdx<<endl;
789 if (fName ==
"Left") {
807 if (fName ==
"Left") {
812 scalers[0]->SetHeader(0xabc00000, 0xffff0000);
813 scalers[1]->SetHeader(0xabc10000, 0xffff0000);
814 scalers[2]->SetHeader(0xabc20000, 0xffff0000);
815 scalers[3]->SetHeader(0xabc30000, 0xffff0000);
817 scalers[1]->SetClock(4, 7, 1024);
825 scalers[0]->SetHeader(0xceb00000, 0xffff0000);
826 scalers[1]->SetHeader(0xceb10000, 0xffff0000);
827 scalers[2]->SetHeader(0xceb20000, 0xffff0000);
828 scalers[3]->SetHeader(0xceb30000, 0xffff0000);
829 scalers[0]->SetClock(4, 7, 1024);
840 cout <<
"THcScalerEvtHandler:: WARN: same slot defined twice"<<endl;
851 if(fDebugFile) *fDebugFile <<
"THcScalerEvtHandler:: Name of scaler bank "<<fName<<endl;
852 for (
size_t i=0; i<
scalers.size(); i++) {
854 *fDebugFile <<
"Scaler # "<<i<<endl;
855 scalers[i]->SetDebugFile(fDebugFile);
856 scalers[i]->DebugPrint(fDebugFile);
881 if (
Nvars == 0)
return;
889 if(fDebugFile) *fDebugFile <<
"THcScalerEVtHandler:: Have gHaVars "<<gHaVars<<endl;
891 cout <<
"No gHaVars ?! Well, that's a problem !!"<<endl;
894 if(fDebugFile) *fDebugFile <<
"THcScalerEvtHandler:: scalerloc size "<<
scalerloc.size()<<endl;
895 const Int_t* count = 0;
896 for (
size_t i = 0; i <
scalerloc.size(); i++) {
898 &
dvars[i], kDouble, count);
907 string sdatalc, skeylc;
908 sdatalc =
""; skeylc =
"";
909 for (string::const_iterator p =
910 sdata.begin(); p != sdata.end(); ++p) {
911 sdatalc += tolower(*p);
913 for (string::const_iterator p =
914 skey.begin(); p != skey.end(); ++p) {
915 skeylc += tolower(*p);
917 if (sdatalc.find(skeylc,0) == string::npos)
return -1;
918 return sdatalc.find(skeylc,0);
static const UInt_t ICURRENT
std::vector< HCScalerLoc * > scalerloc
virtual void SetAutoSave(Long64_t autos=-300000000)
std::set< UInt_t > fModuleSet
static const UInt_t ITIME
static const UInt_t ICHARGE
std::vector< std::string > fBCM_Name
std::vector< Decoder::GenScaler * > scalers
virtual Int_t ReadDatabase(const TDatime &date)
Double_t * fBCM_SatQuadratic
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
std::vector< UInt_t * > fDelayedEvents
virtual void SetDelayedType(int evtype)
const char * Data() const
static Bool_t Initialized()
void AddVars(TString name, TString desc, UInt_t iscal, UInt_t ichan, UInt_t ikind)
static const UInt_t ICOUNT
std::vector< UInt_t > scal_prev_read
static const UInt_t MAXCHAN
UInt_t GetEvLength() const
Double_t * fBCM_SatOffset
Int_t fbcm_Current_Threshold_Index
std::vector< UInt_t > scal_present_read
const UInt_t * GetRawDataBuffer() const
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
static const UInt_t IRATE
static const UInt_t defaultDT
std::vector< UInt_t > scal_overflows
THcScalerEvtHandler(const char *, const char *)
static size_t FindNoCase(const std::string &sdata, const std::string &skey)
virtual EStatus Init(const TDatime &run_time)
Int_t LoadParmValues(const DBRequest *list, const char *prefix="")
Retrieve parameter values from the parameter cache.
Double_t * fBCM_delta_charge
ClassImp(THcDCLookupTTDConv) THcDCLookupTTDConv
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Event handler for Hall C scalers.
virtual Int_t End(THaRunBase *r=0)
Short_t Max(Short_t a, Short_t b)
std::set< UInt_t > fRocSet
R__EXTERN class THcParmList * gHcParms
Double_t fbcm_Current_Threshold
Int_t Analyze(THaEvData *evdata)
virtual ~THcScalerEvtHandler()
Int_t AnalyzeBuffer(UInt_t *rdata, Bool_t onlysync)