ROOT logo
/* $Id: TestPreprocessor.C 30923 2009-02-09 15:47:08Z hristov $ */

// This class runs the test preprocessor
// It uses AliTestShuttle to simulate a full Shuttle process

// The input data is created in the functions
//   CreateDCSAliasMap() creates input that would in the same way come from DCS
//   ReadDCSAliasMap() reads from a file
//   CreateInputFilesMap() creates a list of local files, that can be accessed by the shuttle

void VZEROTestPreprocessor()
{
  // load library
  gSystem->Load("libTestShuttle.so");

   // create AliTestShuttle instance
  // The parameters are run, startTime, endTime
  AliTestShuttle* shuttle = new AliTestShuttle(12345, 0, 123450);

  // TODO if needed, change location of OCDB and Reference test folders
  // by default they are set to $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB and TestReference
  AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/OCDB");
  AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB");

  printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
  printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());


  // TODO(1)
  //
  // The shuttle can read DCS data, if the preprocessor should be tested to process DCS data,
  // some fake data has to be created.
  //
  // The "fake" input data can be taken using either (a) or (b):
  // (a) data from a file: Use ReadDCSAliasMap()
  //     the format of the file is explained in ReadDCSAliasMap()
  //     To use it uncomment the following line:
  //
  //TMap* dcsAliasMap = ReadDCSAliasMap();
  //
  // (b) generated in this macro: Use CreateDCSAliasMap() and its documentation
  //     To use it uncomment the following line:
  //
  TMap* dcsAliasMap = CreateDCSAliasMap();

  // now give the alias map to the shuttle
  shuttle->SetDCSInput(dcsAliasMap);

  // TODO(2)
  //
  // The shuttle can also process files that originate from DCS, DAQ and HLT.
  // To test it, we provide some local files and locations where these would be found when
  // the online machinery would be there.
  // In real life this functions would be produces by the sub-detectors
  // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
  //
  // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
  // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
  // In this example we add a file originating from the GDC with the id PEDESTALS
  // Three files originating from different LDCs but with the same id are also added
  // Note that the test preprocessor name is TPC. The name of the detector's preprocessor must follow
  // the "online" naming convention ALICE-INT-2003-039.
//  shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "PEDESTALS", "GDC0", "file1.root");
//  shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC0", "file2a.root");
//  shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC1", "file2b.root");
//  shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC2", "file2c.root");
//  shuttle->AddInputFile(AliShuttleInterface::kHLT, "TPC", "HLTData", "source1", "hlt_file1.root");
  shuttle->AddInputFile(AliShuttleInterface::kDAQ, "V00", "V00da_results", "source1", "VZERO/V00da_results.txt");
//
  // TODO(3)
  //
  // The shuttle can read run type stored in the DAQ logbook.
  // To test it, we must provide the run type manually. They will be retrieved in the preprocessor
  // using GetRunType function.
  shuttle->SetInputRunType("PHYSICS");

  // TODO(4)
  //
  // The shuttle can read run parameters stored in the DAQ run logbook.
  // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
  // using GetRunParameter function.
  shuttle->AddInputRunParameter("totalEvents", "30000");
  shuttle->AddInputRunParameter("NumberOfGDCs", "15");

  // TODO(5)
  //
  // This is for preprocessor that require data from HLT.
  // Since HLT may be switched off, the preprocessor should first query the Run logbook where
  // the HLT status is stored. SHUTTLE implements a shortcut function (GetHLTStatus) that returns
  // a bool directly. 1 = HLT ON, 0 = HLT OFF
  //

  Bool_t hltStatus=kFALSE;
  shuttle->SetInputHLTStatus(hltStatus);


  // TODO(6)
  // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
  AliPreprocessor* vzeroPreprocessor = new AliVZEROPreprocessor(shuttle);

  // Test the preprocessor
  shuttle->Process();

  // TODO(7)
  // In the preprocessor AliShuttleInterface::Store should be called to put the final
  // data to the CDB. To check if all went fine have a look at the files produced in
  // $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/SHUTTLE/Data
  //
  // Check the file which should have been created
  AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
  			->Get("VZERO/Calib/Data", 0);
  if (!chkEntry)
  {
    printf("The file is not there. Something went wrong.\n");
    return;
  }
	chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
	->Get("VZERO/Trigger/Data", 0);
	if (!chkEntry)
	{
		printf("The file is not there. Something went wrong.\n");
		return;
	}
	
  AliTestDataDCS* output = dynamic_cast<AliTestDataDCS*> (chkEntry->GetObject());
  // If everything went fine, draw the result
  if (output)
    output->Draw();
}

