Skip to content

Commit a8e4a0d

Browse files
authored
Merge branch 'AliceO2Group:dev' into new-detector4
2 parents 4ead620 + db7b2f0 commit a8e4a0d

File tree

124 files changed

+3351
-2948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3351
-2948
lines changed

.github/workflows/reports.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ jobs:
1717
if: github.repository == 'AliceO2Group/AliceO2'
1818

1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- name: Set up Python 3.10
2222
uses: actions/setup-python@v5
2323
with:
2424
python-version: '3.10'
25-
- uses: actions/cache@v2
25+
- uses: actions/cache@v4
2626
name: Configure pip caching
2727
with:
2828
path: ~/.cache/pip

CCDB/include/CCDB/CCDBDownloader.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct HeaderObjectPair_t {
4747

4848
typedef struct DownloaderRequestData {
4949
std::vector<std::string> hosts;
50+
std::vector<std::string> locations;
5051
std::string path;
5152
long timestamp;
5253
HeaderObjectPair_t hoPair;
@@ -231,12 +232,13 @@ class CCDBDownloader
231232
std::string prepareRedirectedURL(std::string address, std::string potentialHost) const;
232233

233234
/**
234-
* Returns a vector of possible content locations based on the redirect headers.
235+
* Updates the locations vector with the the locations.
235236
*
236-
* @param baseUrl Content path.
237237
* @param headerMap Map containing response headers.
238+
* @param locations Location list to be updated.
239+
* @param locIndex Index of the next locaiton to be tried.
238240
*/
239-
std::vector<std::string> getLocations(std::multimap<std::string, std::string>* headerMap) const;
241+
void updateLocations(std::multimap<std::string, std::string>* headerMap, std::vector<std::string>* locations, int* locIndex) const;
240242

241243
std::string mUserAgentId = "CCDBDownloader";
242244
/**

CCDB/include/CCDB/CcdbApi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ class CcdbApi //: public DatabaseInterface
388388
static bool removeSemaphore(std::string const& name, bool remove = false);
389389
static void removeLeakingSemaphores(std::string const& basedir, bool remove = false);
390390

391-
void loadFileToMemory(o2::pmr::vector<char>& dest, const std::string& path, std::map<std::string, std::string>* localHeaders = nullptr) const;
391+
void loadFileToMemory(o2::pmr::vector<char>& dest, const std::string& path, std::map<std::string, std::string>* localHeaders = nullptr, bool fetchLocalMetaData = true) const;
392392
void loadFileToMemory(o2::pmr::vector<char>& dest, std::string const& path,
393393
std::map<std::string, std::string> const& metadata, long timestamp,
394394
std::map<std::string, std::string>* headers, std::string const& etag,

CCDB/src/CCDBDownloader.cxx

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void CCDBDownloader::tryNewHost(PerformData* performData, CURL* easy_handle)
362362
{
363363
auto requestData = performData->requestData;
364364
std::string newUrl = requestData->hosts.at(performData->hostInd) + "/" + requestData->path + "/" + std::to_string(requestData->timestamp);
365-
LOG(debug) << "Connecting to another host " << newUrl;
365+
LOG(debug) << "Connecting to another host " << newUrl << "\n";
366366
requestData->hoPair.header.clear();
367367
curl_easy_setopt(easy_handle, CURLOPT_URL, newUrl.c_str());
368368
mHandlesToBeAdded.push_back(easy_handle);
@@ -374,9 +374,11 @@ void CCDBDownloader::getLocalContent(PerformData* performData, std::string& newL
374374
LOG(debug) << "Redirecting to local content " << newLocation << "\n";
375375
if (requestData->localContentCallback(newLocation)) {
376376
contentRetrieved = true;
377+
LOG(debug) << "Local content retrieved succesfully: " << newLocation << " n";
377378
} else {
378379
// Prepare next redirect url
379380
newLocation = getNewLocation(performData, locations);
381+
LOG(debug) << "Failed to retrieve local content: " << newLocation << "\n";
380382
}
381383
}
382384

@@ -396,15 +398,15 @@ std::string CCDBDownloader::getNewLocation(PerformData* performData, std::vector
396398
void CCDBDownloader::httpRedirect(PerformData* performData, std::string& newLocation, CURL* easy_handle)
397399
{
398400
auto requestData = performData->requestData;
399-
LOG(debug) << "Trying content location " << newLocation;
401+
LOG(debug) << "Trying content location " << newLocation << "\n";
400402
curl_easy_setopt(easy_handle, CURLOPT_URL, newLocation.c_str());
401403
mHandlesToBeAdded.push_back(easy_handle);
402404
}
403405

404406
void CCDBDownloader::followRedirect(PerformData* performData, CURL* easy_handle, std::vector<std::string>& locations, bool& rescheduled, bool& contentRetrieved)
405407
{
406408
std::string newLocation = getNewLocation(performData, locations);
407-
if (newLocation.find("alien:/", 0) != std::string::npos || newLocation.find("file:/", 0) != std::string::npos) {
409+
while (!contentRetrieved && (newLocation.find("alien:/", 0) != std::string::npos || newLocation.find("file:/", 0) != std::string::npos)) {
408410
getLocalContent(performData, newLocation, contentRetrieved, locations);
409411
}
410412
if (!contentRetrieved && newLocation != "") {
@@ -508,17 +510,17 @@ void CCDBDownloader::transferFinished(CURL* easy_handle, CURLcode curlCode)
508510
std::string currentHost = requestData->hosts[performData->hostInd];
509511
std::string loggingMessage = prepareLogMessage(currentHost, requestData->userAgent, requestData->path, requestData->timestamp, requestData->headers, httpCode);
510512

511-
// Get alternative locations for the same host
512-
auto locations = getLocations(&(requestData->hoPair.header));
513+
// Get new locations based on received headers
514+
updateLocations(&(requestData->hoPair.header), &requestData->locations, &performData->locInd);
513515

514516
// React to received http code
515517
if (200 <= httpCode && httpCode < 400) {
516518
LOG(debug) << loggingMessage;
517519
if (304 == httpCode) {
518520
LOGP(debug, "Object exists but I am not serving it since it's already in your possession");
519521
contentRetrieved = true;
520-
} else if (300 <= httpCode && httpCode < 400 && performData->locInd < locations.size()) {
521-
followRedirect(performData, easy_handle, locations, rescheduled, contentRetrieved);
522+
} else if (300 <= httpCode && httpCode < 400 && performData->locInd < requestData->locations.size()) {
523+
followRedirect(performData, easy_handle, requestData->locations, rescheduled, contentRetrieved);
522524
} else if (200 <= httpCode && httpCode < 300) {
523525
contentRetrieved = true; // Can be overruled by following error check
524526
}
@@ -531,8 +533,16 @@ void CCDBDownloader::transferFinished(CURL* easy_handle, CURLcode curlCode)
531533
contentRetrieved = false;
532534
}
533535

534-
// Check if content was retrieved, or scheduled to be retrieved
535-
if (!rescheduled && !contentRetrieved && performData->locInd == locations.size()) {
536+
// Check if content was retrieved or scheduled to be retrieved
537+
if (!rescheduled && !contentRetrieved) {
538+
// Current location failed without providing 3xx http code, try next redirect for the same host
539+
if (performData->locInd < requestData->locations.size()) {
540+
followRedirect(performData, easy_handle, requestData->locations, rescheduled, contentRetrieved);
541+
}
542+
}
543+
544+
// Check again because content might have been retrieved or rescheduled via a redirect
545+
if (!rescheduled && !contentRetrieved) {
536546
// Ran out of locations to redirect, try new host
537547
if (++performData->hostInd < requestData->hosts.size()) {
538548
tryNewHost(performData, easy_handle);
@@ -650,24 +660,37 @@ CURLcode CCDBDownloader::perform(CURL* handle)
650660
return batchBlockingPerform(handleVector).back();
651661
}
652662

653-
std::vector<std::string> CCDBDownloader::getLocations(std::multimap<std::string, std::string>* headerMap) const
663+
void CCDBDownloader::updateLocations(std::multimap<std::string, std::string>* headerMap, std::vector<std::string>* locations, int* locIndex) const
654664
{
655-
std::vector<std::string> locs;
665+
std::vector<std::string> newLocations;
666+
656667
auto iter = headerMap->find("Location");
657668
if (iter != headerMap->end()) {
658-
locs.push_back(iter->second);
669+
auto range = headerMap->equal_range("Location");
670+
for (auto it = range.first; it != range.second; ++it) {
671+
if (std::find(locations->begin(), locations->end(), it->second) == locations->end()) {
672+
if (std::find(newLocations.begin(), newLocations.end(), it->second) == newLocations.end()) {
673+
newLocations.push_back(it->second);
674+
}
675+
}
676+
}
659677
}
678+
660679
// add alternative locations (not yet included)
661680
auto iter2 = headerMap->find("Content-Location");
662681
if (iter2 != headerMap->end()) {
663682
auto range = headerMap->equal_range("Content-Location");
664683
for (auto it = range.first; it != range.second; ++it) {
665-
if (std::find(locs.begin(), locs.end(), it->second) == locs.end()) {
666-
locs.push_back(it->second);
684+
if (std::find(locations->begin(), locations->end(), it->second) == locations->end()) {
685+
if (std::find(newLocations.begin(), newLocations.end(), it->second) == newLocations.end()) {
686+
newLocations.push_back(it->second);
687+
}
667688
}
668689
}
669690
}
670-
return locs;
691+
692+
// Insert location list at the current location index. This assures that the provided locations will be tried first.
693+
locations->insert(locations->begin() + (*locIndex), newLocations.begin(), newLocations.end());
671694
}
672695

673696
std::vector<CURLcode> CCDBDownloader::batchBlockingPerform(std::vector<CURL*> const& handleVector)

CCDB/src/CcdbApi.cxx

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,23 @@ size_t header_map_callback(char* buffer, size_t size, size_t nitems, void* userd
667667
}
668668
}
669669
}
670+
671+
// Keep only the first ETag encountered
672+
if (key == "ETag") {
673+
auto cl = headers->find("ETag");
674+
if (cl != headers->end()) {
675+
insert = false;
676+
}
677+
}
678+
679+
// Keep only the first Content-Type encountered
680+
if (key == "Content-Type") {
681+
auto cl = headers->find("Content-Type");
682+
if (cl != headers->end()) {
683+
insert = false;
684+
}
685+
}
686+
670687
if (insert) {
671688
headers->insert(std::make_pair(key, value));
672689
}
@@ -1971,20 +1988,32 @@ void CcdbApi::vectoredLoadFileToMemory(std::vector<RequestContext>& requestConte
19711988
bool CcdbApi::loadLocalContentToMemory(o2::pmr::vector<char>& dest, std::string& url) const
19721989
{
19731990
if (url.find("alien:/", 0) != std::string::npos) {
1974-
loadFileToMemory(dest, url, nullptr); // headers loaded from the file in case of the snapshot reading only
1975-
return true;
1991+
std::map<std::string, std::string> localHeaders;
1992+
loadFileToMemory(dest, url, &localHeaders, false);
1993+
auto it = localHeaders.find("Error");
1994+
if (it != localHeaders.end() && it->second == "An error occurred during retrieval") {
1995+
return false;
1996+
} else {
1997+
return true;
1998+
}
19761999
}
19772000
if ((url.find("file:/", 0) != std::string::npos)) {
19782001
std::string path = url.substr(7);
19792002
if (std::filesystem::exists(path)) {
1980-
loadFileToMemory(dest, path, nullptr);
1981-
return true;
2003+
std::map<std::string, std::string> localHeaders;
2004+
loadFileToMemory(dest, url, &localHeaders, o2::utils::Str::endsWith(path, ".root"));
2005+
auto it = localHeaders.find("Error");
2006+
if (it != localHeaders.end() && it->second == "An error occurred during retrieval") {
2007+
return false;
2008+
} else {
2009+
return true;
2010+
}
19822011
}
19832012
}
19842013
return false;
19852014
}
19862015

1987-
void CcdbApi::loadFileToMemory(o2::pmr::vector<char>& dest, const std::string& path, std::map<std::string, std::string>* localHeaders) const
2016+
void CcdbApi::loadFileToMemory(o2::pmr::vector<char>& dest, const std::string& path, std::map<std::string, std::string>* localHeaders, bool fetchLocalMetaData) const
19882017
{
19892018
// Read file to memory as vector. For special case of the locally cached file retriev metadata stored directly in the file
19902019
constexpr size_t MaxCopySize = 0x1L << 25;
@@ -2032,7 +2061,7 @@ void CcdbApi::loadFileToMemory(o2::pmr::vector<char>& dest, const std::string& p
20322061
totalread += nread;
20332062
} while (nread == (long)MaxCopySize);
20342063

2035-
if (localHeaders) {
2064+
if (localHeaders && fetchLocalMetaData) {
20362065
TMemFile memFile("name", const_cast<char*>(dest.data()), dest.size(), "READ");
20372066
auto storedmeta = (std::map<std::string, std::string>*)extractFromTFile(memFile, TClass::GetClass("std::map<std::string, std::string>"), CCDBMETA_ENTRY);
20382067
if (storedmeta) {

CODEOWNERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/DataFormats/Detectors/CPV @peressounko @kharlov
3030
/DataFormats/Detectors/CTP @lietava
3131
/DataFormats/Detectors/EMCAL @mfasDa @jokonig
32-
/DataFormats/Detectors/FIT @jotwinow @afurs @andreasmolander @arvindkhuntia @mslupeck
32+
/DataFormats/Detectors/FIT @jotwinow @afurs @andreasmolander @sahilupadhyaya92
3333
/DataFormats/Detectors/FOCAL @maxrauch @mfasDa @iarsene @matthiasrichter
3434
/DataFormats/Detectors/GlobalTracking @shahor02
3535
/DataFormats/Detectors/GlobalTrackingWorkflow @shahor02
@@ -59,7 +59,7 @@
5959
/Detectors/Calibration @chiarazampolli @shahor02
6060
/Detectors/CPV @peressounko @kharlov
6161
/Detectors/EMCAL @mfasDa @jokonig
62-
/Detectors/FIT @jotwinow @afurs @andreasmolander @arvindkhuntia @mslupeck
62+
/Detectors/FIT @jotwinow @afurs @andreasmolander @sahilupadhyaya92
6363
/Detectors/FOCAL @maxrauch @mfasDa @iarsene @matthiasrichter
6464
/Detectors/Geometry @sawenzel @shahor02
6565
/Detectors/GlobalTracking @shahor02

Detectors/CTP/workflowScalers/include/CTPWorkflowScalers/RunManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CTPRunManager : public ctpCCDBManager
4747
CTPRunManager() = default;
4848
void init();
4949
int loadRun(const std::string& cfg);
50-
int startRun(const std::string& cfg);
50+
int setRunConfigBK(uint32_t runNumber, const std::string& cfg);
5151
int stopRun(uint32_t irun, long timeStamp);
5252
int addScalers(uint32_t irun, std::time_t time, bool start = 0);
5353
int processMessage(std::string& topic, const std::string& message);

Detectors/CTP/workflowScalers/include/CTPWorkflowScalers/ctpCCDBManager.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ class ctpCCDBManager
2727
int saveRunScalersToCCDB(CTPRunScalers& scalers, long timeStart, long timeStop);
2828
int saveRunScalersToQCDB(CTPRunScalers& scalers, long timeStart, long timeStop);
2929
int saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart);
30+
int saveSoxOrbit(uint32_t runNumber, uint32_t soxOrbit, long timeStart);
31+
int saveOrbitReset(long timeStamp);
3032
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run, bool& ok);
3133
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run);
3234
CTPRunScalers getScalersFromCCDB(long timestamp, std::string, bool& ok);
33-
void setCCDBPathConfig(std::string path) { mCCDBPathCTPConfig = path; };
34-
void setCCDBPathScalers(std::string path) { mCCDBPathCTPScalers = path; };
35-
void setQCDBPathScalers(std::string path) { mQCDBPathCTPScalers = path; };
3635
static void setCCDBHost(std::string host) { mCCDBHost = host; };
3736
static void setQCDBHost(std::string host) { mQCDBHost = host; };
3837

@@ -42,9 +41,11 @@ class ctpCCDBManager
4241
// std::string mQCDBHost = "http://ali-qcdb.cern.ch:8083";
4342
static std::string mCCDBHost;
4443
static std::string mQCDBHost;
45-
std::string mCCDBPathCTPScalers = "CTP/Calib/Scalers";
46-
std::string mCCDBPathCTPConfig = "CTP/Config/Config";
47-
std::string mQCDBPathCTPScalers = "qc/CTP/Scalers";
44+
const std::string mCCDBPathCTPScalers = "CTP/Calib/Scalers";
45+
// std::string mCCDBPathCTPConfig = "CTP/Config/Config"; - in Configuration.h
46+
const std::string mQCDBPathCTPScalers = "qc/CTP/Scalers";
47+
const std::string mCCDBPathSoxOrbit = "CTP/Calib/FirstRunOrbit";
48+
const std::string mCCDBPathOrbitReset = "CTP/Calib/OrbitReset";
4849
ClassDefNV(ctpCCDBManager, 1);
4950
};
5051
} // namespace ctp

Detectors/CTP/workflowScalers/src/RunManager.cxx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int CTPActiveRun::send2BK(std::unique_ptr<BkpClient>& BKClient, size_t ts, bool
5757
std::string clsname = cfg.getClassNameFromHWIndex(cls.first);
5858
// clsname = std::to_string(runOri) + "_" + clsname;
5959
try {
60-
BKClient->triggerCounters()->createOrUpdateForRun(runNumber, clsname, ts, cntsbk[0], cntsbk[1], cntsbk[2], cntsbk[3], cntsbk[4], cntsbk[5]);
60+
BKClient->ctpTriggerCounters()->createOrUpdateForRun(runNumber, clsname, ts, cntsbk[0], cntsbk[1], cntsbk[2], cntsbk[3], cntsbk[4], cntsbk[5]);
6161
} catch (std::runtime_error& error) {
6262
std::cerr << "An error occurred: " << error.what() << std::endl;
6363
return 1;
@@ -124,8 +124,19 @@ int CTPRunManager::loadRun(const std::string& cfg)
124124

125125
return 0;
126126
}
127-
int CTPRunManager::startRun(const std::string& cfg)
127+
int CTPRunManager::setRunConfigBK(uint32_t runNumber, const std::string& cfg)
128128
{
129+
std::cout << "Printing cfg:" << cfg << std::endl;
130+
if (mBKClient) {
131+
try {
132+
uint32_t runNumber = 1;
133+
mBKClient->run()->setRawCtpTriggerConfiguration(runNumber, cfg);
134+
} catch (std::runtime_error& error) {
135+
std::cerr << "An error occurred: " << error.what() << std::endl;
136+
return 1;
137+
}
138+
LOG(info) << "Run BK:" << runNumber << " CFG:" << cfg;
139+
}
129140
return 0;
130141
}
131142
int CTPRunManager::stopRun(uint32_t irun, long timeStamp)
@@ -221,6 +232,13 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
221232
loadRun(message);
222233
return 0;
223234
}
235+
if (topic.find("soxorbit") != std::string::npos) {
236+
return 0;
237+
}
238+
if (topic.find("orbitreset") != std::string::npos) {
239+
return 0;
240+
}
241+
static int nerror = 0;
224242
if (topic.find("sox") != std::string::npos) {
225243
// get config
226244
size_t irun = message.find("run");
@@ -230,17 +248,15 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
230248
}
231249
LOG(info) << "SOX received, Run keyword position:" << irun;
232250
std::string cfg = message.substr(irun, message.size() - irun);
233-
startRun(cfg);
234251
firstcounters = message.substr(0, irun);
235-
}
236-
if (topic.find("eox") != std::string::npos) {
252+
} else if (topic.find("eox") != std::string::npos) {
237253
LOG(info) << "EOX received";
238254
mEOX = 1;
239-
}
240-
static int nerror = 0;
241-
if (topic == "rocnts") {
242-
if (nerror < 1) {
243-
LOG(warning) << "Skipping topic rocnts";
255+
} else if (topic.find("cnts") != std::string::npos) {
256+
// just continue
257+
} else {
258+
if (nerror < 10) {
259+
LOG(warning) << "Skipping topic:" << topic;
244260
nerror++;
245261
}
246262
return 0;
@@ -293,6 +309,7 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
293309
mActiveRunNumbers[i] = mCounters[i];
294310
mActiveRuns[i] = run->second;
295311
mRunsLoaded.erase(run);
312+
setRunConfigBK(mActiveRuns[i]->cfg.getRunNumber(), mActiveRuns[i]->cfg.getConfigString());
296313
addScalers(i, tt, 1);
297314
saveRunScalersToQCDB(mActiveRuns[i]->scalers, tt * 1000, tt * 1000);
298315
} else {

0 commit comments

Comments
 (0)