ROOT logo
// $Id$

#if !defined(__CINT__) || defined(__MAKECINT__)
#include "Riostream.h"
#include "AliCDBManager.h"
#include "AliCDBEntry.h"
#include "AliGRPObject.h"
#include "AliDAQ.h"
#endif

/**
 * @file EnableHLTInGRP.C
 * @author Artur Szostak <artursz@iafrica.com>
 * @ingroup alihlt_tutorial
 * @brief Patches GRP to process recorded data with HT in mode A.
 *
 * Usage:
 * <pre>
 *   aliroot -b -q 'EnableHLTInGRP.C(\<runNumber\>,\<grpPath\>)'
 * </pre>
 * Where \<runNumber\> is the number of the run the GRP corresponds to. This
 * can be found from the file name of the GRP entry of interest in the CDB.
 * \<grpPath\> is the path to the local GRP/GRP/Data directory where the GRP
 * entry to be modified is stored. Setting a value for \<grpPath\> is optional
 * and is the current working directory by default.
 *
 * Data recorded in mode A will not have the HT bit set in the GRP's active
 * detector mask. Trying to process such data with the HT framework will fail.
 * To be able to process such runs the GRP must be downloaded and patched with
 * this macro. It will set the HT bit in the GRP and write a new version of
 * the GRP with and incremented version number.
 * 
 * @return true if the macro completed successfully and false otherwise.
 */
bool EnableHLTInGRP(Int_t runNumber,
		    const char* cdbURI = "local://$ALICE_ROOT/OCDB",
		    const char* grpPath = "local://./")
{
	AliCDBManager* cdb = AliCDBManager::Instance();
	cdb->SetDefaultStorage(cdbURI);
	cdb->SetSpecificStorage("GRP/GRP/Data", grpPath);
	cdb->SetRun(runNumber);
	AliCDBEntry* entry = (AliCDBEntry*)cdb->Get("GRP/GRP/Data")->Clone();
	if (entry == NULL)
	{
		cerr << "ERROR: Could not fetch the GRP entry for run " << runNumber << " and path " << grpPath << endl;
		return false;
	}
	AliGRPObject* grp = (AliGRPObject*)entry->GetObject();
	if (grp == NULL)
	{
		cerr << "ERROR: Could not fetch the GRP object for run " << runNumber << " and path " << grpPath << endl;
		return false;
	}
	grp->SetDetectorMask(grp->GetDetectorMask() | (0x1 << AliDAQ::kHLTId));
	entry->SetVersion(entry->GetId().GetVersion() + 1);
	cdb->Put(entry);
	return true;
}

/// Just print the usage if no parameters are given.
void EnableHLTInGRP()
{
	cout << "Usage: EnableHLTInGRP.C'(<runNumber> [, <grpPath>])'" << endl;
	cout << "Where <runNumber> is the number of the run the GRP corresponds to." << endl;
	cout << "This can be found from the file name of the GRP entry of interest in the CDB." << endl;
	cout << "<grpPath> is the path to the local GRP/GRP/Data directory where the GRP entry to be modified is stored." << endl;
	cout << "Setting a value for <grpPath> is optional and is the current working directory by default." << endl;
}
 EnableHLTInGRP.C:1
 EnableHLTInGRP.C:2
 EnableHLTInGRP.C:3
 EnableHLTInGRP.C:4
 EnableHLTInGRP.C:5
 EnableHLTInGRP.C:6
 EnableHLTInGRP.C:7
 EnableHLTInGRP.C:8
 EnableHLTInGRP.C:9
 EnableHLTInGRP.C:10
 EnableHLTInGRP.C:11
 EnableHLTInGRP.C:12
 EnableHLTInGRP.C:13
 EnableHLTInGRP.C:14
 EnableHLTInGRP.C:15
 EnableHLTInGRP.C:16
 EnableHLTInGRP.C:17
 EnableHLTInGRP.C:18
 EnableHLTInGRP.C:19
 EnableHLTInGRP.C:20
 EnableHLTInGRP.C:21
 EnableHLTInGRP.C:22
 EnableHLTInGRP.C:23
 EnableHLTInGRP.C:24
 EnableHLTInGRP.C:25
 EnableHLTInGRP.C:26
 EnableHLTInGRP.C:27
 EnableHLTInGRP.C:28
 EnableHLTInGRP.C:29
 EnableHLTInGRP.C:30
 EnableHLTInGRP.C:31
 EnableHLTInGRP.C:32
 EnableHLTInGRP.C:33
 EnableHLTInGRP.C:34
 EnableHLTInGRP.C:35
 EnableHLTInGRP.C:36
 EnableHLTInGRP.C:37
 EnableHLTInGRP.C:38
 EnableHLTInGRP.C:39
 EnableHLTInGRP.C:40
 EnableHLTInGRP.C:41
 EnableHLTInGRP.C:42
 EnableHLTInGRP.C:43
 EnableHLTInGRP.C:44
 EnableHLTInGRP.C:45
 EnableHLTInGRP.C:46
 EnableHLTInGRP.C:47
 EnableHLTInGRP.C:48
 EnableHLTInGRP.C:49
 EnableHLTInGRP.C:50
 EnableHLTInGRP.C:51
 EnableHLTInGRP.C:52
 EnableHLTInGRP.C:53
 EnableHLTInGRP.C:54
 EnableHLTInGRP.C:55
 EnableHLTInGRP.C:56
 EnableHLTInGRP.C:57
 EnableHLTInGRP.C:58
 EnableHLTInGRP.C:59
 EnableHLTInGRP.C:60
 EnableHLTInGRP.C:61
 EnableHLTInGRP.C:62
 EnableHLTInGRP.C:63
 EnableHLTInGRP.C:64
 EnableHLTInGRP.C:65
 EnableHLTInGRP.C:66
 EnableHLTInGRP.C:67
 EnableHLTInGRP.C:68
 EnableHLTInGRP.C:69
 EnableHLTInGRP.C:70