TMap* CreateDCSAliasMap()
{
  // Creates a DCS structure
  // The structure is the following:
  //   TMap (key --> value)
  //     <DCSAlias> --> <valueList>
  //     <DCSAlias> is a string
  //     <valueList> is a TObjArray of AliDCSValue
  //     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue

  // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
  // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias

  TMap* aliasMap = new TMap;
  aliasMap->SetOwner(1);
  TRandom random;

	FILE *fp = fopen("VZERO/DCSValues.txt","r");

	char name[50];
	Float_t val;
	while(!(EOF == fscanf(fp,"%s %f",name,&val))){
		TObjArray* valueSet = new TObjArray;
		valueSet->SetOwner(1);

		TString aliasName=name;
		
		//printf("alias: %s\t\t",aliasName.Data());

		int timeStamp=10;
		
		
		if(aliasName.Contains("HV")) {
			for(int i=0;i<10;i++){
				dcsVal = new AliDCSValue((Float_t) (val+random.Gaus(0,10)), timeStamp+10*i);
				valueSet->Add(dcsVal);
			}
		} else {
			for(int i=0;i<2;i++){
				AliDCSValue* dcsVal = new AliDCSValue((Int_t) (val), timeStamp+10*i);
				valueSet->Add(dcsVal);
			}
		}
		
		aliasMap->Add(new TObjString(aliasName), valueSet);

	}
	fclose(fp);
  return aliasMap;
}

TMap* ReadDCSAliasMap()
{
  // Open a file that contains DCS input data
  // The CDB framework is used to open the file, this means the file is located
  // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
  // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
  // An explanation of the structure can be found in CreateDCSAliasMap()

  AliCDBEntry *entry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
  			->Get("DET/DCS/Data", 0);
  return dynamic_cast<TMap*> (entry->GetObject());
}

