+//---------------------------------------------------------------------
+void AliSimulation::WriteGRPEntry()
+{
+ // Get the necessary information from galice (generator, trigger etc) and
+ // write a GRP entry corresponding to the settings in the Config.C used
+ // note that Hall probes and Cavern and Surface Atmos pressures are not simulated.
+
+
+ AliInfo("Writing global run parameters entry into the OCDB");
+
+ AliGRPObject* grpObj = new AliGRPObject();
+
+ grpObj->SetRunType("PHYSICS");
+ grpObj->SetTimeStart(0);
+ grpObj->SetTimeEnd(9999);
+
+ const AliGenerator *gen = gAlice->GetMCApp()->Generator();
+ if (gen) {
+ grpObj->SetBeamEnergy(gen->GetEnergyCMS());
+ TString projectile;
+ Int_t a,z;
+ gen->GetProjectile(projectile,a,z);
+ TString target;
+ gen->GetTarget(target,a,z);
+ TString beamType = projectile + "-" + target;
+ beamType.ReplaceAll(" ","");
+ if (!beamType.CompareTo("-")) {
+ grpObj->SetBeamType("UNKNOWN");
+ }
+ else {
+ grpObj->SetBeamType(beamType);
+ // Heavy ion run, the event specie is set to kHighMult
+ fEventSpecie = AliRecoParam::kHighMult;
+ if ((strcmp(beamType,"p-p") == 0) ||
+ (strcmp(beamType,"p-") == 0) ||
+ (strcmp(beamType,"-p") == 0) ||
+ (strcmp(beamType,"P-P") == 0) ||
+ (strcmp(beamType,"P-") == 0) ||
+ (strcmp(beamType,"-P") == 0)) {
+ // Proton run, the event specie is set to kLowMult
+ fEventSpecie = AliRecoParam::kLowMult;
+ }
+ }
+ } else {
+ AliWarning("Unknown beam type and energy! Setting energy to 0");
+ grpObj->SetBeamEnergy(0);
+ grpObj->SetBeamType("UNKNOWN");
+ }
+
+ UInt_t detectorPattern = 0;
+ Int_t nDets = 0;
+ TObjArray *detArray = gAlice->Detectors();
+ for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors-1; iDet++) {
+ if (detArray->FindObject(AliDAQ::OfflineModuleName(iDet))) {
+ detectorPattern |= (1 << iDet);
+ nDets++;
+ }
+ }
+ // CTP
+ if (!fMakeTrigger.IsNull() || strcmp(gAlice->GetTriggerDescriptor(),""))
+ detectorPattern |= (1 << AliDAQ::DetectorID("TRG"));
+
+ // HLT
+ if (!fRunHLT.IsNull())
+ detectorPattern |= (1 << AliDAQ::kHLTId);
+
+ grpObj->SetNumberOfDetectors((Char_t)nDets);
+ grpObj->SetDetectorMask((Int_t)detectorPattern);
+ grpObj->SetLHCPeriod("LHC08c");
+ grpObj->SetLHCState("STABLE_BEAMS");
+ grpObj->SetLHCLuminosity(0,(AliGRPObject::Stats)0);
+ grpObj->SetBeamIntensity(0,(AliGRPObject::Stats)0);
+
+ AliMagF *field = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
+ Float_t solenoidField = field ? TMath::Abs(field->SolenoidField()) : 0;
+ Float_t factor = field ? field->Factor() : 0;
+ Float_t l3current = TMath::Abs(factor)*solenoidField*30000./5.;
+ grpObj->SetL3Current(l3current,(AliGRPObject::Stats)0);
+
+ if (factor > 0) {
+ grpObj->SetL3Polarity(0);
+ grpObj->SetDipolePolarity(0);
+ }
+ else {
+ grpObj->SetL3Polarity(1);
+ grpObj->SetDipolePolarity(1);
+ }
+
+ if (TMath::Abs(factor) != 0)
+ grpObj->SetDipoleCurrent(6000,(AliGRPObject::Stats)0);
+ else
+ grpObj->SetDipoleCurrent(0,(AliGRPObject::Stats)0);
+
+ grpObj->SetCavernTemperature(0,(AliGRPObject::Stats)0);
+
+ //grpMap->Add(new TObjString("fCavernPressure"),new TObjString("0")); ---> not inserted in simulation with the new object, since it is now an AliDCSSensor
+
+ // Now store the entry in OCDB
+ AliCDBManager* man = AliCDBManager::Instance();
+
+ AliCDBId id("GRP/GRP/Data", man->GetRun(), man->GetRun(), 1, 1);
+ AliCDBMetaData *metadata= new AliCDBMetaData();
+
+ metadata->SetResponsible("alice-off@cern.ch");
+ metadata->SetComment("Automatically produced GRP entry for Monte Carlo");
+
+ man->Put(grpObj,id,metadata);
+}
+
+