#include "THaEvData.h"
#include "THaFastBusWord.h"
#include "THaCrateMap.h"
#include "THaUsrstrutils.h"
#include "THaBenchmark.h"
#include "TError.h"
#include <cstring>
#include <cstdio>
#include <cctype>
#include <iostream>
#include <iomanip>
#include <ctime>
#ifndef STANDALONE
#include "THaVarList.h"
#include "THaGlobals.h"
#endif
using namespace std;
TBits THaEvData::fgInstances;
const Double_t THaEvData::kBig = 1e38;
#ifndef NDEBUG
Bool_t THaEvData::fgAllowUnimpl = false;
#else
Bool_t THaEvData::fgAllowUnimpl = true;
#endif
const TString THaEvData::fgDefaultCrateMapName = "cratemap";
TString THaEvData::fgCrateMapName;
Bool_t THaEvData::fgNeedInit = true;
THaEvData::THaEvData() :
first_load(true), first_decode(true), fTrigSupPS(true),
buffer(0), run_num(0), run_type(0), fRunTime(0), evt_time(0),
recent_event(0), fNSlotUsed(0), fNSlotClear(0), fMap(0),
fDoBench(kFALSE), fBench(0)
{
fInstance = fgInstances.FirstNullBit();
fgInstances.SetBitNumber(fInstance);
fInstance++;
cmap = new THaCrateMap( fgDefaultCrateMapName );
crateslot = new THaSlotData*[MAXROC*MAXSLOT];
fSlotUsed = new UShort_t[MAXROC*MAXSLOT];
fSlotClear = new UShort_t[MAXROC*MAXSLOT];
memset(crateslot,0,MAXROC*MAXSLOT*sizeof(THaSlotData*));
fRunTime = time(0);
#ifndef STANDALONE
if( gHaVars ) {
VarDef vars[] = {
{ "runnum", "Run number", kInt, 0, &run_num },
{ "runtype", "CODA run type", kInt, 0, &run_type },
{ "runtime", "CODA run time", kULong, 0, &fRunTime },
{ "evnum", "Event number", kInt, 0, &event_num },
{ "evtyp", "Event type", kInt, 0, &event_type },
{ "evlen", "Event Length", kInt, 0, &event_length },
{ "evtime", "Event time", kULong, 0, &evt_time },
{ 0 }
};
TString prefix("g");
if( fInstance > 1 )
prefix.Append(Form("%d",fInstance));
prefix.Append(".");
gHaVars->DefineVariables( vars, prefix, "THaEvData::THaEvData" );
} else
Warning("THaEvData::THaEvData","No global variable list found. "
"Variables not registered.");
#endif
ResetBit(kVerbose);
ResetBit(kDebug);
}
THaEvData::~THaEvData() {
if( fDoBench ) {
Float_t a,b;
fBench->Summary(a,b);
}
delete fBench;
#ifndef STANDALONE
if( gHaVars ) {
TString prefix("g");
if( fInstance > 1 )
prefix.Append(Form("%d",fInstance));
prefix.Append(".*");
gHaVars->RemoveRegexp( prefix );
}
#endif
for( int i=0; i<MAXROC*MAXSLOT; i++ )
delete crateslot[i];
delete [] crateslot;
delete cmap;
delete [] fSlotUsed;
delete [] fSlotClear;
fInstance--;
fgInstances.ResetBitNumber(fInstance);
}
const char* THaEvData::DevType(int crate, int slot) const {
return ( GoodIndex(crate,slot) ) ?
crateslot[idx(crate,slot)]->devType() : " ";
}
void THaEvData::SetRunTime( ULong64_t tloc )
{
if( fRunTime == tloc )
return;
fRunTime = tloc;
init_cmap();
}
void THaEvData::EnableBenchmarks( Bool_t enable )
{
fDoBench = enable;
if( fDoBench ) {
if( !fBench )
fBench = new THaBenchmark;
} else {
delete fBench;
fBench = 0;
}
}
void THaEvData::EnableHelicity( Bool_t enable )
{
SetBit(kHelicityEnabled, enable);
}
void THaEvData::EnableScalers( Bool_t enable )
{
SetBit(kScalersEnabled, enable);
}
void THaEvData::SetVerbose( UInt_t level )
{
SetBit(kVerbose,(level!=0));
}
void THaEvData::SetDebug( UInt_t level )
{
SetBit(kDebug,(level!=0));
}
void THaEvData::SetOrigPS(Int_t evtyp)
{
fTrigSupPS = true;
if (evtyp == PRESCALE_EVTYPE) {
fTrigSupPS = false;
return;
} else if (evtyp != TS_PRESCALE_EVTYPE) {
cout << "SetOrigPS::Warn: PS factors";
cout << " originate only from evtype ";
cout << PRESCALE_EVTYPE << " or ";
cout << TS_PRESCALE_EVTYPE << endl;
}
}
TString THaEvData::GetOrigPS() const
{
TString answer = "PS from ";
if (fTrigSupPS) {
answer += " Trig Sup evtype ";
answer.Append(Form("%d",TS_PRESCALE_EVTYPE));
} else {
answer += " PS evtype ";
answer.Append(Form("%d",PRESCALE_EVTYPE));
}
return answer;
}
void THaEvData::hexdump(const char* cbuff, size_t nlen)
{
const int NW = 16; const char* p = cbuff;
while( p<cbuff+nlen ) {
cout << dec << setw(4) << setfill('0') << (size_t)(p-cbuff) << " ";
int nelem = TMath::Min((Long_t)NW,(Long_t)(cbuff+nlen-p));
for(int i=0; i<NW; i++) {
UInt_t c = (i<nelem) ? *(const unsigned char*)(p+i) : 0;
cout << " " << hex << setfill('0') << setw(2) << c << dec;
} cout << setfill(' ') << " ";
for(int i=0; i<NW; i++) {
char c = (i<nelem) ? *(p+i) : 0;
if(isgraph(c)||c==' ') cout << c; else cout << ".";
} cout << endl;
p += NW;
}
}
void THaEvData::SetCrateMapName( const char* name ) {
if( name && *name ) {
if( fgCrateMapName != name ) {
fgCrateMapName = name;
fgNeedInit = true;
}
} else if( fgCrateMapName != fgDefaultCrateMapName ) {
fgCrateMapName = fgDefaultCrateMapName;
fgNeedInit = true;
}
}
int THaEvData::init_cmap() {
if( fgCrateMapName.IsNull() )
fgCrateMapName = fgDefaultCrateMapName;
if( !fMap || fgNeedInit || fgCrateMapName != fMap->GetName() ) {
delete fMap;
fMap = new THaCrateMap( fgCrateMapName );
}
if (TestBit(kDebug)) cout << "Init crate map " << endl;
if( fMap->init(GetRunTime()) == THaCrateMap::CM_ERR )
return HED_FATAL;
fgNeedInit = false;
return HED_OK;
}
void THaEvData::makeidx(int crate, int slot)
{
int idx = slot+MAXSLOT*crate;
delete crateslot[idx];
crateslot[idx] = new THaSlotData(crate,slot);
if( !fMap ) return;
if( fMap->crateUsed(crate) && fMap->slotUsed(crate,slot)) {
crateslot[idx]
->define( crate, slot, fMap->getNchan(crate,slot),
fMap->getNdata(crate,slot) );
fSlotUsed[fNSlotUsed++] = idx;
if( fMap->slotClear(crate,slot))
fSlotClear[fNSlotClear++] = idx;
}
}
void THaEvData::PrintOut() const {
cout << "THaEvData::PrintOut() called" << endl;
}
void THaEvData::PrintSlotData(int crate, int slot) const {
if( GoodIndex(crate,slot)) {
crateslot[idx(crate,slot)]->print();
} else {
cout << "THaEvData: Warning: Crate, slot combination";
cout << "\nexceeds limits. Cannot print"<<endl;
}
return;
}
int THaEvData::init_slotdata(const THaCrateMap* map)
{
if(!map) return HED_ERR;
for( int i=0; i<fNSlotUsed; i++ ) {
THaSlotData* module = crateslot[fSlotUsed[i]];
int crate = module->getCrate();
int slot = module->getSlot();
if( !map->crateUsed(crate) || !map->slotUsed(crate,slot) ||
!map->slotClear(crate,slot)) {
for( int k=0; k<fNSlotClear; k++ ) {
if( module == crateslot[fSlotClear[k]] ) {
for( int j=k+1; j<fNSlotClear; j++ )
fSlotClear[j-1] = fSlotClear[j];
fNSlotClear--;
break;
}
}
}
if( !map->crateUsed(crate) || !map->slotUsed(crate,slot)) {
for( int j=i+1; j<fNSlotUsed; j++ )
fSlotUsed[j-1] = fSlotUsed[j];
fNSlotUsed--;
}
}
return HED_OK;
}
ClassImp(THaEvData)
ClassImp(THaBenchmark)
Last change: Sat Nov 7 21:26:45 2009
Last generated: 2009-11-07 21:26
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.