void WriteDCSAliasMap()
{
  // This writes the output from CreateDCSAliasMap to a CDB file

  TMap* dcsAliasMap = CreateDCSAliasMap();

  AliCDBMetaData metaData;
	metaData.SetBeamPeriod(0);
	metaData.SetResponsible("Responsible person");
	metaData.SetComment("Test object for TestPreprocessor.C");

  AliCDBId id("DET/DCS/Data", 0, 0);

  // look into AliTestShuttle's CDB main folder

  AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
  			->Put(dcsAliasMap, id, &metaData);
}
 VZEROTestPreprocessor.C:1
 VZEROTestPreprocessor.C:2
 VZEROTestPreprocessor.C:3
 VZEROTestPreprocessor.C:4
 VZEROTestPreprocessor.C:5
 VZEROTestPreprocessor.C:6
 VZEROTestPreprocessor.C:7
 VZEROTestPreprocessor.C:8
 VZEROTestPreprocessor.C:9
 VZEROTestPreprocessor.C:10
 VZEROTestPreprocessor.C:11
 VZEROTestPreprocessor.C:12
 VZEROTestPreprocessor.C:13
 VZEROTestPreprocessor.C:14
 VZEROTestPreprocessor.C:15
 VZEROTestPreprocessor.C:16
 VZEROTestPreprocessor.C:17
 VZEROTestPreprocessor.C:18
 VZEROTestPreprocessor.C:19
 VZEROTestPreprocessor.C:20
 VZEROTestPreprocessor.C:21
 VZEROTestPreprocessor.C:22
 VZEROTestPreprocessor.C:23
 VZEROTestPreprocessor.C:24
 VZEROTestPreprocessor.C:25
 VZEROTestPreprocessor.C:26
 VZEROTestPreprocessor.C:27
 VZEROTestPreprocessor.C:28
 VZEROTestPreprocessor.C:29
 VZEROTestPreprocessor.C:30
 VZEROTestPreprocessor.C:31
 VZEROTestPreprocessor.C:32
 VZEROTestPreprocessor.C:33
 VZEROTestPreprocessor.C:34
 VZEROTestPreprocessor.C:35
 VZEROTestPreprocessor.C:36
 VZEROTestPreprocessor.C:37
 VZEROTestPreprocessor.C:38
 VZEROTestPreprocessor.C:39
 VZEROTestPreprocessor.C:40
 VZEROTestPreprocessor.C:41
 VZEROTestPreprocessor.C:42
 VZEROTestPreprocessor.C:43
 VZEROTestPreprocessor.C:44
 VZEROTestPreprocessor.C:45
 VZEROTestPreprocessor.C:46
 VZEROTestPreprocessor.C:47
 VZEROTestPreprocessor.C:48
 VZEROTestPreprocessor.C:49
 VZEROTestPreprocessor.C:50
 VZEROTestPreprocessor.C:51
 VZEROTestPreprocessor.C:52
 VZEROTestPreprocessor.C:53
 VZEROTestPreprocessor.C:54
 VZEROTestPreprocessor.C:55
 VZEROTestPreprocessor.C:56
 VZEROTestPreprocessor.C:57
 VZEROTestPreprocessor.C:58
 VZEROTestPreprocessor.C:59
 VZEROTestPreprocessor.C:60
 VZEROTestPreprocessor.C:61
 VZEROTestPreprocessor.C:62
 VZEROTestPreprocessor.C:63
 VZEROTestPreprocessor.C:64
 VZEROTestPreprocessor.C:65
 VZEROTestPreprocessor.C:66
 VZEROTestPreprocessor.C:67
 VZEROTestPreprocessor.C:68
 VZEROTestPreprocessor.C:69
 VZEROTestPreprocessor.C:70
 VZEROTestPreprocessor.C:71
 VZEROTestPreprocessor.C:72
 VZEROTestPreprocessor.C:73
 VZEROTestPreprocessor.C:74
 VZEROTestPreprocessor.C:75
 VZEROTestPreprocessor.C:76
 VZEROTestPreprocessor.C:77
 VZEROTestPreprocessor.C:78
 VZEROTestPreprocessor.C:79
 VZEROTestPreprocessor.C:80
 VZEROTestPreprocessor.C:81
 VZEROTestPreprocessor.C:82
 VZEROTestPreprocessor.C:83
 VZEROTestPreprocessor.C:84
 VZEROTestPreprocessor.C:85
 VZEROTestPreprocessor.C:86
 VZEROTestPreprocessor.C:87
 VZEROTestPreprocessor.C:88
 VZEROTestPreprocessor.C:89
 VZEROTestPreprocessor.C:90
 VZEROTestPreprocessor.C:91
 VZEROTestPreprocessor.C:92
 VZEROTestPreprocessor.C:93
 VZEROTestPreprocessor.C:94
 VZEROTestPreprocessor.C:95
 VZEROTestPreprocessor.C:96
 VZEROTestPreprocessor.C:97
 VZEROTestPreprocessor.C:98
 VZEROTestPreprocessor.C:99
 VZEROTestPreprocessor.C:100
 VZEROTestPreprocessor.C:101
 VZEROTestPreprocessor.C:102
 VZEROTestPreprocessor.C:103
 VZEROTestPreprocessor.C:104
 VZEROTestPreprocessor.C:105
 VZEROTestPreprocessor.C:106
 VZEROTestPreprocessor.C:107
 VZEROTestPreprocessor.C:108
 VZEROTestPreprocessor.C:109
 VZEROTestPreprocessor.C:110
 VZEROTestPreprocessor.C:111
 VZEROTestPreprocessor.C:112
 VZEROTestPreprocessor.C:113
 VZEROTestPreprocessor.C:114
 VZEROTestPreprocessor.C:115
 VZEROTestPreprocessor.C:116
 VZEROTestPreprocessor.C:117
 VZEROTestPreprocessor.C:118
 VZEROTestPreprocessor.C:119
 VZEROTestPreprocessor.C:120
 VZEROTestPreprocessor.C:121
 VZEROTestPreprocessor.C:122
 VZEROTestPreprocessor.C:123
 VZEROTestPreprocessor.C:124
 VZEROTestPreprocessor.C:125
 VZEROTestPreprocessor.C:126
 VZEROTestPreprocessor.C:127
 VZEROTestPreprocessor.C:128
 VZEROTestPreprocessor.C:129
 VZEROTestPreprocessor.C:130
 VZEROTestPreprocessor.C:131
 VZEROTestPreprocessor.C:132
 VZEROTestPreprocessor.C:133
 VZEROTestPreprocessor.C:134
 VZEROTestPreprocessor.C:135
 VZEROTestPreprocessor.C:136
 VZEROTestPreprocessor.C:137
 VZEROTestPreprocessor.C:138
 VZEROTestPreprocessor.C:139
 VZEROTestPreprocessor.C:140
 VZEROTestPreprocessor.C:141
 VZEROTestPreprocessor.C:142
 VZEROTestPreprocessor.C:143
 VZEROTestPreprocessor.C:144
 VZEROTestPreprocessor.C:145
 VZEROTestPreprocessor.C:146
 VZEROTestPreprocessor.C:147
 VZEROTestPreprocessor.C:148
 VZEROTestPreprocessor.C:149
 VZEROTestPreprocessor.C:150
 VZEROTestPreprocessor.C:151
 VZEROTestPreprocessor.C:152
 VZEROTestPreprocessor.C:153
 VZEROTestPreprocessor.C:154
 VZEROTestPreprocessor.C:155
 VZEROTestPreprocessor.C:156
 VZEROTestPreprocessor.C:157
 VZEROTestPreprocessor.C:158
 VZEROTestPreprocessor.C:159
 VZEROTestPreprocessor.C:160
 VZEROTestPreprocessor.C:161
 VZEROTestPreprocessor.C:162
 VZEROTestPreprocessor.C:163
 VZEROTestPreprocessor.C:164
 VZEROTestPreprocessor.C:165
 VZEROTestPreprocessor.C:166
 VZEROTestPreprocessor.C:167
 VZEROTestPreprocessor.C:168
 VZEROTestPreprocessor.C:169
 VZEROTestPreprocessor.C:170
 VZEROTestPreprocessor.C:171
 VZEROTestPreprocessor.C:172
 VZEROTestPreprocessor.C:173
 VZEROTestPreprocessor.C:174
 VZEROTestPreprocessor.C:175
 VZEROTestPreprocessor.C:176
 VZEROTestPreprocessor.C:177
 VZEROTestPreprocessor.C:178
 VZEROTestPreprocessor.C:179
 VZEROTestPreprocessor.C:180
 VZEROTestPreprocessor.C:181
 VZEROTestPreprocessor.C:182
 VZEROTestPreprocessor.C:183
 VZEROTestPreprocessor.C:184
 VZEROTestPreprocessor.C:185
 VZEROTestPreprocessor.C:186
 VZEROTestPreprocessor.C:187
 VZEROTestPreprocessor.C:188
 VZEROTestPreprocessor.C:189
 VZEROTestPreprocessor.C:190
 VZEROTestPreprocessor.C:191
 VZEROTestPreprocessor.C:192
 VZEROTestPreprocessor.C:193
 VZEROTestPreprocessor.C:194
 VZEROTestPreprocessor.C:195
 VZEROTestPreprocessor.C:196
 VZEROTestPreprocessor.C:197
 VZEROTestPreprocessor.C:198
 VZEROTestPreprocessor.C:199
 VZEROTestPreprocessor.C:200
 VZEROTestPreprocessor.C:201
 VZEROTestPreprocessor.C:202
 VZEROTestPreprocessor.C:203
 VZEROTestPreprocessor.C:204
 VZEROTestPreprocessor.C:205
 VZEROTestPreprocessor.C:206
 VZEROTestPreprocessor.C:207
 VZEROTestPreprocessor.C:208
 VZEROTestPreprocessor.C:209
 VZEROTestPreprocessor.C:210
 VZEROTestPreprocessor.C:211
 VZEROTestPreprocessor.C:212
 VZEROTestPreprocessor.C:213