AliPhysics  608b256 (608b256)
AliPWGJETrainHelpers.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2016, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 #include <cstdlib>
17 #include <iostream>
18 #include <string>
19 #include <vector>
20 
21 #include <TSystem.h>
22 #include <TString.h>
23 #include <TError.h>
24 
25 #include "AliPWGJETrainHelpers.h"
26 
28 {
29  // NOTE: `Getenv(...)` returns `nullptr` if the environment variable isn't available.
30  // std::string _cannot_ be set to `nullptr`, so we retrieve the result as a `const char*`
31  // and then convert it to a `std::string` if it is not null. We use std::string for
32  // convenience and to simplify string comparison.
33 
34  // Automatically set shared common variables
35  // The run period (ex. "LHC15o")
36  const char * tempPeriod = gSystem->Getenv("ALIEN_JDL_LPMPRODUCTIONTAG");
37  std::string period = tempPeriod ? tempPeriod : "";
38  // Either "pp", "pPb" or "PbPb"
39  const char * tempCollType = gSystem->Getenv("ALIEN_JDL_LPMINTERACTIONTYPE");
40  std::string collType = tempCollType ? tempCollType : "";
41  // Used to get MC.
42  const char * tempProdType = gSystem->Getenv("ALIEN_JDL_LPMPRODUCTIONTYPE");
43  std::string prodType = tempProdType ? tempProdType : "";
44 
45  // In the case of the metadataset, the standard environment variables above will not be set.
46  // Instead, we attempt to retrieve the variable from the first enabled metadataset. This requires looping
47  // over the available metadatasets until we find a non-null value.
48  // We assume that all children in the metadataset should have the same collision system and production type.
49  // Although this isn't the case for the period, since the variables are supposed to be the same
50  // in all metadatasets (according to Markus Z.), the track cuts presumably must all be the same for
51  // all periods in a metadataset.
52  const char * tempChildDatasets = gSystem->Getenv("CHILD_DATASETS");
53  // Used to get MC.
54  const std::string childDatasets = tempChildDatasets ? tempChildDatasets : "";
55  const int nChildDatasets = std::atoi(childDatasets.c_str());
56  for (int i = 1; i <= nChildDatasets; i++) {
57  if (period == "") {
58  tempPeriod = gSystem->Getenv(TString::Format("ALIEN_JDL_child_%i_LPMPRODUCTIONTAG", i));
59  period = tempPeriod ? tempPeriod : "";
60  }
61  if (collType == "") {
62  tempCollType = gSystem->Getenv(TString::Format("ALIEN_JDL_child_%i_LPMINTERACTIONTYPE", i));
63  collType = tempCollType ? tempCollType : "";
64  }
65  if (prodType == "") {
66  tempProdType = gSystem->Getenv(TString::Format("ALIEN_JDL_child_%i_LPMPRODUCTIONTYPE", i));
67  prodType = tempProdType ? tempProdType : "";
68  }
69  }
70  // Validate the extract variables. Each one must be set at this point.
71  if (period == "" || collType == "" || prodType == "") {
72  // Somehow failed to extract the variables which should always be available.
73  ::Fatal("AliPWGJETrainHelpers", "Somehow failed to extract the period, collision type, or production type.\n");
74  }
75 
76  // Determine if it's an MC production.
77  const bool mc = (prodType == "MC");
78 
79  // Determine if it's Run 2
80  std::string yearString = period.substr(3, 2);
81  int productionYear = std::atoi(yearString.c_str());
82  const bool isRun2 = productionYear > 14;
83 
84  // We need to return multiple values, so we use a vector and convert the bools to strings temporarily.
85  // They should be converted back after returning.
86  // (Not that the bool text doesn't really matter as long as it's non-zero, but we select "true" as it
87  // corresponds to the variables being true).
88  return std::vector<std::string>{period, collType, mc ? "true" : "", isRun2 ? "true" : ""};
89 }
90 
TSystem * gSystem
static std::vector< std::string > ExtractAliEnProductionValuesForLEGOTrain()