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