#include <stdlib.h>
#include "AliRunTag.h"
#include "AliDetectorTag.h"
#include "AliEventTag.h"
ClassImp(AliRunTag)
AliRunTag::AliRunTag() :
TObject(),
fAliceRunId(-1),
fAliceMagneticField(0.0),
fAliceDipoleField(0.0),
fAliceRunStartTime(0),
fAliceRunStopTime(0),
fAlirootVersion(0),
fRootVersion(0),
fGeant3Version(0),
fLHCPeriod(0),
fRecPass(0),
fProductionName(0),
fAliceRunValidated(0),
fAliceRunGlobalQuality(0),
fAliceBeamEnergy(0.0),
fAliceBeamType(0),
fAliceCalibrationVersion(0),
fAliceDataType(0),
fNumFiles(0),
fBeamTriggers(0),
fCollisionTriggers(0),
fEmptyTriggers(0),
fASideTriggers(0),
fCSideTriggers(0),
fHMTriggers(0),
fMuonTriggers(0),
fCollisionRate(0.0),
fMeanVertex(0.0),
fVertexQuality(0.0),
fNumDetectors(0),
fFileTags(100),
fDetectorTag(),
fLHCTag(),
fActiveTriggerClasses(""),
fQA(),
fQALength(0),
fQAArray(NULL),
fESLength(0),
fEventSpecies(NULL)
{
}
AliRunTag::~AliRunTag() {
if ( fQAArray )
delete [] fQAArray ;
if ( fEventSpecies )
delete [] fEventSpecies ;
fFileTags.Delete();
}
AliRunTag::AliRunTag(const AliRunTag& tag):
TObject(),
fAliceRunId(tag.fAliceRunId),
fAliceMagneticField(tag.fAliceMagneticField),
fAliceDipoleField(tag.fAliceDipoleField),
fAliceRunStartTime(tag.fAliceRunStartTime),
fAliceRunStopTime(tag.fAliceRunStopTime),
fAlirootVersion(tag.fAlirootVersion),
fRootVersion(tag.fRootVersion),
fGeant3Version(tag.fGeant3Version),
fLHCPeriod(tag.fLHCPeriod),
fRecPass(tag.fRecPass),
fProductionName(tag.fProductionName),
fAliceRunValidated(tag.fAliceRunValidated),
fAliceRunGlobalQuality(tag.fAliceRunGlobalQuality),
fAliceBeamEnergy(tag.fAliceBeamEnergy),
fAliceBeamType(tag.fAliceBeamType),
fAliceCalibrationVersion(tag.fAliceCalibrationVersion),
fAliceDataType(tag.fAliceDataType),
fNumFiles(0),
fBeamTriggers(tag.fBeamTriggers),
fCollisionTriggers(tag.fCollisionTriggers),
fEmptyTriggers(tag.fEmptyTriggers),
fASideTriggers(tag.fASideTriggers),
fCSideTriggers(tag.fCSideTriggers),
fHMTriggers(tag.fHMTriggers),
fMuonTriggers(tag.fMuonTriggers),
fCollisionRate(tag.fCollisionRate),
fMeanVertex(tag.fMeanVertex),
fVertexQuality(tag.fVertexQuality),
fNumDetectors(tag.fNumDetectors),
fFileTags(100),
fDetectorTag(tag.fDetectorTag),
fLHCTag(tag.fLHCTag),
fActiveTriggerClasses(tag.fActiveTriggerClasses),
fQA(tag.fQA),
fQALength(tag.fQALength),
fQAArray(NULL),
fESLength(tag.fESLength),
fEventSpecies(NULL)
{
if (fQALength == 0 )
fQAArray = NULL ;
else {
fQAArray = new ULong_t[fQALength] ;
memcpy(fQAArray, tag.fQAArray, fQALength*sizeof(ULong_t)) ;
}
if (fESLength == 0 )
fEventSpecies = NULL ;
else {
fEventSpecies = new Bool_t[fESLength] ;
memcpy(fEventSpecies, tag.fEventSpecies, fESLength*sizeof(Bool_t)) ;
}
for (int ifl=0; ifl<tag.fNumFiles; ifl++) {
AddFileTag(new AliFileTag(*tag.GetFileTag(ifl)));
}
}
AliRunTag& AliRunTag::operator = (const AliRunTag& tag) {
if(&tag != this) {
fAliceRunId = tag.fAliceRunId ;
fAliceMagneticField = tag.fAliceMagneticField ;
fAliceDipoleField = tag.fAliceDipoleField ;
fAliceRunStartTime = tag.fAliceRunStartTime ;
fAliceRunStopTime = tag.fAliceRunStopTime ;
fAlirootVersion = tag.fAlirootVersion ;
fRootVersion = tag.fRootVersion ;
fGeant3Version = tag.fGeant3Version ;
fLHCPeriod = tag.fLHCPeriod ;
fRecPass = tag.fRecPass ;
fProductionName = tag.fProductionName ;
fAliceRunValidated = tag.fAliceRunValidated ;
fAliceRunGlobalQuality = tag.fAliceRunGlobalQuality ;
fAliceBeamEnergy = tag.fAliceBeamEnergy ;
fAliceBeamType = tag.fAliceBeamType ;
fAliceCalibrationVersion = tag.fAliceCalibrationVersion ;
fAliceDataType = tag.fAliceDataType ;
fBeamTriggers = tag.fBeamTriggers;
fCollisionTriggers = tag.fCollisionTriggers;
fEmptyTriggers = tag.fEmptyTriggers;
fASideTriggers = tag.fASideTriggers;
fCSideTriggers = tag.fCSideTriggers;
fHMTriggers = tag.fHMTriggers;
fMuonTriggers = tag.fMuonTriggers;
fCollisionRate = tag.fCollisionRate;
fMeanVertex = tag.fMeanVertex;
fVertexQuality = tag.fVertexQuality;
fNumDetectors = tag.fNumDetectors ;
fDetectorTag = tag.fDetectorTag ;
fLHCTag = tag.fLHCTag ;
fActiveTriggerClasses = tag.fActiveTriggerClasses;
fQA = tag.fQA ;
fQALength = tag.fQALength ;
if (fQAArray)
delete [] fQAArray ;
if (fQALength == 0 )
fQAArray = NULL ;
else {
fQAArray = new ULong_t[fQALength] ;
memcpy(fQAArray, tag.fQAArray, fQALength*sizeof(ULong_t)) ;
}
fESLength = tag.fESLength ;
if (fEventSpecies)
delete [] fEventSpecies ;
if (fESLength == 0 )
fEventSpecies = NULL ;
else {
fEventSpecies = new Bool_t[fESLength] ;
memcpy(fEventSpecies, tag.fEventSpecies, fESLength*sizeof(Bool_t)) ;
}
for (int ifl=0; ifl<tag.fNumFiles; ifl++) {
AddFileTag(new AliFileTag(*tag.GetFileTag(ifl)));
}
}
return *this ;
}
Bool_t AliRunTag::Add(const AliRunTag* tag)
{
if (fAliceRunId==-1) {
*this = *tag;
return kTRUE;
}
if (fAliceRunId != tag->fAliceRunId) {
AliWarning(Form("Run IDs are different: %d %d",fAliceRunId,tag->fAliceRunId));
return kFALSE;
}
fBeamTriggers += tag->fBeamTriggers;
fCollisionTriggers += tag->fCollisionTriggers;
fEmptyTriggers += tag->fEmptyTriggers;
fASideTriggers += tag->fASideTriggers;
fCSideTriggers += tag->fCSideTriggers;
fHMTriggers += tag->fHMTriggers;
fMuonTriggers += tag->fMuonTriggers;
AliFileTag* eftag = 0;
for (int i=0;i<tag->fNumFiles;i++) {
AliFileTag* tftag = (AliFileTag*)tag->GetFileTag(i);
if (fNumFiles>0) eftag = (AliFileTag*)GetFileTag(fNumFiles-1);
else {
eftag = new AliFileTag();
eftag->SetMD5("");
eftag->SetTURL("");
eftag->SetSize(0);
AddFileTag(eftag);
}
int nev = tftag->GetNEvents();
for (int j=0;j<nev;j++) {
AliEventTag* tge = (AliEventTag*)tftag->GetEventTag(j);
if (tge) eftag->AddEventTag(*tge);
}
}
return kTRUE;
}
void AliRunTag::CopyStandardContent(AliRunTag *oldtag) {
SetRunId(oldtag->GetRunId());
SetMagneticField(oldtag->GetMagneticField());
SetDipoleField(oldtag->GetDipoleField());
SetRunStartTime(oldtag->GetRunStartTime());
SetRunStopTime(oldtag->GetRunStopTime());
SetAlirootVersion(oldtag->GetAlirootVersion());
SetRootVersion(oldtag->GetRootVersion());
SetGeant3Version(oldtag->GetGeant3Version());
SetLHCPeriod(oldtag->GetLHCPeriod());
SetReconstructionPass(oldtag->GetReconstructionPass());
SetProductionName(oldtag->GetProductionName());
SetRunValidation(oldtag->GetRunValidation());
SetRunQuality(oldtag->GetRunQuality());
SetBeamEnergy(oldtag->GetBeamEnergy());
SetBeamType(oldtag->GetBeamType());
SetCalibVersion(oldtag->GetCalibVersion());
SetDataType(oldtag->GetDataType());
SetBeamTriggers(oldtag->GetBeamTriggers());
SetCollisionTriggers(oldtag->GetCollisionTriggers());
SetEmptyTriggers(oldtag->GetEmptyTriggers());
SetASideTriggers(oldtag->GetASideTriggers());
SetCSideTriggers(oldtag->GetCSideTriggers());
SetHMTriggers(oldtag->GetHMTriggers());
SetMuonTriggers(oldtag->GetMuonTriggers());
SetCollisionRate(oldtag->GetCollisionRate());
SetMeanVertex(oldtag->GetMeanVertex());
SetVertexQuality(oldtag->GetVertexQuality());
SetLHCTag(oldtag->GetLHCTag()->GetLuminosity(),oldtag->GetLHCTag()->GetLHCState());
SetDetectorTag(oldtag->GetDetectorTags()->GetIntDetectorMaskDAQ(), oldtag->GetDetectorTags()->GetIntDetectorMaskReco());
SetActiveTriggerClasses(oldtag->GetActiveTriggerClasses());
SetQA(*(oldtag->GetQA())) ;
SetQAArray(oldtag->GetQAArray(), oldtag->GetQALength()) ;
SetEventSpecies(oldtag->GetEventSpecies(), oldtag->GetESLength()) ;
for (int ifile=0; ifile<oldtag->GetNFiles(); ifile++) {
AliFileTag *ntag = new AliFileTag();
ntag->CopyFileInfo((const AliFileTag &) *(oldtag->GetFileTag(ifile)));
AddFileTag(ntag);
}
}
void AliRunTag::UpdateFromRunTable(AliRunTag *tabtag)
{
SetBeamTriggers(tabtag->GetBeamTriggers());
SetCollisionTriggers(tabtag->GetCollisionTriggers());
SetEmptyTriggers(tabtag->GetEmptyTriggers());
SetASideTriggers(tabtag->GetASideTriggers());
SetCSideTriggers(tabtag->GetCSideTriggers());
SetHMTriggers(tabtag->GetHMTriggers());
SetMuonTriggers(tabtag->GetMuonTriggers());
SetCollisionRate(tabtag->GetCollisionRate());
SetMeanVertex(tabtag->GetMeanVertex());
SetVertexQuality(tabtag->GetVertexQuality());
SetRunQuality(tabtag->GetRunQuality());
fLHCTag.UpdateFromRunTable(*tabtag->GetLHCTag());
fDetectorTag.UpdateFromRunTable(*tabtag->GetDetectorTags());
}
void AliRunTag::SetQAArray(ULong_t * qa, Int_t qalength) {
if (qa && qalength > 0) {
fQALength = qalength ;
if (fQAArray)
delete [] fQAArray ;
fQAArray = new ULong_t[qalength] ;
memcpy(fQAArray, qa, qalength*sizeof(ULong_t)) ;
}
}
void AliRunTag::SetEventSpecies(Bool_t * es, Int_t eslength) {
if (es && eslength >0 ) {
fESLength = eslength ;
if (fEventSpecies)
delete [] fEventSpecies ;
fEventSpecies = new Bool_t[eslength] ;
memcpy(fEventSpecies, es, eslength*sizeof(Bool_t)) ;
}
}
void AliRunTag::SetLHCTag(Float_t lumin, TString type) {
fLHCTag.SetLuminosity(lumin);
fLHCTag.SetLHCState(type);
}
void AliRunTag::SetDetectorTag(UInt_t mask, UInt_t maskReco) {
fDetectorTag.SetDetectorMaskDAQ(mask);
if (maskReco == 0)
fDetectorTag.SetDetectorMaskReco(mask);
else
fDetectorTag.SetDetectorMaskReco(maskReco);
int ndet = 0;
for (int iter=0; iter<32; iter++)
ndet += (mask & (1 << iter)) > 0;
fNumDetectors = ndet;
}
void AliRunTag::AddEventTag(const AliEventTag & EvTag) {
((AliFileTag *) fFileTags[fNumFiles-1])->AddEventTag(EvTag);
}
void AliRunTag::AddFileTag(AliFileTag *t) {
if (fNumFiles == fFileTags.GetSize()-1) fFileTags.Expand(fFileTags.GetSize()*2);
fFileTags[fNumFiles++] = t;
}
void AliRunTag::Clear(const char *) {
fFileTags.Delete();
fNumFiles = 0;
if ( fQAArray ) {
delete [] fQAArray ;
fQAArray = 0x0;
}
fQALength=0;
if ( fEventSpecies ) {
delete [] fEventSpecies ;
fEventSpecies = 0x0;
}
fESLength=0;
}
const AliEventTag* AliRunTag::GetEventTag(int evt) const
{
int curev = evt;
int curf = 0;
if (evt >= GetNEvents()) return 0;
while (curev >= ((AliFileTag *) fFileTags[curf])->GetNEvents()) {
curev -= ((AliFileTag *) fFileTags[curf])->GetNEvents();
curf++;
}
return ((AliFileTag *) fFileTags[curf])->GetEventTag(curev);
}
AliFileTag *AliRunTag::GetFileTagForEvent(int evt)
{
int curev = evt;
int curf = 0;
if (evt >= GetNEvents()) return 0;
while (curev >= ((AliFileTag *) fFileTags[curf])->GetNEvents()) {
curev -= ((AliFileTag *) fFileTags[curf])->GetNEvents();
curf++;
}
return (AliFileTag *) fFileTags[curf];
}
Int_t AliRunTag::GetNEvents() const
{
Int_t evtot = 0;
for (int iter=0; iter<fNumFiles; iter++)
evtot += ((AliFileTag *) fFileTags[iter])->GetNEvents();
return evtot;
}
Int_t AliRunTag::GetFileId(const char *guid)
{
for (int iter=0; iter<fNumFiles; iter++) {
if (!strcmp(((AliFileTag *) fFileTags[iter])->GetGUID(), guid))
return iter;
}
return -1;
}